UNPKG

prepack

Version:

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

101 lines (69 loc) 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _index = require("../../methods/index.js"); var _index2 = require("../../values/index.js"); var _singletons = require("../../singletons.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) { // ECMA262 24.2.2.1 let func = new _index2.NativeFunctionValue(realm, "DataView", "DataView", 3, (context, [_buffer, byteOffset, byteLength], argCount, NewTarget) => { let buffer = _buffer; // 1. If NewTarget is undefined, throw a TypeError exception. if (!NewTarget) { throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError); } buffer = buffer.throwIfNotConcrete(); // 2. If Type(buffer) is not Object, throw a TypeError exception. if (!(buffer instanceof _index2.ObjectValue)) { throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError); } // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. if (!("$ArrayBufferData" in buffer)) { throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError); } // 4. Let offset be ? ToIndex(byteOffset). let offset = _singletons.To.ToIndexPartial(realm, byteOffset); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if ((0, _index.IsDetachedBuffer)(realm, buffer)) { throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError); } // 6. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]] internal slot. let bufferByteLength = buffer.$ArrayBufferByteLength; (0, _invariant.default)(typeof bufferByteLength === "number"); // 7. If offset > bufferByteLength, throw a RangeError exception. if (offset > bufferByteLength) { throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError); } // 8. If byteLength is undefined, then let viewByteLength; if (!byteLength || byteLength instanceof _index2.UndefinedValue) { // a. Let viewByteLength be bufferByteLength - offset. viewByteLength = bufferByteLength - offset; } else { // 9. Else, // a. Let viewByteLength be ? ToIndex(byteLength). viewByteLength = _singletons.To.ToIndexPartial(realm, byteLength); // b. If offset+viewByteLength > bufferByteLength, throw a RangeError exception. if (offset + viewByteLength > bufferByteLength) { throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError); } } // 10. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). let O = _singletons.Create.OrdinaryCreateFromConstructor(realm, NewTarget, "DataViewPrototype", { $DataView: undefined, $ViewedArrayBuffer: undefined, $ByteLength: undefined, $ByteOffset: undefined }); // 11. Set O's [[DataView]] internal slot to true. O.$DataView = true; // 12. Set O's [[ViewedArrayBuffer]] internal slot to buffer. O.$ViewedArrayBuffer = buffer; // 13. Set O's [[ByteLength]] internal slot to viewByteLength. O.$ByteLength = viewByteLength; // 14. Set O's [[ByteOffset]] internal slot to offset. O.$ByteOffset = offset; // 15. Return O. return O; }); return func; } //# sourceMappingURL=DataView.js.map