Kernel-Promises.js 24 KB

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