Platform-Node.js 3.5 KB

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