Platform-Node.js 3.8 KB

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