Platform-Node.js 3.5 KB

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