Skip to content

Commit

Permalink
[Refactor] extract TA tables to separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 21, 2024
1 parent 226cfb1 commit 16eb13c
Show file tree
Hide file tree
Showing 38 changed files with 384 additions and 425 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions 2015/GetValueFromBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'; };

Expand Down Expand Up @@ -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"');
}
Expand Down
19 changes: 4 additions & 15 deletions 2015/SetValueInBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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"');
}
Expand All @@ -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

Expand Down
31 changes: 31 additions & 0 deletions 2015/tables/typed-array-objects.js
Original file line number Diff line number Diff line change
@@ -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
}
};
15 changes: 2 additions & 13 deletions 2016/GetValueFromBuffer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions 2016/SetValueInBuffer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions 2016/tables/typed-array-objects.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions 2017/GetValueFromBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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"');
}
Expand Down
19 changes: 4 additions & 15 deletions 2017/SetValueInBuffer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions 2017/tables/typed-array-objects.js
Original file line number Diff line number Diff line change
@@ -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
}
};
15 changes: 2 additions & 13 deletions 2018/GetValueFromBuffer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 16eb13c

Please sign in to comment.