Spaces.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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;
  69. $1 = smalltalk.send(smalltalk.send(self['@frame'], "_contentWindow", []), "_eval_", [smalltalk.send(smalltalk.send("(", "__comma", [smalltalk.send(aBlock, "_compiledSource", [])]), "__comma", [")()"])]);
  70. return $1;
  71. },
  72. args: ["aBlock"],
  73. source: "do: aBlock\x0a\x09^ frame contentWindow eval: '(', aBlock compiledSource, ')()'",
  74. messageSends: ["eval:", ",", "compiledSource", "contentWindow"],
  75. referencedClasses: []
  76. }),
  77. smalltalk.ObjectSpace);
  78. smalltalk.addMethod(
  79. "_frame",
  80. smalltalk.method({
  81. selector: "frame",
  82. category: 'accessing',
  83. fn: function () {
  84. var self = this;
  85. return self['@frame'];
  86. },
  87. args: [],
  88. source: "frame\x0a\x09^ frame",
  89. messageSends: [],
  90. referencedClasses: []
  91. }),
  92. smalltalk.ObjectSpace);
  93. smalltalk.addMethod(
  94. "_initialize",
  95. smalltalk.method({
  96. selector: "initialize",
  97. category: 'initialization',
  98. fn: function () {
  99. var self = this;
  100. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  101. smalltalk.send(self, "_create", []);
  102. return self;
  103. },
  104. args: [],
  105. source: "initialize\x0a\x09super initialize.\x0a\x09self create",
  106. messageSends: ["initialize", "create"],
  107. referencedClasses: []
  108. }),
  109. smalltalk.ObjectSpace);
  110. smalltalk.addMethod(
  111. "_release",
  112. smalltalk.method({
  113. selector: "release",
  114. category: 'releasing',
  115. fn: function () {
  116. var self = this;
  117. self['@frame'] = nil;
  118. return self;
  119. },
  120. args: [],
  121. source: "release\x0a\x09frame := nil",
  122. messageSends: [],
  123. referencedClasses: []
  124. }),
  125. smalltalk.ObjectSpace);
  126. smalltalk.addMethod(
  127. "_whenReadyDo_",
  128. smalltalk.method({
  129. selector: "whenReadyDo:",
  130. category: 'events',
  131. fn: function (aBlock) {
  132. var self = this;
  133. smalltalk.send(smalltalk.send(window, "_jQuery_", [self['@frame']]), "_bind_do_", ["load", aBlock]);
  134. return self;
  135. },
  136. args: ["aBlock"],
  137. source: "whenReadyDo: aBlock\x0a\x09(window jQuery: frame) \x0a\x09\x09bind: 'load'\x0a\x09\x09do: aBlock",
  138. messageSends: ["bind:do:", "jQuery:"],
  139. referencedClasses: []
  140. }),
  141. smalltalk.ObjectSpace);
  142. smalltalk.addMethod(
  143. "_on_",
  144. smalltalk.method({
  145. selector: "on:",
  146. category: 'instance creation',
  147. fn: function (aFrame) {
  148. var self = this;
  149. var $2, $3, $1;
  150. $2 = smalltalk.send(self, "_basicNew", []);
  151. smalltalk.send($2, "_connectTo_", [aFrame]);
  152. $3 = smalltalk.send($2, "_yourself", []);
  153. $1 = $3;
  154. return $1;
  155. },
  156. args: ["aFrame"],
  157. source: "on: aFrame\x0a\x09^ self basicNew\x0a\x09\x09connectTo: aFrame;\x0a\x09\x09yourself",
  158. messageSends: ["connectTo:", "basicNew", "yourself"],
  159. referencedClasses: []
  160. }),
  161. smalltalk.ObjectSpace.klass);
  162. smalltalk.addClass('ObjectSpaceTest', smalltalk.TestCase, ['space'], 'Spaces');
  163. smalltalk.addMethod(
  164. "_setUp",
  165. smalltalk.method({
  166. selector: "setUp",
  167. category: 'initialization',
  168. fn: function () {
  169. var self = this;
  170. self['@space'] = smalltalk.send(smalltalk.ObjectSpace || ObjectSpace, "_new", []);
  171. return self;
  172. },
  173. args: [],
  174. source: "setUp\x0a\x09space := ObjectSpace new",
  175. messageSends: ["new"],
  176. referencedClasses: ["ObjectSpace"]
  177. }),
  178. smalltalk.ObjectSpaceTest);
  179. smalltalk.addMethod(
  180. "_tearDown",
  181. smalltalk.method({
  182. selector: "tearDown",
  183. category: 'initialization',
  184. fn: function () {
  185. var self = this;
  186. smalltalk.send(self['@space'], "_destroy", []);
  187. self['@space'] = nil;
  188. return self;
  189. },
  190. args: [],
  191. source: "tearDown\x0a\x09space destroy.\x0a\x09space := nil",
  192. messageSends: ["destroy"],
  193. referencedClasses: []
  194. }),
  195. smalltalk.ObjectSpaceTest);
  196. smalltalk.addMethod(
  197. "_testCreate",
  198. smalltalk.method({
  199. selector: "testCreate",
  200. category: 'tests',
  201. fn: function () {
  202. var self = this;
  203. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(self['@space'], "_frame", []), "_notNil", [])]);
  204. return self;
  205. },
  206. args: [],
  207. source: "testCreate\x0a\x0a\x09self assert: space frame notNil",
  208. messageSends: ["assert:", "notNil", "frame"],
  209. referencedClasses: []
  210. }),
  211. smalltalk.ObjectSpaceTest);
  212. smalltalk.addMethod(
  213. "_testEvaluation",
  214. smalltalk.method({
  215. selector: "testEvaluation",
  216. category: 'tests',
  217. fn: function () {
  218. var self = this;
  219. var result;
  220. 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])]);}]);
  221. return self;
  222. },
  223. args: [],
  224. 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 ]",
  225. messageSends: ["whenReadyDo:", "do:", "assert:equals:", "name", "class", "deny:", "=", "=="],
  226. referencedClasses: ["Smalltalk"]
  227. }),
  228. smalltalk.ObjectSpaceTest);
  229. smalltalk.addMethod(
  230. "_testRelease",
  231. smalltalk.method({
  232. selector: "testRelease",
  233. category: 'tests',
  234. fn: function () {
  235. var self = this;
  236. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(self['@space'], "_frame", []), "_isNil", [])]);
  237. smalltalk.send(self['@space'], "_release", []);
  238. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(self['@space'], "_frame", []), "_isNil", [])]);
  239. return self;
  240. },
  241. args: [],
  242. source: "testRelease\x0a\x0a\x09self deny: space frame isNil.\x0a\x0a\x09space release.\x0a\x09\x0a\x09self assert: space frame isNil",
  243. messageSends: ["deny:", "isNil", "frame", "release", "assert:"],
  244. referencedClasses: []
  245. }),
  246. smalltalk.ObjectSpaceTest);