123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- define("amber_core/Kernel-Promises", ["amber/boot", "amber_core/Kernel-Objects", "amber_core/Kernel-Infrastructure"], function($boot){"use strict";
- var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
- $core.addPackage('Kernel-Promises');
- $core.packages["Kernel-Promises"].innerEval = function (expr) { return eval(expr); };
- $core.packages["Kernel-Promises"].transport = {"type":"amd","amdNamespace":"amber_core"};
- $core.addClass('Thenable', $globals.Object, [], 'Kernel-Promises');
- //>>excludeStart("ide", pragmas.excludeIdeData);
- $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.";
- //>>excludeEnd("ide");
- $core.addMethod(
- $core.method({
- selector: "all:",
- protocol: 'promises',
- fn: function (nadicBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- return self.then(function (array) {
- return nadicBlock._valueWithPossibleArguments_(array);
- });
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"all:",{nadicBlock:nadicBlock},$globals.Thenable)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["nadicBlock"],
- source: "all: nadicBlock\x0a<return self.then(function (array) {\x0a return nadicBlock._valueWithPossibleArguments_(array);\x0a})>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.Thenable);
- $core.addMethod(
- $core.method({
- selector: "catch:",
- protocol: 'promises',
- fn: function (aBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- return self.then(null, function (err) {
- return aBlock._value_(err);
- });
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.Thenable)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aBlock"],
- source: "catch: aBlock\x0a<return self.then(null, function (err) {\x0a return aBlock._value_(err);\x0a})>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.Thenable);
- $core.addMethod(
- $core.method({
- selector: "on:do:",
- protocol: 'promises',
- fn: function (aClass,aBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- return self.then(null, function (err) {
- if (err._isKindOf_(aClass)) return aBlock._value_(err);
- else throw err;
- });
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.Thenable)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aClass", "aBlock"],
- source: "on: aClass do: aBlock\x0a<return self.then(null, function (err) {\x0a if (err._isKindOf_(aClass)) return aBlock._value_(err);\x0a else throw err;\x0a})>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.Thenable);
- $core.addMethod(
- $core.method({
- selector: "on:do:catch:",
- protocol: 'promises',
- fn: function (aClass,aBlock,anotherBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- return self.then(null, function (err) {
- try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }
- return anotherBlock._value_(err);
- });
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.Thenable)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aClass", "aBlock", "anotherBlock"],
- source: "on: aClass do: aBlock catch: anotherBlock\x0a<return self.then(null, function (err) {\x0a try { if (err._isKindOf_(aClass)) return aBlock._value_(err); } catch (e) { err = e; }\x0a return anotherBlock._value_(err);\x0a})>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.Thenable);
- $core.addMethod(
- $core.method({
- selector: "then:",
- protocol: 'promises',
- fn: function (aBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- return self.then(function (result) {
- return aBlock._value_(result);
- });
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"then:",{aBlock:aBlock},$globals.Thenable)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aBlock"],
- source: "then: aBlock\x0a<return self.then(function (result) {\x0a return aBlock._value_(result);\x0a})>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.Thenable);
- $core.addClass('Promise', $globals.Thenable, [], 'Kernel-Promises');
- $core.addMethod(
- $core.method({
- selector: "all:",
- protocol: '*Kernel-Promises',
- fn: function (nadicBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var js = self["@jsObject"];
- if (typeof js.then === "function")
- return $globals.Thenable.fn.prototype._all_.call(js, nadicBlock);
- else
- return self._doesNotUnderstand_(
- $globals.Message._new()
- ._selector_("all:")
- ._arguments_([nadicBlock])
- );
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"all:",{nadicBlock:nadicBlock},$globals.JSObjectProxy)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["nadicBlock"],
- source: "all: nadicBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._all_.call(js, nadicBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22all:\x22)\x0a ._arguments_([nadicBlock])\x0a )>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.JSObjectProxy);
- $core.addMethod(
- $core.method({
- selector: "catch:",
- protocol: '*Kernel-Promises',
- fn: function (aBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var js = self["@jsObject"];
- if (typeof js.then === "function")
- return $globals.Thenable.fn.prototype._catch_.call(js, aBlock);
- else
- return self._doesNotUnderstand_(
- $globals.Message._new()
- ._selector_("catch:")
- ._arguments_([aBlock])
- );
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"catch:",{aBlock:aBlock},$globals.JSObjectProxy)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aBlock"],
- 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 )>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.JSObjectProxy);
- $core.addMethod(
- $core.method({
- selector: "on:do:",
- protocol: '*Kernel-Promises',
- fn: function (aClass,aBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var js = self["@jsObject"];
- if (typeof js.then === "function")
- return $globals.Thenable.fn.prototype._on_do_.call(js, aClass, aBlock);
- else
- return self._doesNotUnderstand_(
- $globals.Message._new()
- ._selector_("on:do:")
- ._arguments_([aClass, aBlock])
- );
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"on:do:",{aClass:aClass,aBlock:aBlock},$globals.JSObjectProxy)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aClass", "aBlock"],
- 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 )>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.JSObjectProxy);
- $core.addMethod(
- $core.method({
- selector: "on:do:catch:",
- protocol: '*Kernel-Promises',
- fn: function (aClass,aBlock,anotherBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var js = self["@jsObject"];
- if (typeof js.then === "function")
- return $globals.Thenable.fn.prototype._on_do_catch_.call(js, aClass, aBlock, anotherBlock);
- else
- return self._doesNotUnderstand_(
- $globals.Message._new()
- ._selector_("on:do:catch:")
- ._arguments_([aClass, aBlock, anotherBlock])
- );
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"on:do:catch:",{aClass:aClass,aBlock:aBlock,anotherBlock:anotherBlock},$globals.JSObjectProxy)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aClass", "aBlock", "anotherBlock"],
- 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 )>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.JSObjectProxy);
- $core.addMethod(
- $core.method({
- selector: "then:",
- protocol: '*Kernel-Promises',
- fn: function (aBlock){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var js = self["@jsObject"];
- if (typeof js.then === "function")
- return $globals.Thenable.fn.prototype._then_.call(js, aBlock);
- else
- return self._doesNotUnderstand_(
- $globals.Message._new()
- ._selector_("then:")
- ._arguments_([aBlock])
- );
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"then:",{aBlock:aBlock},$globals.JSObjectProxy)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["aBlock"],
- source: "then: aBlock\x0a<var js = self[\x22@jsObject\x22];\x0aif (typeof js.then === \x22function\x22)\x0a return $globals.Thenable.fn.prototype._then_.call(js, aBlock);\x0aelse\x0a return self._doesNotUnderstand_(\x0a $globals.Message._new()\x0a ._selector_(\x22then:\x22)\x0a ._arguments_([aBlock])\x0a )>",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: []
- }),
- $globals.JSObjectProxy);
- });
|