2
0

Spaces.js 12 KB

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