boot.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /* ====================================================================
  2. |
  3. | Amber Smalltalk
  4. | http://amber-lang.net
  5. |
  6. ======================================================================
  7. ======================================================================
  8. |
  9. | Copyright (c) 2010-2014
  10. | Nicolas Petton <petton.nicolas@gmail.com>
  11. |
  12. | Copyright (c) 2012-2016
  13. | The Amber team https://lolg.it/org/amber/members
  14. | Amber contributors (see /CONTRIBUTORS)
  15. |
  16. | Amber is released under the MIT license
  17. |
  18. | Permission is hereby granted, free of charge, to any person obtaining
  19. | a copy of this software and associated documentation files (the
  20. | 'Software'), to deal in the Software without restriction, including
  21. | without limitation the rights to use, copy, modify, merge, publish,
  22. | distribute, sublicense, and/or sell copies of the Software, and to
  23. | permit persons to whom the Software is furnished to do so, subject to
  24. | the following conditions:
  25. |
  26. | The above copyright notice and this permission notice shall be
  27. | included in all copies or substantial portions of the Software.
  28. |
  29. | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  30. | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  32. | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  33. | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  34. | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  35. | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. |
  37. ==================================================================== */
  38. //jshint eqnull:true
  39. define(['require', './brikz', './compatibility'], function (require, Brikz) {
  40. "use strict";
  41. function inherits(child, parent) {
  42. child.prototype = Object.create(parent.prototype, {
  43. constructor: {
  44. value: child,
  45. enumerable: false, configurable: true, writable: true
  46. }
  47. });
  48. return child;
  49. }
  50. function SmalltalkGlobalsBrik(brikz, st) {
  51. // jshint evil:true
  52. var jsGlobals = new Function("return this")();
  53. var globals = Object.create(jsGlobals);
  54. globals.SmalltalkSettings = {};
  55. this.globals = globals;
  56. }
  57. function RootBrik(brikz, st) {
  58. /* Smalltalk foundational objects */
  59. /* SmalltalkRoot is the hidden root of the normal Amber hierarchy.
  60. All objects including `ProtoObject` inherit from SmalltalkRoot.
  61. Detached roots (eg. wrapped JS classes like Number or Date)
  62. do not directly inherit from SmalltalkRoot, but employ a workaround.*/
  63. function SmalltalkRoot() {
  64. }
  65. function SmalltalkProtoObject() {
  66. }
  67. function SmalltalkObject() {
  68. }
  69. function SmalltalkNil() {
  70. }
  71. inherits(SmalltalkProtoObject, SmalltalkRoot);
  72. inherits(SmalltalkObject, SmalltalkProtoObject);
  73. inherits(SmalltalkNil, SmalltalkObject);
  74. this.Object = SmalltalkObject;
  75. this.nilAsReceiver = new SmalltalkNil();
  76. // Adds an `isNil` property to the `nil` object. When sending
  77. // nil objects from one environment to another, doing
  78. // `anObject == nil` (in JavaScript) does not always answer
  79. // true as the referenced nil object might come from the other
  80. // environment.
  81. Object.defineProperty(this.nilAsReceiver, 'isNil', {
  82. value: true,
  83. enumerable: false, configurable: false, writable: false
  84. });
  85. // Fake root class of the system.
  86. // Effective superclass of all classes created with `nil subclass: ...`.
  87. this.nilAsClass = {fn: SmalltalkRoot};
  88. this.__init__ = function () {
  89. var globals = brikz.smalltalkGlobals.globals;
  90. var addCoupledClass = brikz.classes.addCoupledClass;
  91. st.addPackage("Kernel-Objects");
  92. addCoupledClass("ProtoObject", undefined, "Kernel-Objects", SmalltalkProtoObject);
  93. addCoupledClass("Object", globals.ProtoObject, "Kernel-Objects", SmalltalkObject);
  94. addCoupledClass("UndefinedObject", globals.Object, "Kernel-Objects", SmalltalkNil);
  95. };
  96. this.__init__.once = true;
  97. }
  98. OrganizeBrik.deps = ["augments", "root"];
  99. function OrganizeBrik(brikz, st) {
  100. var SmalltalkObject = brikz.root.Object;
  101. function SmalltalkOrganizer() {
  102. }
  103. function SmalltalkPackageOrganizer() {
  104. this.elements = [];
  105. }
  106. function SmalltalkClassOrganizer() {
  107. this.elements = [];
  108. }
  109. inherits(SmalltalkOrganizer, SmalltalkObject);
  110. inherits(SmalltalkPackageOrganizer, SmalltalkOrganizer);
  111. inherits(SmalltalkClassOrganizer, SmalltalkOrganizer);
  112. this.__init__ = function () {
  113. var globals = brikz.smalltalkGlobals.globals;
  114. var addCoupledClass = brikz.classes.addCoupledClass;
  115. st.addPackage("Kernel-Infrastructure");
  116. addCoupledClass("Organizer", globals.Object, "Kernel-Infrastructure", SmalltalkOrganizer);
  117. addCoupledClass("PackageOrganizer", globals.Organizer, "Kernel-Infrastructure", SmalltalkPackageOrganizer);
  118. addCoupledClass("ClassOrganizer", globals.Organizer, "Kernel-Infrastructure", SmalltalkClassOrganizer);
  119. };
  120. this.__init__.once = true;
  121. this.setupClassOrganization = function (klass) {
  122. klass.organization = new SmalltalkClassOrganizer();
  123. klass.organization.theClass = klass;
  124. };
  125. this.setupPackageOrganization = function (pkg) {
  126. pkg.organization = new SmalltalkPackageOrganizer();
  127. };
  128. this.addOrganizationElement = function (owner, element) {
  129. owner.organization.elements.addElement(element);
  130. };
  131. this.removeOrganizationElement = function (owner, element) {
  132. owner.organization.elements.removeElement(element);
  133. };
  134. }
  135. SelectorsBrik.deps = ["selectorConversion"];
  136. function SelectorsBrik(brikz, st) {
  137. var selectorSet = Object.create(null);
  138. var selectors = this.selectors = [];
  139. var selectorPairs = this.selectorPairs = [];
  140. this.registerSelector = function (stSelector) {
  141. if (selectorSet[stSelector]) return null;
  142. var jsSelector = st.st2js(stSelector);
  143. selectorSet[stSelector] = true;
  144. selectors.push(stSelector);
  145. var pair = {st: stSelector, js: jsSelector};
  146. selectorPairs.push(pair);
  147. return pair;
  148. };
  149. st.allSelectors = function () {
  150. return selectors;
  151. };
  152. }
  153. PackagesBrik.deps = ["organize", "root"];
  154. function PackagesBrik(brikz, st) {
  155. var setupPackageOrganization = brikz.organize.setupPackageOrganization;
  156. var SmalltalkObject = brikz.root.Object;
  157. function SmalltalkPackage() {
  158. }
  159. inherits(SmalltalkPackage, SmalltalkObject);
  160. this.__init__ = function () {
  161. var globals = brikz.smalltalkGlobals.globals;
  162. var addCoupledClass = brikz.classes.addCoupledClass;
  163. st.addPackage("Kernel-Infrastructure");
  164. addCoupledClass("Package", globals.Object, "Kernel-Infrastructure", SmalltalkPackage);
  165. };
  166. this.__init__.once = true;
  167. st.packages = {};
  168. /* Smalltalk package creation. To add a Package, use smalltalk.addPackage() */
  169. function pkg(spec) {
  170. var that = new SmalltalkPackage();
  171. that.pkgName = spec.pkgName;
  172. setupPackageOrganization(that);
  173. that.properties = spec.properties || {};
  174. return that;
  175. }
  176. /* Add a package to the system, creating a new one if needed.
  177. If pkgName is null or empty we return nil.
  178. If package already exists we still update the properties of it. */
  179. st.addPackage = function (pkgName, properties) {
  180. if (!pkgName) {
  181. return null;
  182. }
  183. if (!(st.packages[pkgName])) {
  184. st.packages[pkgName] = pkg({
  185. pkgName: pkgName,
  186. properties: properties
  187. });
  188. } else {
  189. if (properties) {
  190. st.packages[pkgName].properties = properties;
  191. }
  192. }
  193. return st.packages[pkgName];
  194. };
  195. }
  196. ClassesBrik.deps = ["organize", "root", "smalltalkGlobals"];
  197. function ClassesBrik(brikz, st) {
  198. var setupClassOrganization = brikz.organize.setupClassOrganization;
  199. var addOrganizationElement = brikz.organize.addOrganizationElement;
  200. var removeOrganizationElement = brikz.organize.removeOrganizationElement;
  201. var globals = brikz.smalltalkGlobals.globals;
  202. var nilAsClass = brikz.root.nilAsClass;
  203. var SmalltalkObject = brikz.root.Object;
  204. nilAsClass.klass = {fn: SmalltalkClass};
  205. function SmalltalkBehavior() {
  206. }
  207. function SmalltalkClass() {
  208. }
  209. function SmalltalkMetaclass() {
  210. }
  211. inherits(SmalltalkBehavior, SmalltalkObject);
  212. inherits(SmalltalkClass, SmalltalkBehavior);
  213. inherits(SmalltalkMetaclass, SmalltalkBehavior);
  214. SmalltalkBehavior.prototype.toString = function () {
  215. return 'Smalltalk ' + this.className;
  216. };
  217. SmalltalkMetaclass.prototype.meta = true;
  218. this.__init__ = function () {
  219. var globals = brikz.smalltalkGlobals.globals;
  220. var addCoupledClass = brikz.classes.addCoupledClass;
  221. st.addPackage("Kernel-Classes");
  222. addCoupledClass("Behavior", globals.Object, "Kernel-Classes", SmalltalkBehavior);
  223. addCoupledClass("Metaclass", globals.Behavior, "Kernel-Classes", SmalltalkMetaclass);
  224. addCoupledClass("Class", globals.Behavior, "Kernel-Classes", SmalltalkClass);
  225. // Manually bootstrap the metaclass hierarchy
  226. globals.ProtoObject.klass.superclass = nilAsClass.klass = globals.Class;
  227. addSubclass(globals.ProtoObject.klass);
  228. };
  229. this.__init__.once = true;
  230. /* Smalltalk classes */
  231. var classes = [];
  232. /* Smalltalk class creation. A class is an instance of an automatically
  233. created metaclass object. Newly created classes (not their metaclass)
  234. should be added to the system, see smalltalk.addClass().
  235. Superclass linking is *not* handled here, see api.initialize() */
  236. function klass(spec) {
  237. var setSuperClass = spec.superclass;
  238. if (!spec.superclass) {
  239. spec.superclass = nilAsClass;
  240. }
  241. var meta = metaclass(spec);
  242. var that = meta.instanceClass;
  243. that.superclass = setSuperClass;
  244. that.fn = spec.fn || inherits(function () {
  245. }, spec.superclass.fn);
  246. that.subclasses = [];
  247. setupClass(that, spec);
  248. that.className = spec.className;
  249. meta.className = spec.className + ' class';
  250. meta.superclass = spec.superclass.klass;
  251. return that;
  252. }
  253. function metaclass(spec) {
  254. var that = new SmalltalkMetaclass();
  255. that.fn = inherits(function () {
  256. }, spec.superclass.klass.fn);
  257. wireKlass(that);
  258. that.instanceClass = new that.fn();
  259. setupClass(that, {});
  260. return that;
  261. }
  262. function setupClass(klass, spec) {
  263. klass.iVarNames = spec.iVarNames || [];
  264. if (spec.pkg) {
  265. klass.pkg = spec.pkg;
  266. }
  267. setupClassOrganization(klass);
  268. Object.defineProperty(klass, "methods", {
  269. value: Object.create(null),
  270. enumerable: false, configurable: true, writable: true
  271. });
  272. }
  273. function wireKlass(klass) {
  274. Object.defineProperty(klass.fn.prototype, "klass", {
  275. value: klass,
  276. enumerable: false, configurable: true, writable: true
  277. });
  278. }
  279. this.wireKlass = wireKlass;
  280. /* Add a class to the system, creating a new one if needed.
  281. A Package is lazily created if one with given name does not exist. */
  282. st.addClass = function (className, superclass, iVarNames, pkgName) {
  283. // While subclassing nil is allowed, it might be an error, so
  284. // warn about it.
  285. if (typeof superclass == 'undefined' || superclass && superclass.isNil) {
  286. console.warn('Compiling ' + className + ' as a subclass of `nil`. A dependency might be missing.');
  287. }
  288. return rawAddClass(pkgName, className, superclass, iVarNames, null);
  289. };
  290. function rawAddClass(pkgName, className, superclass, iVarNames, fn) {
  291. var pkg = st.packages[pkgName];
  292. if (!pkg) {
  293. throw new Error("Missing package " + pkgName);
  294. }
  295. if (superclass == null || superclass.isNil) {
  296. superclass = null;
  297. }
  298. var theClass = globals.hasOwnProperty(className) && globals[className];
  299. if (theClass && theClass.superclass == superclass && !fn) {
  300. if (iVarNames) theClass.iVarNames = iVarNames;
  301. if (pkg) theClass.pkg = pkg;
  302. } else {
  303. if (theClass) {
  304. iVarNames = iVarNames || theClass.iVarNames;
  305. st.removeClass(theClass);
  306. }
  307. theClass = globals[className] = klass({
  308. className: className,
  309. superclass: superclass,
  310. pkg: pkg,
  311. iVarNames: iVarNames,
  312. fn: fn
  313. });
  314. addSubclass(theClass);
  315. }
  316. classes.addElement(theClass);
  317. addOrganizationElement(pkg, theClass);
  318. if (st._classAdded) st._classAdded(theClass);
  319. return theClass;
  320. }
  321. st.removeClass = function (klass) {
  322. removeOrganizationElement(klass.pkg, klass);
  323. classes.removeElement(klass);
  324. removeSubclass(klass);
  325. delete globals[klass.className];
  326. };
  327. function addSubclass(klass) {
  328. if (klass.superclass) {
  329. klass.superclass.subclasses.addElement(klass);
  330. }
  331. }
  332. function removeSubclass(klass) {
  333. if (klass.superclass) {
  334. klass.superclass.subclasses.removeElement(klass);
  335. }
  336. }
  337. /* Create a new class coupling with a JavaScript constructor,
  338. and add it to the system.*/
  339. this.addCoupledClass = function (className, superclass, pkgName, fn) {
  340. return rawAddClass(pkgName, className, superclass, null, fn);
  341. };
  342. /* Create an alias for an existing class */
  343. st.alias = function (klass, alias) {
  344. globals[alias] = klass;
  345. };
  346. /* Answer all registered Smalltalk classes */
  347. //TODO: remove the function and make smalltalk.classes an array
  348. st.classes = this.classes = function () {
  349. return classes;
  350. };
  351. function metaSubclasses(metaclass) {
  352. return metaclass.instanceClass.subclasses
  353. .filter(function (each) {
  354. return !each.meta;
  355. })
  356. .map(function (each) {
  357. return each.klass;
  358. });
  359. }
  360. st.metaSubclasses = metaSubclasses;
  361. st.traverseClassTree = function (klass, fn) {
  362. var queue = [klass];
  363. for (var i = 0; i < queue.length; ++i) {
  364. var item = queue[i];
  365. fn(item);
  366. var subclasses = item.meta ? metaSubclasses(item) : item.subclasses;
  367. queue.push.apply(queue, subclasses);
  368. }
  369. };
  370. }
  371. MethodsBrik.deps = ["organize", "selectors", "root", "selectorConversion"];
  372. function MethodsBrik(brikz, st) {
  373. var addOrganizationElement = brikz.organize.addOrganizationElement;
  374. var registerSelector = brikz.selectors.registerSelector;
  375. var SmalltalkObject = brikz.root.Object;
  376. function SmalltalkMethod() {
  377. }
  378. inherits(SmalltalkMethod, SmalltalkObject);
  379. this.__init__ = function () {
  380. var globals = brikz.smalltalkGlobals.globals;
  381. var addCoupledClass = brikz.classes.addCoupledClass;
  382. st.addPackage("Kernel-Methods");
  383. addCoupledClass("CompiledMethod", globals.Object, "Kernel-Methods", SmalltalkMethod);
  384. };
  385. this.__init__.once = true;
  386. /* Smalltalk method object. To add a method to a class,
  387. use api.addMethod() */
  388. st.method = function (spec) {
  389. var that = new SmalltalkMethod();
  390. var selector = spec.selector;
  391. that.selector = selector;
  392. that.jsSelector = st.st2js(selector);
  393. that.args = spec.args || {};
  394. that.protocol = spec.protocol;
  395. that.source = spec.source;
  396. that.messageSends = spec.messageSends || [];
  397. that.referencedClasses = spec.referencedClasses || [];
  398. that.fn = spec.fn;
  399. return that;
  400. };
  401. /* Add/remove a method to/from a class */
  402. st.addMethod = function (method, klass) {
  403. klass.methods[method.selector] = method;
  404. method.methodClass = klass;
  405. // During the bootstrap, #addCompiledMethod is not used.
  406. // Therefore we populate the organizer here too
  407. addOrganizationElement(klass, method.protocol);
  408. var newSelectors = [];
  409. function selectorInUse(stSelector) {
  410. var pair = registerSelector(stSelector);
  411. if (pair) {
  412. newSelectors.push(pair);
  413. }
  414. }
  415. selectorInUse(method.selector);
  416. method.messageSends.forEach(selectorInUse);
  417. if (st._methodAdded) st._methodAdded(method, klass);
  418. if (st._selectorsAdded) st._selectorsAdded(newSelectors);
  419. };
  420. st.removeMethod = function (method, klass) {
  421. if (klass !== method.methodClass) {
  422. throw new Error(
  423. "Refusing to remove method " +
  424. method.methodClass.className + ">>" + method.selector +
  425. " from different class " +
  426. klass.className);
  427. }
  428. delete klass.methods[method.selector];
  429. if (st._methodRemoved) st._methodRemoved(method, klass);
  430. // Do *not* delete protocols from here.
  431. // This is handled by #removeCompiledMethod
  432. };
  433. }
  434. function AugmentsBrik(brikz, st) {
  435. /* Array extensions */
  436. Array.prototype.addElement = function (el) {
  437. if (typeof el === 'undefined') {
  438. return;
  439. }
  440. if (this.indexOf(el) == -1) {
  441. this.push(el);
  442. }
  443. };
  444. Array.prototype.removeElement = function (el) {
  445. var i = this.indexOf(el);
  446. if (i !== -1) {
  447. this.splice(i, 1);
  448. }
  449. };
  450. }
  451. SmalltalkInitBrik.deps = ["globals", "classes"];
  452. function SmalltalkInitBrik(brikz, st) {
  453. var globals = brikz.smalltalkGlobals.globals;
  454. var initialized = false;
  455. var runtimeLoadedPromise = new Promise(function (resolve, reject) {
  456. require(['./kernel-runtime'], resolve, reject);
  457. });
  458. /* Smalltalk initialization. Called on page load */
  459. st.initialize = function () {
  460. return runtimeLoadedPromise.then(function (configureWithRuntime) {
  461. if (initialized) {
  462. return;
  463. }
  464. configureWithRuntime(brikz);
  465. st.alias(globals.Array, "OrderedCollection");
  466. st.alias(globals.Date, "Time");
  467. st.classes().forEach(function (klass) {
  468. klass._initialize();
  469. });
  470. initialized = true;
  471. });
  472. };
  473. }
  474. function SelectorConversionBrik(brikz, st) {
  475. /* Convert a Smalltalk selector into a JS selector */
  476. st.st2js = function (string) {
  477. return '_' + string
  478. .replace(/:/g, '_')
  479. .replace(/[\&]/g, '_and')
  480. .replace(/[\|]/g, '_or')
  481. .replace(/[+]/g, '_plus')
  482. .replace(/-/g, '_minus')
  483. .replace(/[*]/g, '_star')
  484. .replace(/[\/]/g, '_slash')
  485. .replace(/[\\]/g, '_backslash')
  486. .replace(/[\~]/g, '_tild')
  487. .replace(/>/g, '_gt')
  488. .replace(/</g, '_lt')
  489. .replace(/=/g, '_eq')
  490. .replace(/,/g, '_comma')
  491. .replace(/[@]/g, '_at');
  492. };
  493. /* Convert a string to a valid smalltalk selector.
  494. if you modify the following functions, also change st2js
  495. accordingly */
  496. st.js2st = function (selector) {
  497. if (selector.match(/^__/)) {
  498. return binaryJsToSt(selector);
  499. } else {
  500. return keywordJsToSt(selector);
  501. }
  502. };
  503. function keywordJsToSt(selector) {
  504. return selector.replace(/^_/, '').replace(/_/g, ':');
  505. }
  506. function binaryJsToSt(selector) {
  507. return selector
  508. .replace(/^_/, '')
  509. .replace(/_and/g, '&')
  510. .replace(/_or/g, '|')
  511. .replace(/_plus/g, '+')
  512. .replace(/_minus/g, '-')
  513. .replace(/_star/g, '*')
  514. .replace(/_slash/g, '/')
  515. .replace(/_backslash/g, '\\')
  516. .replace(/_tild/g, '~')
  517. .replace(/_gt/g, '>')
  518. .replace(/_lt/g, '<')
  519. .replace(/_eq/g, '=')
  520. .replace(/_comma/g, ',')
  521. .replace(/_at/g, '@');
  522. }
  523. st.st2prop = function (stSelector) {
  524. var colonPosition = stSelector.indexOf(':');
  525. return colonPosition === -1 ? stSelector : stSelector.slice(0, colonPosition);
  526. };
  527. }
  528. /* Adds AMD and requirejs related methods to the api */
  529. function AMDBrik(brikz, st) {
  530. st.amdRequire = require;
  531. st.defaultTransportType = st.defaultTransportType || "amd";
  532. st.defaultAmdNamespace = st.defaultAmdNamespace || "amber_core";
  533. }
  534. /* Defines asReceiver to be present at load time */
  535. /* (logically it belongs more to PrimitiveBrik) */
  536. AsReceiverBrik.deps = ["smalltalkGlobals", "root"];
  537. function AsReceiverBrik(brikz, st) {
  538. var globals = brikz.smalltalkGlobals.globals;
  539. var nilAsReceiver = brikz.root.nilAsReceiver;
  540. /**
  541. * This function is used all over the compiled amber code.
  542. * It takes any value (JavaScript or Smalltalk)
  543. * and returns a proper Amber Smalltalk receiver.
  544. *
  545. * null or undefined -> nilAsReceiver,
  546. * object having Smalltalk signature -> unchanged,
  547. * otherwise wrapped foreign (JS) object
  548. */
  549. this.asReceiver = function (o) {
  550. if (o == null) return nilAsReceiver;
  551. else if (o.klass != null) return o;
  552. else return globals.JSObjectProxy._on_(o);
  553. };
  554. }
  555. var api = {};
  556. var brikz = new Brikz(api);
  557. /* Making smalltalk that can load */
  558. brikz.smalltalkGlobals = SmalltalkGlobalsBrik;
  559. brikz.root = RootBrik;
  560. brikz.selectors = SelectorsBrik;
  561. brikz.organize = OrganizeBrik;
  562. brikz.selectorConversion = SelectorConversionBrik;
  563. brikz.packages = PackagesBrik;
  564. brikz.classes = ClassesBrik;
  565. brikz.methods = MethodsBrik;
  566. brikz.stInit = SmalltalkInitBrik;
  567. brikz.augments = AugmentsBrik;
  568. brikz.asReceiver = AsReceiverBrik;
  569. brikz.amd = AMDBrik;
  570. brikz.rebuild();
  571. return {
  572. api: api,
  573. nil/* TODO deprecate */: brikz.root.nilAsReceiver,
  574. nilAsReceiver: brikz.root.nilAsReceiver,
  575. dnu/* TODO deprecate */: brikz.root.nilAsClass,
  576. nilAsClass: brikz.root.nilAsClass,
  577. globals: brikz.smalltalkGlobals.globals,
  578. asReceiver: brikz.asReceiver.asReceiver
  579. };
  580. });