Platform-Node.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. define("amber_core/Platform-Node", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. $core.addPackage('Platform-Node');
  4. $core.packages["Platform-Node"].innerEval = function (expr) { return eval(expr); };
  5. $core.packages["Platform-Node"].transport = {"type":"amd","amdNamespace":"amber_core"};
  6. $core.addClass('NodePlatform', $globals.Object, [], 'Platform-Node');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.NodePlatform.comment="I am `Platform` service implementation for node-like environment.";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "globals",
  13. protocol: 'accessing',
  14. fn: function (){
  15. var self=this;
  16. return global;
  17. },
  18. //>>excludeStart("ide", pragmas.excludeIdeData);
  19. args: [],
  20. source: "globals\x0a\x09^ global",
  21. referencedClasses: [],
  22. //>>excludeEnd("ide");
  23. messageSends: []
  24. }),
  25. $globals.NodePlatform);
  26. $core.addMethod(
  27. $core.method({
  28. selector: "newXhr",
  29. protocol: 'accessing',
  30. fn: function (){
  31. var self=this;
  32. function $XMLHttpRequest(){return $globals.XMLHttpRequest||(typeof XMLHttpRequest=="undefined"?nil:XMLHttpRequest)}
  33. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  34. return $core.withContext(function($ctx1) {
  35. //>>excludeEnd("ctx");
  36. var $receiver;
  37. if(($receiver = $XMLHttpRequest()) == null || $receiver.isNil){
  38. self._error_("XMLHttpRequest not available.");
  39. } else {
  40. return $recv($XMLHttpRequest())._new();
  41. };
  42. return self;
  43. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  44. }, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.NodePlatform)});
  45. //>>excludeEnd("ctx");
  46. },
  47. //>>excludeStart("ide", pragmas.excludeIdeData);
  48. args: [],
  49. source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ XMLHttpRequest new ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
  50. referencedClasses: ["XMLHttpRequest"],
  51. //>>excludeEnd("ide");
  52. messageSends: ["ifNotNil:ifNil:", "new", "error:"]
  53. }),
  54. $globals.NodePlatform);
  55. $core.addMethod(
  56. $core.method({
  57. selector: "initialize",
  58. protocol: 'testing',
  59. fn: function (){
  60. var self=this;
  61. function $Platform(){return $globals.Platform||(typeof Platform=="undefined"?nil:Platform)}
  62. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  63. return $core.withContext(function($ctx1) {
  64. //>>excludeEnd("ctx");
  65. var $1;
  66. $1=self._isFeasible();
  67. if($core.assert($1)){
  68. $recv($Platform())._registerIfNone_(self._new());
  69. };
  70. return self;
  71. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  72. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.NodePlatform.klass)});
  73. //>>excludeEnd("ctx");
  74. },
  75. //>>excludeStart("ide", pragmas.excludeIdeData);
  76. args: [],
  77. source: "initialize\x0a\x09self isFeasible ifTrue: [ Platform registerIfNone: self new ]",
  78. referencedClasses: ["Platform"],
  79. //>>excludeEnd("ide");
  80. messageSends: ["ifTrue:", "isFeasible", "registerIfNone:", "new"]
  81. }),
  82. $globals.NodePlatform.klass);
  83. $core.addMethod(
  84. $core.method({
  85. selector: "isFeasible",
  86. protocol: 'testing',
  87. fn: function (){
  88. var self=this;
  89. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  90. return $core.withContext(function($ctx1) {
  91. //>>excludeEnd("ctx");
  92. return typeof global !== "undefined";
  93. return self;
  94. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  95. }, function($ctx1) {$ctx1.fill(self,"isFeasible",{},$globals.NodePlatform.klass)});
  96. //>>excludeEnd("ctx");
  97. },
  98. //>>excludeStart("ide", pragmas.excludeIdeData);
  99. args: [],
  100. source: "isFeasible\x0a<return typeof global !== \x22undefined\x22>",
  101. referencedClasses: [],
  102. //>>excludeEnd("ide");
  103. messageSends: []
  104. }),
  105. $globals.NodePlatform.klass);
  106. });