PromisePrototype.js [plain text]
function catch(onRejected)
{
"use strict";
return this.then(@undefined, onRejected);
}
function then(onFulfilled, onRejected)
{
"use strict";
if (!@isPromise(this))
@throwTypeError("|this| is not a Promise");
var constructor = @speciesConstructor(this, @Promise);
var promise;
var promiseOrCapability;
if (constructor === @Promise) {
promiseOrCapability = @newPromise();
promise = promiseOrCapability;
} else {
promiseOrCapability = @newPromiseCapabilitySlow(constructor);
promise = promiseOrCapability.@promise;
}
@performPromiseThen(this, onFulfilled, onRejected, promiseOrCapability);
return promise;
}
function finally(onFinally)
{
"use strict";
if (!@isObject(this))
@throwTypeError("|this| is not an object");
var constructor = @speciesConstructor(this, @Promise);
@assert(@isConstructor(constructor));
var thenFinally;
var catchFinally;
if (!@isCallable(onFinally)) {
thenFinally = onFinally;
catchFinally = onFinally;
} else {
thenFinally = (0, (value) => {
@assert(@isCallable(onFinally));
var result = onFinally();
@assert(@isConstructor(constructor));
var promise = @promiseResolve(constructor, result);
return promise.then(() => value);
});
catchFinally = (0, (reason) => {
@assert(@isCallable(onFinally));
var result = onFinally();
@assert(@isConstructor(constructor));
var promise = @promiseResolve(constructor, result);
return promise.then(() => { throw reason; });
});
}
return this.then(thenFinally, catchFinally);
}