prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
58 lines (42 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _index = require("../../values/index.js");
var _index2 = require("../../methods/index.js");
var _promise = require("../../methods/promise.js");
var _invariant = _interopRequireDefault(require("../../invariant.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* strict-local */
function _default(realm, obj) {
// ECMA262 25.4.5.1
obj.defineNativeMethod("catch", 1, (context, [onRejected]) => {
// 1. Let promise be the this value.
let promise = context; // 2. Return ? Invoke(promise, "then", « undefined, onRejected »).
return (0, _index2.Invoke)(realm, promise, "then", [realm.intrinsics.undefined, onRejected]);
}); // ECMA262 25.4.5.3
obj.defineNativeMethod("then", 2, (context, [onFulfilled, onRejected]) => {
// 1. Let promise be the this value.
let promise = context; // 2. If IsPromise(promise) is false, throw a TypeError exception.
if (!(0, _index2.IsPromise)(realm, promise)) {
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
}
(0, _invariant.default)(promise instanceof _index.ObjectValue); // 3. Let C be ? SpeciesConstructor(promise, %Promise%).
let C = (0, _index2.SpeciesConstructor)(realm, promise, realm.intrinsics.Promise); // 4. Let resultCapability be ? NewPromiseCapability(C).
let resultCapability = (0, _promise.NewPromiseCapability)(realm, C); // 5. Return PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability).
return (0, _promise.PerformPromiseThen)(realm, promise, onFulfilled, onRejected, resultCapability);
}); // ECMA262 25.4.5.4 Promise.prototype [ @@toStringTag ]
obj.defineNativeProperty(realm.intrinsics.SymbolToStringTag, new _index.StringValue(realm, "Promise"), {
writable: false
});
}
//# sourceMappingURL=PromisePrototype.js.map