Platform-Node.js 3.4 KB

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