Platform-Node.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
  3. var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
  5. $core.addPackage("Platform-Node");
  6. $core.packages["Platform-Node"].innerEval = function (expr) { return eval(expr); };
  7. $core.packages["Platform-Node"].transport = {"type":"amd","amdNamespace":"amber_core"};
  8. $core.addClass("NodePlatform", $globals.Object, [], "Platform-Node");
  9. //>>excludeStart("ide", pragmas.excludeIdeData);
  10. $globals.NodePlatform.comment="I am `Platform` service implementation for node-like environment.";
  11. //>>excludeEnd("ide");
  12. $core.addMethod(
  13. $core.method({
  14. selector: "globals",
  15. protocol: "accessing",
  16. fn: function (){
  17. var self=this;
  18. return global;
  19. },
  20. //>>excludeStart("ide", pragmas.excludeIdeData);
  21. args: [],
  22. source: "globals\x0a\x09^ global",
  23. referencedClasses: [],
  24. //>>excludeEnd("ide");
  25. messageSends: []
  26. }),
  27. $globals.NodePlatform);
  28. $core.addMethod(
  29. $core.method({
  30. selector: "newXhr",
  31. protocol: "accessing",
  32. fn: function (){
  33. var self=this;
  34. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  35. return $core.withContext(function($ctx1) {
  36. //>>excludeEnd("ctx");
  37. var $receiver;
  38. if(($receiver = $globals.XMLHttpRequest) == null || $receiver.a$nil){
  39. self._error_("XMLHttpRequest not available.");
  40. } else {
  41. return $recv($globals.XMLHttpRequest)._new();
  42. }
  43. return self;
  44. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  45. }, function($ctx1) {$ctx1.fill(self,"newXhr",{},$globals.NodePlatform)});
  46. //>>excludeEnd("ctx");
  47. },
  48. //>>excludeStart("ide", pragmas.excludeIdeData);
  49. args: [],
  50. source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ XMLHttpRequest new ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
  51. referencedClasses: ["XMLHttpRequest"],
  52. //>>excludeEnd("ide");
  53. messageSends: ["ifNotNil:ifNil:", "new", "error:"]
  54. }),
  55. $globals.NodePlatform);
  56. $core.addMethod(
  57. $core.method({
  58. selector: "initialize",
  59. protocol: "testing",
  60. fn: function (){
  61. var self=this;
  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($globals.Platform)._registerIfNone_(self._new());
  69. }
  70. return self;
  71. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  72. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.NodePlatform.a$cls)});
  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.a$cls);
  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.a$cls)});
  96. //>>excludeEnd("ctx");
  97. },
  98. //>>excludeStart("ide", pragmas.excludeIdeData);
  99. args: [],
  100. source: "isFeasible\x0a<inlineJS: 'return typeof global !== \x22undefined\x22'>",
  101. referencedClasses: [],
  102. //>>excludeEnd("ide");
  103. messageSends: []
  104. }),
  105. $globals.NodePlatform.a$cls);
  106. });