Kernel-Promises.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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: "all:",
  194. protocol: 'composites',
  195. fn: function (aCollection){
  196. var self=this;
  197. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  198. return $core.withContext(function($ctx1) {
  199. //>>excludeEnd("ctx");
  200. return Promise.all($recv(aCollection)._asArray());
  201. return self;
  202. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  203. }, function($ctx1) {$ctx1.fill(self,"all:",{aCollection:aCollection},$globals.Promise.klass)});
  204. //>>excludeEnd("ctx");
  205. },
  206. //>>excludeStart("ide", pragmas.excludeIdeData);
  207. args: ["aCollection"],
  208. source: "all: aCollection\x0a\x22Returns a Promise resolved with results of sub-promises.\x22\x0a<return Promise.all($recv(aCollection)._asArray())>",
  209. referencedClasses: [],
  210. //>>excludeEnd("ide");
  211. messageSends: []
  212. }),
  213. $globals.Promise.klass);
  214. $core.addMethod(
  215. $core.method({
  216. selector: "any:",
  217. protocol: 'composites',
  218. fn: function (aCollection){
  219. var self=this;
  220. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  221. return $core.withContext(function($ctx1) {
  222. //>>excludeEnd("ctx");
  223. return Promise.race($recv(aCollection)._asArray());
  224. return self;
  225. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  226. }, function($ctx1) {$ctx1.fill(self,"any:",{aCollection:aCollection},$globals.Promise.klass)});
  227. //>>excludeEnd("ctx");
  228. },
  229. //>>excludeStart("ide", pragmas.excludeIdeData);
  230. args: ["aCollection"],
  231. source: "any: aCollection\x0a\x22Returns a Promise resolved with first result of sub-promises.\x22\x0a<return Promise.race($recv(aCollection)._asArray())>",
  232. referencedClasses: [],
  233. //>>excludeEnd("ide");
  234. messageSends: []
  235. }),
  236. $globals.Promise.klass);
  237. $core.addMethod(
  238. $core.method({
  239. selector: "forBlock:",
  240. protocol: 'instance creation',
  241. fn: function (aBlock){
  242. var self=this;
  243. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  244. return $core.withContext(function($ctx1) {
  245. //>>excludeEnd("ctx");
  246. return $recv(self._new())._then_(aBlock);
  247. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  248. }, function($ctx1) {$ctx1.fill(self,"forBlock:",{aBlock:aBlock},$globals.Promise.klass)});
  249. //>>excludeEnd("ctx");
  250. },
  251. //>>excludeStart("ide", pragmas.excludeIdeData);
  252. args: ["aBlock"],
  253. 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",
  254. referencedClasses: [],
  255. //>>excludeEnd("ide");
  256. messageSends: ["then:", "new"]
  257. }),
  258. $globals.Promise.klass);
  259. $core.addMethod(
  260. $core.method({
  261. selector: "new",
  262. protocol: 'instance creation',
  263. fn: function (){
  264. var self=this;
  265. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  266. return $core.withContext(function($ctx1) {
  267. //>>excludeEnd("ctx");
  268. return Promise.resolve();
  269. return self;
  270. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  271. }, function($ctx1) {$ctx1.fill(self,"new",{},$globals.Promise.klass)});
  272. //>>excludeEnd("ctx");
  273. },
  274. //>>excludeStart("ide", pragmas.excludeIdeData);
  275. args: [],
  276. source: "new\x0a\x22Returns a dumb Promise resolved with nil.\x22\x0a<return Promise.resolve()>",
  277. referencedClasses: [],
  278. //>>excludeEnd("ide");
  279. messageSends: []
  280. }),
  281. $globals.Promise.klass);
  282. $core.addMethod(
  283. $core.method({
  284. selector: "new:",
  285. protocol: 'instance creation',
  286. fn: function (aBlock){
  287. var self=this;
  288. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  289. return $core.withContext(function($ctx1) {
  290. //>>excludeEnd("ctx");
  291. return new Promise(function (resolve, reject) {
  292. var model = {value: resolve, signal: reject}; // TODO make faster
  293. aBlock._value_(model);
  294. });
  295. return self;
  296. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  297. }, function($ctx1) {$ctx1.fill(self,"new:",{aBlock:aBlock},$globals.Promise.klass)});
  298. //>>excludeEnd("ctx");
  299. },
  300. //>>excludeStart("ide", pragmas.excludeIdeData);
  301. args: ["aBlock"],
  302. 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})>",
  303. referencedClasses: [],
  304. //>>excludeEnd("ide");
  305. messageSends: []
  306. }),
  307. $globals.Promise.klass);
  308. $core.addMethod(
  309. $core.method({
  310. selector: "signal:",
  311. protocol: 'instance creation',
  312. fn: function (anObject){
  313. var self=this;
  314. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  315. return $core.withContext(function($ctx1) {
  316. //>>excludeEnd("ctx");
  317. return $recv(anObject)._in_(function (x) {return Promise.reject(x)});
  318. return self;
  319. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  320. }, function($ctx1) {$ctx1.fill(self,"signal:",{anObject:anObject},$globals.Promise.klass)});
  321. //>>excludeEnd("ctx");
  322. },
  323. //>>excludeStart("ide", pragmas.excludeIdeData);
  324. args: ["anObject"],
  325. source: "signal: anObject\x0a\x22Returns a Promise rejected with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.reject(x)})>",
  326. referencedClasses: [],
  327. //>>excludeEnd("ide");
  328. messageSends: []
  329. }),
  330. $globals.Promise.klass);
  331. $core.addMethod(
  332. $core.method({
  333. selector: "value:",
  334. protocol: 'instance creation',
  335. fn: function (anObject){
  336. var self=this;
  337. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  338. return $core.withContext(function($ctx1) {
  339. //>>excludeEnd("ctx");
  340. return $recv(anObject)._in_(function (x) {return Promise.resolve(x)});
  341. return self;
  342. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  343. }, function($ctx1) {$ctx1.fill(self,"value:",{anObject:anObject},$globals.Promise.klass)});
  344. //>>excludeEnd("ctx");
  345. },
  346. //>>excludeStart("ide", pragmas.excludeIdeData);
  347. args: ["anObject"],
  348. source: "value: anObject\x0a\x22Returns a Promise resolved with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.resolve(x)})>",
  349. referencedClasses: [],
  350. //>>excludeEnd("ide");
  351. messageSends: []
  352. }),
  353. $globals.Promise.klass);
  354. $core.addMethod(
  355. $core.method({
  356. selector: "catch:",
  357. protocol: '*Kernel-Promises',
  358. fn: function (aBlock){
  359. var self=this;
  360. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  361. return $core.withContext(function($ctx1) {
  362. //>>excludeEnd("ctx");
  363. var js = self["@jsObject"];
  364. if (typeof js.then === "function")
  365. return $globals.Thenable.fn.prototype._catch_.call(js, aBlock);
  366. else
  367. return self._doesNotUnderstand_(
  368. $globals.Message._new()
  369. ._selector_("catch:")
  370. ._arguments_([aBlock])
  371. );
  372. return self;
  373. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  374. }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.JSObjectProxy)});
  375. //>>excludeEnd("ctx");
  376. },
  377. //>>excludeStart("ide", pragmas.excludeIdeData);
  378. args: ["aBlock"],
  379. 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 )>",
  380. referencedClasses: [],
  381. //>>excludeEnd("ide");
  382. messageSends: []
  383. }),
  384. $globals.JSObjectProxy);
  385. $core.addMethod(
  386. $core.method({
  387. selector: "on:do:",
  388. protocol: '*Kernel-Promises',
  389. fn: function (aClass,aBlock){
  390. var self=this;
  391. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  392. return $core.withContext(function($ctx1) {
  393. //>>excludeEnd("ctx");
  394. var js = self["@jsObject"];
  395. if (typeof js.then === "function")
  396. return $globals.Thenable.fn.prototype._on_do_.call(js, aClass, aBlock);
  397. else
  398. return self._doesNotUnderstand_(
  399. $globals.Message._new()
  400. ._selector_("on:do:")
  401. ._arguments_([aClass, aBlock])
  402. );
  403. return self;
  404. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  405. }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  406. //>>excludeEnd("ctx");
  407. },
  408. //>>excludeStart("ide", pragmas.excludeIdeData);
  409. args: ["aClass", "aBlock"],
  410. 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 )>",
  411. referencedClasses: [],
  412. //>>excludeEnd("ide");
  413. messageSends: []
  414. }),
  415. $globals.JSObjectProxy);
  416. $core.addMethod(
  417. $core.method({
  418. selector: "on:do:catch:",
  419. protocol: '*Kernel-Promises',
  420. fn: function (aClass,aBlock,anotherBlock){
  421. var self=this;
  422. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  423. return $core.withContext(function($ctx1) {
  424. //>>excludeEnd("ctx");
  425. var js = self["@jsObject"];
  426. if (typeof js.then === "function")
  427. return $globals.Thenable.fn.prototype._on_do_catch_.call(js, aClass, aBlock, anotherBlock);
  428. else
  429. return self._doesNotUnderstand_(
  430. $globals.Message._new()
  431. ._selector_("on:do:catch:")
  432. ._arguments_([aClass, aBlock, anotherBlock])
  433. );
  434. return self;
  435. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  436. }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  437. //>>excludeEnd("ctx");
  438. },
  439. //>>excludeStart("ide", pragmas.excludeIdeData);
  440. args: ["aClass", "aBlock", "anotherBlock"],
  441. 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 )>",
  442. referencedClasses: [],
  443. //>>excludeEnd("ide");
  444. messageSends: []
  445. }),
  446. $globals.JSObjectProxy);
  447. $core.addMethod(
  448. $core.method({
  449. selector: "then:",
  450. protocol: '*Kernel-Promises',
  451. fn: function (aBlockOrArray){
  452. var self=this;
  453. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  454. return $core.withContext(function($ctx1) {
  455. //>>excludeEnd("ctx");
  456. var js = self["@jsObject"];
  457. if (typeof js.then === "function")
  458. return $globals.Thenable.fn.prototype._then_.call(js, aBlockOrArray);
  459. else
  460. return self._doesNotUnderstand_(
  461. $globals.Message._new()
  462. ._selector_("then:")
  463. ._arguments_([aBlockOrArray])
  464. );
  465. return self;
  466. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  467. }, function($ctx1) {$ctx1.fill(self,"then:",{aBlockOrArray:aBlockOrArray},$globals.JSObjectProxy)});
  468. //>>excludeEnd("ctx");
  469. },
  470. //>>excludeStart("ide", pragmas.excludeIdeData);
  471. args: ["aBlockOrArray"],
  472. 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 )>",
  473. referencedClasses: [],
  474. //>>excludeEnd("ide");
  475. messageSends: []
  476. }),
  477. $globals.JSObjectProxy);
  478. $core.addMethod(
  479. $core.method({
  480. selector: "then:catch:",
  481. protocol: '*Kernel-Promises',
  482. fn: function (aBlockOrArray,anotherBlock){
  483. var self=this;
  484. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  485. return $core.withContext(function($ctx1) {
  486. //>>excludeEnd("ctx");
  487. var js = self["@jsObject"];
  488. if (typeof js.then === "function")
  489. return $globals.Thenable.fn.prototype._then_catch_.call(js, aBlockOrArray, anotherBlock);
  490. else
  491. return self._doesNotUnderstand_(
  492. $globals.Message._new()
  493. ._selector_("then:catch:")
  494. ._arguments_([aBlockOrArray, anotherBlock])
  495. );
  496. return self;
  497. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  498. }, function($ctx1) {$ctx1.fill(self,"then:catch:",{aBlockOrArray:aBlockOrArray,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  499. //>>excludeEnd("ctx");
  500. },
  501. //>>excludeStart("ide", pragmas.excludeIdeData);
  502. args: ["aBlockOrArray", "anotherBlock"],
  503. 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 )>",
  504. referencedClasses: [],
  505. //>>excludeEnd("ide");
  506. messageSends: []
  507. }),
  508. $globals.JSObjectProxy);
  509. $core.addMethod(
  510. $core.method({
  511. selector: "then:on:do:",
  512. protocol: '*Kernel-Promises',
  513. fn: function (aBlockOrArray,aClass,aBlock){
  514. var self=this;
  515. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  516. return $core.withContext(function($ctx1) {
  517. //>>excludeEnd("ctx");
  518. var js = self["@jsObject"];
  519. if (typeof js.then === "function")
  520. return $globals.Thenable.fn.prototype._then_on_do_.call(js, aBlockOrArray, aClass, aBlock);
  521. else
  522. return self._doesNotUnderstand_(
  523. $globals.Message._new()
  524. ._selector_("then:on:do:")
  525. ._arguments_([aBlockOrArray, aClass, aBlock])
  526. );
  527. return self;
  528. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  529. }, function($ctx1) {$ctx1.fill(self,"then:on:do:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  530. //>>excludeEnd("ctx");
  531. },
  532. //>>excludeStart("ide", pragmas.excludeIdeData);
  533. args: ["aBlockOrArray", "aClass", "aBlock"],
  534. 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 )>",
  535. referencedClasses: [],
  536. //>>excludeEnd("ide");
  537. messageSends: []
  538. }),
  539. $globals.JSObjectProxy);
  540. $core.addMethod(
  541. $core.method({
  542. selector: "then:on:do:catch:",
  543. protocol: '*Kernel-Promises',
  544. fn: function (aBlockOrArray,aClass,aBlock,anotherBlock){
  545. var self=this;
  546. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  547. return $core.withContext(function($ctx1) {
  548. //>>excludeEnd("ctx");
  549. var js = self["@jsObject"];
  550. if (typeof js.then === "function")
  551. return $globals.Thenable.fn.prototype._then_on_do_catch_.call(js, aBlockOrArray, aClass, aBlock, anotherBlock);
  552. else
  553. return self._doesNotUnderstand_(
  554. $globals.Message._new()
  555. ._selector_("then:on:do:catch:")
  556. ._arguments_([aBlockOrArray, aClass, aBlock, anotherBlock])
  557. );
  558. return self;
  559. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  560. }, function($ctx1) {$ctx1.fill(self,"then:on:do:catch:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  561. //>>excludeEnd("ctx");
  562. },
  563. //>>excludeStart("ide", pragmas.excludeIdeData);
  564. args: ["aBlockOrArray", "aClass", "aBlock", "anotherBlock"],
  565. 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 )>",
  566. referencedClasses: [],
  567. //>>excludeEnd("ide");
  568. messageSends: []
  569. }),
  570. $globals.JSObjectProxy);
  571. });