Platform-Node.js 3.8 KB

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