Spaces.js 12 KB

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