UNPKG

prepack

Version:

Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.

53 lines (38 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (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, _invariant2.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 }); }; var _index = require("../../values/index.js"); var _index2 = require("../../methods/index.js"); var _promise = require("../../methods/promise.js"); var _invariant = require("../../invariant.js"); var _invariant2 = _interopRequireDefault(_invariant); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } //# sourceMappingURL=PromisePrototype.js.map