boot.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-2017
  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([
  40. 'require', './kernel-checks', './brikz', './kernel-fundamentals', './kernel-language', './compatibility' /* TODO remove */
  41. ], function (require, _, Brikz, configureWithFundamentals, configureWithHierarchy) {
  42. "use strict";
  43. require(['./kernel-runtime']); // preload
  44. function SmalltalkInitBrik (brikz, st) {
  45. var initialized = false;
  46. var runtimeLoadedPromise = new Promise(function (resolve, reject) {
  47. require(['./kernel-runtime'], resolve, reject);
  48. });
  49. /* Smalltalk initialization. Called on page load */
  50. st.initialize = function () {
  51. return runtimeLoadedPromise.then(function (configureWithRuntime) {
  52. if (initialized) return;
  53. brikz.classes.bootstrapHierarchy();
  54. configureWithRuntime(brikz);
  55. brikz.startImage.run();
  56. initialized = true;
  57. });
  58. };
  59. }
  60. /* Adds AMD and requirejs related methods to the api */
  61. function AMDBrik (brikz, st) {
  62. st.amdRequire = require;
  63. st.defaultTransportType = st.defaultTransportType || "amd";
  64. st.defaultAmdNamespace = st.defaultAmdNamespace || "amber_core";
  65. }
  66. /* Defines asReceiver to be present at load time */
  67. /* (logically it belongs more to PrimitiveBrik) */
  68. AsReceiverBrik.deps = ["nil"];
  69. function AsReceiverBrik (brikz, st) {
  70. var nilAsReceiver = brikz.nil.nilAsReceiver;
  71. /**
  72. * This function is used all over the compiled amber code.
  73. * It takes any value (JavaScript or Smalltalk)
  74. * and returns a proper Amber Smalltalk receiver.
  75. *
  76. * null or undefined -> nilAsReceiver,
  77. * object having Smalltalk signature -> unchanged,
  78. * otherwise wrapped foreign (JS) object
  79. */
  80. this.asReceiver = function (o) {
  81. if (o == null) return nilAsReceiver;
  82. else if (o.a$cls != null) return o;
  83. else return st.wrapJavaScript(o);
  84. };
  85. }
  86. var api = {};
  87. var brikz = new Brikz(api);
  88. configureWithFundamentals(brikz);
  89. configureWithHierarchy(brikz);
  90. brikz.asReceiver = AsReceiverBrik;
  91. brikz.stInit = SmalltalkInitBrik;
  92. brikz.amd = AMDBrik;
  93. brikz.rebuild();
  94. return {
  95. api: api,
  96. nil/* TODO deprecate */: brikz.nil.nilAsReceiver,
  97. nilAsReceiver: brikz.nil.nilAsReceiver,
  98. nilAsValue: brikz.nil.nilAsValue,
  99. dnu/* TODO deprecate */: brikz.classes.nilAsClass,
  100. nilAsClass: brikz.classes.nilAsClass,
  101. globals: brikz.smalltalkGlobals.globals,
  102. asReceiver: brikz.asReceiver.asReceiver
  103. };
  104. });