boot.js 24 KB

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