From fa171dbb7fdc92c208df2961de4873e7dd74f92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 28 Sep 2020 16:56:54 +0200 Subject: [PATCH] lib: use remaining typed arrays from primordials PR-URL: https://github.com/nodejs/node/pull/35499 Reviewed-By: Joyee Cheung Reviewed-By: Benjamin Gruenbaum Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Ujjwal Sharma Reviewed-By: Shingo Inoue --- lib/.eslintrc.yaml | 8 ++++++++ lib/buffer.js | 3 ++- lib/internal/buffer.js | 1 + lib/internal/child_process.js | 1 + lib/internal/encoding.js | 2 ++ lib/internal/http2/core.js | 2 ++ lib/internal/process/per_thread.js | 1 + lib/internal/streams/buffer_list.js | 1 + lib/internal/util/comparisons.js | 1 + lib/internal/util/inspect.js | 6 +++++- lib/internal/util/types.js | 3 ++- lib/internal/worker.js | 1 + lib/zlib.js | 2 ++ 13 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 35ced9e9011016..20e01898695507 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -11,6 +11,8 @@ rules: - error - name: Array message: "Use `const { Array } = primordials;` instead of the global." + - name: ArrayBuffer + message: "Use `const { ArrayBuffer } = primordials;` instead of the global." - name: BigInt message: "Use `const { BigInt } = primordials;` instead of the global." - name: BigInt64Array @@ -67,6 +69,12 @@ rules: message: "Use `const { URIError } = primordials;` instead of the global." - name: Uint16Array message: "Use `const { Uint16Array } = primordials;` instead of the global." + - name: Uint32Array + message: "Use `const { Uint32Array } = primordials;` instead of the global." + - name: Uint8Array + message: "Use `const { Uint8Array } = primordials;` instead of the global." + - name: Uint8ClampedArray + message: "Use `const { Uint8ClampedArray } = primordials;` instead of the global." - name: WeakMap message: "Use `const { WeakMap } = primordials;` instead of the global." - name: WeakSet diff --git a/lib/buffer.js b/lib/buffer.js index bed6bcbae47193..2c89a249f37dea 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -39,6 +39,7 @@ const { ObjectSetPrototypeOf, SymbolSpecies, SymbolToPrimitive, + Uint8Array, Uint8ArrayPrototype, } = primordials; @@ -403,7 +404,7 @@ function SlowBuffer(length) { return createUnsafeBuffer(length); } -ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8Array.prototype); +ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype); ObjectSetPrototypeOf(SlowBuffer, Uint8Array); function allocate(size) { diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js index fa682575217994..4a2c13f168b9a6 100644 --- a/lib/internal/buffer.js +++ b/lib/internal/buffer.js @@ -6,6 +6,7 @@ const { Float64Array, MathFloor, Number, + Uint8Array, } = primordials; const { diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index b068a740817c60..cb035c812a9b3a 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -5,6 +5,7 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, + Uint8Array, } = primordials; const { diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index de0a1b7cc799bb..5226bf518dac38 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -10,6 +10,8 @@ const { ObjectGetOwnPropertyDescriptors, Symbol, SymbolToStringTag, + Uint32Array, + Uint8Array, } = primordials; const { diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 80f9834006ba56..8a29b82cd69c73 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -15,6 +15,8 @@ const { ReflectGetPrototypeOf, Set, Symbol, + Uint32Array, + Uint8Array, } = primordials; const { diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index cfc0e3463cedaf..b8f03ffef1939b 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -18,6 +18,7 @@ const { SetPrototype, SetPrototypeHas, StringPrototypeReplace, + Uint32Array, } = primordials; const { diff --git a/lib/internal/streams/buffer_list.js b/lib/internal/streams/buffer_list.js index fc8dd1b1f0fded..2551bee4473de4 100644 --- a/lib/internal/streams/buffer_list.js +++ b/lib/internal/streams/buffer_list.js @@ -2,6 +2,7 @@ const { SymbolIterator, + Uint8Array, } = primordials; const { Buffer } = require('buffer'); diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 9d4cdf9f183f16..2c10f0c8929752 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -20,6 +20,7 @@ const { StringPrototypeValueOf, SymbolPrototypeValueOf, SymbolToStringTag, + Uint8Array, } = primordials; const { compare } = internalBinding('buffer'); diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 7f75325e863128..cf2f32accaedd9 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -58,6 +58,10 @@ const { SymbolIterator, SymbolToStringTag, Uint16Array, + Uint32Array, + Uint8Array, + Uint8ArrayPrototype, + Uint8ClampedArray, uncurryThis, } = primordials; @@ -138,7 +142,7 @@ const mapSizeGetter = uncurryThis( ObjectGetOwnPropertyDescriptor(MapPrototype, 'size').get); const typedArraySizeGetter = uncurryThis( ObjectGetOwnPropertyDescriptor( - ObjectGetPrototypeOf(Uint8Array.prototype), 'length').get); + ObjectGetPrototypeOf(Uint8ArrayPrototype), 'length').get); let hexSlice; diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 676f386a2458d4..4b9eeb469b2d19 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -5,10 +5,11 @@ const { ObjectGetOwnPropertyDescriptor, ObjectGetPrototypeOf, SymbolToStringTag, + Uint8ArrayPrototype, uncurryThis, } = primordials; -const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8Array.prototype); +const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype); const TypedArrayProto_toStringTag = uncurryThis( diff --git a/lib/internal/worker.js b/lib/internal/worker.js index e521064fb33ea2..2b943d1ec072d6 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -14,6 +14,7 @@ const { String, Symbol, SymbolFor, + Uint32Array, } = primordials; const EventEmitter = require('events'); diff --git a/lib/zlib.js b/lib/zlib.js index 609c50afd52f22..05e0594f1981ae 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -22,6 +22,7 @@ 'use strict'; const { + ArrayBuffer, Error, MathMax, NumberIsFinite, @@ -33,6 +34,7 @@ const { ObjectKeys, ObjectSetPrototypeOf, Symbol, + Uint32Array, } = primordials; const {