2
0

Spaces.js 12 KB

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