Platform-Node.js 3.9 KB

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