Spaces.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. define("amber_core/Spaces", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Kernel-Objects", "amber_core/Kernel-Exceptions", "amber_core/SUnit"], function(smalltalk,nil,_st, globals){
  2. smalltalk.addPackage('Spaces');
  3. smalltalk.packages["Spaces"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('ObjectSpace', globals.Object, ['frame'], 'Spaces');
  5. globals.ObjectSpace.comment="I am a connection to another Smalltalk environment.\x0aThe implementation creates an iframe on the same location as the window, and connect to the Amber environment.\x0a\x0a\x0a\x0a## Usage example:\x0a\x0a\x09| space |\x0a\x09\x0a\x09space := ObjectSpace new.\x0a\x09space do: [ smalltalk ] \x22Answers aSmalltalk\x22\x0a\x09(space do: [ smalltalk ]) == smalltalk \x22Answers false\x22\x0a\x09\x0a\x09space release \x22Remove the object space environment\x22";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "connectTo:",
  9. protocol: 'initialization',
  10. fn: function (aFrame){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. self._release();
  14. self["@frame"]=aFrame;
  15. return self}, function($ctx1) {$ctx1.fill(self,"connectTo:",{aFrame:aFrame},globals.ObjectSpace)})},
  16. args: ["aFrame"],
  17. source: "connectTo: aFrame\x0a\x09self release.\x0a\x09frame := aFrame",
  18. messageSends: ["release"],
  19. referencedClasses: []
  20. }),
  21. globals.ObjectSpace);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "create",
  25. protocol: 'initialization',
  26. fn: function (){
  27. var self=this;
  28. return smalltalk.withContext(function($ctx1) {
  29. var $1;
  30. $1="body"._asJQuery();
  31. $ctx1.sendIdx["asJQuery"]=1;
  32. _st($1)._append_("<iframe style=\x22display: none;\x22></iframe>");
  33. self["@frame"]=_st(_st("iframe"._asJQuery())._get())._last();
  34. _st(_st(self["@frame"])._contentWindow())._location_(_st(window)._location());
  35. return self}, function($ctx1) {$ctx1.fill(self,"create",{},globals.ObjectSpace)})},
  36. args: [],
  37. source: "create\x0a\x09'body' asJQuery append: '<iframe style=\x22display: none;\x22></iframe>'.\x0a\x09frame := 'iframe' asJQuery get last.\x0a\x09frame contentWindow location: window location",
  38. messageSends: ["append:", "asJQuery", "last", "get", "location:", "contentWindow", "location"],
  39. referencedClasses: []
  40. }),
  41. globals.ObjectSpace);
  42. smalltalk.addMethod(
  43. smalltalk.method({
  44. selector: "destroy",
  45. protocol: 'releasing',
  46. fn: function (){
  47. var self=this;
  48. return smalltalk.withContext(function($ctx1) {
  49. var $1;
  50. $1=self["@frame"];
  51. if(($receiver = $1) == nil || $receiver == null){
  52. return self;
  53. } else {
  54. $1;
  55. };
  56. _st(_st(self["@frame"])._asJQuery())._remove();
  57. self._release();
  58. return self}, function($ctx1) {$ctx1.fill(self,"destroy",{},globals.ObjectSpace)})},
  59. args: [],
  60. source: "destroy\x0a\x09frame ifNil: [ ^ self ].\x0a\x09frame asJQuery remove.\x0a\x0a\x09self release",
  61. messageSends: ["ifNil:", "remove", "asJQuery", "release"],
  62. referencedClasses: []
  63. }),
  64. globals.ObjectSpace);
  65. smalltalk.addMethod(
  66. smalltalk.method({
  67. selector: "do:",
  68. protocol: 'evaluating',
  69. fn: function (aBlock){
  70. var self=this;
  71. function $ObjectSpaceConnectionError(){return globals.ObjectSpaceConnectionError||(typeof ObjectSpaceConnectionError=="undefined"?nil:ObjectSpaceConnectionError)}
  72. return smalltalk.withContext(function($ctx1) {
  73. var $1,$2,$4,$5,$3;
  74. $1=self._isConnected();
  75. if(! smalltalk.assert($1)){
  76. $2=_st($ObjectSpaceConnectionError())._signal();
  77. return $2;
  78. };
  79. $4=_st(self["@frame"])._contentWindow();
  80. $5=_st("(".__comma(_st(aBlock)._compiledSource())).__comma(")()");
  81. $ctx1.sendIdx[","]=1;
  82. $3=_st($4)._eval_($5);
  83. return $3;
  84. }, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},globals.ObjectSpace)})},
  85. args: ["aBlock"],
  86. source: "do: aBlock\x0a\x09self isConnected ifFalse: [ ^ ObjectSpaceConnectionError signal ].\x0a\x09^ frame contentWindow eval: '(', aBlock compiledSource, ')()'",
  87. messageSends: ["ifFalse:", "isConnected", "signal", "eval:", "contentWindow", ",", "compiledSource"],
  88. referencedClasses: ["ObjectSpaceConnectionError"]
  89. }),
  90. globals.ObjectSpace);
  91. smalltalk.addMethod(
  92. smalltalk.method({
  93. selector: "frame",
  94. protocol: 'accessing',
  95. fn: function (){
  96. var self=this;
  97. var $1;
  98. $1=self["@frame"];
  99. return $1;
  100. },
  101. args: [],
  102. source: "frame\x0a\x09^ frame",
  103. messageSends: [],
  104. referencedClasses: []
  105. }),
  106. globals.ObjectSpace);
  107. smalltalk.addMethod(
  108. smalltalk.method({
  109. selector: "initialize",
  110. protocol: 'initialization',
  111. fn: function (){
  112. var self=this;
  113. return smalltalk.withContext(function($ctx1) {
  114. globals.ObjectSpace.superclass.fn.prototype._initialize.apply(_st(self), []);
  115. self._create();
  116. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.ObjectSpace)})},
  117. args: [],
  118. source: "initialize\x0a\x09super initialize.\x0a\x09self create",
  119. messageSends: ["initialize", "create"],
  120. referencedClasses: []
  121. }),
  122. globals.ObjectSpace);
  123. smalltalk.addMethod(
  124. smalltalk.method({
  125. selector: "isConnected",
  126. protocol: 'initialization',
  127. fn: function (){
  128. var self=this;
  129. return smalltalk.withContext(function($ctx1) {
  130. var $1;
  131. $1=_st(self._frame())._notNil();
  132. return $1;
  133. }, function($ctx1) {$ctx1.fill(self,"isConnected",{},globals.ObjectSpace)})},
  134. args: [],
  135. source: "isConnected\x0a\x09^ self frame notNil",
  136. messageSends: ["notNil", "frame"],
  137. referencedClasses: []
  138. }),
  139. globals.ObjectSpace);
  140. smalltalk.addMethod(
  141. smalltalk.method({
  142. selector: "release",
  143. protocol: 'releasing',
  144. fn: function (){
  145. var self=this;
  146. self["@frame"]=nil;
  147. return self},
  148. args: [],
  149. source: "release\x0a\x09frame := nil",
  150. messageSends: [],
  151. referencedClasses: []
  152. }),
  153. globals.ObjectSpace);
  154. smalltalk.addMethod(
  155. smalltalk.method({
  156. selector: "whenReadyDo:",
  157. protocol: 'events',
  158. fn: function (aBlock){
  159. var self=this;
  160. return smalltalk.withContext(function($ctx1) {
  161. _st(_st(self["@frame"])._asJQuery())._bind_do_("load",aBlock);
  162. return self}, function($ctx1) {$ctx1.fill(self,"whenReadyDo:",{aBlock:aBlock},globals.ObjectSpace)})},
  163. args: ["aBlock"],
  164. source: "whenReadyDo: aBlock\x0a\x09frame asJQuery\x0a\x09\x09bind: 'load'\x0a\x09\x09do: aBlock",
  165. messageSends: ["bind:do:", "asJQuery"],
  166. referencedClasses: []
  167. }),
  168. globals.ObjectSpace);
  169. smalltalk.addMethod(
  170. smalltalk.method({
  171. selector: "on:",
  172. protocol: 'instance creation',
  173. fn: function (aFrame){
  174. var self=this;
  175. return smalltalk.withContext(function($ctx1) {
  176. var $2,$3,$1;
  177. $2=self._basicNew();
  178. _st($2)._connectTo_(aFrame);
  179. $3=_st($2)._yourself();
  180. $1=$3;
  181. return $1;
  182. }, function($ctx1) {$ctx1.fill(self,"on:",{aFrame:aFrame},globals.ObjectSpace.klass)})},
  183. args: ["aFrame"],
  184. source: "on: aFrame\x0a\x09^ self basicNew\x0a\x09\x09connectTo: aFrame;\x0a\x09\x09yourself",
  185. messageSends: ["connectTo:", "basicNew", "yourself"],
  186. referencedClasses: []
  187. }),
  188. globals.ObjectSpace.klass);
  189. smalltalk.addClass('ObjectSpaceConnectionError', globals.Error, [], 'Spaces');
  190. smalltalk.addMethod(
  191. smalltalk.method({
  192. selector: "messageText",
  193. protocol: 'accessing',
  194. fn: function (){
  195. var self=this;
  196. return "The ObjectSpace is not connected";
  197. },
  198. args: [],
  199. source: "messageText\x0a\x09^ 'The ObjectSpace is not connected'",
  200. messageSends: [],
  201. referencedClasses: []
  202. }),
  203. globals.ObjectSpaceConnectionError);
  204. smalltalk.addClass('ObjectSpaceTest', globals.TestCase, ['space'], 'Spaces');
  205. smalltalk.addMethod(
  206. smalltalk.method({
  207. selector: "setUp",
  208. protocol: 'initialization',
  209. fn: function (){
  210. var self=this;
  211. function $ObjectSpace(){return globals.ObjectSpace||(typeof ObjectSpace=="undefined"?nil:ObjectSpace)}
  212. return smalltalk.withContext(function($ctx1) {
  213. self["@space"]=_st($ObjectSpace())._new();
  214. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},globals.ObjectSpaceTest)})},
  215. args: [],
  216. source: "setUp\x0a\x09space := ObjectSpace new",
  217. messageSends: ["new"],
  218. referencedClasses: ["ObjectSpace"]
  219. }),
  220. globals.ObjectSpaceTest);
  221. smalltalk.addMethod(
  222. smalltalk.method({
  223. selector: "tearDown",
  224. protocol: 'initialization',
  225. fn: function (){
  226. var self=this;
  227. return smalltalk.withContext(function($ctx1) {
  228. _st(self["@space"])._destroy();
  229. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},globals.ObjectSpaceTest)})},
  230. args: [],
  231. source: "tearDown\x0a\x09space destroy",
  232. messageSends: ["destroy"],
  233. referencedClasses: []
  234. }),
  235. globals.ObjectSpaceTest);
  236. smalltalk.addMethod(
  237. smalltalk.method({
  238. selector: "testConnection",
  239. protocol: 'tests',
  240. fn: function (){
  241. var self=this;
  242. function $ObjectSpaceConnectionError(){return globals.ObjectSpaceConnectionError||(typeof ObjectSpaceConnectionError=="undefined"?nil:ObjectSpaceConnectionError)}
  243. return smalltalk.withContext(function($ctx1) {
  244. _st(self["@space"])._destroy();
  245. self._deny_(_st(self["@space"])._isConnected());
  246. self._should_raise_((function(){
  247. return smalltalk.withContext(function($ctx2) {
  248. return _st(self["@space"])._do_((function(){
  249. }));
  250. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ObjectSpaceConnectionError());
  251. return self}, function($ctx1) {$ctx1.fill(self,"testConnection",{},globals.ObjectSpaceTest)})},
  252. args: [],
  253. source: "testConnection\x0a\x09space destroy.\x0a\x09self deny: space isConnected.\x0a\x09self should: [ space do: [] ] raise: ObjectSpaceConnectionError",
  254. messageSends: ["destroy", "deny:", "isConnected", "should:raise:", "do:"],
  255. referencedClasses: ["ObjectSpaceConnectionError"]
  256. }),
  257. globals.ObjectSpaceTest);
  258. smalltalk.addMethod(
  259. smalltalk.method({
  260. selector: "testCreate",
  261. protocol: 'tests',
  262. fn: function (){
  263. var self=this;
  264. return smalltalk.withContext(function($ctx1) {
  265. self._assert_(_st(_st(self["@space"])._frame())._notNil());
  266. $ctx1.sendIdx["assert:"]=1;
  267. self._assert_(_st(self["@space"])._isConnected());
  268. return self}, function($ctx1) {$ctx1.fill(self,"testCreate",{},globals.ObjectSpaceTest)})},
  269. args: [],
  270. source: "testCreate\x0a\x0a\x09self assert: space frame notNil.\x0a\x09self assert: space isConnected",
  271. messageSends: ["assert:", "notNil", "frame", "isConnected"],
  272. referencedClasses: []
  273. }),
  274. globals.ObjectSpaceTest);
  275. smalltalk.addMethod(
  276. smalltalk.method({
  277. selector: "testEvaluation",
  278. protocol: 'tests',
  279. fn: function (){
  280. var self=this;
  281. var result;
  282. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  283. return smalltalk.withContext(function($ctx1) {
  284. var $2,$1;
  285. _st(self["@space"])._whenReadyDo_((function(){
  286. return smalltalk.withContext(function($ctx2) {
  287. result=_st(self["@space"])._do_((function(){
  288. return smalltalk;
  289. }));
  290. result;
  291. $2=_st(result)._class();
  292. $ctx2.sendIdx["class"]=1;
  293. $1=_st($2)._name();
  294. self._assert_equals_($1,"Smalltalk");
  295. self._deny_(_st(_st(result)._class()).__eq($Smalltalk()));
  296. $ctx2.sendIdx["deny:"]=1;
  297. return self._deny_(_st(result).__eq_eq(smalltalk));
  298. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  299. return self}, function($ctx1) {$ctx1.fill(self,"testEvaluation",{result:result},globals.ObjectSpaceTest)})},
  300. args: [],
  301. source: "testEvaluation\x0a\x09| result |\x0a\x0a\x09space whenReadyDo: [\x0a\x09\x09result := space do: [ smalltalk ].\x0a\x0a\x09\x09self assert: result class name equals: 'Smalltalk'.\x0a\x09\x09self deny: result class = Smalltalk.\x0a\x09\x09self deny: result == smalltalk ]",
  302. messageSends: ["whenReadyDo:", "do:", "assert:equals:", "name", "class", "deny:", "=", "=="],
  303. referencedClasses: ["Smalltalk"]
  304. }),
  305. globals.ObjectSpaceTest);
  306. smalltalk.addMethod(
  307. smalltalk.method({
  308. selector: "testRelease",
  309. protocol: 'tests',
  310. fn: function (){
  311. var self=this;
  312. return smalltalk.withContext(function($ctx1) {
  313. var $2,$1;
  314. $2=_st(self["@space"])._frame();
  315. $ctx1.sendIdx["frame"]=1;
  316. $1=_st($2)._isNil();
  317. $ctx1.sendIdx["isNil"]=1;
  318. self._deny_($1);
  319. _st(self["@space"])._release();
  320. self._assert_(_st(_st(self["@space"])._frame())._isNil());
  321. return self}, function($ctx1) {$ctx1.fill(self,"testRelease",{},globals.ObjectSpaceTest)})},
  322. args: [],
  323. source: "testRelease\x0a\x0a\x09self deny: space frame isNil.\x0a\x0a\x09space release.\x0a\x09\x0a\x09self assert: space frame isNil",
  324. messageSends: ["deny:", "isNil", "frame", "release", "assert:"],
  325. referencedClasses: []
  326. }),
  327. globals.ObjectSpaceTest);
  328. });