summaryrefslogtreecommitdiff
path: root/ext/node/polyfills
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills')
-rw-r--r--ext/node/polyfills/internal/console/constructor.mjs8
-rw-r--r--ext/node/polyfills/internal/util/types.ts85
-rw-r--r--ext/node/polyfills/internal_binding/types.ts320
3 files changed, 57 insertions, 356 deletions
diff --git a/ext/node/polyfills/internal/console/constructor.mjs b/ext/node/polyfills/internal/console/constructor.mjs
index e9160cf70..45bca6675 100644
--- a/ext/node/polyfills/internal/console/constructor.mjs
+++ b/ext/node/polyfills/internal/console/constructor.mjs
@@ -5,7 +5,9 @@
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
-const ops = core.ops;
+const {
+ op_preview_entries,
+} = core.ensureFastOps(true);
// Mock trace for now
const trace = () => {};
@@ -502,7 +504,7 @@ const consoleMethods = {
let isKeyValue = false;
let i = 0;
if (mapIter) {
- const res = ops.op_preview_entries(tabularData, true);
+ const res = op_preview_entries(tabularData, true);
tabularData = res[0];
isKeyValue = res[1];
}
@@ -537,7 +539,7 @@ const consoleMethods = {
const setIter = isSetIterator(tabularData);
if (setIter) {
- tabularData = ops.op_preview_entries(tabularData, false);
+ tabularData = op_preview_entries(tabularData, false);
}
const setlike = setIter || mapIter || isSet(tabularData);
diff --git a/ext/node/polyfills/internal/util/types.ts b/ext/node/polyfills/internal/util/types.ts
index 3e2004c2b..58b1b1045 100644
--- a/ext/node/polyfills/internal/util/types.ts
+++ b/ext/node/polyfills/internal/util/types.ts
@@ -24,17 +24,16 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
+import { primordials } from "ext:core/mod.js";
import * as bindingTypes from "ext:deno_node/internal_binding/types.ts";
export {
isCryptoKey,
isKeyObject,
} from "ext:deno_node/internal/crypto/_keys.ts";
-
-// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
-const _getTypedArrayToStringTag = Object.getOwnPropertyDescriptor(
- Object.getPrototypeOf(Uint8Array).prototype,
- Symbol.toStringTag,
-)!.get!;
+const {
+ ArrayBufferIsView,
+ TypedArrayPrototypeGetSymbolToStringTag,
+} = primordials;
export function isArrayBufferView(
value: unknown,
@@ -51,98 +50,82 @@ export function isArrayBufferView(
| Uint8ClampedArray
| Uint16Array
| Uint32Array {
- return ArrayBuffer.isView(value);
+ return ArrayBufferIsView(value);
}
export function isBigInt64Array(value: unknown): value is BigInt64Array {
- return _getTypedArrayToStringTag.call(value) === "BigInt64Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "BigInt64Array";
}
export function isBigUint64Array(value: unknown): value is BigUint64Array {
- return _getTypedArrayToStringTag.call(value) === "BigUint64Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "BigUint64Array";
}
export function isFloat32Array(value: unknown): value is Float32Array {
- return _getTypedArrayToStringTag.call(value) === "Float32Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Float32Array";
}
export function isFloat64Array(value: unknown): value is Float64Array {
- return _getTypedArrayToStringTag.call(value) === "Float64Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Float64Array";
}
export function isInt8Array(value: unknown): value is Int8Array {
- return _getTypedArrayToStringTag.call(value) === "Int8Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Int8Array";
}
export function isInt16Array(value: unknown): value is Int16Array {
- return _getTypedArrayToStringTag.call(value) === "Int16Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Int16Array";
}
export function isInt32Array(value: unknown): value is Int32Array {
- return _getTypedArrayToStringTag.call(value) === "Int32Array";
-}
-
-export type TypedArray =
- | BigInt64Array
- | BigUint64Array
- | Float32Array
- | Float64Array
- | Int8Array
- | Int16Array
- | Int32Array
- | Uint8Array
- | Uint8ClampedArray
- | Uint16Array
- | Uint32Array;
-
-export function isTypedArray(value: unknown): value is TypedArray {
- return _getTypedArrayToStringTag.call(value) !== undefined;
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Int32Array";
}
export function isUint8Array(value: unknown): value is Uint8Array {
- return _getTypedArrayToStringTag.call(value) === "Uint8Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Uint8Array";
}
export function isUint8ClampedArray(
value: unknown,
): value is Uint8ClampedArray {
- return _getTypedArrayToStringTag.call(value) === "Uint8ClampedArray";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Uint8ClampedArray";
}
export function isUint16Array(value: unknown): value is Uint16Array {
- return _getTypedArrayToStringTag.call(value) === "Uint16Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Uint16Array";
}
export function isUint32Array(value: unknown): value is Uint32Array {
- return _getTypedArrayToStringTag.call(value) === "Uint32Array";
+ return TypedArrayPrototypeGetSymbolToStringTag(value) === "Uint32Array";
}
export const {
// isExternal,
- isDate,
+ isAnyArrayBuffer,
isArgumentsObject,
+ isArrayBuffer,
+ isAsyncFunction,
isBigIntObject,
isBooleanObject,
- isNumberObject,
- isStringObject,
- isSymbolObject,
- isNativeError,
- isRegExp,
- isAsyncFunction,
+ isBoxedPrimitive,
+ isDataView,
+ isDate,
isGeneratorFunction,
isGeneratorObject,
- isPromise,
isMap,
- isSet,
isMapIterator,
+ isModuleNamespaceObject,
+ isNativeError,
+ isNumberObject,
+ isPromise,
+ isProxy,
+ isRegExp,
+ isSet,
isSetIterator,
+ isSharedArrayBuffer,
+ isStringObject,
+ isSymbolObject,
+ isTypedArray,
isWeakMap,
isWeakSet,
- isArrayBuffer,
- isDataView,
- isSharedArrayBuffer,
- isProxy,
- isModuleNamespaceObject,
- isAnyArrayBuffer,
- isBoxedPrimitive,
} = bindingTypes;
diff --git a/ext/node/polyfills/internal_binding/types.ts b/ext/node/polyfills/internal_binding/types.ts
index aa3781944..2d301ba1b 100644
--- a/ext/node/polyfills/internal_binding/types.ts
+++ b/ext/node/polyfills/internal_binding/types.ts
@@ -21,319 +21,35 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// TODO(petamoriken): enable prefer-primordials for node polyfills
-// deno-lint-ignore-file prefer-primordials
+import { core } from "ext:core/mod.js";
-const { core } = globalThis.__bootstrap;
-const { ops } = core;
-
-// https://tc39.es/ecma262/#sec-bigint.prototype.valueof
-const _bigIntValueOf = BigInt.prototype.valueOf;
-
-// https://tc39.es/ecma262/#sec-boolean.prototype.valueof
-const _booleanValueOf = Boolean.prototype.valueOf;
-
-// https://tc39.es/ecma262/#sec-date.prototype.valueof
-const _dateValueOf = Date.prototype.valueOf;
-
-// https://tc39.es/ecma262/#sec-number.prototype.valueof
-const _numberValueOf = Number.prototype.valueOf;
-
-// https://tc39.es/ecma262/#sec-string.prototype.valueof
-const _stringValueOf = String.prototype.valueOf;
-
-// https://tc39.es/ecma262/#sec-symbol.prototype.valueof
-const _symbolValueOf = Symbol.prototype.valueOf;
-
-// https://tc39.es/ecma262/#sec-weakmap.prototype.has
-const _weakMapHas = WeakMap.prototype.has;
-
-// https://tc39.es/ecma262/#sec-weakset.prototype.has
-const _weakSetHas = WeakSet.prototype.has;
-
-// https://tc39.es/ecma262/#sec-get-arraybuffer.prototype.bytelength
-const _getArrayBufferByteLength = Object.getOwnPropertyDescriptor(
- ArrayBuffer.prototype,
- "byteLength",
-)!.get!;
-
-// https://tc39.es/ecma262/#sec-get-sharedarraybuffer.prototype.bytelength
-let _getSharedArrayBufferByteLength;
-
-// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
-const _getTypedArrayToStringTag = Object.getOwnPropertyDescriptor(
- Object.getPrototypeOf(Uint8Array).prototype,
- Symbol.toStringTag,
-)!.get!;
-
-// https://tc39.es/ecma262/#sec-get-set.prototype.size
-const _getSetSize = Object.getOwnPropertyDescriptor(
- Set.prototype,
- "size",
-)!.get!;
-
-// https://tc39.es/ecma262/#sec-get-map.prototype.size
-const _getMapSize = Object.getOwnPropertyDescriptor(
- Map.prototype,
- "size",
-)!.get!;
-
-function isObjectLike(
- value: unknown,
-): value is Record<string | number | symbol, unknown> {
- return value !== null && typeof value === "object";
-}
-
-export function isAnyArrayBuffer(
- value: unknown,
-): value is ArrayBuffer | SharedArrayBuffer {
- return ops.op_is_any_arraybuffer(value);
-}
-
-export function isArgumentsObject(value: unknown): value is IArguments {
- return core.isArgumentsObject(value);
-}
-
-export function isArrayBuffer(value: unknown): value is ArrayBuffer {
- try {
- _getArrayBufferByteLength.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isAsyncFunction(
- value: unknown,
-): value is (...args: unknown[]) => Promise<unknown> {
- return core.isAsyncFunction(value);
-}
-
-// deno-lint-ignore ban-types
-export function isBooleanObject(value: unknown): value is Boolean {
- if (!isObjectLike(value)) {
- return false;
- }
-
- try {
- _booleanValueOf.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isBoxedPrimitive(
- value: unknown,
- // deno-lint-ignore ban-types
-): value is Boolean | String | Number | Symbol | BigInt {
- return (
- isBooleanObject(value) ||
- isStringObject(value) ||
- isNumberObject(value) ||
- isSymbolObject(value) ||
- isBigIntObject(value)
- );
-}
-
-export function isDataView(value: unknown): value is DataView {
- return (
- ArrayBuffer.isView(value) &&
- _getTypedArrayToStringTag.call(value) === undefined
- );
-}
-
-export function isDate(value: unknown): value is Date {
- try {
- _dateValueOf.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isGeneratorFunction(
- value: unknown,
-): value is GeneratorFunction {
- return core.isGeneratorFunction(value);
-}
-
-export function isGeneratorObject(value: unknown): value is Generator {
- return core.isGeneratorObject(value);
-}
-
-export function isMap(value: unknown): value is Map<unknown, unknown> {
- try {
- _getMapSize.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isMapIterator(
- value: unknown,
-): value is IterableIterator<[unknown, unknown]> {
- return core.isMapIterator(value);
-}
-
-export function isModuleNamespaceObject(
- value: unknown,
-): value is Record<string | number | symbol, unknown> {
- return core.isModuleNamespaceObject(value);
-}
-
-export function isNativeError(value: unknown): value is Error {
- return core.isNativeError(value);
-}
-
-// deno-lint-ignore ban-types
-export function isNumberObject(value: unknown): value is Number {
- if (!isObjectLike(value)) {
- return false;
- }
-
- try {
- _numberValueOf.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isBigIntObject(value: unknown): value is bigint {
- if (!isObjectLike(value)) {
- return false;
- }
-
- try {
- _bigIntValueOf.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isPromise(value: unknown): value is Promise<unknown> {
- return core.isPromise(value);
-}
-
-export function isProxy(
- value: unknown,
-): value is Record<string | number | symbol, unknown> {
- return core.isProxy(value);
-}
-
-export function isRegExp(value: unknown): value is RegExp {
- return core.isRegExp(value);
-}
-
-export function isSet(value: unknown): value is Set<unknown> {
- try {
- _getSetSize.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isSetIterator(
- value: unknown,
-): value is IterableIterator<unknown> {
- return core.isSetIterator(value);
-}
-
-export function isSharedArrayBuffer(
- value: unknown,
-): value is SharedArrayBuffer {
- // TODO(kt3k): add SharedArrayBuffer to primordials
- _getSharedArrayBufferByteLength ??= Object.getOwnPropertyDescriptor(
- SharedArrayBuffer.prototype,
- "byteLength",
- )!.get!;
-
- try {
- _getSharedArrayBufferByteLength.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-// deno-lint-ignore ban-types
-export function isStringObject(value: unknown): value is String {
- if (!isObjectLike(value)) {
- return false;
- }
-
- try {
- _stringValueOf.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-// deno-lint-ignore ban-types
-export function isSymbolObject(value: unknown): value is Symbol {
- if (!isObjectLike(value)) {
- return false;
- }
-
- try {
- _symbolValueOf.call(value);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isWeakMap(
- value: unknown,
-): value is WeakMap<Record<string | number | symbol, unknown>, unknown> {
- try {
- // deno-lint-ignore no-explicit-any
- _weakMapHas.call(value, null as any);
- return true;
- } catch {
- return false;
- }
-}
-
-export function isWeakSet(
- value: unknown,
-): value is WeakSet<Record<string | number | symbol, unknown>> {
- try {
- // deno-lint-ignore no-explicit-any
- _weakSetHas.call(value, null as any);
- return true;
- } catch {
- return false;
- }
-}
-
-export default {
- isAsyncFunction,
- isGeneratorFunction,
+export const {
+ // isExternal,
isAnyArrayBuffer,
- isArrayBuffer,
isArgumentsObject,
+ isArrayBuffer,
+ isAsyncFunction,
+ isBigIntObject,
+ isBooleanObject,
isBoxedPrimitive,
isDataView,
- // isExternal,
+ isDate,
+ isGeneratorFunction,
+ isGeneratorObject,
isMap,
isMapIterator,
isModuleNamespaceObject,
isNativeError,
+ isNumberObject,
isPromise,
+ isProxy,
+ isRegExp,
isSet,
isSetIterator,
+ isSharedArrayBuffer,
+ isStringObject,
+ isSymbolObject,
+ isTypedArray,
isWeakMap,
isWeakSet,
- isRegExp,
- isDate,
- isStringObject,
- isNumberObject,
- isBooleanObject,
- isBigIntObject,
-};
+} = core;