Promise.prototype.rawDispatch = function Promise_rawDispatch(resolve, op, args) {
var self = this;
asap(function Promise_dispatch_task() {
Promise_getHandler(self).dispatch(resolve, op, args);
});
};
Promise.prototype.dispatch = function Promise_dispatch(op, args) {
var deferred = Promise_defer();
this.rawDispatch(deferred.resolve, op, args);
return deferred.promise;
};
Promise.prototype.get = function Promise_get(name) {
return this.dispatch("get", [name]);
};
Promise.prototype.invoke = function Promise_invoke(name ) {
var args = new Array(arguments.length - 1);
for (var index = 1; index < arguments.length; index++) {
args[index - 1] = arguments[index];
}
return this.dispatch("invoke", [name, args]);
};
Promise.prototype.apply = function Promise_apply(thisp, args) {
return this.dispatch("call", [args, thisp]);
};
Promise.prototype.call = function Promise_call(thisp ) {
var args = new Array(Math.max(0, arguments.length - 1));
for (var index = 1; index < arguments.length; index++) {
args[index - 1] = arguments[index];
}
return this.dispatch("call", [args, thisp]);
};
Promise.prototype.bind = function Promise_bind(thisp ) {
var self = this;
var args = new Array(Math.max(0, arguments.length - 1));
for (var index = 1; index < arguments.length; index++) {
args[index - 1] = arguments[index];
}
return function Promise_bind_bound() {
var boundArgs = args.slice();
for (var index = 0; index < arguments.length; index++) {
boundArgs[boundArgs.length] = arguments[index];
}
return self.dispatch("call", [boundArgs, thisp]);
};
};
Promise.prototype.keys = function Promise_keys() {
return this.dispatch("keys", []);
};
Promise.prototype.iterate = function Promise_iterate() {
return this.dispatch("iterate", []);
};