Platform-Node.js 3.7 KB

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