|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"use strict"; |
|
var util = require("./util.js"); |
|
var ASSERT = require("./assert.js"); |
|
var isPrimitive = util.isPrimitive; |
|
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; |
|
|
|
module.exports = function(Promise) { |
|
var returner = function Promise$_returner() { |
|
return this; |
|
}; |
|
var thrower = function Promise$_thrower() { |
|
throw this; |
|
}; |
|
|
|
var wrapper = function Promise$_wrapper(value, action) { |
|
if (action === 1) { |
|
return function Promise$_thrower() { |
|
throw value; |
|
}; |
|
} |
|
else if (action === 2) { |
|
return function Promise$_returner() { |
|
return value; |
|
}; |
|
} |
|
}; |
|
|
|
|
|
Promise.prototype["return"] = |
|
Promise.prototype.thenReturn = |
|
function Promise$thenReturn(value) { |
|
if (wrapsPrimitiveReceiver && isPrimitive(value)) { |
|
return this._then( |
|
wrapper(value, 2), |
|
void 0, |
|
void 0, |
|
void 0, |
|
void 0, |
|
this.thenReturn |
|
); |
|
} |
|
return this._then(returner, void 0, void 0, |
|
value, void 0, this.thenReturn); |
|
}; |
|
|
|
Promise.prototype["throw"] = |
|
Promise.prototype.thenThrow = |
|
function Promise$thenThrow(reason) { |
|
if (wrapsPrimitiveReceiver && isPrimitive(reason)) { |
|
return this._then( |
|
wrapper(reason, 1), |
|
void 0, |
|
void 0, |
|
void 0, |
|
void 0, |
|
this.thenThrow |
|
); |
|
} |
|
return this._then(thrower, void 0, void 0, |
|
reason, void 0, this.thenThrow); |
|
}; |
|
}; |
|
|