Kernel-Promises.js 24 KB

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