Spaces.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. define("amber_core/Spaces", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects", "amber_core/Kernel-Exceptions", "amber_core/SUnit"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Spaces');
  3. smalltalk.packages["Spaces"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('ObjectSpace', smalltalk.Object, ['frame'], 'Spaces');
  5. smalltalk.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},smalltalk.ObjectSpace)})},
  16. args: ["aFrame"],
  17. source: "connectTo: aFrame\x0a\x09self release.\x0a\x09frame := aFrame",
  18. messageSends: ["release"],
  19. referencedClasses: []
  20. }),
  21. smalltalk.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",{},smalltalk.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. smalltalk.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",{},smalltalk.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. smalltalk.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 smalltalk.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},smalltalk.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. smalltalk.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. smalltalk.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. smalltalk.ObjectSpace.superclass.fn.prototype._initialize.apply(_st(self), []);
  115. self._create();
  116. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.ObjectSpace)})},
  117. args: [],
  118. source: "initialize\x0a\x09super initialize.\x0a\x09self create",
  119. messageSends: ["initialize", "create"],
  120. referencedClasses: []
  121. }),
  122. smalltalk.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",{},smalltalk.ObjectSpace)})},
  134. args: [],
  135. source: "isConnected\x0a\x09^ self frame notNil",
  136. messageSends: ["notNil", "frame"],
  137. referencedClasses: []
  138. }),
  139. smalltalk.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. smalltalk.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},smalltalk.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. smalltalk.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},smalltalk.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. smalltalk.ObjectSpace.klass);
  189. smalltalk.addClass('ObjectSpaceConnectionError', smalltalk.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. smalltalk.ObjectSpaceConnectionError);
  204. smalltalk.addClass('ObjectSpaceTest', smalltalk.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 smalltalk.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",{},smalltalk.ObjectSpaceTest)})},
  215. args: [],
  216. source: "setUp\x0a\x09space := ObjectSpace new",
  217. messageSends: ["new"],
  218. referencedClasses: ["ObjectSpace"]
  219. }),
  220. smalltalk.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",{},smalltalk.ObjectSpaceTest)})},
  230. args: [],
  231. source: "tearDown\x0a\x09space destroy",
  232. messageSends: ["destroy"],
  233. referencedClasses: []
  234. }),
  235. smalltalk.ObjectSpaceTest);
  236. smalltalk.addMethod(
  237. smalltalk.method({
  238. selector: "testConnection",
  239. protocol: 'tests',
  240. fn: function (){
  241. var self=this;
  242. function $ObjectSpaceConnectionError(){return smalltalk.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. return smalltalk.withContext(function($ctx3) {
  250. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  251. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ObjectSpaceConnectionError());
  252. return self}, function($ctx1) {$ctx1.fill(self,"testConnection",{},smalltalk.ObjectSpaceTest)})},
  253. args: [],
  254. source: "testConnection\x0a\x09space destroy.\x0a\x09self deny: space isConnected.\x0a\x09self should: [ space do: [] ] raise: ObjectSpaceConnectionError",
  255. messageSends: ["destroy", "deny:", "isConnected", "should:raise:", "do:"],
  256. referencedClasses: ["ObjectSpaceConnectionError"]
  257. }),
  258. smalltalk.ObjectSpaceTest);
  259. smalltalk.addMethod(
  260. smalltalk.method({
  261. selector: "testCreate",
  262. protocol: 'tests',
  263. fn: function (){
  264. var self=this;
  265. return smalltalk.withContext(function($ctx1) {
  266. self._assert_(_st(_st(self["@space"])._frame())._notNil());
  267. $ctx1.sendIdx["assert:"]=1;
  268. self._assert_(_st(self["@space"])._isConnected());
  269. return self}, function($ctx1) {$ctx1.fill(self,"testCreate",{},smalltalk.ObjectSpaceTest)})},
  270. args: [],
  271. source: "testCreate\x0a\x0a\x09self assert: space frame notNil.\x0a\x09self assert: space isConnected",
  272. messageSends: ["assert:", "notNil", "frame", "isConnected"],
  273. referencedClasses: []
  274. }),
  275. smalltalk.ObjectSpaceTest);
  276. smalltalk.addMethod(
  277. smalltalk.method({
  278. selector: "testEvaluation",
  279. protocol: 'tests',
  280. fn: function (){
  281. var self=this;
  282. var result;
  283. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  284. return smalltalk.withContext(function($ctx1) {
  285. var $2,$1;
  286. _st(self["@space"])._whenReadyDo_((function(){
  287. return smalltalk.withContext(function($ctx2) {
  288. result=_st(self["@space"])._do_((function(){
  289. return smalltalk.withContext(function($ctx3) {
  290. return smalltalk;
  291. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  292. result;
  293. $2=_st(result)._class();
  294. $ctx2.sendIdx["class"]=1;
  295. $1=_st($2)._name();
  296. self._assert_equals_($1,"Smalltalk");
  297. self._deny_(_st(_st(result)._class()).__eq($Smalltalk()));
  298. $ctx2.sendIdx["deny:"]=1;
  299. return self._deny_(_st(result).__eq_eq(smalltalk));
  300. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  301. return self}, function($ctx1) {$ctx1.fill(self,"testEvaluation",{result:result},smalltalk.ObjectSpaceTest)})},
  302. args: [],
  303. 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 ]",
  304. messageSends: ["whenReadyDo:", "do:", "assert:equals:", "name", "class", "deny:", "=", "=="],
  305. referencedClasses: ["Smalltalk"]
  306. }),
  307. smalltalk.ObjectSpaceTest);
  308. smalltalk.addMethod(
  309. smalltalk.method({
  310. selector: "testRelease",
  311. protocol: 'tests',
  312. fn: function (){
  313. var self=this;
  314. return smalltalk.withContext(function($ctx1) {
  315. var $2,$1;
  316. $2=_st(self["@space"])._frame();
  317. $ctx1.sendIdx["frame"]=1;
  318. $1=_st($2)._isNil();
  319. $ctx1.sendIdx["isNil"]=1;
  320. self._deny_($1);
  321. _st(self["@space"])._release();
  322. self._assert_(_st(_st(self["@space"])._frame())._isNil());
  323. return self}, function($ctx1) {$ctx1.fill(self,"testRelease",{},smalltalk.ObjectSpaceTest)})},
  324. args: [],
  325. source: "testRelease\x0a\x0a\x09self deny: space frame isNil.\x0a\x0a\x09space release.\x0a\x09\x0a\x09self assert: space frame isNil",
  326. messageSends: ["deny:", "isNil", "frame", "release", "assert:"],
  327. referencedClasses: []
  328. }),
  329. smalltalk.ObjectSpaceTest);
  330. });