diff --git a/.gitattributes b/.gitattributes index e8352856..4efca1ae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -167,6 +167,7 @@ /2016/min.js spackled linguist-generated=true /2016/modulo.js spackled linguist-generated=true /2016/msFromTime.js spackled linguist-generated=true +/2016/tables/typed-array-objects.js spackled linguist-generated=true /2016/thisBooleanValue.js spackled linguist-generated=true /2016/thisNumberValue.js spackled linguist-generated=true /2016/thisStringValue.js spackled linguist-generated=true @@ -439,6 +440,7 @@ /2018/min.js spackled linguist-generated=true /2018/modulo.js spackled linguist-generated=true /2018/msFromTime.js spackled linguist-generated=true +/2018/tables/typed-array-objects.js spackled linguist-generated=true /2018/thisBooleanValue.js spackled linguist-generated=true /2018/thisNumberValue.js spackled linguist-generated=true /2018/thisStringValue.js spackled linguist-generated=true @@ -914,6 +916,7 @@ /2021/min.js spackled linguist-generated=true /2021/modulo.js spackled linguist-generated=true /2021/msFromTime.js spackled linguist-generated=true +/2021/tables/typed-array-objects.js spackled linguist-generated=true /2021/thisBigIntValue.js spackled linguist-generated=true /2021/thisBooleanValue.js spackled linguist-generated=true /2021/thisNumberValue.js spackled linguist-generated=true @@ -1134,6 +1137,7 @@ /2022/modulo.js spackled linguist-generated=true /2022/msFromTime.js spackled linguist-generated=true /2022/substring.js spackled linguist-generated=true +/2022/tables/typed-array-objects.js spackled linguist-generated=true /2022/thisBigIntValue.js spackled linguist-generated=true /2022/thisBooleanValue.js spackled linguist-generated=true /2022/thisNumberValue.js spackled linguist-generated=true @@ -1350,6 +1354,7 @@ /2023/modulo.js spackled linguist-generated=true /2023/msFromTime.js spackled linguist-generated=true /2023/substring.js spackled linguist-generated=true +/2023/tables/typed-array-objects.js spackled linguist-generated=true /2023/thisBigIntValue.js spackled linguist-generated=true /2023/thisBooleanValue.js spackled linguist-generated=true /2023/thisNumberValue.js spackled linguist-generated=true diff --git a/2015/GetValueFromBuffer.js b/2015/GetValueFromBuffer.js index a9b9e275..76bf970d 100644 --- a/2015/GetValueFromBuffer.js +++ b/2015/GetValueFromBuffer.js @@ -22,18 +22,7 @@ var IsDetachedBuffer = require('./IsDetachedBuffer'); var isArrayBuffer = require('is-array-buffer'); var safeConcat = require('safe-array-concat'); -var table49 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var isUnsignedElementType = function isUnsignedElementType(type) { return $charAt(type, 0) === 'U'; }; @@ -68,7 +57,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type) { // 4. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot. - var elementSize = table49['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } diff --git a/2015/SetValueInBuffer.js b/2015/SetValueInBuffer.js index 7a2dac35..ec9a797d 100644 --- a/2015/SetValueInBuffer.js +++ b/2015/SetValueInBuffer.js @@ -16,18 +16,7 @@ var ToUint8Clamp = require('./ToUint8Clamp'); var isArrayBuffer = require('is-array-buffer'); var hasOwn = require('hasown'); -var table49 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var TypeToAO = { __proto__: null, @@ -57,7 +46,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || !hasOwn(table49, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -85,7 +74,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) // 6. Assert: block is not undefined. - var elementSize = table49[type]; // step 7 + var elementSize = tableTAO.size['$' + type]; // step 7 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } @@ -99,7 +88,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) } else if (type === 'Float64') { // step 2 rawBytes = valueToFloat64Bytes(value, isLittleEndian); } else { - var n = table49[type]; // step 3.a + var n = elementSize; // step 3.a var convOp = TypeToAO[type]; // step 3.b diff --git a/2015/tables/typed-array-objects.js b/2015/tables/typed-array-objects.js new file mode 100644 index 00000000..4b254b22 --- /dev/null +++ b/2015/tables/typed-array-objects.js @@ -0,0 +1,31 @@ +'use strict'; + +// https://262.ecma-international.org/6.0/#table-49 + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2016/GetValueFromBuffer.js b/2016/GetValueFromBuffer.js index a9b9e275..76bf970d 100644 --- a/2016/GetValueFromBuffer.js +++ b/2016/GetValueFromBuffer.js @@ -22,18 +22,7 @@ var IsDetachedBuffer = require('./IsDetachedBuffer'); var isArrayBuffer = require('is-array-buffer'); var safeConcat = require('safe-array-concat'); -var table49 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var isUnsignedElementType = function isUnsignedElementType(type) { return $charAt(type, 0) === 'U'; }; @@ -68,7 +57,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type) { // 4. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot. - var elementSize = table49['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } diff --git a/2016/SetValueInBuffer.js b/2016/SetValueInBuffer.js index 7a2dac35..ec9a797d 100644 --- a/2016/SetValueInBuffer.js +++ b/2016/SetValueInBuffer.js @@ -16,18 +16,7 @@ var ToUint8Clamp = require('./ToUint8Clamp'); var isArrayBuffer = require('is-array-buffer'); var hasOwn = require('hasown'); -var table49 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var TypeToAO = { __proto__: null, @@ -57,7 +46,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || !hasOwn(table49, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -85,7 +74,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) // 6. Assert: block is not undefined. - var elementSize = table49[type]; // step 7 + var elementSize = tableTAO.size['$' + type]; // step 7 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } @@ -99,7 +88,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) } else if (type === 'Float64') { // step 2 rawBytes = valueToFloat64Bytes(value, isLittleEndian); } else { - var n = table49[type]; // step 3.a + var n = elementSize; // step 3.a var convOp = TypeToAO[type]; // step 3.b diff --git a/2016/tables/typed-array-objects.js b/2016/tables/typed-array-objects.js new file mode 100644 index 00000000..4b254b22 --- /dev/null +++ b/2016/tables/typed-array-objects.js @@ -0,0 +1,31 @@ +'use strict'; + +// https://262.ecma-international.org/6.0/#table-49 + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2017/GetValueFromBuffer.js b/2017/GetValueFromBuffer.js index 537d7123..91ac9f3e 100644 --- a/2017/GetValueFromBuffer.js +++ b/2017/GetValueFromBuffer.js @@ -19,18 +19,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table50 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -74,7 +63,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table50['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } diff --git a/2017/SetValueInBuffer.js b/2017/SetValueInBuffer.js index 7a2dac35..ec9a797d 100644 --- a/2017/SetValueInBuffer.js +++ b/2017/SetValueInBuffer.js @@ -16,18 +16,7 @@ var ToUint8Clamp = require('./ToUint8Clamp'); var isArrayBuffer = require('is-array-buffer'); var hasOwn = require('hasown'); -var table49 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var TypeToAO = { __proto__: null, @@ -57,7 +46,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || !hasOwn(table49, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -85,7 +74,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) // 6. Assert: block is not undefined. - var elementSize = table49[type]; // step 7 + var elementSize = tableTAO.size['$' + type]; // step 7 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } @@ -99,7 +88,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) } else if (type === 'Float64') { // step 2 rawBytes = valueToFloat64Bytes(value, isLittleEndian); } else { - var n = table49[type]; // step 3.a + var n = elementSize; // step 3.a var convOp = TypeToAO[type]; // step 3.b diff --git a/2017/tables/typed-array-objects.js b/2017/tables/typed-array-objects.js new file mode 100644 index 00000000..dc8692a6 --- /dev/null +++ b/2017/tables/typed-array-objects.js @@ -0,0 +1,31 @@ +'use strict'; + +// https://262.ecma-international.org/8.0/#table-59 + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2018/GetValueFromBuffer.js b/2018/GetValueFromBuffer.js index 537d7123..91ac9f3e 100644 --- a/2018/GetValueFromBuffer.js +++ b/2018/GetValueFromBuffer.js @@ -19,18 +19,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table50 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -74,7 +63,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table50['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } diff --git a/2018/SetValueInBuffer.js b/2018/SetValueInBuffer.js index 7a2dac35..ec9a797d 100644 --- a/2018/SetValueInBuffer.js +++ b/2018/SetValueInBuffer.js @@ -16,18 +16,7 @@ var ToUint8Clamp = require('./ToUint8Clamp'); var isArrayBuffer = require('is-array-buffer'); var hasOwn = require('hasown'); -var table49 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var TypeToAO = { __proto__: null, @@ -57,7 +46,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || !hasOwn(table49, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -85,7 +74,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) // 6. Assert: block is not undefined. - var elementSize = table49[type]; // step 7 + var elementSize = tableTAO.size['$' + type]; // step 7 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } @@ -99,7 +88,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) } else if (type === 'Float64') { // step 2 rawBytes = valueToFloat64Bytes(value, isLittleEndian); } else { - var n = table49[type]; // step 3.a + var n = elementSize; // step 3.a var convOp = TypeToAO[type]; // step 3.b diff --git a/2018/tables/typed-array-objects.js b/2018/tables/typed-array-objects.js new file mode 100644 index 00000000..dc8692a6 --- /dev/null +++ b/2018/tables/typed-array-objects.js @@ -0,0 +1,31 @@ +'use strict'; + +// https://262.ecma-international.org/8.0/#table-59 + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2019/GetValueFromBuffer.js b/2019/GetValueFromBuffer.js index 909e3a5b..36d5b423 100644 --- a/2019/GetValueFromBuffer.js +++ b/2019/GetValueFromBuffer.js @@ -18,18 +18,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table59 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -73,7 +62,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table59['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } diff --git a/2019/SetValueInBuffer.js b/2019/SetValueInBuffer.js index 7a2dac35..ec9a797d 100644 --- a/2019/SetValueInBuffer.js +++ b/2019/SetValueInBuffer.js @@ -16,18 +16,7 @@ var ToUint8Clamp = require('./ToUint8Clamp'); var isArrayBuffer = require('is-array-buffer'); var hasOwn = require('hasown'); -var table49 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var TypeToAO = { __proto__: null, @@ -57,7 +46,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || !hasOwn(table49, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -85,7 +74,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) // 6. Assert: block is not undefined. - var elementSize = table49[type]; // step 7 + var elementSize = tableTAO.size['$' + type]; // step 7 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "Float32", or "Float64"'); } @@ -99,7 +88,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value) } else if (type === 'Float64') { // step 2 rawBytes = valueToFloat64Bytes(value, isLittleEndian); } else { - var n = table49[type]; // step 3.a + var n = elementSize; // step 3.a var convOp = TypeToAO[type]; // step 3.b diff --git a/2019/tables/typed-array-objects.js b/2019/tables/typed-array-objects.js new file mode 100644 index 00000000..1a2707c0 --- /dev/null +++ b/2019/tables/typed-array-objects.js @@ -0,0 +1,31 @@ +'use strict'; + +// https://262.ecma-international.org/10.0/#table-49 + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2020/GetValueFromBuffer.js b/2020/GetValueFromBuffer.js index d83678a8..f46d3f16 100644 --- a/2020/GetValueFromBuffer.js +++ b/2020/GetValueFromBuffer.js @@ -19,20 +19,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table61 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $BigInt64: 8, - $BigUint64: 8, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -48,7 +35,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || typeof table61['$' + type] !== 'number') { + if (typeof type !== 'string' || typeof tableTAO.size['$' + type] !== 'number') { throw new $TypeError('Assertion failed: `type` must be a Typed Array element type'); } @@ -76,7 +63,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table61['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "BigInt64", "BigUint64", "Float32", or "Float64"'); } diff --git a/2020/SetValueInBuffer.js b/2020/SetValueInBuffer.js index 52a57bd2..3eebc55a 100644 --- a/2020/SetValueInBuffer.js +++ b/2020/SetValueInBuffer.js @@ -13,20 +13,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var hasOwn = require('hasown'); -var table61 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - BigInt64: 8, - BigUint64: 8, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); var forEach = require('../helpers/forEach'); @@ -45,7 +32,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || !hasOwn(table61, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -80,7 +67,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, // 5. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot. - var elementSize = table61[type]; // step 6 + var elementSize = tableTAO.size['$' + type]; // step 6 // 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. var isLittleEndian = arguments.length > 6 ? arguments[6] : defaultEndianness === 'little'; // step 8 diff --git a/2020/tables/typed-array-objects.js b/2020/tables/typed-array-objects.js new file mode 100644 index 00000000..d5d48475 --- /dev/null +++ b/2020/tables/typed-array-objects.js @@ -0,0 +1,35 @@ +'use strict'; + +// https://262.ecma-international.org/11.0/#table-the-typedarray-constructors + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $BigInt64Array: 'BigInt64', + $BigUint64Array: 'BigUint64', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $BigInt64: 8, + $BigUint64: 8, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2021/GetValueFromBuffer.js b/2021/GetValueFromBuffer.js index d83678a8..f46d3f16 100644 --- a/2021/GetValueFromBuffer.js +++ b/2021/GetValueFromBuffer.js @@ -19,20 +19,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table61 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $BigInt64: 8, - $BigUint64: 8, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -48,7 +35,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || typeof table61['$' + type] !== 'number') { + if (typeof type !== 'string' || typeof tableTAO.size['$' + type] !== 'number') { throw new $TypeError('Assertion failed: `type` must be a Typed Array element type'); } @@ -76,7 +63,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table61['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "BigInt64", "BigUint64", "Float32", or "Float64"'); } diff --git a/2021/SetTypedArrayFromArrayLike.js b/2021/SetTypedArrayFromArrayLike.js index 1466b317..50d3a7a8 100644 --- a/2021/SetTypedArrayFromArrayLike.js +++ b/2021/SetTypedArrayFromArrayLike.js @@ -21,35 +21,7 @@ var ToNumber = require('./ToNumber'); var ToObject = require('./ToObject'); var ToString = require('./ToString'); -var table60Sizes = { - __proto__: null, - $Int8Array: 1, - $Uint8Array: 1, - $Uint8ClampedArray: 1, - $Int16Array: 2, - $Uint16Array: 2, - $Int32Array: 4, - $Uint32Array: 4, - $BigInt64Array: 8, - $BigUint64Array: 8, - $Float32Array: 4, - $Float64Array: 8 -}; - -var table60Types = { - __proto__: null, - $Int8Array: 'Int8', - $Uint8Array: 'Uint8', - $Uint8ClampedArray: 'Uint8C', - $Int16Array: 'Int16', - $Uint16Array: 'Uint16', - $Int32Array: 'Int32', - $Uint32Array: 'Uint32', - $BigInt64Array: 'BigInt64', - $BigUint64Array: 'BigUint64', - $Float32Array: 'Float32', - $Float64Array: 'Float64' -}; +var tableTAO = require('./tables/typed-array-objects'); // https://262.ecma-international.org/12.0/#sec-settypedarrayfromarraylike @@ -77,9 +49,9 @@ module.exports = function SetTypedArrayFromArrayLike(target, targetOffset, sourc var targetName = whichTarget; // step 5 - var targetElementSize = table60Sizes['$' + targetName]; // step 6 + var targetType = tableTAO.name['$' + targetName]; // step 7 - var targetType = table60Types['$' + targetName]; // step 7 + var targetElementSize = tableTAO.size['$' + targetType]; // step 6 var targetByteOffset = typedArrayByteOffset(target); // step 8 diff --git a/2021/SetTypedArrayFromTypedArray.js b/2021/SetTypedArrayFromTypedArray.js index f9c62f0a..62e04755 100644 --- a/2021/SetTypedArrayFromTypedArray.js +++ b/2021/SetTypedArrayFromTypedArray.js @@ -22,35 +22,7 @@ var IsSharedArrayBuffer = require('./IsSharedArrayBuffer'); var SameValue = require('./SameValue'); var SetValueInBuffer = require('./SetValueInBuffer'); -var table60Sizes = { - __proto__: null, - $Int8Array: 1, - $Uint8Array: 1, - $Uint8ClampedArray: 1, - $Int16Array: 2, - $Uint16Array: 2, - $Int32Array: 4, - $Uint32Array: 4, - $BigInt64Array: 8, - $BigUint64Array: 8, - $Float32Array: 4, - $Float64Array: 8 -}; - -var table60Types = { - __proto__: null, - $Int8Array: 'Int8', - $Uint8Array: 'Uint8', - $Uint8ClampedArray: 'Uint8C', - $Int16Array: 'Int16', - $Uint16Array: 'Uint16', - $Int32Array: 'Int32', - $Uint32Array: 'Uint32', - $BigInt64Array: 'BigInt64', - $BigUint64Array: 'BigUint64', - $Float32Array: 'Float32', - $Float64Array: 'Float64' -}; +var tableTAO = require('./tables/typed-array-objects'); // https://262.ecma-international.org/12.0/#sec-settypedarrayfromtypedarray @@ -85,17 +57,17 @@ module.exports = function SetTypedArrayFromTypedArray(target, targetOffset, sour var targetName = whichTarget; // step 7 - var targetType = table60Types['$' + targetName]; // step 8 + var targetType = tableTAO.name['$' + targetName]; // step 8 - var targetElementSize = table60Sizes['$' + targetName]; // step 9 + var targetElementSize = tableTAO.size['$' + targetType]; // step 9 var targetByteOffset = typedArrayByteOffset(target); // step 10 var srcName = whichSource; // step 11 - var srcType = table60Types['$' + srcName]; // step 12 + var srcType = tableTAO.name['$' + srcName]; // step 12 - var srcElementSize = table60Sizes['$' + srcName]; // step 13 + var srcElementSize = tableTAO.size['$' + srcName]; // step 13 var srcLength = typedArrayLength(source); // step 14 diff --git a/2021/SetValueInBuffer.js b/2021/SetValueInBuffer.js index 1cbe93cd..e1bb8c02 100644 --- a/2021/SetValueInBuffer.js +++ b/2021/SetValueInBuffer.js @@ -13,20 +13,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var hasOwn = require('hasown'); -var table60 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - BigInt64: 8, - BigUint64: 8, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); var forEach = require('../helpers/forEach'); @@ -45,7 +32,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, throw new $TypeError('Assertion failed: `byteIndex` must be a non-negative integer'); } - if (typeof type !== 'string' || !hasOwn(table60, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -76,7 +63,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, // 4. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot. - var elementSize = table60[type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 // 6. 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. var isLittleEndian = arguments.length > 6 ? arguments[6] : defaultEndianness === 'little'; // step 6 diff --git a/2021/ValidateAtomicAccess.js b/2021/ValidateAtomicAccess.js index da0bb3ef..88981f05 100644 --- a/2021/ValidateAtomicAccess.js +++ b/2021/ValidateAtomicAccess.js @@ -10,20 +10,7 @@ var typedArrayByteOffset = require('typed-array-byte-offset'); var typedArrayLength = require('typed-array-length'); var whichTypedArray = require('which-typed-array'); -var table60 = { - __proto__: null, - $Int8Array: 1, - $Uint8Array: 1, - $Uint8ClampedArray: 1, - $Int16Array: 2, - $Uint16Array: 2, - $Int32Array: 4, - $Uint32Array: 4, - $BigInt64Array: 8, - $BigUint64Array: 8, - $Float32Array: 4, - $Float64Array: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); // https://262.ecma-international.org/12.0/#sec-validateatomicaccess @@ -49,7 +36,8 @@ module.exports = function ValidateAtomicAccess(typedArray, requestIndex) { var arrayTypeName = whichTypedArray(typedArray); // step 6 - var elementSize = table60['$' + arrayTypeName]; // step 7 + var taType = tableTAO.name['$' + arrayTypeName]; + var elementSize = tableTAO.size['$' + taType]; // step 7 var offset = typedArrayByteOffset(typedArray); // step 8 diff --git a/2021/ValidateIntegerTypedArray.js b/2021/ValidateIntegerTypedArray.js index 93ed10c1..3289853c 100644 --- a/2021/ValidateIntegerTypedArray.js +++ b/2021/ValidateIntegerTypedArray.js @@ -10,20 +10,7 @@ var whichTypedArray = require('which-typed-array'); // https://262.ecma-international.org/12.0/#sec-validateintegertypedarray -var table60 = { - __proto__: null, - $Int8Array: 'Int8', - $Uint8Array: 'Uint8', - $Uint8ClampedArray: 'Uint8C', - $Int16Array: 'Int16', - $Uint16Array: 'Uint16', - $Int32Array: 'Int32', - $Uint32Array: 'Uint32', - $BigInt64Array: 'BigInt64', - $BigUint64Array: 'BigUint64', - $Float32Array: 'Float32', - $Float64Array: 'Float64' -}; +var tableTAO = require('./tables/typed-array-objects'); module.exports = function ValidateIntegerTypedArray(typedArray) { var waitable = arguments.length > 1 ? arguments[1] : false; // step 1 @@ -36,7 +23,7 @@ module.exports = function ValidateIntegerTypedArray(typedArray) { var typeName = whichTypedArray(typedArray); // step 3 - var type = table60['$' + typeName]; // step 4 + var type = tableTAO.name['$' + typeName]; // step 4 if (waitable) { // step 5 if (typeName !== 'Int32Array' && typeName !== 'BigInt64Array') { diff --git a/2021/tables/typed-array-objects.js b/2021/tables/typed-array-objects.js new file mode 100644 index 00000000..d5d48475 --- /dev/null +++ b/2021/tables/typed-array-objects.js @@ -0,0 +1,35 @@ +'use strict'; + +// https://262.ecma-international.org/11.0/#table-the-typedarray-constructors + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $BigInt64Array: 'BigInt64', + $BigUint64Array: 'BigUint64', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $BigInt64: 8, + $BigUint64: 8, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2022/GetValueFromBuffer.js b/2022/GetValueFromBuffer.js index d83678a8..f46d3f16 100644 --- a/2022/GetValueFromBuffer.js +++ b/2022/GetValueFromBuffer.js @@ -19,20 +19,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table61 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $BigInt64: 8, - $BigUint64: 8, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -48,7 +35,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || typeof table61['$' + type] !== 'number') { + if (typeof type !== 'string' || typeof tableTAO.size['$' + type] !== 'number') { throw new $TypeError('Assertion failed: `type` must be a Typed Array element type'); } @@ -76,7 +63,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table61['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "BigInt64", "BigUint64", "Float32", or "Float64"'); } diff --git a/2022/SetValueInBuffer.js b/2022/SetValueInBuffer.js index 1cbe93cd..e1bb8c02 100644 --- a/2022/SetValueInBuffer.js +++ b/2022/SetValueInBuffer.js @@ -13,20 +13,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var hasOwn = require('hasown'); -var table60 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - BigInt64: 8, - BigUint64: 8, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); var forEach = require('../helpers/forEach'); @@ -45,7 +32,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, throw new $TypeError('Assertion failed: `byteIndex` must be a non-negative integer'); } - if (typeof type !== 'string' || !hasOwn(table60, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -76,7 +63,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, // 4. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot. - var elementSize = table60[type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 // 6. 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. var isLittleEndian = arguments.length > 6 ? arguments[6] : defaultEndianness === 'little'; // step 6 diff --git a/2022/TypedArrayElementSize.js b/2022/TypedArrayElementSize.js index 21c3bb86..ea4f95f2 100644 --- a/2022/TypedArrayElementSize.js +++ b/2022/TypedArrayElementSize.js @@ -9,27 +9,14 @@ var whichTypedArray = require('which-typed-array'); // https://262.ecma-international.org/13.0/#sec-typedarrayelementsize -var table71 = { - __proto__: null, - $Int8Array: 1, - $Uint8Array: 1, - $Uint8ClampedArray: 1, - $Int16Array: 2, - $Uint16Array: 2, - $Int32Array: 4, - $Uint32Array: 4, - $BigInt64Array: 8, - $BigUint64Array: 8, - $Float32Array: 4, - $Float64Array: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); module.exports = function TypedArrayElementSize(O) { var type = whichTypedArray(O); if (type === false) { throw new $TypeError('Assertion failed: `O` must be a TypedArray'); } - var size = table71['$' + type]; + var size = tableTAO.size['$' + tableTAO.name['$' + type]]; if (!isInteger(size) || size < 0) { throw new $SyntaxError('Assertion failed: Unknown TypedArray type `' + type + '`'); } diff --git a/2022/TypedArrayElementType.js b/2022/TypedArrayElementType.js index cd765711..103976ac 100644 --- a/2022/TypedArrayElementType.js +++ b/2022/TypedArrayElementType.js @@ -7,27 +7,14 @@ var whichTypedArray = require('which-typed-array'); // https://262.ecma-international.org/13.0/#sec-typedarrayelementtype -var table71 = { - __proto__: null, - $Int8Array: 'Int8', - $Uint8Array: 'Uint8', - $Uint8ClampedArray: 'Uint8C', - $Int16Array: 'Int16', - $Uint16Array: 'Uint16', - $Int32Array: 'Int32', - $Uint32Array: 'Uint32', - $BigInt64Array: 'BigInt64', - $BigUint64Array: 'BigUint64', - $Float32Array: 'Float32', - $Float64Array: 'Float64' -}; +var tableTAO = require('./tables/typed-array-objects'); module.exports = function TypedArrayElementType(O) { var type = whichTypedArray(O); if (type === false) { throw new $TypeError('Assertion failed: `O` must be a TypedArray'); } - var result = table71['$' + type]; + var result = tableTAO.name['$' + type]; if (typeof result !== 'string') { throw new $SyntaxError('Assertion failed: Unknown TypedArray type `' + type + '`'); } diff --git a/2022/tables/typed-array-objects.js b/2022/tables/typed-array-objects.js new file mode 100644 index 00000000..d5d48475 --- /dev/null +++ b/2022/tables/typed-array-objects.js @@ -0,0 +1,35 @@ +'use strict'; + +// https://262.ecma-international.org/11.0/#table-the-typedarray-constructors + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $BigInt64Array: 'BigInt64', + $BigUint64Array: 'BigUint64', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $BigInt64: 8, + $BigUint64: 8, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/2023/GetValueFromBuffer.js b/2023/GetValueFromBuffer.js index d83678a8..f46d3f16 100644 --- a/2023/GetValueFromBuffer.js +++ b/2023/GetValueFromBuffer.js @@ -19,20 +19,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var safeConcat = require('safe-array-concat'); -var table61 = { - __proto__: null, - $Int8: 1, - $Uint8: 1, - $Uint8C: 1, - $Int16: 2, - $Uint16: 2, - $Int32: 4, - $Uint32: 4, - $BigInt64: 8, - $BigUint64: 8, - $Float32: 4, - $Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); @@ -48,7 +35,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp throw new $TypeError('Assertion failed: `byteIndex` must be an integer'); } - if (typeof type !== 'string' || typeof table61['$' + type] !== 'number') { + if (typeof type !== 'string' || typeof tableTAO.size['$' + type] !== 'number') { throw new $TypeError('Assertion failed: `type` must be a Typed Array element type'); } @@ -76,7 +63,7 @@ module.exports = function GetValueFromBuffer(arrayBuffer, byteIndex, type, isTyp // 4. Let block be arrayBuffer.[[ArrayBufferData]]. - var elementSize = table61['$' + type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 if (!elementSize) { throw new $TypeError('Assertion failed: `type` must be one of "Int8", "Uint8", "Uint8C", "Int16", "Uint16", "Int32", "Uint32", "BigInt64", "BigUint64", "Float32", or "Float64"'); } diff --git a/2023/SetValueInBuffer.js b/2023/SetValueInBuffer.js index 1cbe93cd..e1bb8c02 100644 --- a/2023/SetValueInBuffer.js +++ b/2023/SetValueInBuffer.js @@ -13,20 +13,7 @@ var isArrayBuffer = require('is-array-buffer'); var isSharedArrayBuffer = require('is-shared-array-buffer'); var hasOwn = require('hasown'); -var table60 = { - __proto__: null, - Int8: 1, - Uint8: 1, - Uint8C: 1, - Int16: 2, - Uint16: 2, - Int32: 4, - Uint32: 4, - BigInt64: 8, - BigUint64: 8, - Float32: 4, - Float64: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); var defaultEndianness = require('../helpers/defaultEndianness'); var forEach = require('../helpers/forEach'); @@ -45,7 +32,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, throw new $TypeError('Assertion failed: `byteIndex` must be a non-negative integer'); } - if (typeof type !== 'string' || !hasOwn(table60, type)) { + if (typeof type !== 'string' || !hasOwn(tableTAO.size, '$' + type)) { throw new $TypeError('Assertion failed: `type` must be a Typed Array Element Type'); } @@ -76,7 +63,7 @@ module.exports = function SetValueInBuffer(arrayBuffer, byteIndex, type, value, // 4. Let block be arrayBuffer’s [[ArrayBufferData]] internal slot. - var elementSize = table60[type]; // step 5 + var elementSize = tableTAO.size['$' + type]; // step 5 // 6. 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. var isLittleEndian = arguments.length > 6 ? arguments[6] : defaultEndianness === 'little'; // step 6 diff --git a/2023/TypedArrayElementSize.js b/2023/TypedArrayElementSize.js index 21c3bb86..ea4f95f2 100644 --- a/2023/TypedArrayElementSize.js +++ b/2023/TypedArrayElementSize.js @@ -9,27 +9,14 @@ var whichTypedArray = require('which-typed-array'); // https://262.ecma-international.org/13.0/#sec-typedarrayelementsize -var table71 = { - __proto__: null, - $Int8Array: 1, - $Uint8Array: 1, - $Uint8ClampedArray: 1, - $Int16Array: 2, - $Uint16Array: 2, - $Int32Array: 4, - $Uint32Array: 4, - $BigInt64Array: 8, - $BigUint64Array: 8, - $Float32Array: 4, - $Float64Array: 8 -}; +var tableTAO = require('./tables/typed-array-objects'); module.exports = function TypedArrayElementSize(O) { var type = whichTypedArray(O); if (type === false) { throw new $TypeError('Assertion failed: `O` must be a TypedArray'); } - var size = table71['$' + type]; + var size = tableTAO.size['$' + tableTAO.name['$' + type]]; if (!isInteger(size) || size < 0) { throw new $SyntaxError('Assertion failed: Unknown TypedArray type `' + type + '`'); } diff --git a/2023/TypedArrayElementType.js b/2023/TypedArrayElementType.js index cd765711..103976ac 100644 --- a/2023/TypedArrayElementType.js +++ b/2023/TypedArrayElementType.js @@ -7,27 +7,14 @@ var whichTypedArray = require('which-typed-array'); // https://262.ecma-international.org/13.0/#sec-typedarrayelementtype -var table71 = { - __proto__: null, - $Int8Array: 'Int8', - $Uint8Array: 'Uint8', - $Uint8ClampedArray: 'Uint8C', - $Int16Array: 'Int16', - $Uint16Array: 'Uint16', - $Int32Array: 'Int32', - $Uint32Array: 'Uint32', - $BigInt64Array: 'BigInt64', - $BigUint64Array: 'BigUint64', - $Float32Array: 'Float32', - $Float64Array: 'Float64' -}; +var tableTAO = require('./tables/typed-array-objects'); module.exports = function TypedArrayElementType(O) { var type = whichTypedArray(O); if (type === false) { throw new $TypeError('Assertion failed: `O` must be a TypedArray'); } - var result = table71['$' + type]; + var result = tableTAO.name['$' + type]; if (typeof result !== 'string') { throw new $SyntaxError('Assertion failed: Unknown TypedArray type `' + type + '`'); } diff --git a/2023/tables/typed-array-objects.js b/2023/tables/typed-array-objects.js new file mode 100644 index 00000000..d5d48475 --- /dev/null +++ b/2023/tables/typed-array-objects.js @@ -0,0 +1,35 @@ +'use strict'; + +// https://262.ecma-international.org/11.0/#table-the-typedarray-constructors + +module.exports = { + __proto__: null, + name: { + __proto__: null, + $Int8Array: 'Int8', + $Uint8Array: 'Uint8', + $Uint8ClampedArray: 'Uint8C', + $Int16Array: 'Int16', + $Uint16Array: 'Uint16', + $Int32Array: 'Int32', + $Uint32Array: 'Uint32', + $BigInt64Array: 'BigInt64', + $BigUint64Array: 'BigUint64', + $Float32Array: 'Float32', + $Float64Array: 'Float64' + }, + size: { + __proto__: null, + $Int8: 1, + $Uint8: 1, + $Uint8C: 1, + $Int16: 2, + $Uint16: 2, + $Int32: 4, + $Uint32: 4, + $BigInt64: 8, + $BigUint64: 8, + $Float32: 4, + $Float64: 8 + } +}; diff --git a/operations/spackle.js b/operations/spackle.js index 6f19ad29..bee70ba5 100644 --- a/operations/spackle.js +++ b/operations/spackle.js @@ -31,14 +31,19 @@ const writtenOps = [5].concat(years).flatMap((year, i, arr) => { }).map((opFile) => { const op = path.basename(opFile, path.extname(opFile)); const opPath = op.replace('::', '/'); + const isEntryPoint = !opPath.startsWith('tables/'); const thisFile = path.join(process.cwd(), String(year), `${opPath}.js`); - addOpToYear(year, op, opPath); + if (isEntryPoint) { + addOpToYear(year, op, opPath); + } if ((i + 1) < arr.length) { const nextYear = arr[i + 1]; const nextFile = path.join(process.cwd(), String(nextYear), `${opPath}.js`); fs.mkdirSync(path.dirname(nextFile), { recursive: true }); if (!deltas[nextYear].removed.has(op)) { - addOpToYear(nextYear, op, opPath); + if (isEntryPoint) { + addOpToYear(nextYear, op, opPath); + } if (fs.existsSync(thisFile) && !fs.existsSync(nextFile)) { console.log(`writing: ${nextYear}/${opPath} -> ${year}/${opPath}`); @@ -50,6 +55,7 @@ const writtenOps = [5].concat(years).flatMap((year, i, arr) => { const replacement = fs.readFileSync(thisFile, 'utf-8'); fs.writeFileSync(nextFile, process.argv[2] ? replacement : reexport); return { + isEntryPoint, op, opFile: path.relative(process.cwd(), nextFile), year: nextYear, diff --git a/test/helpers/runManifestTest.js b/test/helpers/runManifestTest.js index 96e04af2..1b8dbf4a 100644 --- a/test/helpers/runManifestTest.js +++ b/test/helpers/runManifestTest.js @@ -17,7 +17,7 @@ module.exports = function runManifestTest(test, ES, edition) { test('ES' + edition + ' manifest', { skip: !fs.readdirSync }, function (t) { var files = filter( fs.readdirSync(path.join(__dirname, '../../' + edition), 'utf-8'), - function rejectDotFile(file) { return file[0] !== '.'; } + function rejectDotFile(file) { return file[0] !== '.' && file !== 'tables'; } ); forEach(files, function (file) { var name = path.basename(file, path.extname(file));