Kernel-Promises.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. define(["amber/boot", "amber_core/Kernel-Infrastructure", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
  4. $core.addPackage('Kernel-Promises');
  5. $core.packages["Kernel-Promises"].innerEval = function (expr) { return eval(expr); };
  6. $core.packages["Kernel-Promises"].transport = {"type":"amd","amdNamespace":"amber_core"};
  7. $core.addClass('Thenable', $globals.Object, [], 'Kernel-Promises');
  8. //>>excludeStart("ide", pragmas.excludeIdeData);
  9. $globals.Thenable.comment="I am the abstract base class for Promises.\x0a\x0aMy subclasses should wrap existing JS implementations.\x0a\x0aI contain methods that wrap Promises/A+ `.then` behaviour.";
  10. //>>excludeEnd("ide");
  11. $core.addMethod(
  12. $core.method({
  13. selector: "catch:",
  14. protocol: 'promises',
  15. fn: function (aBlock){
  16. var self=this;
  17. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  18. return $core.withContext(function($ctx1) {
  19. //>>excludeEnd("ctx");
  20. return self.then(null, function (err) {return $core.seamless(function () {
  21. return aBlock._value_(err);
  22. })});
  23. return self;
  24. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  25. }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.Thenable)});
  26. //>>excludeEnd("ctx");
  27. },
  28. //>>excludeStart("ide", pragmas.excludeIdeData);
  29. args: ["aBlock"],
  30. source: "catch: aBlock\x0a<return self.then(null, function (err) {return $core.seamless(function () {\x0a return aBlock._value_(err);\x0a})})>",
  31. referencedClasses: [],
  32. //>>excludeEnd("ide");
  33. messageSends: []
  34. }),
  35. $globals.Thenable);
  36. $core.addMethod(
  37. $core.method({
  38. selector: "on:do:",
  39. protocol: 'promises',
  40. fn: function (aClass,aBlock){
  41. var self=this;
  42. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  43. return $core.withContext(function($ctx1) {
  44. //>>excludeEnd("ctx");
  45. return self.then(null, function (err) {return $core.seamless(function () {
  46. if (err._isKindOf_(aClass)) return aBlock._value_(err);
  47. else throw err;
  48. })});
  49. return self;
  50. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  51. }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.Thenable)});
  52. //>>excludeEnd("ctx");
  53. },
  54. //>>excludeStart("ide", pragmas.excludeIdeData);
  55. args: ["aClass", "aBlock"],
  56. source: "on: aClass do: aBlock\x0a<return self.then(null, function (err) {return $core.seamless(function () {\x0a if (err._isKindOf_(aClass)) return aBlock._value_(err);\x0a else throw err;\x0a})})>",
  57. referencedClasses: [],
  58. //>>excludeEnd("ide");
  59. messageSends: []
  60. }),
  61. $globals.Thenable);
  62. $core.addMethod(
  63. $core.method({
  64. selector: "on:do:catch:",
  65. protocol: 'promises',
  66. fn: function (aClass,aBlock,anotherBlock){
  67. var self=this;
  68. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  69. return $core.withContext(function($ctx1) {
  70. //>>excludeEnd("ctx");
  71. return self.then(null, function (err) {return $core.seamless(function () {
  72. try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }
  73. return anotherBlock._value_(err);
  74. })});
  75. return self;
  76. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  77. }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.Thenable)});
  78. //>>excludeEnd("ctx");
  79. },
  80. //>>excludeStart("ide", pragmas.excludeIdeData);
  81. args: ["aClass", "aBlock", "anotherBlock"],
  82. source: "on: aClass do: aBlock catch: anotherBlock\x0a<return self.then(null, function (err) {return $core.seamless(function () {\x0a try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }\x0a return anotherBlock._value_(err);\x0a})})>",
  83. referencedClasses: [],
  84. //>>excludeEnd("ide");
  85. messageSends: []
  86. }),
  87. $globals.Thenable);
  88. $core.addMethod(
  89. $core.method({
  90. selector: "then:",
  91. protocol: 'promises',
  92. fn: function (aBlockOrArray){
  93. var self=this;
  94. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  95. return $core.withContext(function($ctx1) {
  96. //>>excludeEnd("ctx");
  97. var array = Array.isArray(aBlockOrArray) ? aBlockOrArray : [aBlockOrArray];
  98. return array.reduce(function (soFar, aBlock) {
  99. return soFar.then(typeof aBlock === "function" && aBlock.length > 1 ?
  100. function (result) {return $core.seamless(function () {
  101. if (Array.isArray(result)) {
  102. return aBlock._valueWithPossibleArguments_([result].concat(result.slice(0, aBlock.length-1)));
  103. } else {
  104. return aBlock._value_(result);
  105. }
  106. })} :
  107. function (result) {return $core.seamless(function () {
  108. return aBlock._value_(result);
  109. })}
  110. );
  111. }, self);
  112. return self;
  113. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  114. }, function($ctx1) {$ctx1.fill(self,"then:",{aBlockOrArray:aBlockOrArray},$globals.Thenable)});
  115. //>>excludeEnd("ctx");
  116. },
  117. //>>excludeStart("ide", pragmas.excludeIdeData);
  118. args: ["aBlockOrArray"],
  119. source: "then: aBlockOrArray\x0a\x22Accepts a block or array of blocks.\x0aEach of blocks in the array or the singleton one is\x0aused in .then call to a promise, to accept a result\x0aand transform it to the result for the next one.\x0aIn case a block has more than one argument\x0aand result is an array, first n-1 elements of the array\x0aare put into additional arguments beyond the first.\x0aThe first argument always contains the result as-is.\x22\x0a<\x0avar array = Array.isArray(aBlockOrArray) ? aBlockOrArray : [aBlockOrArray];\x0areturn array.reduce(function (soFar, aBlock) {\x0a return soFar.then(typeof aBlock === \x22function\x22 && aBlock.length >> 1 ?\x0a function (result) {return $core.seamless(function () {\x0a if (Array.isArray(result)) {\x0a return aBlock._valueWithPossibleArguments_([result].concat(result.slice(0, aBlock.length-1)));\x0a } else {\x0a return aBlock._value_(result);\x0a }\x0a })} :\x0a function (result) {return $core.seamless(function () {\x0a return aBlock._value_(result);\x0a })}\x0a );\x0a}, self)>",
  120. referencedClasses: [],
  121. //>>excludeEnd("ide");
  122. messageSends: []
  123. }),
  124. $globals.Thenable);
  125. $core.addMethod(
  126. $core.method({
  127. selector: "then:catch:",
  128. protocol: 'promises',
  129. fn: function (aBlockOrArray,anotherBlock){
  130. var self=this;
  131. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  132. return $core.withContext(function($ctx1) {
  133. //>>excludeEnd("ctx");
  134. return $recv(self._then_(aBlockOrArray))._catch_(anotherBlock);
  135. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  136. }, function($ctx1) {$ctx1.fill(self,"then:catch:",{aBlockOrArray:aBlockOrArray,anotherBlock:anotherBlock},$globals.Thenable)});
  137. //>>excludeEnd("ctx");
  138. },
  139. //>>excludeStart("ide", pragmas.excludeIdeData);
  140. args: ["aBlockOrArray", "anotherBlock"],
  141. source: "then: aBlockOrArray catch: anotherBlock\x0a\x09^ (self then: aBlockOrArray) catch: anotherBlock",
  142. referencedClasses: [],
  143. //>>excludeEnd("ide");
  144. messageSends: ["catch:", "then:"]
  145. }),
  146. $globals.Thenable);
  147. $core.addMethod(
  148. $core.method({
  149. selector: "then:on:do:",
  150. protocol: 'promises',
  151. fn: function (aBlockOrArray,aClass,aBlock){
  152. var self=this;
  153. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  154. return $core.withContext(function($ctx1) {
  155. //>>excludeEnd("ctx");
  156. return $recv(self._then_(aBlockOrArray))._on_do_(aClass,aBlock);
  157. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  158. }, function($ctx1) {$ctx1.fill(self,"then:on:do:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock},$globals.Thenable)});
  159. //>>excludeEnd("ctx");
  160. },
  161. //>>excludeStart("ide", pragmas.excludeIdeData);
  162. args: ["aBlockOrArray", "aClass", "aBlock"],
  163. source: "then: aBlockOrArray on: aClass do: aBlock\x0a\x09^ (self then: aBlockOrArray) on: aClass do: aBlock",
  164. referencedClasses: [],
  165. //>>excludeEnd("ide");
  166. messageSends: ["on:do:", "then:"]
  167. }),
  168. $globals.Thenable);
  169. $core.addMethod(
  170. $core.method({
  171. selector: "then:on:do:catch:",
  172. protocol: 'promises',
  173. fn: function (aBlockOrArray,aClass,aBlock,anotherBlock){
  174. var self=this;
  175. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  176. return $core.withContext(function($ctx1) {
  177. //>>excludeEnd("ctx");
  178. return $recv($recv(self._then_(aBlockOrArray))._on_do_(aClass,aBlock))._catch_(anotherBlock);
  179. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  180. }, function($ctx1) {$ctx1.fill(self,"then:on:do:catch:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.Thenable)});
  181. //>>excludeEnd("ctx");
  182. },
  183. //>>excludeStart("ide", pragmas.excludeIdeData);
  184. args: ["aBlockOrArray", "aClass", "aBlock", "anotherBlock"],
  185. source: "then: aBlockOrArray on: aClass do: aBlock catch: anotherBlock\x0a\x09^ ((self then: aBlockOrArray) on: aClass do: aBlock) catch: anotherBlock",
  186. referencedClasses: [],
  187. //>>excludeEnd("ide");
  188. messageSends: ["catch:", "on:do:", "then:"]
  189. }),
  190. $globals.Thenable);
  191. $core.addClass('Promise', $globals.Thenable, [], 'Kernel-Promises');
  192. $core.addMethod(
  193. $core.method({
  194. selector: "all:",
  195. protocol: 'composites',
  196. fn: function (aCollection){
  197. var self=this;
  198. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  199. return $core.withContext(function($ctx1) {
  200. //>>excludeEnd("ctx");
  201. return Promise.all($recv(aCollection)._asArray());
  202. return self;
  203. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  204. }, function($ctx1) {$ctx1.fill(self,"all:",{aCollection:aCollection},$globals.Promise.klass)});
  205. //>>excludeEnd("ctx");
  206. },
  207. //>>excludeStart("ide", pragmas.excludeIdeData);
  208. args: ["aCollection"],
  209. source: "all: aCollection\x0a\x22Returns a Promise resolved with results of sub-promises.\x22\x0a<return Promise.all($recv(aCollection)._asArray())>",
  210. referencedClasses: [],
  211. //>>excludeEnd("ide");
  212. messageSends: []
  213. }),
  214. $globals.Promise.klass);
  215. $core.addMethod(
  216. $core.method({
  217. selector: "any:",
  218. protocol: 'composites',
  219. fn: function (aCollection){
  220. var self=this;
  221. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  222. return $core.withContext(function($ctx1) {
  223. //>>excludeEnd("ctx");
  224. return Promise.race($recv(aCollection)._asArray());
  225. return self;
  226. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  227. }, function($ctx1) {$ctx1.fill(self,"any:",{aCollection:aCollection},$globals.Promise.klass)});
  228. //>>excludeEnd("ctx");
  229. },
  230. //>>excludeStart("ide", pragmas.excludeIdeData);
  231. args: ["aCollection"],
  232. source: "any: aCollection\x0a\x22Returns a Promise resolved with first result of sub-promises.\x22\x0a<return Promise.race($recv(aCollection)._asArray())>",
  233. referencedClasses: [],
  234. //>>excludeEnd("ide");
  235. messageSends: []
  236. }),
  237. $globals.Promise.klass);
  238. $core.addMethod(
  239. $core.method({
  240. selector: "forBlock:",
  241. protocol: 'instance creation',
  242. fn: function (aBlock){
  243. var self=this;
  244. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  245. return $core.withContext(function($ctx1) {
  246. //>>excludeEnd("ctx");
  247. return $recv(self._new())._then_(aBlock);
  248. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  249. }, function($ctx1) {$ctx1.fill(self,"forBlock:",{aBlock:aBlock},$globals.Promise.klass)});
  250. //>>excludeEnd("ctx");
  251. },
  252. //>>excludeStart("ide", pragmas.excludeIdeData);
  253. args: ["aBlock"],
  254. source: "forBlock: aBlock\x0a\x22Returns a Promise that is resolved with the value of aBlock,\x0aand rejected if error happens while evaluating aBlock.\x22\x0a\x09^ self new then: aBlock",
  255. referencedClasses: [],
  256. //>>excludeEnd("ide");
  257. messageSends: ["then:", "new"]
  258. }),
  259. $globals.Promise.klass);
  260. $core.addMethod(
  261. $core.method({
  262. selector: "new",
  263. protocol: 'instance creation',
  264. fn: function (){
  265. var self=this;
  266. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  267. return $core.withContext(function($ctx1) {
  268. //>>excludeEnd("ctx");
  269. return Promise.resolve();
  270. return self;
  271. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  272. }, function($ctx1) {$ctx1.fill(self,"new",{},$globals.Promise.klass)});
  273. //>>excludeEnd("ctx");
  274. },
  275. //>>excludeStart("ide", pragmas.excludeIdeData);
  276. args: [],
  277. source: "new\x0a\x22Returns a dumb Promise resolved with nil.\x22\x0a<return Promise.resolve()>",
  278. referencedClasses: [],
  279. //>>excludeEnd("ide");
  280. messageSends: []
  281. }),
  282. $globals.Promise.klass);
  283. $core.addMethod(
  284. $core.method({
  285. selector: "new:",
  286. protocol: 'instance creation',
  287. fn: function (aBlock){
  288. var self=this;
  289. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  290. return $core.withContext(function($ctx1) {
  291. //>>excludeEnd("ctx");
  292. return new Promise(function (resolve, reject) {
  293. var model = {value: resolve, signal: reject}; // TODO make faster
  294. aBlock._value_(model);
  295. });
  296. return self;
  297. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  298. }, function($ctx1) {$ctx1.fill(self,"new:",{aBlock:aBlock},$globals.Promise.klass)});
  299. //>>excludeEnd("ctx");
  300. },
  301. //>>excludeStart("ide", pragmas.excludeIdeData);
  302. args: ["aBlock"],
  303. source: "new: aBlock\x0a\x22Returns a Promise that is eventually resolved or rejected.\x0aPass a block that is called with one argument, model.\x0aYou should call model value: ... to resolve the promise\x0aand model signal: ... to reject the promise.\x0aIf error happens during run of the block,\x0apromise is rejected with that error as well.\x22\x0a<return new Promise(function (resolve, reject) {\x0a var model = {value: resolve, signal: reject}; // TODO make faster\x0a aBlock._value_(model);\x0a})>",
  304. referencedClasses: [],
  305. //>>excludeEnd("ide");
  306. messageSends: []
  307. }),
  308. $globals.Promise.klass);
  309. $core.addMethod(
  310. $core.method({
  311. selector: "signal:",
  312. protocol: 'instance creation',
  313. fn: function (anObject){
  314. var self=this;
  315. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  316. return $core.withContext(function($ctx1) {
  317. //>>excludeEnd("ctx");
  318. return $recv(anObject)._in_(function (x) {return Promise.reject(x)});
  319. return self;
  320. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  321. }, function($ctx1) {$ctx1.fill(self,"signal:",{anObject:anObject},$globals.Promise.klass)});
  322. //>>excludeEnd("ctx");
  323. },
  324. //>>excludeStart("ide", pragmas.excludeIdeData);
  325. args: ["anObject"],
  326. source: "signal: anObject\x0a\x22Returns a Promise rejected with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.reject(x)})>",
  327. referencedClasses: [],
  328. //>>excludeEnd("ide");
  329. messageSends: []
  330. }),
  331. $globals.Promise.klass);
  332. $core.addMethod(
  333. $core.method({
  334. selector: "value:",
  335. protocol: 'instance creation',
  336. fn: function (anObject){
  337. var self=this;
  338. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  339. return $core.withContext(function($ctx1) {
  340. //>>excludeEnd("ctx");
  341. return $recv(anObject)._in_(function (x) {return Promise.resolve(x)});
  342. return self;
  343. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  344. }, function($ctx1) {$ctx1.fill(self,"value:",{anObject:anObject},$globals.Promise.klass)});
  345. //>>excludeEnd("ctx");
  346. },
  347. //>>excludeStart("ide", pragmas.excludeIdeData);
  348. args: ["anObject"],
  349. source: "value: anObject\x0a\x22Returns a Promise resolved with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.resolve(x)})>",
  350. referencedClasses: [],
  351. //>>excludeEnd("ide");
  352. messageSends: []
  353. }),
  354. $globals.Promise.klass);
  355. $core.addMethod(
  356. $core.method({
  357. selector: "catch:",
  358. protocol: '*Kernel-Promises',
  359. fn: function (aBlock){
  360. var self=this;
  361. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  362. return $core.withContext(function($ctx1) {
  363. //>>excludeEnd("ctx");
  364. var js = self["@jsObject"];
  365. if (typeof js.then === "function")
  366. return $globals.Thenable.fn.prototype._catch_.call(js, aBlock);
  367. else
  368. return self._doesNotUnderstand_(
  369. $globals.Message._new()
  370. ._selector_("catch:")
  371. ._arguments_([aBlock])
  372. );
  373. return self;
  374. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  375. }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.JSObjectProxy)});
  376. //>>excludeEnd("ctx");
  377. },
  378. //>>excludeStart("ide", pragmas.excludeIdeData);
  379. args: ["aBlock"],
  380. source: "catch: aBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._catch_.call(js, aBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22catch:\x22)\x0a ._arguments_([aBlock])\x0a )>",
  381. referencedClasses: [],
  382. //>>excludeEnd("ide");
  383. messageSends: []
  384. }),
  385. $globals.JSObjectProxy);
  386. $core.addMethod(
  387. $core.method({
  388. selector: "on:do:",
  389. protocol: '*Kernel-Promises',
  390. fn: function (aClass,aBlock){
  391. var self=this;
  392. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  393. return $core.withContext(function($ctx1) {
  394. //>>excludeEnd("ctx");
  395. var js = self["@jsObject"];
  396. if (typeof js.then === "function")
  397. return $globals.Thenable.fn.prototype._on_do_.call(js, aClass, aBlock);
  398. else
  399. return self._doesNotUnderstand_(
  400. $globals.Message._new()
  401. ._selector_("on:do:")
  402. ._arguments_([aClass, aBlock])
  403. );
  404. return self;
  405. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  406. }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  407. //>>excludeEnd("ctx");
  408. },
  409. //>>excludeStart("ide", pragmas.excludeIdeData);
  410. args: ["aClass", "aBlock"],
  411. source: "on: aClass do: aBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._on_do_.call(js, aClass, aBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22on:do:\x22)\x0a ._arguments_([aClass, aBlock])\x0a )>",
  412. referencedClasses: [],
  413. //>>excludeEnd("ide");
  414. messageSends: []
  415. }),
  416. $globals.JSObjectProxy);
  417. $core.addMethod(
  418. $core.method({
  419. selector: "on:do:catch:",
  420. protocol: '*Kernel-Promises',
  421. fn: function (aClass,aBlock,anotherBlock){
  422. var self=this;
  423. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  424. return $core.withContext(function($ctx1) {
  425. //>>excludeEnd("ctx");
  426. var js = self["@jsObject"];
  427. if (typeof js.then === "function")
  428. return $globals.Thenable.fn.prototype._on_do_catch_.call(js, aClass, aBlock, anotherBlock);
  429. else
  430. return self._doesNotUnderstand_(
  431. $globals.Message._new()
  432. ._selector_("on:do:catch:")
  433. ._arguments_([aClass, aBlock, anotherBlock])
  434. );
  435. return self;
  436. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  437. }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  438. //>>excludeEnd("ctx");
  439. },
  440. //>>excludeStart("ide", pragmas.excludeIdeData);
  441. args: ["aClass", "aBlock", "anotherBlock"],
  442. source: "on: aClass do: aBlock catch: anotherBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._on_do_catch_.call(js, aClass, aBlock, anotherBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22on:do:catch:\x22)\x0a ._arguments_([aClass, aBlock, anotherBlock])\x0a )>",
  443. referencedClasses: [],
  444. //>>excludeEnd("ide");
  445. messageSends: []
  446. }),
  447. $globals.JSObjectProxy);
  448. $core.addMethod(
  449. $core.method({
  450. selector: "then:",
  451. protocol: '*Kernel-Promises',
  452. fn: function (aBlockOrArray){
  453. var self=this;
  454. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  455. return $core.withContext(function($ctx1) {
  456. //>>excludeEnd("ctx");
  457. var js = self["@jsObject"];
  458. if (typeof js.then === "function")
  459. return $globals.Thenable.fn.prototype._then_.call(js, aBlockOrArray);
  460. else
  461. return self._doesNotUnderstand_(
  462. $globals.Message._new()
  463. ._selector_("then:")
  464. ._arguments_([aBlockOrArray])
  465. );
  466. return self;
  467. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  468. }, function($ctx1) {$ctx1.fill(self,"then:",{aBlockOrArray:aBlockOrArray},$globals.JSObjectProxy)});
  469. //>>excludeEnd("ctx");
  470. },
  471. //>>excludeStart("ide", pragmas.excludeIdeData);
  472. args: ["aBlockOrArray"],
  473. source: "then: aBlockOrArray\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._then_.call(js, aBlockOrArray);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22then:\x22)\x0a ._arguments_([aBlockOrArray])\x0a )>",
  474. referencedClasses: [],
  475. //>>excludeEnd("ide");
  476. messageSends: []
  477. }),
  478. $globals.JSObjectProxy);
  479. $core.addMethod(
  480. $core.method({
  481. selector: "then:catch:",
  482. protocol: '*Kernel-Promises',
  483. fn: function (aBlockOrArray,anotherBlock){
  484. var self=this;
  485. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  486. return $core.withContext(function($ctx1) {
  487. //>>excludeEnd("ctx");
  488. var js = self["@jsObject"];
  489. if (typeof js.then === "function")
  490. return $globals.Thenable.fn.prototype._then_catch_.call(js, aBlockOrArray, anotherBlock);
  491. else
  492. return self._doesNotUnderstand_(
  493. $globals.Message._new()
  494. ._selector_("then:catch:")
  495. ._arguments_([aBlockOrArray, anotherBlock])
  496. );
  497. return self;
  498. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  499. }, function($ctx1) {$ctx1.fill(self,"then:catch:",{aBlockOrArray:aBlockOrArray,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  500. //>>excludeEnd("ctx");
  501. },
  502. //>>excludeStart("ide", pragmas.excludeIdeData);
  503. args: ["aBlockOrArray", "anotherBlock"],
  504. source: "then: aBlockOrArray catch: anotherBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._then_catch_.call(js, aBlockOrArray, anotherBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22then:catch:\x22)\x0a ._arguments_([aBlockOrArray, anotherBlock])\x0a )>",
  505. referencedClasses: [],
  506. //>>excludeEnd("ide");
  507. messageSends: []
  508. }),
  509. $globals.JSObjectProxy);
  510. $core.addMethod(
  511. $core.method({
  512. selector: "then:on:do:",
  513. protocol: '*Kernel-Promises',
  514. fn: function (aBlockOrArray,aClass,aBlock){
  515. var self=this;
  516. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  517. return $core.withContext(function($ctx1) {
  518. //>>excludeEnd("ctx");
  519. var js = self["@jsObject"];
  520. if (typeof js.then === "function")
  521. return $globals.Thenable.fn.prototype._then_on_do_.call(js, aBlockOrArray, aClass, aBlock);
  522. else
  523. return self._doesNotUnderstand_(
  524. $globals.Message._new()
  525. ._selector_("then:on:do:")
  526. ._arguments_([aBlockOrArray, aClass, aBlock])
  527. );
  528. return self;
  529. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  530. }, function($ctx1) {$ctx1.fill(self,"then:on:do:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  531. //>>excludeEnd("ctx");
  532. },
  533. //>>excludeStart("ide", pragmas.excludeIdeData);
  534. args: ["aBlockOrArray", "aClass", "aBlock"],
  535. source: "then: aBlockOrArray on: aClass do: aBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._then_on_do_.call(js, aBlockOrArray, aClass, aBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22then:on:do:\x22)\x0a ._arguments_([aBlockOrArray, aClass, aBlock])\x0a )>",
  536. referencedClasses: [],
  537. //>>excludeEnd("ide");
  538. messageSends: []
  539. }),
  540. $globals.JSObjectProxy);
  541. $core.addMethod(
  542. $core.method({
  543. selector: "then:on:do:catch:",
  544. protocol: '*Kernel-Promises',
  545. fn: function (aBlockOrArray,aClass,aBlock,anotherBlock){
  546. var self=this;
  547. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  548. return $core.withContext(function($ctx1) {
  549. //>>excludeEnd("ctx");
  550. var js = self["@jsObject"];
  551. if (typeof js.then === "function")
  552. return $globals.Thenable.fn.prototype._then_on_do_catch_.call(js, aBlockOrArray, aClass, aBlock, anotherBlock);
  553. else
  554. return self._doesNotUnderstand_(
  555. $globals.Message._new()
  556. ._selector_("then:on:do:catch:")
  557. ._arguments_([aBlockOrArray, aClass, aBlock, anotherBlock])
  558. );
  559. return self;
  560. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  561. }, function($ctx1) {$ctx1.fill(self,"then:on:do:catch:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  562. //>>excludeEnd("ctx");
  563. },
  564. //>>excludeStart("ide", pragmas.excludeIdeData);
  565. args: ["aBlockOrArray", "aClass", "aBlock", "anotherBlock"],
  566. source: "then: aBlockOrArray on: aClass do: aBlock catch: anotherBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._then_on_do_catch_.call(js, aBlockOrArray, aClass, aBlock, anotherBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22then:on:do:catch:\x22)\x0a ._arguments_([aBlockOrArray, aClass, aBlock, anotherBlock])\x0a )>",
  567. referencedClasses: [],
  568. //>>excludeEnd("ide");
  569. messageSends: []
  570. }),
  571. $globals.JSObjectProxy);
  572. });