Skip to content

Commit

Permalink
lib: use remaining typed arrays from primordials
Browse files Browse the repository at this point in the history
PR-URL: #35499
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
  • Loading branch information
targos authored and MylesBorins committed Nov 16, 2020
1 parent 7f8834f commit ad7281b
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,6 +49,12 @@ rules:
message: "Use `const { Symbol } = 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
Expand Down
3 changes: 2 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
ObjectSetPrototypeOf,
SymbolSpecies,
SymbolToPrimitive,
Uint8Array,
Uint8ArrayPrototype,
} = primordials;

Expand Down Expand Up @@ -400,7 +401,7 @@ function SlowBuffer(length) {
return createUnsafeBuffer(length);
}

ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8Array.prototype);
ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype);
ObjectSetPrototypeOf(SlowBuffer, Uint8Array);

function allocate(size) {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
Float32Array,
MathFloor,
Number,
Uint8Array,
} = primordials;

const {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
Uint8Array,
} = primordials;

const {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const {
ObjectGetOwnPropertyDescriptors,
Symbol,
SymbolToStringTag,
Uint32Array,
Uint8Array,
} = primordials;

const {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const {
ReflectGetPrototypeOf,
Set,
Symbol,
Uint32Array,
Uint8Array,
} = primordials;

const {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
SetPrototype,
SetPrototypeHas,
StringPrototypeReplace,
Uint32Array,
} = primordials;

const {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/streams/buffer_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
SymbolIterator,
Uint8Array,
} = primordials;

const { Buffer } = require('buffer');
Expand Down
1 change: 1 addition & 0 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
StringPrototypeValueOf,
SymbolPrototypeValueOf,
SymbolToStringTag,
Uint8Array,
} = primordials;

const { compare } = internalBinding('buffer');
Expand Down
6 changes: 5 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const {
SymbolIterator,
SymbolToStringTag,
Uint16Array,
Uint32Array,
Uint8Array,
Uint8ArrayPrototype,
Uint8ClampedArray,
uncurryThis,
} = primordials;

Expand Down Expand Up @@ -132,7 +136,7 @@ const mapSizeGetter = uncurryThis(
ObjectGetOwnPropertyDescriptor(MapPrototype, 'size').get);
const typedArraySizeGetter = uncurryThis(
ObjectGetOwnPropertyDescriptor(
ObjectGetPrototypeOf(Uint8Array.prototype), 'length').get);
ObjectGetPrototypeOf(Uint8ArrayPrototype), 'length').get);

let hexSlice;

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
SymbolToStringTag,
Uint8ArrayPrototype,
uncurryThis,
} = primordials;

const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8Array.prototype);
const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype);

const TypedArrayProto_toStringTag =
uncurryThis(
Expand Down
1 change: 1 addition & 0 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
PromiseResolve,
Symbol,
SymbolFor,
Uint32Array,
} = primordials;

const EventEmitter = require('events');
Expand Down
2 changes: 2 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'use strict';

const {
ArrayBuffer,
Error,
MathMax,
NumberIsFinite,
Expand All @@ -33,6 +34,7 @@ const {
ObjectKeys,
ObjectSetPrototypeOf,
Symbol,
Uint32Array,
} = primordials;

const {
Expand Down

0 comments on commit ad7281b

Please sign in to comment.