Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/es-abstract/2018/SetValueInBuffer.js
r0c6b92a r79a0317 3 3 var GetIntrinsic = require('get-intrinsic'); 4 4 5 var $SyntaxError = require('es-errors/syntax'); 5 6 var $TypeError = require('es-errors/type'); 6 7 var $Uint8Array = GetIntrinsic('%Uint8Array%', true); 7 8 8 var isInteger = require(' ../helpers/isInteger');9 var isInteger = require('math-intrinsics/isInteger'); 9 10 10 11 var IsDetachedBuffer = require('./IsDetachedBuffer'); 11 var ToInt16 = require('./ToInt16'); 12 var ToInt32 = require('./ToInt32'); 13 var ToInt8 = require('./ToInt8'); 14 var ToUint16 = require('./ToUint16'); 15 var ToUint32 = require('./ToUint32'); 16 var ToUint8 = require('./ToUint8'); 17 var ToUint8Clamp = require('./ToUint8Clamp'); 12 var NumberToRawBytes = require('./NumberToRawBytes'); 18 13 19 14 var isArrayBuffer = require('is-array-buffer'); 15 var isSharedArrayBuffer = require('is-shared-array-buffer'); 20 16 var hasOwn = require('hasown'); 21 17 22 18 var tableTAO = require('./tables/typed-array-objects'); 23 19 24 var TypeToAO = {25 __proto__: null,26 Int8: ToInt8,27 Uint8: ToUint8,28 Uint8C: ToUint8Clamp,29 Int16: ToInt16,30 Uint16: ToUint16,31 Int32: ToInt32,32 Uint32: ToUint3233 };34 35 20 var defaultEndianness = require('../helpers/defaultEndianness'); 36 21 var forEach = require('../helpers/forEach'); 37 var integerToNBytes = require('../helpers/integerToNBytes');38 var valueToFloat32Bytes = require('../helpers/valueToFloat32Bytes');39 var valueToFloat64Bytes = require('../helpers/valueToFloat64Bytes');40 22 41 // https://262.ecma-international.org/ 6.0/#sec-setvalueinbuffer23 // https://262.ecma-international.org/8.0/#sec-setvalueinbuffer 42 24 43 module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) { 44 if (!isArrayBuffer(arrayBuffer)) { 45 throw new $TypeError('Assertion failed: `arrayBuffer` must be an ArrayBuffer'); 25 /* eslint max-params: 0 */ 26 27 module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, isTypedArray, order) { 28 var isSAB = isSharedArrayBuffer(arrayBuffer); 29 if (!isArrayBuffer(arrayBuffer) && !isSAB) { 30 throw new $TypeError('Assertion failed: `arrayBuffer` must be an ArrayBuffer or a SharedArrayBuffer'); 46 31 } 47 32 … … 58 43 } 59 44 60 if (arguments.length > 4 && typeof arguments[4] !== 'boolean') { 45 if (typeof isTypedArray !== 'boolean') { 46 throw new $TypeError('Assertion failed: `isTypedArray` must be a boolean'); 47 } 48 if (order !== 'SeqCst' && order !== 'Unordered' && order !== 'Init') { 49 throw new $TypeError('Assertion failed: `order` must be `"SeqCst"`, `"Unordered"`, or `"Init"`'); 50 } 51 52 if (arguments.length > 6 && typeof arguments[6] !== 'boolean') { 61 53 throw new $TypeError('Assertion failed: `isLittleEndian` must be a boolean, if present'); 62 54 } … … 74 66 // 4. Assert: Type(value) is Number. 75 67 76 // 5. Let block be arrayBuffer ’s [[ArrayBufferData]] internal slot.68 // 5. Let block be arrayBuffer.[[ArrayBufferData]]. 77 69 78 // 6. Assert: block is not undefined.70 var elementSize = tableTAO.size['$' + type]; // step 6 79 71 80 var elementSize = tableTAO.size['$' + type]; // step 7 81 if (!elementSize) { 82 throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); 72 // 7. If isLittleEndian is not present, set isLittleEndian to to the value of the [[LittleEndian]] field of the surrounding agent's Agent Record. 73 var isLittleEndian = arguments.length > 6 ? arguments[6] : defaultEndianness === 'little'; // step 8 74 75 var rawBytes = NumberToRawBytes(type, value, isLittleEndian); // step 8 76 77 if (isSAB) { // step 9 78 /* 79 Let execution be the [[CandidateExecution]] field of the surrounding agent's Agent Record. 80 Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier(). 81 If isTypedArray is true and IsNoTearConfiguration(type, order) is true, let noTear be true; otherwise let noTear be false. 82 Append WriteSharedMemory { [[Order]]: order, [[NoTear]]: noTear, [[Block]]: block, [[ByteIndex]]: byteIndex, [[ElementSize]]: elementSize, [[Payload]]: rawBytes } to eventList. 83 */ 84 throw new $SyntaxError('SharedArrayBuffer is not supported by this implementation'); 85 } else { 86 // 10. Store the individual bytes of rawBytes into block, in order, starting at block[byteIndex]. 87 var arr = new $Uint8Array(arrayBuffer, byteIndex, elementSize); 88 forEach(rawBytes, function (rawByte, i) { 89 arr[i] = rawByte; 90 }); 83 91 } 84 92 85 // 8. If isLittleEndian is not present, set isLittleEndian to either true or false. The choice is implementation dependent and should be the alternative that is most efficient for the implementation. An implementation must use the same value each time this step is executed and the same value must be used for the corresponding step in the GetValueFromBuffer abstract operation. 86 var isLittleEndian = arguments.length > 4 ? arguments[4] : defaultEndianness === 'little'; // step 8 87 88 var rawBytes; 89 if (type === 'Float32') { // step 1 90 rawBytes = valueToFloat32Bytes(value, isLittleEndian); 91 } else if (type === 'Float64') { // step 2 92 rawBytes = valueToFloat64Bytes(value, isLittleEndian); 93 } else { 94 var n = elementSize; // step 3.a 95 96 var convOp = TypeToAO[type]; // step 3.b 97 98 var intValue = convOp(value); // step 3.c 99 100 rawBytes = integerToNBytes(intValue, n, isLittleEndian); // step 3.d, 3.e, 4 101 } 102 103 // 12. Store the individual bytes of rawBytes into block, in order, starting at block[byteIndex]. 104 var arr = new $Uint8Array(arrayBuffer, byteIndex, elementSize); 105 forEach(rawBytes, function (rawByte, i) { 106 arr[i] = rawByte; 107 }); 108 109 // 13. Return NormalCompletion(undefined). 93 // 11. Return NormalCompletion(undefined). 110 94 };
Note:
See TracChangeset
for help on using the changeset viewer.