Kernel-Promises.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. define("amber_core/Kernel-Promises", ["amber/boot", "amber_core/Kernel-Objects", "amber_core/Kernel-Infrastructure"], function($boot){"use strict";
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. $core.addPackage('Kernel-Promises');
  4. $core.packages["Kernel-Promises"].innerEval = function (expr) { return eval(expr); };
  5. $core.packages["Kernel-Promises"].transport = {"type":"amd","amdNamespace":"amber_core"};
  6. $core.addClass('Thenable', $globals.Object, [], 'Kernel-Promises');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $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.";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "catch:",
  13. protocol: 'promises',
  14. fn: function (aBlock){
  15. var self=this;
  16. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  17. return $core.withContext(function($ctx1) {
  18. //>>excludeEnd("ctx");
  19. return self.then(null, function (err) {return $core.seamless(function () {
  20. return aBlock._value_(err);
  21. })});
  22. return self;
  23. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  24. }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.Thenable)});
  25. //>>excludeEnd("ctx");
  26. },
  27. //>>excludeStart("ide", pragmas.excludeIdeData);
  28. args: ["aBlock"],
  29. source: "catch: aBlock\x0a<return self.then(null, function (err) {return $core.seamless(function () {\x0a return aBlock._value_(err);\x0a})})>",
  30. referencedClasses: [],
  31. //>>excludeEnd("ide");
  32. messageSends: []
  33. }),
  34. $globals.Thenable);
  35. $core.addMethod(
  36. $core.method({
  37. selector: "on:do:",
  38. protocol: 'promises',
  39. fn: function (aClass,aBlock){
  40. var self=this;
  41. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  42. return $core.withContext(function($ctx1) {
  43. //>>excludeEnd("ctx");
  44. return self.then(null, function (err) {return $core.seamless(function () {
  45. if (err._isKindOf_(aClass)) return aBlock._value_(err);
  46. else throw err;
  47. })});
  48. return self;
  49. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  50. }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.Thenable)});
  51. //>>excludeEnd("ctx");
  52. },
  53. //>>excludeStart("ide", pragmas.excludeIdeData);
  54. args: ["aClass", "aBlock"],
  55. 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})})>",
  56. referencedClasses: [],
  57. //>>excludeEnd("ide");
  58. messageSends: []
  59. }),
  60. $globals.Thenable);
  61. $core.addMethod(
  62. $core.method({
  63. selector: "on:do:catch:",
  64. protocol: 'promises',
  65. fn: function (aClass,aBlock,anotherBlock){
  66. var self=this;
  67. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  68. return $core.withContext(function($ctx1) {
  69. //>>excludeEnd("ctx");
  70. return self.then(null, function (err) {return $core.seamless(function () {
  71. try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }
  72. return anotherBlock._value_(err);
  73. })});
  74. return self;
  75. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  76. }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.Thenable)});
  77. //>>excludeEnd("ctx");
  78. },
  79. //>>excludeStart("ide", pragmas.excludeIdeData);
  80. args: ["aClass", "aBlock", "anotherBlock"],
  81. 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})})>",
  82. referencedClasses: [],
  83. //>>excludeEnd("ide");
  84. messageSends: []
  85. }),
  86. $globals.Thenable);
  87. $core.addMethod(
  88. $core.method({
  89. selector: "then:",
  90. protocol: 'promises',
  91. fn: function (aBlockOrArray){
  92. var self=this;
  93. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  94. return $core.withContext(function($ctx1) {
  95. //>>excludeEnd("ctx");
  96. var array = Array.isArray(aBlockOrArray) ? aBlockOrArray : [aBlockOrArray];
  97. return array.reduce(function (soFar, aBlock) {
  98. return soFar.then(typeof aBlock === "function" && aBlock.length > 1 ?
  99. function (result) {return $core.seamless(function () {
  100. if (Array.isArray(result)) {
  101. return aBlock._valueWithPossibleArguments_([result].concat(result.slice(0, aBlock.length-1)));
  102. } else {
  103. return aBlock._value_(result);
  104. }
  105. })} :
  106. function (result) {return $core.seamless(function () {
  107. return aBlock._value_(result);
  108. })}
  109. );
  110. }, self);
  111. return self;
  112. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  113. }, function($ctx1) {$ctx1.fill(self,"then:",{aBlockOrArray:aBlockOrArray},$globals.Thenable)});
  114. //>>excludeEnd("ctx");
  115. },
  116. //>>excludeStart("ide", pragmas.excludeIdeData);
  117. args: ["aBlockOrArray"],
  118. 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)>",
  119. referencedClasses: [],
  120. //>>excludeEnd("ide");
  121. messageSends: []
  122. }),
  123. $globals.Thenable);
  124. $core.addMethod(
  125. $core.method({
  126. selector: "then:catch:",
  127. protocol: 'promises',
  128. fn: function (aBlockOrArray,anotherBlock){
  129. var self=this;
  130. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  131. return $core.withContext(function($ctx1) {
  132. //>>excludeEnd("ctx");
  133. return $recv(self._then_(aBlockOrArray))._catch_(anotherBlock);
  134. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  135. }, function($ctx1) {$ctx1.fill(self,"then:catch:",{aBlockOrArray:aBlockOrArray,anotherBlock:anotherBlock},$globals.Thenable)});
  136. //>>excludeEnd("ctx");
  137. },
  138. //>>excludeStart("ide", pragmas.excludeIdeData);
  139. args: ["aBlockOrArray", "anotherBlock"],
  140. source: "then: aBlockOrArray catch: anotherBlock\x0a\x09^ (self then: aBlockOrArray) catch: anotherBlock",
  141. referencedClasses: [],
  142. //>>excludeEnd("ide");
  143. messageSends: ["catch:", "then:"]
  144. }),
  145. $globals.Thenable);
  146. $core.addMethod(
  147. $core.method({
  148. selector: "then:on:do:",
  149. protocol: 'promises',
  150. fn: function (aBlockOrArray,aClass,aBlock){
  151. var self=this;
  152. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  153. return $core.withContext(function($ctx1) {
  154. //>>excludeEnd("ctx");
  155. return $recv(self._then_(aBlockOrArray))._on_do_(aClass,aBlock);
  156. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  157. }, function($ctx1) {$ctx1.fill(self,"then:on:do:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock},$globals.Thenable)});
  158. //>>excludeEnd("ctx");
  159. },
  160. //>>excludeStart("ide", pragmas.excludeIdeData);
  161. args: ["aBlockOrArray", "aClass", "aBlock"],
  162. source: "then: aBlockOrArray on: aClass do: aBlock\x0a\x09^ (self then: aBlockOrArray) on: aClass do: aBlock",
  163. referencedClasses: [],
  164. //>>excludeEnd("ide");
  165. messageSends: ["on:do:", "then:"]
  166. }),
  167. $globals.Thenable);
  168. $core.addMethod(
  169. $core.method({
  170. selector: "then:on:do:catch:",
  171. protocol: 'promises',
  172. fn: function (aBlockOrArray,aClass,aBlock,anotherBlock){
  173. var self=this;
  174. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  175. return $core.withContext(function($ctx1) {
  176. //>>excludeEnd("ctx");
  177. return $recv($recv(self._then_(aBlockOrArray))._on_do_(aClass,aBlock))._catch_(anotherBlock);
  178. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  179. }, function($ctx1) {$ctx1.fill(self,"then:on:do:catch:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.Thenable)});
  180. //>>excludeEnd("ctx");
  181. },
  182. //>>excludeStart("ide", pragmas.excludeIdeData);
  183. args: ["aBlockOrArray", "aClass", "aBlock", "anotherBlock"],
  184. source: "then: aBlockOrArray on: aClass do: aBlock catch: anotherBlock\x0a\x09^ ((self then: aBlockOrArray) on: aClass do: aBlock) catch: anotherBlock",
  185. referencedClasses: [],
  186. //>>excludeEnd("ide");
  187. messageSends: ["catch:", "on:do:", "then:"]
  188. }),
  189. $globals.Thenable);
  190. $core.addClass('Promise', $globals.Thenable, [], 'Kernel-Promises');
  191. $core.addMethod(
  192. $core.method({
  193. selector: "forBlock:",
  194. protocol: 'instance creation',
  195. fn: function (aBlock){
  196. var self=this;
  197. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  198. return $core.withContext(function($ctx1) {
  199. //>>excludeEnd("ctx");
  200. return Promise.resolve().then(function () {return $core.seamless(function () {return $recv(aBlock)._value_()})});
  201. return self;
  202. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  203. }, function($ctx1) {$ctx1.fill(self,"forBlock:",{aBlock:aBlock},$globals.Promise.klass)});
  204. //>>excludeEnd("ctx");
  205. },
  206. //>>excludeStart("ide", pragmas.excludeIdeData);
  207. args: ["aBlock"],
  208. 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<return Promise.resolve().then(function () {return $core.seamless(function () {return $recv(aBlock)._value_()})})>",
  209. referencedClasses: [],
  210. //>>excludeEnd("ide");
  211. messageSends: []
  212. }),
  213. $globals.Promise.klass);
  214. $core.addMethod(
  215. $core.method({
  216. selector: "new:",
  217. protocol: 'instance creation',
  218. fn: function (aBlock){
  219. var self=this;
  220. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  221. return $core.withContext(function($ctx1) {
  222. //>>excludeEnd("ctx");
  223. return new Promise(function (resolve, reject) {
  224. var model = {value: resolve, signal: reject}; // TODO make faster
  225. aBlock._value_(model);
  226. });
  227. return self;
  228. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  229. }, function($ctx1) {$ctx1.fill(self,"new:",{aBlock:aBlock},$globals.Promise.klass)});
  230. //>>excludeEnd("ctx");
  231. },
  232. //>>excludeStart("ide", pragmas.excludeIdeData);
  233. args: ["aBlock"],
  234. 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})>",
  235. referencedClasses: [],
  236. //>>excludeEnd("ide");
  237. messageSends: []
  238. }),
  239. $globals.Promise.klass);
  240. $core.addMethod(
  241. $core.method({
  242. selector: "signal:",
  243. protocol: 'instance creation',
  244. fn: function (anObject){
  245. var self=this;
  246. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  247. return $core.withContext(function($ctx1) {
  248. //>>excludeEnd("ctx");
  249. return $recv(anObject)._in_(function (x) {return Promise.reject(x)});
  250. return self;
  251. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  252. }, function($ctx1) {$ctx1.fill(self,"signal:",{anObject:anObject},$globals.Promise.klass)});
  253. //>>excludeEnd("ctx");
  254. },
  255. //>>excludeStart("ide", pragmas.excludeIdeData);
  256. args: ["anObject"],
  257. source: "signal: anObject\x0a\x22Returns a Promise rejected with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.reject(x)})>",
  258. referencedClasses: [],
  259. //>>excludeEnd("ide");
  260. messageSends: []
  261. }),
  262. $globals.Promise.klass);
  263. $core.addMethod(
  264. $core.method({
  265. selector: "value:",
  266. protocol: 'instance creation',
  267. fn: function (anObject){
  268. var self=this;
  269. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  270. return $core.withContext(function($ctx1) {
  271. //>>excludeEnd("ctx");
  272. return $recv(anObject)._in_(function (x) {return Promise.resolve(x)});
  273. return self;
  274. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  275. }, function($ctx1) {$ctx1.fill(self,"value:",{anObject:anObject},$globals.Promise.klass)});
  276. //>>excludeEnd("ctx");
  277. },
  278. //>>excludeStart("ide", pragmas.excludeIdeData);
  279. args: ["anObject"],
  280. source: "value: anObject\x0a\x22Returns a Promise resolved with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.resolve(x)})>",
  281. referencedClasses: [],
  282. //>>excludeEnd("ide");
  283. messageSends: []
  284. }),
  285. $globals.Promise.klass);
  286. $core.addMethod(
  287. $core.method({
  288. selector: "catch:",
  289. protocol: '*Kernel-Promises',
  290. fn: function (aBlock){
  291. var self=this;
  292. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  293. return $core.withContext(function($ctx1) {
  294. //>>excludeEnd("ctx");
  295. var js = self["@jsObject"];
  296. if (typeof js.then === "function")
  297. return $globals.Thenable.fn.prototype._catch_.call(js, aBlock);
  298. else
  299. return self._doesNotUnderstand_(
  300. $globals.Message._new()
  301. ._selector_("catch:")
  302. ._arguments_([aBlock])
  303. );
  304. return self;
  305. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  306. }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.JSObjectProxy)});
  307. //>>excludeEnd("ctx");
  308. },
  309. //>>excludeStart("ide", pragmas.excludeIdeData);
  310. args: ["aBlock"],
  311. 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 )>",
  312. referencedClasses: [],
  313. //>>excludeEnd("ide");
  314. messageSends: []
  315. }),
  316. $globals.JSObjectProxy);
  317. $core.addMethod(
  318. $core.method({
  319. selector: "on:do:",
  320. protocol: '*Kernel-Promises',
  321. fn: function (aClass,aBlock){
  322. var self=this;
  323. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  324. return $core.withContext(function($ctx1) {
  325. //>>excludeEnd("ctx");
  326. var js = self["@jsObject"];
  327. if (typeof js.then === "function")
  328. return $globals.Thenable.fn.prototype._on_do_.call(js, aClass, aBlock);
  329. else
  330. return self._doesNotUnderstand_(
  331. $globals.Message._new()
  332. ._selector_("on:do:")
  333. ._arguments_([aClass, aBlock])
  334. );
  335. return self;
  336. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  337. }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  338. //>>excludeEnd("ctx");
  339. },
  340. //>>excludeStart("ide", pragmas.excludeIdeData);
  341. args: ["aClass", "aBlock"],
  342. 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 )>",
  343. referencedClasses: [],
  344. //>>excludeEnd("ide");
  345. messageSends: []
  346. }),
  347. $globals.JSObjectProxy);
  348. $core.addMethod(
  349. $core.method({
  350. selector: "on:do:catch:",
  351. protocol: '*Kernel-Promises',
  352. fn: function (aClass,aBlock,anotherBlock){
  353. var self=this;
  354. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  355. return $core.withContext(function($ctx1) {
  356. //>>excludeEnd("ctx");
  357. var js = self["@jsObject"];
  358. if (typeof js.then === "function")
  359. return $globals.Thenable.fn.prototype._on_do_catch_.call(js, aClass, aBlock, anotherBlock);
  360. else
  361. return self._doesNotUnderstand_(
  362. $globals.Message._new()
  363. ._selector_("on:do:catch:")
  364. ._arguments_([aClass, aBlock, anotherBlock])
  365. );
  366. return self;
  367. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  368. }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  369. //>>excludeEnd("ctx");
  370. },
  371. //>>excludeStart("ide", pragmas.excludeIdeData);
  372. args: ["aClass", "aBlock", "anotherBlock"],
  373. 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 )>",
  374. referencedClasses: [],
  375. //>>excludeEnd("ide");
  376. messageSends: []
  377. }),
  378. $globals.JSObjectProxy);
  379. $core.addMethod(
  380. $core.method({
  381. selector: "then:",
  382. protocol: '*Kernel-Promises',
  383. fn: function (aBlockOrArray){
  384. var self=this;
  385. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  386. return $core.withContext(function($ctx1) {
  387. //>>excludeEnd("ctx");
  388. var js = self["@jsObject"];
  389. if (typeof js.then === "function")
  390. return $globals.Thenable.fn.prototype._then_.call(js, aBlockOrArray);
  391. else
  392. return self._doesNotUnderstand_(
  393. $globals.Message._new()
  394. ._selector_("then:")
  395. ._arguments_([aBlockOrArray])
  396. );
  397. return self;
  398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  399. }, function($ctx1) {$ctx1.fill(self,"then:",{aBlockOrArray:aBlockOrArray},$globals.JSObjectProxy)});
  400. //>>excludeEnd("ctx");
  401. },
  402. //>>excludeStart("ide", pragmas.excludeIdeData);
  403. args: ["aBlockOrArray"],
  404. 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 )>",
  405. referencedClasses: [],
  406. //>>excludeEnd("ide");
  407. messageSends: []
  408. }),
  409. $globals.JSObjectProxy);
  410. $core.addMethod(
  411. $core.method({
  412. selector: "then:catch:",
  413. protocol: '*Kernel-Promises',
  414. fn: function (aBlockOrArray,anotherBlock){
  415. var self=this;
  416. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  417. return $core.withContext(function($ctx1) {
  418. //>>excludeEnd("ctx");
  419. var js = self["@jsObject"];
  420. if (typeof js.then === "function")
  421. return $globals.Thenable.fn.prototype._then_catch_.call(js, aBlockOrArray, anotherBlock);
  422. else
  423. return self._doesNotUnderstand_(
  424. $globals.Message._new()
  425. ._selector_("then:catch:")
  426. ._arguments_([aBlockOrArray, anotherBlock])
  427. );
  428. return self;
  429. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  430. }, function($ctx1) {$ctx1.fill(self,"then:catch:",{aBlockOrArray:aBlockOrArray,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  431. //>>excludeEnd("ctx");
  432. },
  433. //>>excludeStart("ide", pragmas.excludeIdeData);
  434. args: ["aBlockOrArray", "anotherBlock"],
  435. 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 )>",
  436. referencedClasses: [],
  437. //>>excludeEnd("ide");
  438. messageSends: []
  439. }),
  440. $globals.JSObjectProxy);
  441. $core.addMethod(
  442. $core.method({
  443. selector: "then:on:do:",
  444. protocol: '*Kernel-Promises',
  445. fn: function (aBlockOrArray,aClass,aBlock){
  446. var self=this;
  447. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  448. return $core.withContext(function($ctx1) {
  449. //>>excludeEnd("ctx");
  450. var js = self["@jsObject"];
  451. if (typeof js.then === "function")
  452. return $globals.Thenable.fn.prototype._then_on_do_.call(js, aBlockOrArray, aClass, aBlock);
  453. else
  454. return self._doesNotUnderstand_(
  455. $globals.Message._new()
  456. ._selector_("then:on:do:")
  457. ._arguments_([aBlockOrArray, aClass, aBlock])
  458. );
  459. return self;
  460. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  461. }, function($ctx1) {$ctx1.fill(self,"then:on:do:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  462. //>>excludeEnd("ctx");
  463. },
  464. //>>excludeStart("ide", pragmas.excludeIdeData);
  465. args: ["aBlockOrArray", "aClass", "aBlock"],
  466. 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 )>",
  467. referencedClasses: [],
  468. //>>excludeEnd("ide");
  469. messageSends: []
  470. }),
  471. $globals.JSObjectProxy);
  472. $core.addMethod(
  473. $core.method({
  474. selector: "then:on:do:catch:",
  475. protocol: '*Kernel-Promises',
  476. fn: function (aBlockOrArray,aClass,aBlock,anotherBlock){
  477. var self=this;
  478. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  479. return $core.withContext(function($ctx1) {
  480. //>>excludeEnd("ctx");
  481. var js = self["@jsObject"];
  482. if (typeof js.then === "function")
  483. return $globals.Thenable.fn.prototype._then_on_do_catch_.call(js, aBlockOrArray, aClass, aBlock, anotherBlock);
  484. else
  485. return self._doesNotUnderstand_(
  486. $globals.Message._new()
  487. ._selector_("then:on:do:catch:")
  488. ._arguments_([aBlockOrArray, aClass, aBlock, anotherBlock])
  489. );
  490. return self;
  491. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  492. }, function($ctx1) {$ctx1.fill(self,"then:on:do:catch:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  493. //>>excludeEnd("ctx");
  494. },
  495. //>>excludeStart("ide", pragmas.excludeIdeData);
  496. args: ["aBlockOrArray", "aClass", "aBlock", "anotherBlock"],
  497. 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 )>",
  498. referencedClasses: [],
  499. //>>excludeEnd("ide");
  500. messageSends: []
  501. }),
  502. $globals.JSObjectProxy);
  503. });