Ignore:
Timestamp:
01/21/25 03:08:24 (3 days ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
0c6b92a
Message:

F4 Finalna Verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/es-abstract/2018/SetValueInBuffer.js

    r0c6b92a r79a0317  
    33var GetIntrinsic = require('get-intrinsic');
    44
     5var $SyntaxError = require('es-errors/syntax');
    56var $TypeError = require('es-errors/type');
    67var $Uint8Array = GetIntrinsic('%Uint8Array%', true);
    78
    8 var isInteger = require('../helpers/isInteger');
     9var isInteger = require('math-intrinsics/isInteger');
    910
    1011var 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');
     12var NumberToRawBytes = require('./NumberToRawBytes');
    1813
    1914var isArrayBuffer = require('is-array-buffer');
     15var isSharedArrayBuffer = require('is-shared-array-buffer');
    2016var hasOwn = require('hasown');
    2117
    2218var tableTAO = require('./tables/typed-array-objects');
    2319
    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: ToUint32
    33 };
    34 
    3520var defaultEndianness = require('../helpers/defaultEndianness');
    3621var forEach = require('../helpers/forEach');
    37 var integerToNBytes = require('../helpers/integerToNBytes');
    38 var valueToFloat32Bytes = require('../helpers/valueToFloat32Bytes');
    39 var valueToFloat64Bytes = require('../helpers/valueToFloat64Bytes');
    4022
    41 // https://262.ecma-international.org/6.0/#sec-setvalueinbuffer
     23// https://262.ecma-international.org/8.0/#sec-setvalueinbuffer
    4224
    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
     27module.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');
    4631        }
    4732
     
    5843        }
    5944
    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') {
    6153                throw new $TypeError('Assertion failed: `isLittleEndian` must be a boolean, if present');
    6254        }
     
    7466        // 4. Assert: Type(value) is Number.
    7567
    76         // 5. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot.
     68        // 5. Let block be arrayBuffer.[[ArrayBufferData]].
    7769
    78         // 6. Assert: block is not undefined.
     70        var elementSize = tableTAO.size['$' + type]; // step 6
    7971
    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                });
    8391        }
    8492
    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).
    11094};
Note: See TracChangeset for help on using the changeset viewer.