Kernel-Promises.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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 Promise.resolve().then(function () {return $core.seamless(function () {return $recv(aBlock)._value_()})});
  247. return self;
  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<return Promise.resolve().then(function () {return $core.seamless(function () {return $recv(aBlock)._value_()})})>",
  255. referencedClasses: [],
  256. //>>excludeEnd("ide");
  257. messageSends: []
  258. }),
  259. $globals.Promise.klass);
  260. $core.addMethod(
  261. $core.method({
  262. selector: "new:",
  263. protocol: 'instance creation',
  264. fn: function (aBlock){
  265. var self=this;
  266. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  267. return $core.withContext(function($ctx1) {
  268. //>>excludeEnd("ctx");
  269. return new Promise(function (resolve, reject) {
  270. var model = {value: resolve, signal: reject}; // TODO make faster
  271. aBlock._value_(model);
  272. });
  273. return self;
  274. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  275. }, function($ctx1) {$ctx1.fill(self,"new:",{aBlock:aBlock},$globals.Promise.klass)});
  276. //>>excludeEnd("ctx");
  277. },
  278. //>>excludeStart("ide", pragmas.excludeIdeData);
  279. args: ["aBlock"],
  280. 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})>",
  281. referencedClasses: [],
  282. //>>excludeEnd("ide");
  283. messageSends: []
  284. }),
  285. $globals.Promise.klass);
  286. $core.addMethod(
  287. $core.method({
  288. selector: "signal:",
  289. protocol: 'instance creation',
  290. fn: function (anObject){
  291. var self=this;
  292. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  293. return $core.withContext(function($ctx1) {
  294. //>>excludeEnd("ctx");
  295. return $recv(anObject)._in_(function (x) {return Promise.reject(x)});
  296. return self;
  297. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  298. }, function($ctx1) {$ctx1.fill(self,"signal:",{anObject:anObject},$globals.Promise.klass)});
  299. //>>excludeEnd("ctx");
  300. },
  301. //>>excludeStart("ide", pragmas.excludeIdeData);
  302. args: ["anObject"],
  303. source: "signal: anObject\x0a\x22Returns a Promise rejected with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.reject(x)})>",
  304. referencedClasses: [],
  305. //>>excludeEnd("ide");
  306. messageSends: []
  307. }),
  308. $globals.Promise.klass);
  309. $core.addMethod(
  310. $core.method({
  311. selector: "value:",
  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.resolve(x)});
  319. return self;
  320. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  321. }, function($ctx1) {$ctx1.fill(self,"value:",{anObject:anObject},$globals.Promise.klass)});
  322. //>>excludeEnd("ctx");
  323. },
  324. //>>excludeStart("ide", pragmas.excludeIdeData);
  325. args: ["anObject"],
  326. source: "value: anObject\x0a\x22Returns a Promise resolved with anObject.\x22\x0a<return $recv(anObject)._in_(function (x) {return Promise.resolve(x)})>",
  327. referencedClasses: [],
  328. //>>excludeEnd("ide");
  329. messageSends: []
  330. }),
  331. $globals.Promise.klass);
  332. $core.addMethod(
  333. $core.method({
  334. selector: "catch:",
  335. protocol: '*Kernel-Promises',
  336. fn: function (aBlock){
  337. var self=this;
  338. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  339. return $core.withContext(function($ctx1) {
  340. //>>excludeEnd("ctx");
  341. var js = self["@jsObject"];
  342. if (typeof js.then === "function")
  343. return $globals.Thenable.fn.prototype._catch_.call(js, aBlock);
  344. else
  345. return self._doesNotUnderstand_(
  346. $globals.Message._new()
  347. ._selector_("catch:")
  348. ._arguments_([aBlock])
  349. );
  350. return self;
  351. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  352. }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.JSObjectProxy)});
  353. //>>excludeEnd("ctx");
  354. },
  355. //>>excludeStart("ide", pragmas.excludeIdeData);
  356. args: ["aBlock"],
  357. 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 )>",
  358. referencedClasses: [],
  359. //>>excludeEnd("ide");
  360. messageSends: []
  361. }),
  362. $globals.JSObjectProxy);
  363. $core.addMethod(
  364. $core.method({
  365. selector: "on:do:",
  366. protocol: '*Kernel-Promises',
  367. fn: function (aClass,aBlock){
  368. var self=this;
  369. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  370. return $core.withContext(function($ctx1) {
  371. //>>excludeEnd("ctx");
  372. var js = self["@jsObject"];
  373. if (typeof js.then === "function")
  374. return $globals.Thenable.fn.prototype._on_do_.call(js, aClass, aBlock);
  375. else
  376. return self._doesNotUnderstand_(
  377. $globals.Message._new()
  378. ._selector_("on:do:")
  379. ._arguments_([aClass, aBlock])
  380. );
  381. return self;
  382. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  383. }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  384. //>>excludeEnd("ctx");
  385. },
  386. //>>excludeStart("ide", pragmas.excludeIdeData);
  387. args: ["aClass", "aBlock"],
  388. 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 )>",
  389. referencedClasses: [],
  390. //>>excludeEnd("ide");
  391. messageSends: []
  392. }),
  393. $globals.JSObjectProxy);
  394. $core.addMethod(
  395. $core.method({
  396. selector: "on:do:catch:",
  397. protocol: '*Kernel-Promises',
  398. fn: function (aClass,aBlock,anotherBlock){
  399. var self=this;
  400. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  401. return $core.withContext(function($ctx1) {
  402. //>>excludeEnd("ctx");
  403. var js = self["@jsObject"];
  404. if (typeof js.then === "function")
  405. return $globals.Thenable.fn.prototype._on_do_catch_.call(js, aClass, aBlock, anotherBlock);
  406. else
  407. return self._doesNotUnderstand_(
  408. $globals.Message._new()
  409. ._selector_("on:do:catch:")
  410. ._arguments_([aClass, aBlock, anotherBlock])
  411. );
  412. return self;
  413. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  414. }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  415. //>>excludeEnd("ctx");
  416. },
  417. //>>excludeStart("ide", pragmas.excludeIdeData);
  418. args: ["aClass", "aBlock", "anotherBlock"],
  419. 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 )>",
  420. referencedClasses: [],
  421. //>>excludeEnd("ide");
  422. messageSends: []
  423. }),
  424. $globals.JSObjectProxy);
  425. $core.addMethod(
  426. $core.method({
  427. selector: "then:",
  428. protocol: '*Kernel-Promises',
  429. fn: function (aBlockOrArray){
  430. var self=this;
  431. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  432. return $core.withContext(function($ctx1) {
  433. //>>excludeEnd("ctx");
  434. var js = self["@jsObject"];
  435. if (typeof js.then === "function")
  436. return $globals.Thenable.fn.prototype._then_.call(js, aBlockOrArray);
  437. else
  438. return self._doesNotUnderstand_(
  439. $globals.Message._new()
  440. ._selector_("then:")
  441. ._arguments_([aBlockOrArray])
  442. );
  443. return self;
  444. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  445. }, function($ctx1) {$ctx1.fill(self,"then:",{aBlockOrArray:aBlockOrArray},$globals.JSObjectProxy)});
  446. //>>excludeEnd("ctx");
  447. },
  448. //>>excludeStart("ide", pragmas.excludeIdeData);
  449. args: ["aBlockOrArray"],
  450. 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 )>",
  451. referencedClasses: [],
  452. //>>excludeEnd("ide");
  453. messageSends: []
  454. }),
  455. $globals.JSObjectProxy);
  456. $core.addMethod(
  457. $core.method({
  458. selector: "then:catch:",
  459. protocol: '*Kernel-Promises',
  460. fn: function (aBlockOrArray,anotherBlock){
  461. var self=this;
  462. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  463. return $core.withContext(function($ctx1) {
  464. //>>excludeEnd("ctx");
  465. var js = self["@jsObject"];
  466. if (typeof js.then === "function")
  467. return $globals.Thenable.fn.prototype._then_catch_.call(js, aBlockOrArray, anotherBlock);
  468. else
  469. return self._doesNotUnderstand_(
  470. $globals.Message._new()
  471. ._selector_("then:catch:")
  472. ._arguments_([aBlockOrArray, anotherBlock])
  473. );
  474. return self;
  475. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  476. }, function($ctx1) {$ctx1.fill(self,"then:catch:",{aBlockOrArray:aBlockOrArray,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  477. //>>excludeEnd("ctx");
  478. },
  479. //>>excludeStart("ide", pragmas.excludeIdeData);
  480. args: ["aBlockOrArray", "anotherBlock"],
  481. 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 )>",
  482. referencedClasses: [],
  483. //>>excludeEnd("ide");
  484. messageSends: []
  485. }),
  486. $globals.JSObjectProxy);
  487. $core.addMethod(
  488. $core.method({
  489. selector: "then:on:do:",
  490. protocol: '*Kernel-Promises',
  491. fn: function (aBlockOrArray,aClass,aBlock){
  492. var self=this;
  493. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  494. return $core.withContext(function($ctx1) {
  495. //>>excludeEnd("ctx");
  496. var js = self["@jsObject"];
  497. if (typeof js.then === "function")
  498. return $globals.Thenable.fn.prototype._then_on_do_.call(js, aBlockOrArray, aClass, aBlock);
  499. else
  500. return self._doesNotUnderstand_(
  501. $globals.Message._new()
  502. ._selector_("then:on:do:")
  503. ._arguments_([aBlockOrArray, aClass, aBlock])
  504. );
  505. return self;
  506. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  507. }, function($ctx1) {$ctx1.fill(self,"then:on:do:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
  508. //>>excludeEnd("ctx");
  509. },
  510. //>>excludeStart("ide", pragmas.excludeIdeData);
  511. args: ["aBlockOrArray", "aClass", "aBlock"],
  512. 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 )>",
  513. referencedClasses: [],
  514. //>>excludeEnd("ide");
  515. messageSends: []
  516. }),
  517. $globals.JSObjectProxy);
  518. $core.addMethod(
  519. $core.method({
  520. selector: "then:on:do:catch:",
  521. protocol: '*Kernel-Promises',
  522. fn: function (aBlockOrArray,aClass,aBlock,anotherBlock){
  523. var self=this;
  524. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  525. return $core.withContext(function($ctx1) {
  526. //>>excludeEnd("ctx");
  527. var js = self["@jsObject"];
  528. if (typeof js.then === "function")
  529. return $globals.Thenable.fn.prototype._then_on_do_catch_.call(js, aBlockOrArray, aClass, aBlock, anotherBlock);
  530. else
  531. return self._doesNotUnderstand_(
  532. $globals.Message._new()
  533. ._selector_("then:on:do:catch:")
  534. ._arguments_([aBlockOrArray, aClass, aBlock, anotherBlock])
  535. );
  536. return self;
  537. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  538. }, function($ctx1) {$ctx1.fill(self,"then:on:do:catch:",{aBlockOrArray:aBlockOrArray,aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
  539. //>>excludeEnd("ctx");
  540. },
  541. //>>excludeStart("ide", pragmas.excludeIdeData);
  542. args: ["aBlockOrArray", "aClass", "aBlock", "anotherBlock"],
  543. 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 )>",
  544. referencedClasses: [],
  545. //>>excludeEnd("ide");
  546. messageSends: []
  547. }),
  548. $globals.JSObjectProxy);
  549. });