Spaces.js 12 KB

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