Platform-Node.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. pragmas: [],
  28. messageSends: []
  29. }),
  30. $globals.NodePlatform);
  31. $core.addMethod(
  32. $core.method({
  33. selector: "newXhr",
  34. protocol: "accessing",
  35. fn: function (){
  36. var self=this,$self=this;
  37. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  38. return $core.withContext(function($ctx1) {
  39. //>>excludeEnd("ctx");
  40. var $receiver;
  41. if(($receiver = $globals.XMLHttpRequest) == null || $receiver.a$nil){
  42. $self._error_("XMLHttpRequest not available.");
  43. } else {
  44. return $recv($globals.XMLHttpRequest)._new();
  45. }
  46. return self;
  47. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  48. }, function($ctx1) {$ctx1.fill(self,"newXhr",{})});
  49. //>>excludeEnd("ctx");
  50. },
  51. //>>excludeStart("ide", pragmas.excludeIdeData);
  52. args: [],
  53. source: "newXhr\x0a\x09XMLHttpRequest\x0a\x09\x09ifNotNil: [ ^ XMLHttpRequest new ]\x0a\x09\x09ifNil: [ self error: 'XMLHttpRequest not available.' ]",
  54. referencedClasses: ["XMLHttpRequest"],
  55. //>>excludeEnd("ide");
  56. pragmas: [],
  57. messageSends: ["ifNotNil:ifNil:", "new", "error:"]
  58. }),
  59. $globals.NodePlatform);
  60. $core.addMethod(
  61. $core.method({
  62. selector: "initialize",
  63. protocol: "testing",
  64. fn: function (){
  65. var self=this,$self=this;
  66. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  67. return $core.withContext(function($ctx1) {
  68. //>>excludeEnd("ctx");
  69. var $1;
  70. $1=$self._isFeasible();
  71. if($core.assert($1)){
  72. $recv($globals.Platform)._registerIfNone_($self._new());
  73. }
  74. return self;
  75. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  76. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  77. //>>excludeEnd("ctx");
  78. },
  79. //>>excludeStart("ide", pragmas.excludeIdeData);
  80. args: [],
  81. source: "initialize\x0a\x09self isFeasible ifTrue: [ Platform registerIfNone: self new ]",
  82. referencedClasses: ["Platform"],
  83. //>>excludeEnd("ide");
  84. pragmas: [],
  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",{})});
  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. pragmas: [["inlineJS:", ["return typeof process !== \x22undefined\x22 && process && process.versions && process.versions.node != null"]]],
  109. messageSends: []
  110. }),
  111. $globals.NodePlatform.a$cls);
  112. });