Spaces.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. category: '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. category: '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. category: '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. category: '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. category: 'accessing',
  95. fn: function (){
  96. var self=this;
  97. return smalltalk.withContext(function($ctx1) {
  98. var $1;
  99. $1=self["@frame"];
  100. return $1;
  101. }, function($ctx1) {$ctx1.fill(self,"frame",{},smalltalk.ObjectSpace)})},
  102. args: [],
  103. source: "frame\x0a\x09^ frame",
  104. messageSends: [],
  105. referencedClasses: []
  106. }),
  107. smalltalk.ObjectSpace);
  108. smalltalk.addMethod(
  109. smalltalk.method({
  110. selector: "initialize",
  111. category: 'initialization',
  112. fn: function (){
  113. var self=this;
  114. return smalltalk.withContext(function($ctx1) {
  115. smalltalk.ObjectSpace.superclass.fn.prototype._initialize.apply(_st(self), []);
  116. self._create();
  117. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.ObjectSpace)})},
  118. args: [],
  119. source: "initialize\x0a\x09super initialize.\x0a\x09self create",
  120. messageSends: ["initialize", "create"],
  121. referencedClasses: []
  122. }),
  123. smalltalk.ObjectSpace);
  124. smalltalk.addMethod(
  125. smalltalk.method({
  126. selector: "isConnected",
  127. category: 'initialization',
  128. fn: function (){
  129. var self=this;
  130. return smalltalk.withContext(function($ctx1) {
  131. var $1;
  132. $1=_st(self._frame())._notNil();
  133. return $1;
  134. }, function($ctx1) {$ctx1.fill(self,"isConnected",{},smalltalk.ObjectSpace)})},
  135. args: [],
  136. source: "isConnected\x0a\x09^ self frame notNil",
  137. messageSends: ["notNil", "frame"],
  138. referencedClasses: []
  139. }),
  140. smalltalk.ObjectSpace);
  141. smalltalk.addMethod(
  142. smalltalk.method({
  143. selector: "release",
  144. category: 'releasing',
  145. fn: function (){
  146. var self=this;
  147. return smalltalk.withContext(function($ctx1) {
  148. self["@frame"]=nil;
  149. return self}, function($ctx1) {$ctx1.fill(self,"release",{},smalltalk.ObjectSpace)})},
  150. args: [],
  151. source: "release\x0a\x09frame := nil",
  152. messageSends: [],
  153. referencedClasses: []
  154. }),
  155. smalltalk.ObjectSpace);
  156. smalltalk.addMethod(
  157. smalltalk.method({
  158. selector: "whenReadyDo:",
  159. category: 'events',
  160. fn: function (aBlock){
  161. var self=this;
  162. return smalltalk.withContext(function($ctx1) {
  163. _st(_st(self["@frame"])._asJQuery())._bind_do_("load",aBlock);
  164. return self}, function($ctx1) {$ctx1.fill(self,"whenReadyDo:",{aBlock:aBlock},smalltalk.ObjectSpace)})},
  165. args: ["aBlock"],
  166. source: "whenReadyDo: aBlock\x0a\x09frame asJQuery\x0a\x09\x09bind: 'load'\x0a\x09\x09do: aBlock",
  167. messageSends: ["bind:do:", "asJQuery"],
  168. referencedClasses: []
  169. }),
  170. smalltalk.ObjectSpace);
  171. smalltalk.addMethod(
  172. smalltalk.method({
  173. selector: "on:",
  174. category: 'instance creation',
  175. fn: function (aFrame){
  176. var self=this;
  177. return smalltalk.withContext(function($ctx1) {
  178. var $2,$3,$1;
  179. $2=self._basicNew();
  180. _st($2)._connectTo_(aFrame);
  181. $3=_st($2)._yourself();
  182. $1=$3;
  183. return $1;
  184. }, function($ctx1) {$ctx1.fill(self,"on:",{aFrame:aFrame},smalltalk.ObjectSpace.klass)})},
  185. args: ["aFrame"],
  186. source: "on: aFrame\x0a\x09^ self basicNew\x0a\x09\x09connectTo: aFrame;\x0a\x09\x09yourself",
  187. messageSends: ["connectTo:", "basicNew", "yourself"],
  188. referencedClasses: []
  189. }),
  190. smalltalk.ObjectSpace.klass);
  191. smalltalk.addClass('ObjectSpaceConnectionError', smalltalk.Error, [], 'Spaces');
  192. smalltalk.addMethod(
  193. smalltalk.method({
  194. selector: "messageText",
  195. category: 'accessing',
  196. fn: function (){
  197. var self=this;
  198. return smalltalk.withContext(function($ctx1) {
  199. return "The ObjectSpace is not connected";
  200. }, function($ctx1) {$ctx1.fill(self,"messageText",{},smalltalk.ObjectSpaceConnectionError)})},
  201. args: [],
  202. source: "messageText\x0a\x09^ 'The ObjectSpace is not connected'",
  203. messageSends: [],
  204. referencedClasses: []
  205. }),
  206. smalltalk.ObjectSpaceConnectionError);
  207. smalltalk.addClass('ObjectSpaceTest', smalltalk.TestCase, ['space'], 'Spaces');
  208. smalltalk.addMethod(
  209. smalltalk.method({
  210. selector: "setUp",
  211. category: 'initialization',
  212. fn: function (){
  213. var self=this;
  214. function $ObjectSpace(){return smalltalk.ObjectSpace||(typeof ObjectSpace=="undefined"?nil:ObjectSpace)}
  215. return smalltalk.withContext(function($ctx1) {
  216. self["@space"]=_st($ObjectSpace())._new();
  217. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.ObjectSpaceTest)})},
  218. args: [],
  219. source: "setUp\x0a\x09space := ObjectSpace new",
  220. messageSends: ["new"],
  221. referencedClasses: ["ObjectSpace"]
  222. }),
  223. smalltalk.ObjectSpaceTest);
  224. smalltalk.addMethod(
  225. smalltalk.method({
  226. selector: "tearDown",
  227. category: 'initialization',
  228. fn: function (){
  229. var self=this;
  230. return smalltalk.withContext(function($ctx1) {
  231. _st(self["@space"])._destroy();
  232. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.ObjectSpaceTest)})},
  233. args: [],
  234. source: "tearDown\x0a\x09space destroy",
  235. messageSends: ["destroy"],
  236. referencedClasses: []
  237. }),
  238. smalltalk.ObjectSpaceTest);
  239. smalltalk.addMethod(
  240. smalltalk.method({
  241. selector: "testConnection",
  242. category: 'tests',
  243. fn: function (){
  244. var self=this;
  245. function $ObjectSpaceConnectionError(){return smalltalk.ObjectSpaceConnectionError||(typeof ObjectSpaceConnectionError=="undefined"?nil:ObjectSpaceConnectionError)}
  246. return smalltalk.withContext(function($ctx1) {
  247. _st(self["@space"])._destroy();
  248. self._deny_(_st(self["@space"])._isConnected());
  249. self._should_raise_((function(){
  250. return smalltalk.withContext(function($ctx2) {
  251. return _st(self["@space"])._do_((function(){
  252. return smalltalk.withContext(function($ctx3) {
  253. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  254. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ObjectSpaceConnectionError());
  255. return self}, function($ctx1) {$ctx1.fill(self,"testConnection",{},smalltalk.ObjectSpaceTest)})},
  256. args: [],
  257. source: "testConnection\x0a\x09space destroy.\x0a\x09self deny: space isConnected.\x0a\x09self should: [ space do: [] ] raise: ObjectSpaceConnectionError",
  258. messageSends: ["destroy", "deny:", "isConnected", "should:raise:", "do:"],
  259. referencedClasses: ["ObjectSpaceConnectionError"]
  260. }),
  261. smalltalk.ObjectSpaceTest);
  262. smalltalk.addMethod(
  263. smalltalk.method({
  264. selector: "testCreate",
  265. category: 'tests',
  266. fn: function (){
  267. var self=this;
  268. return smalltalk.withContext(function($ctx1) {
  269. self._assert_(_st(_st(self["@space"])._frame())._notNil());
  270. $ctx1.sendIdx["assert:"]=1;
  271. self._assert_(_st(self["@space"])._isConnected());
  272. return self}, function($ctx1) {$ctx1.fill(self,"testCreate",{},smalltalk.ObjectSpaceTest)})},
  273. args: [],
  274. source: "testCreate\x0a\x0a\x09self assert: space frame notNil.\x0a\x09self assert: space isConnected",
  275. messageSends: ["assert:", "notNil", "frame", "isConnected"],
  276. referencedClasses: []
  277. }),
  278. smalltalk.ObjectSpaceTest);
  279. smalltalk.addMethod(
  280. smalltalk.method({
  281. selector: "testEvaluation",
  282. category: 'tests',
  283. fn: function (){
  284. var self=this;
  285. var result;
  286. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  287. return smalltalk.withContext(function($ctx1) {
  288. var $2,$1;
  289. _st(self["@space"])._whenReadyDo_((function(){
  290. return smalltalk.withContext(function($ctx2) {
  291. result=_st(self["@space"])._do_((function(){
  292. return smalltalk.withContext(function($ctx3) {
  293. return smalltalk;
  294. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  295. result;
  296. $2=_st(result)._class();
  297. $ctx2.sendIdx["class"]=1;
  298. $1=_st($2)._name();
  299. self._assert_equals_($1,"Smalltalk");
  300. self._deny_(_st(_st(result)._class()).__eq($Smalltalk()));
  301. $ctx2.sendIdx["deny:"]=1;
  302. return self._deny_(_st(result).__eq_eq(smalltalk));
  303. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  304. return self}, function($ctx1) {$ctx1.fill(self,"testEvaluation",{result:result},smalltalk.ObjectSpaceTest)})},
  305. args: [],
  306. 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 ]",
  307. messageSends: ["whenReadyDo:", "do:", "assert:equals:", "name", "class", "deny:", "=", "=="],
  308. referencedClasses: ["Smalltalk"]
  309. }),
  310. smalltalk.ObjectSpaceTest);
  311. smalltalk.addMethod(
  312. smalltalk.method({
  313. selector: "testRelease",
  314. category: 'tests',
  315. fn: function (){
  316. var self=this;
  317. return smalltalk.withContext(function($ctx1) {
  318. var $2,$1;
  319. $2=_st(self["@space"])._frame();
  320. $ctx1.sendIdx["frame"]=1;
  321. $1=_st($2)._isNil();
  322. $ctx1.sendIdx["isNil"]=1;
  323. self._deny_($1);
  324. _st(self["@space"])._release();
  325. self._assert_(_st(_st(self["@space"])._frame())._isNil());
  326. return self}, function($ctx1) {$ctx1.fill(self,"testRelease",{},smalltalk.ObjectSpaceTest)})},
  327. args: [],
  328. source: "testRelease\x0a\x0a\x09self deny: space frame isNil.\x0a\x0a\x09space release.\x0a\x09\x0a\x09self assert: space frame isNil",
  329. messageSends: ["deny:", "isNil", "frame", "release", "assert:"],
  330. referencedClasses: []
  331. }),
  332. smalltalk.ObjectSpaceTest);
  333. });