2
0

Spaces.js 12 KB

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