Spaces.js 10 KB

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