From 7f8a4232be14d95747d28fe1c6f7c9578feb1436 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 2 Apr 2021 07:37:35 -0500 Subject: [PATCH 1/8] lib: add tsconfig for code completions --- tsconfig.json | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000000000..e08e38fcea48cd --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,79 @@ +{ + "include": ["lib","doc"], + "exclude": ["src","tools","out"], + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "baseUrl": ".", + "paths": { + "internal/*": ["./lib/internal/*"], + "constants": ["./lib/constants.js"], + "net": ["./lib/net.js"], + "trace_events": ["./lib/trace_events.js"], + "events": ["./lib/events.js"], + "repl": ["./lib/repl.js"], + "util": ["./lib/util.js"], + "dgram": ["./lib/dgram.js"], + "vm": ["./lib/vm.js"], + "stream": ["./lib/stream.js"], + "child_process": ["./lib/child_process.js"], + "assert": ["./lib/assert.js"], + "_tls_wrap": ["./lib/_tls_wrap.js"], + "http2": ["./lib/http2.js"], + "util/types": ["./lib/util/types.js"], + "inspector": ["./lib/inspector.js"], + "os": ["./lib/os.js"], + "_http_server": ["./lib/_http_server.js"], + "timers/promises": ["./lib/timers/promises.js"], + "console": ["./lib/console.js"], + "perf_hooks": ["./lib/perf_hooks.js"], + "readline": ["./lib/readline.js"], + "path/win32": ["./lib/path/win32.js"], + "path/posix": ["./lib/path/posix.js"], + "punycode": ["./lib/punycode.js"], + "stream/promises": ["./lib/stream/promises.js"], + "_http_incoming": ["./lib/_http_incoming.js"], + "https": ["./lib/https.js"], + "_stream_wrap": ["./lib/_stream_wrap.js"], + "domain": ["./lib/domain.js"], + "dns": ["./lib/dns.js"], + "_http_client": ["./lib/_http_client.js"], + "diagnostics_channel": ["./lib/diagnostics_channel.js"], + "assert/strict": ["./lib/assert/strict.js"], + "tty": ["./lib/tty.js"], + "_http_agent": ["./lib/_http_agent.js"], + "timers": ["./lib/timers.js"], + "_http_outgoing": ["./lib/_http_outgoing.js"], + "querystring": ["./lib/querystring.js"], + "_tls_common": ["./lib/_tls_common.js"], + "module": ["./lib/module.js"], + "_stream_passthrough": ["./lib/_stream_passthrough.js"], + "_stream_transform": ["./lib/_stream_transform.js"], + "worker_threads": ["./lib/worker_threads.js"], + "sys": ["./lib/sys.js"], + "_stream_duplex": ["./lib/_stream_duplex.js"], + "path": ["./lib/path.js"], + "_http_common": ["./lib/_http_common.js"], + "string_decoder": ["./lib/string_decoder.js"], + "cluster": ["./lib/cluster.js"], + "v8": ["./lib/v8.js"], + "crypto": ["./lib/crypto.js"], + "wasi": ["./lib/wasi.js"], + "_stream_readable": ["./lib/_stream_readable.js"], + "zlib": ["./lib/zlib.js"], + "url": ["./lib/url.js"], + "tls": ["./lib/tls.js"], + "dns/promises": ["./lib/dns/promises.js"], + "fs/promises": ["./lib/fs/promises.js"], + "_stream_writable": ["./lib/_stream_writable.js"], + "async_hooks": ["./lib/async_hooks.js"], + "process": ["./lib/process.js"], + "http": ["./lib/http.js"], + "buffer": ["./lib/buffer.js"], + "fs": ["./lib/fs.js"], + }, + "noEmit": true, + "target": "ESNext", + "module": "CommonJS" + } +} From a84a0f45ab7e2aed7a7d63f2609e46209bfd6c92 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 2 Apr 2021 07:54:10 -0500 Subject: [PATCH 2/8] order keys nit --- tsconfig.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index e08e38fcea48cd..d8ec38a4c8391b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,9 @@ "compilerOptions": { "allowJs": true, "checkJs": true, + "noEmit": true, + "target": "ESNext", + "module": "CommonJS", "baseUrl": ".", "paths": { "internal/*": ["./lib/internal/*"], @@ -71,9 +74,6 @@ "http": ["./lib/http.js"], "buffer": ["./lib/buffer.js"], "fs": ["./lib/fs.js"], - }, - "noEmit": true, - "target": "ESNext", - "module": "CommonJS" + } } } From 12b6fa74b8f3f6ed7b4f41cc9db4a77f69c1ea55 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 2 Apr 2021 11:04:58 -0500 Subject: [PATCH 3/8] nit sort paths --- tsconfig.json | 106 +++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index d8ec38a4c8391b..01dc012e1ac605 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,71 +9,71 @@ "module": "CommonJS", "baseUrl": ".", "paths": { - "internal/*": ["./lib/internal/*"], + "_http_agent": ["./lib/_http_agent.js"], + "_http_client": ["./lib/_http_client.js"], + "_http_common": ["./lib/_http_common.js"], + "_http_incoming": ["./lib/_http_incoming.js"], + "_http_outgoing": ["./lib/_http_outgoing.js"], + "_http_server": ["./lib/_http_server.js"], + "_stream_duplex": ["./lib/_stream_duplex.js"], + "_stream_passthrough": ["./lib/_stream_passthrough.js"], + "_stream_readable": ["./lib/_stream_readable.js"], + "_stream_transform": ["./lib/_stream_transform.js"], + "_stream_wrap": ["./lib/_stream_wrap.js"], + "_stream_writable": ["./lib/_stream_writable.js"], + "_tls_common": ["./lib/_tls_common.js"], + "_tls_wrap": ["./lib/_tls_wrap.js"], + "assert": ["./lib/assert.js"], + "assert/strict": ["./lib/assert/strict.js"], + "async_hooks": ["./lib/async_hooks.js"], + "buffer": ["./lib/buffer.js"], + "child_process": ["./lib/child_process.js"], + "cluster": ["./lib/cluster.js"], + "console": ["./lib/console.js"], "constants": ["./lib/constants.js"], - "net": ["./lib/net.js"], - "trace_events": ["./lib/trace_events.js"], - "events": ["./lib/events.js"], - "repl": ["./lib/repl.js"], - "util": ["./lib/util.js"], + "crypto": ["./lib/crypto.js"], "dgram": ["./lib/dgram.js"], - "vm": ["./lib/vm.js"], - "stream": ["./lib/stream.js"], - "child_process": ["./lib/child_process.js"], - "assert": ["./lib/assert.js"], - "_tls_wrap": ["./lib/_tls_wrap.js"], + "diagnostics_channel": ["./lib/diagnostics_channel.js"], + "dns": ["./lib/dns.js"], + "dns/promises": ["./lib/dns/promises.js"], + "domain": ["./lib/domain.js"], + "events": ["./lib/events.js"], + "fs": ["./lib/fs.js"], + "fs/promises": ["./lib/fs/promises.js"], + "http": ["./lib/http.js"], "http2": ["./lib/http2.js"], - "util/types": ["./lib/util/types.js"], + "https": ["./lib/https.js"], "inspector": ["./lib/inspector.js"], + "internal/*": ["./lib/internal/*"], + "module": ["./lib/module.js"], + "net": ["./lib/net.js"], "os": ["./lib/os.js"], - "_http_server": ["./lib/_http_server.js"], - "timers/promises": ["./lib/timers/promises.js"], - "console": ["./lib/console.js"], - "perf_hooks": ["./lib/perf_hooks.js"], - "readline": ["./lib/readline.js"], - "path/win32": ["./lib/path/win32.js"], + "path": ["./lib/path.js"], "path/posix": ["./lib/path/posix.js"], + "path/win32": ["./lib/path/win32.js"], + "perf_hooks": ["./lib/perf_hooks.js"], + "process": ["./lib/process.js"], "punycode": ["./lib/punycode.js"], - "stream/promises": ["./lib/stream/promises.js"], - "_http_incoming": ["./lib/_http_incoming.js"], - "https": ["./lib/https.js"], - "_stream_wrap": ["./lib/_stream_wrap.js"], - "domain": ["./lib/domain.js"], - "dns": ["./lib/dns.js"], - "_http_client": ["./lib/_http_client.js"], - "diagnostics_channel": ["./lib/diagnostics_channel.js"], - "assert/strict": ["./lib/assert/strict.js"], - "tty": ["./lib/tty.js"], - "_http_agent": ["./lib/_http_agent.js"], - "timers": ["./lib/timers.js"], - "_http_outgoing": ["./lib/_http_outgoing.js"], "querystring": ["./lib/querystring.js"], - "_tls_common": ["./lib/_tls_common.js"], - "module": ["./lib/module.js"], - "_stream_passthrough": ["./lib/_stream_passthrough.js"], - "_stream_transform": ["./lib/_stream_transform.js"], - "worker_threads": ["./lib/worker_threads.js"], - "sys": ["./lib/sys.js"], - "_stream_duplex": ["./lib/_stream_duplex.js"], - "path": ["./lib/path.js"], - "_http_common": ["./lib/_http_common.js"], + "readline": ["./lib/readline.js"], + "repl": ["./lib/repl.js"], + "stream": ["./lib/stream.js"], + "stream/promises": ["./lib/stream/promises.js"], "string_decoder": ["./lib/string_decoder.js"], - "cluster": ["./lib/cluster.js"], + "sys": ["./lib/sys.js"], + "timers": ["./lib/timers.js"], + "timers/promises": ["./lib/timers/promises.js"], + "tls": ["./lib/tls.js"], + "trace_events": ["./lib/trace_events.js"], + "tty": ["./lib/tty.js"], + "url": ["./lib/url.js"], + "util": ["./lib/util.js"], + "util/types": ["./lib/util/types.js"], "v8": ["./lib/v8.js"], - "crypto": ["./lib/crypto.js"], + "vm": ["./lib/vm.js"], "wasi": ["./lib/wasi.js"], - "_stream_readable": ["./lib/_stream_readable.js"], + "worker_threads": ["./lib/worker_threads.js"], "zlib": ["./lib/zlib.js"], - "url": ["./lib/url.js"], - "tls": ["./lib/tls.js"], - "dns/promises": ["./lib/dns/promises.js"], - "fs/promises": ["./lib/fs/promises.js"], - "_stream_writable": ["./lib/_stream_writable.js"], - "async_hooks": ["./lib/async_hooks.js"], - "process": ["./lib/process.js"], - "http": ["./lib/http.js"], - "buffer": ["./lib/buffer.js"], - "fs": ["./lib/fs.js"], } } } From 87cfcbff31886c78c13dd8c5fb191468f11976d1 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 2 Apr 2021 16:40:56 -0500 Subject: [PATCH 4/8] add primordials typings --- lib/internal/per_context/primordials.js | 297 +++++++------- tsconfig.json | 3 +- typings/primordials.d.ts | 497 ++++++++++++++++++++++++ 3 files changed, 654 insertions(+), 143 deletions(-) create mode 100644 typings/primordials.d.ts diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 311b3c324cfced..16bb9b263dbe02 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -1,11 +1,11 @@ 'use strict'; - +// let primordials = Object.create(null); /* eslint-disable node-core/prefer-primordials */ // This file subclasses and stores the JS builtins that come from the VM // so that Node.js's builtin modules do not need to later look these up from // the global proxy, which can be mutated by users. - +// let primordials = Object.create(null); const { defineProperty: ReflectDefineProperty, getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor, @@ -51,7 +51,7 @@ function getNewKey(key) { `${key[0].toUpperCase()}${key.slice(1)}`; } -function copyAccessor(dest, prefix, key, { enumerable, get, set }) { +function copyAccessor(dest, prefix, key, { enumerable, get, set }, path) { ReflectDefineProperty(dest, `${prefix}Get${key}`, { value: uncurryThis(get), enumerable @@ -64,14 +64,17 @@ function copyAccessor(dest, prefix, key, { enumerable, get, set }) { } } -function copyPropsRenamed(src, dest, prefix) { +function copyPropsRenamed(src, dest, prefix, path = []) { for (const key of ReflectOwnKeys(src)) { const newKey = getNewKey(key); const desc = ReflectGetOwnPropertyDescriptor(src, key); if ('get' in desc) { - copyAccessor(dest, prefix, newKey, desc); + copyAccessor(dest, prefix, newKey, desc, [...path, key]); } else { const name = `${prefix}${newKey}`; + if ([...path, key].every(s => typeof s === 'string')) { + console.log(`export const ${name}: typeof ${[...path, key ].join('.')}`); + } ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { @@ -85,12 +88,12 @@ function copyPropsRenamed(src, dest, prefix) { } } -function copyPropsRenamedBound(src, dest, prefix) { +function copyPropsRenamedBound(src, dest, prefix, path = []) { for (const key of ReflectOwnKeys(src)) { const newKey = getNewKey(key); const desc = ReflectGetOwnPropertyDescriptor(src, key); if ('get' in desc) { - copyAccessor(dest, prefix, newKey, desc); + copyAccessor(dest, prefix, newKey, desc, [...path, key]); } else { const { value } = desc; if (typeof value === 'function') { @@ -99,6 +102,9 @@ function copyPropsRenamedBound(src, dest, prefix) { const name = `${prefix}${newKey}`; ReflectDefineProperty(dest, name, desc); + if ([...path, key].every(s => typeof s === 'string')) { + console.log(`export const ${name}: typeof ${[...path, key].join('.')}`); + } if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { value: applyBind(value, src), @@ -108,19 +114,22 @@ function copyPropsRenamedBound(src, dest, prefix) { } } -function copyPrototype(src, dest, prefix) { +function copyPrototype(src, dest, prefix, path = []) { for (const key of ReflectOwnKeys(src)) { const newKey = getNewKey(key); const desc = ReflectGetOwnPropertyDescriptor(src, key); if ('get' in desc) { - copyAccessor(dest, prefix, newKey, desc); + copyAccessor(dest, prefix, newKey, desc, [...path, key]); } else { const { value } = desc; + const name = `${prefix}${newKey}`; if (typeof value === 'function') { + if ([...path, key].every(s => typeof s === 'string')) { + console.log(`export const ${name}: UncurryThis`); + } desc.value = uncurryThis(value); } - const name = `${prefix}${newKey}`; ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { @@ -139,6 +148,7 @@ function copyPrototype(src, dest, prefix) { encodeURIComponent, ].forEach((fn) => { primordials[fn.name] = fn; + console.log(`export const ${fn.name}: typeof globalThis.${fn.name};`); }); // Create copies of the namespace objects @@ -147,7 +157,7 @@ function copyPrototype(src, dest, prefix) { 'Math', 'Reflect', ].forEach((name) => { - copyPropsRenamed(global[name], primordials, name); + copyPropsRenamed(global[name], primordials, name, [name]); }); // Create copies of intrinsic objects @@ -190,8 +200,9 @@ function copyPrototype(src, dest, prefix) { ].forEach((name) => { const original = global[name]; primordials[name] = original; - copyPropsRenamed(original, primordials, name); - copyPrototype(original.prototype, primordials, `${name}Prototype`); + console.log(`export const ${name}: typeof globalThis.${name};`); + copyPropsRenamed(original, primordials, name, [name]); + copyPrototype(original.prototype, primordials, `${name}Prototype`, [name, 'prototype']); }); // Create copies of intrinsic objects that require a valid `this` to call @@ -202,147 +213,149 @@ function copyPrototype(src, dest, prefix) { ].forEach((name) => { const original = global[name]; primordials[name] = original; - copyPropsRenamedBound(original, primordials, name); - copyPrototype(original.prototype, primordials, `${name}Prototype`); + console.log(`export const ${name}: typeof globalThis.${name};`); + copyPropsRenamedBound(original, primordials, name, [name]); + copyPrototype(original.prototype, primordials, `${name}Prototype`, [name, 'prototype']); }); // Create copies of abstract intrinsic objects that are not directly exposed // on the global object. // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object -[ - { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, - { name: 'ArrayIterator', original: { - prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), - } }, - { name: 'StringIterator', original: { - prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), - } }, -].forEach(({ name, original }) => { - primordials[name] = original; - // The static %TypedArray% methods require a valid `this`, but can't be bound, - // as they need a subclass constructor as the receiver: - copyPrototype(original, primordials, name); - copyPrototype(original.prototype, primordials, `${name}Prototype`); -}); +// [ +// { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, +// { name: 'ArrayIterator', original: { +// prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), +// } }, +// { name: 'StringIterator', original: { +// prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), +// } }, +// ].forEach(({ name, original }) => { +// primordials[name] = original; +// // The static %TypedArray% methods require a valid `this`, but can't be bound, +// // as they need a subclass constructor as the receiver: +// copyPrototype(original, primordials, name, [name]); +// copyPrototype(original.prototype, primordials, `${name}Prototype`, [name, 'prototype']); +// }); -/* eslint-enable node-core/prefer-primordials */ +// /* eslint-enable node-core/prefer-primordials */ -const { - ArrayPrototypeForEach, - FunctionPrototypeCall, - Map, - ObjectFreeze, - ObjectSetPrototypeOf, - Set, - SymbolIterator, - WeakMap, - WeakSet, -} = primordials; +// const { +// ArrayPrototypeForEach, +// FunctionPrototypeCall, +// Map, +// ObjectFreeze, +// ObjectSetPrototypeOf, +// Set, +// SymbolIterator, +// WeakMap, +// WeakSet, +// } = primordials; -// Because these functions are used by `makeSafe`, which is exposed -// on the `primordials` object, it's important to use const references -// to the primordials that they use: -const createSafeIterator = (factory, next) => { - class SafeIterator { - constructor(iterable) { - this._iterator = factory(iterable); - } - next() { - return next(this._iterator); - } - [SymbolIterator]() { - return this; - } - } - ObjectSetPrototypeOf(SafeIterator.prototype, null); - ObjectFreeze(SafeIterator.prototype); - ObjectFreeze(SafeIterator); - return SafeIterator; -}; +// // Because these functions are used by `makeSafe`, which is exposed +// // on the `primordials` object, it's important to use const references +// // to the primordials that they use: +// const createSafeIterator = (factory, next) => { +// class SafeIterator { +// constructor(iterable) { +// this._iterator = factory(iterable); +// } +// next() { +// return next(this._iterator); +// } +// [SymbolIterator]() { +// return this; +// } +// } +// ObjectSetPrototypeOf(SafeIterator.prototype, null); +// ObjectFreeze(SafeIterator.prototype); +// ObjectFreeze(SafeIterator); +// return SafeIterator; +// }; -primordials.SafeArrayIterator = createSafeIterator( - primordials.ArrayPrototypeSymbolIterator, - primordials.ArrayIteratorPrototypeNext -); -primordials.SafeStringIterator = createSafeIterator( - primordials.StringPrototypeSymbolIterator, - primordials.StringIteratorPrototypeNext -); +// primordials.SafeArrayIterator = createSafeIterator( +// primordials.ArrayPrototypeSymbolIterator, +// primordials.ArrayIteratorPrototypeNext +// ); +// primordials.SafeStringIterator = createSafeIterator( +// primordials.StringPrototypeSymbolIterator, +// primordials.StringIteratorPrototypeNext +// ); -const copyProps = (src, dest) => { - ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => { - if (!ReflectGetOwnPropertyDescriptor(dest, key)) { - ReflectDefineProperty( - dest, - key, - ReflectGetOwnPropertyDescriptor(src, key)); - } - }); -}; +// const copyProps = (src, dest) => { +// ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => { +// if (!ReflectGetOwnPropertyDescriptor(dest, key)) { +// ReflectDefineProperty( +// dest, +// key, +// ReflectGetOwnPropertyDescriptor(src, key)); +// } +// }); +// }; -const makeSafe = (unsafe, safe) => { - if (SymbolIterator in unsafe.prototype) { - const dummy = new unsafe(); - let next; // We can reuse the same `next` method. +// const makeSafe = (unsafe, safe) => { +// if (SymbolIterator in unsafe.prototype) { +// const dummy = new unsafe(); +// let next; // We can reuse the same `next` method. - ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => { - if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) { - const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key); - if ( - typeof desc.value === 'function' && - desc.value.length === 0 && - SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {}) - ) { - const createIterator = uncurryThis(desc.value); - next ??= uncurryThis(createIterator(dummy).next); - const SafeIterator = createSafeIterator(createIterator, next); - desc.value = function() { - return new SafeIterator(this); - }; - } - ReflectDefineProperty(safe.prototype, key, desc); - } - }); - } else { - copyProps(unsafe.prototype, safe.prototype); - } - copyProps(unsafe, safe); +// ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => { +// if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) { +// const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key); +// if ( +// typeof desc.value === 'function' && +// desc.value.length === 0 && +// SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {}) +// ) { +// const createIterator = uncurryThis(desc.value); +// next ??= uncurryThis(createIterator(dummy).next); +// const SafeIterator = createSafeIterator(createIterator, next); +// desc.value = function() { +// return new SafeIterator(this); +// }; +// } +// ReflectDefineProperty(safe.prototype, key, desc); +// } +// }); +// } else { +// copyProps(unsafe.prototype, safe.prototype); +// } +// copyProps(unsafe, safe); - ObjectSetPrototypeOf(safe.prototype, null); - ObjectFreeze(safe.prototype); - ObjectFreeze(safe); - return safe; -}; -primordials.makeSafe = makeSafe; +// ObjectSetPrototypeOf(safe.prototype, null); +// ObjectFreeze(safe.prototype); +// ObjectFreeze(safe); +// return safe; +// }; +// primordials.makeSafe = makeSafe; -// Subclass the constructors because we need to use their prototype -// methods later. -// Defining the `constructor` is necessary here to avoid the default -// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`. -primordials.SafeMap = makeSafe( - Map, - class SafeMap extends Map { - constructor(i) { super(i); } // eslint-disable-line no-useless-constructor - } -); -primordials.SafeWeakMap = makeSafe( - WeakMap, - class SafeWeakMap extends WeakMap { - constructor(i) { super(i); } // eslint-disable-line no-useless-constructor - } -); -primordials.SafeSet = makeSafe( - Set, - class SafeSet extends Set { - constructor(i) { super(i); } // eslint-disable-line no-useless-constructor - } -); -primordials.SafeWeakSet = makeSafe( - WeakSet, - class SafeWeakSet extends WeakSet { - constructor(i) { super(i); } // eslint-disable-line no-useless-constructor - } -); +// // Subclass the constructors because we need to use their prototype +// // methods later. +// // Defining the `constructor` is necessary here to avoid the default +// // constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`. +// primordials.SafeMap = makeSafe( +// Map, +// class SafeMap extends Map { +// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor +// } +// ); +// primordials.SafeWeakMap = makeSafe( +// WeakMap, +// class SafeWeakMap extends WeakMap { +// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor +// } +// ); +// primordials.SafeSet = makeSafe( +// Set, +// class SafeSet extends Set { +// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor +// } +// ); +// primordials.SafeWeakSet = makeSafe( +// WeakSet, +// class SafeWeakSet extends WeakSet { +// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor +// } +// ); + +// ObjectSetPrototypeOf(primordials, null); +// ObjectFreeze(primordials); -ObjectSetPrototypeOf(primordials, null); -ObjectFreeze(primordials); diff --git a/tsconfig.json b/tsconfig.json index 01dc012e1ac605..0993c65fa3a455 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,10 @@ { "include": ["lib","doc"], "exclude": ["src","tools","out"], + "files": ["./typings/primordials.d.ts"], "compilerOptions": { "allowJs": true, - "checkJs": true, + "checkJs": false, "noEmit": true, "target": "ESNext", "module": "CommonJS", diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts new file mode 100644 index 00000000000000..946462ff473a67 --- /dev/null +++ b/typings/primordials.d.ts @@ -0,0 +1,497 @@ +type UncurryThis any> = (self: ThisParameterType, ...args: Parameters) => ReturnType; + +/** + * why + */ +declare namespace primordials {export const decodeURI: typeof globalThis.decodeURI; + export const decodeURIComponent: typeof globalThis.decodeURIComponent; + export const encodeURI: typeof globalThis.encodeURI; + export const encodeURIComponent: typeof globalThis.encodeURIComponent; + export const JSONParse: typeof JSON.parse + export const JSONStringify: typeof JSON.stringify + export const MathAbs: typeof Math.abs + export const MathAcos: typeof Math.acos + export const MathAcosh: typeof Math.acosh + export const MathAsin: typeof Math.asin + export const MathAsinh: typeof Math.asinh + export const MathAtan: typeof Math.atan + export const MathAtanh: typeof Math.atanh + export const MathAtan2: typeof Math.atan2 + export const MathCeil: typeof Math.ceil + export const MathCbrt: typeof Math.cbrt + export const MathExpm1: typeof Math.expm1 + export const MathClz32: typeof Math.clz32 + export const MathCos: typeof Math.cos + export const MathCosh: typeof Math.cosh + export const MathExp: typeof Math.exp + export const MathFloor: typeof Math.floor + export const MathFround: typeof Math.fround + export const MathHypot: typeof Math.hypot + export const MathImul: typeof Math.imul + export const MathLog: typeof Math.log + export const MathLog1p: typeof Math.log1p + export const MathLog2: typeof Math.log2 + export const MathLog10: typeof Math.log10 + export const MathMax: typeof Math.max + export const MathMin: typeof Math.min + export const MathPow: typeof Math.pow + export const MathRandom: typeof Math.random + export const MathRound: typeof Math.round + export const MathSign: typeof Math.sign + export const MathSin: typeof Math.sin + export const MathSinh: typeof Math.sinh + export const MathSqrt: typeof Math.sqrt + export const MathTan: typeof Math.tan + export const MathTanh: typeof Math.tanh + export const MathTrunc: typeof Math.trunc + export const MathE: typeof Math.E + export const MathLN10: typeof Math.LN10 + export const MathLN2: typeof Math.LN2 + export const MathLOG10E: typeof Math.LOG10E + export const MathLOG2E: typeof Math.LOG2E + export const MathPI: typeof Math.PI + export const MathSQRT1_2: typeof Math.SQRT1_2 + export const MathSQRT2: typeof Math.SQRT2 + export const ReflectDefineProperty: typeof Reflect.defineProperty + export const ReflectDeleteProperty: typeof Reflect.deleteProperty + export const ReflectApply: typeof Reflect.apply + export const ReflectConstruct: typeof Reflect.construct + export const ReflectGet: typeof Reflect.get + export const ReflectGetOwnPropertyDescriptor: typeof Reflect.getOwnPropertyDescriptor + export const ReflectGetPrototypeOf: typeof Reflect.getPrototypeOf + export const ReflectHas: typeof Reflect.has + export const ReflectIsExtensible: typeof Reflect.isExtensible + export const ReflectOwnKeys: typeof Reflect.ownKeys + export const ReflectPreventExtensions: typeof Reflect.preventExtensions + export const ReflectSet: typeof Reflect.set + export const ReflectSetPrototypeOf: typeof Reflect.setPrototypeOf + export const AggregateError: typeof globalThis.AggregateError; + export const AggregateErrorLength: typeof AggregateError.length + export const AggregateErrorName: typeof AggregateError.name + export const AggregateErrorPrototype: typeof AggregateError.prototype + export const Array: typeof globalThis.Array; + export const ArrayLength: typeof Array.length + export const ArrayName: typeof Array.name + export const ArrayPrototype: typeof Array.prototype + export const ArrayIsArray: typeof Array.isArray + export const ArrayFrom: typeof Array.from + export const ArrayOf: typeof Array.of + export const ArrayPrototypeConcat: UncurryThis + export const ArrayPrototypeCopyWithin: UncurryThis + export const ArrayPrototypeFill: UncurryThis + export const ArrayPrototypeFind: UncurryThis + export const ArrayPrototypeFindIndex: UncurryThis + export const ArrayPrototypeLastIndexOf: UncurryThis + export const ArrayPrototypePop: UncurryThis + export const ArrayPrototypePush: UncurryThis + export const ArrayPrototypeReverse: UncurryThis + export const ArrayPrototypeShift: UncurryThis + export const ArrayPrototypeUnshift: UncurryThis + export const ArrayPrototypeSlice: UncurryThis + export const ArrayPrototypeSort: UncurryThis + export const ArrayPrototypeSplice: UncurryThis + export const ArrayPrototypeIncludes: UncurryThis + export const ArrayPrototypeIndexOf: UncurryThis + export const ArrayPrototypeJoin: UncurryThis + export const ArrayPrototypeKeys: UncurryThis + export const ArrayPrototypeEntries: UncurryThis + export const ArrayPrototypeValues: UncurryThis + export const ArrayPrototypeForEach: UncurryThis + export const ArrayPrototypeFilter: UncurryThis + export const ArrayPrototypeFlat: UncurryThis + export const ArrayPrototypeFlatMap: UncurryThis + export const ArrayPrototypeMap: UncurryThis + export const ArrayPrototypeEvery: UncurryThis + export const ArrayPrototypeSome: UncurryThis + export const ArrayPrototypeReduce: UncurryThis + export const ArrayPrototypeReduceRight: UncurryThis + export const ArrayPrototypeToLocaleString: UncurryThis + export const ArrayPrototypeToString: UncurryThis + export const ArrayBuffer: typeof globalThis.ArrayBuffer; + export const ArrayBufferLength: typeof ArrayBuffer.length + export const ArrayBufferName: typeof ArrayBuffer.name + export const ArrayBufferPrototype: typeof ArrayBuffer.prototype + export const ArrayBufferIsView: typeof ArrayBuffer.isView + export const ArrayBufferPrototypeSlice: UncurryThis + export const BigInt: typeof globalThis.BigInt; + export const BigIntLength: typeof BigInt.length + export const BigIntName: typeof BigInt.name + export const BigIntPrototype: typeof BigInt.prototype + export const BigIntAsUintN: typeof BigInt.asUintN + export const BigIntAsIntN: typeof BigInt.asIntN + export const BigIntPrototypeToLocaleString: UncurryThis + export const BigIntPrototypeToString: UncurryThis + export const BigIntPrototypeValueOf: UncurryThis + export const BigInt64Array: typeof globalThis.BigInt64Array; + export const BigInt64ArrayLength: typeof BigInt64Array.length + export const BigInt64ArrayName: typeof BigInt64Array.name + export const BigInt64ArrayPrototype: typeof BigInt64Array.prototype + export const BigInt64ArrayBYTES_PER_ELEMENT: typeof BigInt64Array.BYTES_PER_ELEMENT + export const BigUint64Array: typeof globalThis.BigUint64Array; + export const BigUint64ArrayLength: typeof BigUint64Array.length + export const BigUint64ArrayName: typeof BigUint64Array.name + export const BigUint64ArrayPrototype: typeof BigUint64Array.prototype + export const BigUint64ArrayBYTES_PER_ELEMENT: typeof BigUint64Array.BYTES_PER_ELEMENT + export const Boolean: typeof globalThis.Boolean; + export const BooleanLength: typeof Boolean.length + export const BooleanName: typeof Boolean.name + export const BooleanPrototype: typeof Boolean.prototype + export const BooleanPrototypeToString: UncurryThis + export const BooleanPrototypeValueOf: UncurryThis + export const DataView: typeof globalThis.DataView; + export const DataViewLength: typeof DataView.length + export const DataViewName: typeof DataView.name + export const DataViewPrototype: typeof DataView.prototype + export const DataViewPrototypeGetInt8: UncurryThis + export const DataViewPrototypeSetInt8: UncurryThis + export const DataViewPrototypeGetUint8: UncurryThis + export const DataViewPrototypeSetUint8: UncurryThis + export const DataViewPrototypeGetInt16: UncurryThis + export const DataViewPrototypeSetInt16: UncurryThis + export const DataViewPrototypeGetUint16: UncurryThis + export const DataViewPrototypeSetUint16: UncurryThis + export const DataViewPrototypeGetInt32: UncurryThis + export const DataViewPrototypeSetInt32: UncurryThis + export const DataViewPrototypeGetUint32: UncurryThis + export const DataViewPrototypeSetUint32: UncurryThis + export const DataViewPrototypeGetFloat32: UncurryThis + export const DataViewPrototypeSetFloat32: UncurryThis + export const DataViewPrototypeGetFloat64: UncurryThis + export const DataViewPrototypeSetFloat64: UncurryThis + export const DataViewPrototypeGetBigInt64: UncurryThis + export const DataViewPrototypeSetBigInt64: UncurryThis + export const DataViewPrototypeGetBigUint64: UncurryThis + export const DataViewPrototypeSetBigUint64: UncurryThis + export const Date: typeof globalThis.Date; + export const DateLength: typeof Date.length + export const DateName: typeof Date.name + export const DatePrototype: typeof Date.prototype + export const DateNow: typeof Date.now + export const DateParse: typeof Date.parse + export const DateUTC: typeof Date.UTC + export const DatePrototypeToString: UncurryThis + export const DatePrototypeToDateString: UncurryThis + export const DatePrototypeToTimeString: UncurryThis + export const DatePrototypeToISOString: UncurryThis + export const DatePrototypeToUTCString: UncurryThis + export const DatePrototypeToGMTString: UncurryThis + export const DatePrototypeGetDate: UncurryThis + export const DatePrototypeSetDate: UncurryThis + export const DatePrototypeGetDay: UncurryThis + export const DatePrototypeGetFullYear: UncurryThis + export const DatePrototypeSetFullYear: UncurryThis + export const DatePrototypeGetHours: UncurryThis + export const DatePrototypeSetHours: UncurryThis + export const DatePrototypeGetMilliseconds: UncurryThis + export const DatePrototypeSetMilliseconds: UncurryThis + export const DatePrototypeGetMinutes: UncurryThis + export const DatePrototypeSetMinutes: UncurryThis + export const DatePrototypeGetMonth: UncurryThis + export const DatePrototypeSetMonth: UncurryThis + export const DatePrototypeGetSeconds: UncurryThis + export const DatePrototypeSetSeconds: UncurryThis + export const DatePrototypeGetTime: UncurryThis + export const DatePrototypeSetTime: UncurryThis + export const DatePrototypeGetTimezoneOffset: UncurryThis + export const DatePrototypeGetUTCDate: UncurryThis + export const DatePrototypeSetUTCDate: UncurryThis + export const DatePrototypeGetUTCDay: UncurryThis + export const DatePrototypeGetUTCFullYear: UncurryThis + export const DatePrototypeSetUTCFullYear: UncurryThis + export const DatePrototypeGetUTCHours: UncurryThis + export const DatePrototypeSetUTCHours: UncurryThis + export const DatePrototypeGetUTCMilliseconds: UncurryThis + export const DatePrototypeSetUTCMilliseconds: UncurryThis + export const DatePrototypeGetUTCMinutes: UncurryThis + export const DatePrototypeSetUTCMinutes: UncurryThis + export const DatePrototypeGetUTCMonth: UncurryThis + export const DatePrototypeSetUTCMonth: UncurryThis + export const DatePrototypeGetUTCSeconds: UncurryThis + export const DatePrototypeSetUTCSeconds: UncurryThis + export const DatePrototypeValueOf: UncurryThis + export const DatePrototypeGetYear: UncurryThis + export const DatePrototypeSetYear: UncurryThis + export const DatePrototypeToJSON: UncurryThis + export const DatePrototypeToLocaleString: UncurryThis + export const DatePrototypeToLocaleDateString: UncurryThis + export const DatePrototypeToLocaleTimeString: UncurryThis + export const Error: typeof globalThis.Error; + export const ErrorLength: typeof Error.length + export const ErrorName: typeof Error.name + export const ErrorPrototype: typeof Error.prototype + export const ErrorCaptureStackTrace: typeof Error.captureStackTrace + export const ErrorStackTraceLimit: typeof Error.stackTraceLimit + export const ErrorPrototypeToString: UncurryThis + export const EvalError: typeof globalThis.EvalError; + export const EvalErrorLength: typeof EvalError.length + export const EvalErrorName: typeof EvalError.name + export const EvalErrorPrototype: typeof EvalError.prototype + export const Float32Array: typeof globalThis.Float32Array; + export const Float32ArrayLength: typeof Float32Array.length + export const Float32ArrayName: typeof Float32Array.name + export const Float32ArrayPrototype: typeof Float32Array.prototype + export const Float32ArrayBYTES_PER_ELEMENT: typeof Float32Array.BYTES_PER_ELEMENT + export const Float64Array: typeof globalThis.Float64Array; + export const Float64ArrayLength: typeof Float64Array.length + export const Float64ArrayName: typeof Float64Array.name + export const Float64ArrayPrototype: typeof Float64Array.prototype + export const Float64ArrayBYTES_PER_ELEMENT: typeof Float64Array.BYTES_PER_ELEMENT + export const Function: typeof globalThis.Function; + export const FunctionLength: typeof Function.length + export const FunctionName: typeof Function.name + export const FunctionPrototype: typeof Function.prototype + export const FunctionPrototypeApply: UncurryThis + export const FunctionPrototypeBind: UncurryThis + export const FunctionPrototypeCall: UncurryThis + export const FunctionPrototypeToString: UncurryThis + export const Int16Array: typeof globalThis.Int16Array; + export const Int16ArrayLength: typeof Int16Array.length + export const Int16ArrayName: typeof Int16Array.name + export const Int16ArrayPrototype: typeof Int16Array.prototype + export const Int16ArrayBYTES_PER_ELEMENT: typeof Int16Array.BYTES_PER_ELEMENT + export const Int32Array: typeof globalThis.Int32Array; + export const Int32ArrayLength: typeof Int32Array.length + export const Int32ArrayName: typeof Int32Array.name + export const Int32ArrayPrototype: typeof Int32Array.prototype + export const Int32ArrayBYTES_PER_ELEMENT: typeof Int32Array.BYTES_PER_ELEMENT + export const Int8Array: typeof globalThis.Int8Array; + export const Int8ArrayLength: typeof Int8Array.length + export const Int8ArrayName: typeof Int8Array.name + export const Int8ArrayPrototype: typeof Int8Array.prototype + export const Int8ArrayBYTES_PER_ELEMENT: typeof Int8Array.BYTES_PER_ELEMENT + export const Map: typeof globalThis.Map; + export const MapLength: typeof Map.length + export const MapName: typeof Map.name + export const MapPrototype: typeof Map.prototype + export const MapPrototypeGet: UncurryThis + export const MapPrototypeSet: UncurryThis + export const MapPrototypeHas: UncurryThis + export const MapPrototypeDelete: UncurryThis + export const MapPrototypeClear: UncurryThis + export const MapPrototypeEntries: UncurryThis + export const MapPrototypeForEach: UncurryThis + export const MapPrototypeKeys: UncurryThis + export const MapPrototypeValues: UncurryThis + export const Number: typeof globalThis.Number; + export const NumberLength: typeof Number.length + export const NumberName: typeof Number.name + export const NumberPrototype: typeof Number.prototype + export const NumberIsFinite: typeof Number.isFinite + export const NumberIsInteger: typeof Number.isInteger + export const NumberIsNaN: typeof Number.isNaN + export const NumberIsSafeInteger: typeof Number.isSafeInteger + export const NumberParseFloat: typeof Number.parseFloat + export const NumberParseInt: typeof Number.parseInt + export const NumberMAX_VALUE: typeof Number.MAX_VALUE + export const NumberMIN_VALUE: typeof Number.MIN_VALUE + export const NumberNaN: typeof Number.NaN + export const NumberNEGATIVE_INFINITY: typeof Number.NEGATIVE_INFINITY + export const NumberPOSITIVE_INFINITY: typeof Number.POSITIVE_INFINITY + export const NumberMAX_SAFE_INTEGER: typeof Number.MAX_SAFE_INTEGER + export const NumberMIN_SAFE_INTEGER: typeof Number.MIN_SAFE_INTEGER + export const NumberEPSILON: typeof Number.EPSILON + export const NumberPrototypeToExponential: UncurryThis + export const NumberPrototypeToFixed: UncurryThis + export const NumberPrototypeToPrecision: UncurryThis + export const NumberPrototypeToString: UncurryThis + export const NumberPrototypeValueOf: UncurryThis + export const NumberPrototypeToLocaleString: UncurryThis + export const Object: typeof globalThis.Object; + export const ObjectLength: typeof Object.length + export const ObjectName: typeof Object.name + export const ObjectPrototype: typeof Object.prototype + export const ObjectAssign: typeof Object.assign + export const ObjectGetOwnPropertyDescriptor: typeof Object.getOwnPropertyDescriptor + export const ObjectGetOwnPropertyDescriptors: typeof Object.getOwnPropertyDescriptors + export const ObjectGetOwnPropertyNames: typeof Object.getOwnPropertyNames + export const ObjectGetOwnPropertySymbols: typeof Object.getOwnPropertySymbols + export const ObjectIs: typeof Object.is + export const ObjectPreventExtensions: typeof Object.preventExtensions + export const ObjectSeal: typeof Object.seal + export const ObjectCreate: typeof Object.create + export const ObjectDefineProperties: typeof Object.defineProperties + export const ObjectDefineProperty: typeof Object.defineProperty + export const ObjectFreeze: typeof Object.freeze + export const ObjectGetPrototypeOf: typeof Object.getPrototypeOf + export const ObjectSetPrototypeOf: typeof Object.setPrototypeOf + export const ObjectIsExtensible: typeof Object.isExtensible + export const ObjectIsFrozen: typeof Object.isFrozen + export const ObjectIsSealed: typeof Object.isSealed + export const ObjectKeys: typeof Object.keys + export const ObjectEntries: typeof Object.entries + export const ObjectFromEntries: typeof Object.fromEntries + export const ObjectValues: typeof Object.values + export const ObjectPrototype__defineGetter__: UncurryThis + export const ObjectPrototype__defineSetter__: UncurryThis + export const ObjectPrototypeHasOwnProperty: UncurryThis + export const ObjectPrototype__lookupGetter__: UncurryThis + export const ObjectPrototype__lookupSetter__: UncurryThis + export const ObjectPrototypeIsPrototypeOf: UncurryThis + export const ObjectPrototypePropertyIsEnumerable: UncurryThis + export const ObjectPrototypeToString: UncurryThis + export const ObjectPrototypeValueOf: UncurryThis + export const ObjectPrototypeToLocaleString: UncurryThis + export const RangeError: typeof globalThis.RangeError; + export const RangeErrorLength: typeof RangeError.length + export const RangeErrorName: typeof RangeError.name + export const RangeErrorPrototype: typeof RangeError.prototype + export const ReferenceError: typeof globalThis.ReferenceError; + export const ReferenceErrorLength: typeof ReferenceError.length + export const ReferenceErrorName: typeof ReferenceError.name + export const ReferenceErrorPrototype: typeof ReferenceError.prototype + export const RegExp: typeof globalThis.RegExp; + export const RegExpLength: typeof RegExp.length + export const RegExpName: typeof RegExp.name + export const RegExpPrototype: typeof RegExp.prototype + export const RegExpPrototypeExec: UncurryThis + export const RegExpPrototypeCompile: UncurryThis + export const RegExpPrototypeToString: UncurryThis + export const RegExpPrototypeTest: UncurryThis + export const Set: typeof globalThis.Set; + export const SetLength: typeof Set.length + export const SetName: typeof Set.name + export const SetPrototype: typeof Set.prototype + export const SetPrototypeHas: UncurryThis + export const SetPrototypeAdd: UncurryThis + export const SetPrototypeDelete: UncurryThis + export const SetPrototypeClear: UncurryThis + export const SetPrototypeEntries: UncurryThis + export const SetPrototypeForEach: UncurryThis + export const SetPrototypeValues: UncurryThis + export const SetPrototypeKeys: UncurryThis + export const String: typeof globalThis.String; + export const StringLength: typeof String.length + export const StringName: typeof String.name + export const StringPrototype: typeof String.prototype + export const StringFromCharCode: typeof String.fromCharCode + export const StringFromCodePoint: typeof String.fromCodePoint + export const StringRaw: typeof String.raw + export const StringPrototypeAnchor: UncurryThis + export const StringPrototypeBig: UncurryThis + export const StringPrototypeBlink: UncurryThis + export const StringPrototypeBold: UncurryThis + export const StringPrototypeCharAt: UncurryThis + export const StringPrototypeCharCodeAt: UncurryThis + export const StringPrototypeCodePointAt: UncurryThis + export const StringPrototypeConcat: UncurryThis + export const StringPrototypeEndsWith: UncurryThis + export const StringPrototypeFontcolor: UncurryThis + export const StringPrototypeFontsize: UncurryThis + export const StringPrototypeFixed: UncurryThis + export const StringPrototypeIncludes: UncurryThis + export const StringPrototypeIndexOf: UncurryThis + export const StringPrototypeItalics: UncurryThis + export const StringPrototypeLastIndexOf: UncurryThis + export const StringPrototypeLink: UncurryThis + export const StringPrototypeLocaleCompare: UncurryThis + export const StringPrototypeMatch: UncurryThis + export const StringPrototypeMatchAll: UncurryThis + export const StringPrototypeNormalize: UncurryThis + export const StringPrototypePadEnd: UncurryThis + export const StringPrototypePadStart: UncurryThis + export const StringPrototypeRepeat: UncurryThis + export const StringPrototypeReplace: UncurryThis + export const StringPrototypeSearch: UncurryThis + export const StringPrototypeSlice: UncurryThis + export const StringPrototypeSmall: UncurryThis + export const StringPrototypeSplit: UncurryThis + export const StringPrototypeStrike: UncurryThis + export const StringPrototypeSub: UncurryThis + export const StringPrototypeSubstr: UncurryThis + export const StringPrototypeSubstring: UncurryThis + export const StringPrototypeSup: UncurryThis + export const StringPrototypeStartsWith: UncurryThis + export const StringPrototypeToString: UncurryThis + export const StringPrototypeTrim: UncurryThis + export const StringPrototypeTrimStart: UncurryThis + export const StringPrototypeTrimLeft: UncurryThis + export const StringPrototypeTrimEnd: UncurryThis + export const StringPrototypeTrimRight: UncurryThis + export const StringPrototypeToLocaleLowerCase: UncurryThis + export const StringPrototypeToLocaleUpperCase: UncurryThis + export const StringPrototypeToLowerCase: UncurryThis + export const StringPrototypeToUpperCase: UncurryThis + export const StringPrototypeValueOf: UncurryThis + export const StringPrototypeReplaceAll: UncurryThis + export const Symbol: typeof globalThis.Symbol; + export const SymbolLength: typeof Symbol.length + export const SymbolName: typeof Symbol.name + export const SymbolPrototype: typeof Symbol.prototype + export const SymbolFor: typeof Symbol.for + export const SymbolKeyFor: typeof Symbol.keyFor + export const SymbolAsyncIterator: typeof Symbol.asyncIterator + export const SymbolHasInstance: typeof Symbol.hasInstance + export const SymbolIsConcatSpreadable: typeof Symbol.isConcatSpreadable + export const SymbolIterator: typeof Symbol.iterator + export const SymbolMatch: typeof Symbol.match + export const SymbolMatchAll: typeof Symbol.matchAll + export const SymbolReplace: typeof Symbol.replace + export const SymbolSearch: typeof Symbol.search + export const SymbolSpecies: typeof Symbol.species + export const SymbolSplit: typeof Symbol.split + export const SymbolToPrimitive: typeof Symbol.toPrimitive + export const SymbolToStringTag: typeof Symbol.toStringTag + export const SymbolUnscopables: typeof Symbol.unscopables + export const SymbolPrototypeToString: UncurryThis + export const SymbolPrototypeValueOf: UncurryThis + export const SyntaxError: typeof globalThis.SyntaxError; + export const SyntaxErrorLength: typeof SyntaxError.length + export const SyntaxErrorName: typeof SyntaxError.name + export const SyntaxErrorPrototype: typeof SyntaxError.prototype + export const TypeError: typeof globalThis.TypeError; + export const TypeErrorLength: typeof TypeError.length + export const TypeErrorName: typeof TypeError.name + export const TypeErrorPrototype: typeof TypeError.prototype + export const URIError: typeof globalThis.URIError; + export const URIErrorLength: typeof URIError.length + export const URIErrorName: typeof URIError.name + export const URIErrorPrototype: typeof URIError.prototype + export const Uint16Array: typeof globalThis.Uint16Array; + export const Uint16ArrayLength: typeof Uint16Array.length + export const Uint16ArrayName: typeof Uint16Array.name + export const Uint16ArrayPrototype: typeof Uint16Array.prototype + export const Uint16ArrayBYTES_PER_ELEMENT: typeof Uint16Array.BYTES_PER_ELEMENT + export const Uint32Array: typeof globalThis.Uint32Array; + export const Uint32ArrayLength: typeof Uint32Array.length + export const Uint32ArrayName: typeof Uint32Array.name + export const Uint32ArrayPrototype: typeof Uint32Array.prototype + export const Uint32ArrayBYTES_PER_ELEMENT: typeof Uint32Array.BYTES_PER_ELEMENT + export const Uint8Array: typeof globalThis.Uint8Array; + export const Uint8ArrayLength: typeof Uint8Array.length + export const Uint8ArrayName: typeof Uint8Array.name + export const Uint8ArrayPrototype: typeof Uint8Array.prototype + export const Uint8ArrayBYTES_PER_ELEMENT: typeof Uint8Array.BYTES_PER_ELEMENT + export const Uint8ClampedArray: typeof globalThis.Uint8ClampedArray; + export const Uint8ClampedArrayLength: typeof Uint8ClampedArray.length + export const Uint8ClampedArrayName: typeof Uint8ClampedArray.name + export const Uint8ClampedArrayPrototype: typeof Uint8ClampedArray.prototype + export const Uint8ClampedArrayBYTES_PER_ELEMENT: typeof Uint8ClampedArray.BYTES_PER_ELEMENT + export const WeakMap: typeof globalThis.WeakMap; + export const WeakMapLength: typeof WeakMap.length + export const WeakMapName: typeof WeakMap.name + export const WeakMapPrototype: typeof WeakMap.prototype + export const WeakMapPrototypeDelete: UncurryThis + export const WeakMapPrototypeGet: UncurryThis + export const WeakMapPrototypeSet: UncurryThis + export const WeakMapPrototypeHas: UncurryThis + export const WeakSet: typeof globalThis.WeakSet; + export const WeakSetLength: typeof WeakSet.length + export const WeakSetName: typeof WeakSet.name + export const WeakSetPrototype: typeof WeakSet.prototype + export const WeakSetPrototypeDelete: UncurryThis + export const WeakSetPrototypeHas: UncurryThis + export const WeakSetPrototypeAdd: UncurryThis + export const Promise: typeof globalThis.Promise; + export const PromiseLength: typeof Promise.length + export const PromiseName: typeof Promise.name + export const PromisePrototype: typeof Promise.prototype + export const PromiseAll: typeof Promise.all + export const PromiseRace: typeof Promise.race + export const PromiseResolve: typeof Promise.resolve + export const PromiseReject: typeof Promise.reject + export const PromiseAllSettled: typeof Promise.allSettled + export const PromiseAny: typeof Promise.any + export const PromisePrototypeThen: UncurryThis + export const PromisePrototypeCatch: UncurryThis + export const PromisePrototypeFinally: UncurryThis +} From 85ea829edc6d35b1e2cd1fd0b4ab2b90f41766fd Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 2 Apr 2021 16:44:59 -0500 Subject: [PATCH 5/8] woops, undo the generator cruft for the typings --- lib/internal/per_context/primordials.js | 297 +++++++++++------------- 1 file changed, 142 insertions(+), 155 deletions(-) diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 16bb9b263dbe02..311b3c324cfced 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -1,11 +1,11 @@ 'use strict'; -// let primordials = Object.create(null); + /* eslint-disable node-core/prefer-primordials */ // This file subclasses and stores the JS builtins that come from the VM // so that Node.js's builtin modules do not need to later look these up from // the global proxy, which can be mutated by users. -// let primordials = Object.create(null); + const { defineProperty: ReflectDefineProperty, getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor, @@ -51,7 +51,7 @@ function getNewKey(key) { `${key[0].toUpperCase()}${key.slice(1)}`; } -function copyAccessor(dest, prefix, key, { enumerable, get, set }, path) { +function copyAccessor(dest, prefix, key, { enumerable, get, set }) { ReflectDefineProperty(dest, `${prefix}Get${key}`, { value: uncurryThis(get), enumerable @@ -64,17 +64,14 @@ function copyAccessor(dest, prefix, key, { enumerable, get, set }, path) { } } -function copyPropsRenamed(src, dest, prefix, path = []) { +function copyPropsRenamed(src, dest, prefix) { for (const key of ReflectOwnKeys(src)) { const newKey = getNewKey(key); const desc = ReflectGetOwnPropertyDescriptor(src, key); if ('get' in desc) { - copyAccessor(dest, prefix, newKey, desc, [...path, key]); + copyAccessor(dest, prefix, newKey, desc); } else { const name = `${prefix}${newKey}`; - if ([...path, key].every(s => typeof s === 'string')) { - console.log(`export const ${name}: typeof ${[...path, key ].join('.')}`); - } ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { @@ -88,12 +85,12 @@ function copyPropsRenamed(src, dest, prefix, path = []) { } } -function copyPropsRenamedBound(src, dest, prefix, path = []) { +function copyPropsRenamedBound(src, dest, prefix) { for (const key of ReflectOwnKeys(src)) { const newKey = getNewKey(key); const desc = ReflectGetOwnPropertyDescriptor(src, key); if ('get' in desc) { - copyAccessor(dest, prefix, newKey, desc, [...path, key]); + copyAccessor(dest, prefix, newKey, desc); } else { const { value } = desc; if (typeof value === 'function') { @@ -102,9 +99,6 @@ function copyPropsRenamedBound(src, dest, prefix, path = []) { const name = `${prefix}${newKey}`; ReflectDefineProperty(dest, name, desc); - if ([...path, key].every(s => typeof s === 'string')) { - console.log(`export const ${name}: typeof ${[...path, key].join('.')}`); - } if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { value: applyBind(value, src), @@ -114,22 +108,19 @@ function copyPropsRenamedBound(src, dest, prefix, path = []) { } } -function copyPrototype(src, dest, prefix, path = []) { +function copyPrototype(src, dest, prefix) { for (const key of ReflectOwnKeys(src)) { const newKey = getNewKey(key); const desc = ReflectGetOwnPropertyDescriptor(src, key); if ('get' in desc) { - copyAccessor(dest, prefix, newKey, desc, [...path, key]); + copyAccessor(dest, prefix, newKey, desc); } else { const { value } = desc; - const name = `${prefix}${newKey}`; if (typeof value === 'function') { - if ([...path, key].every(s => typeof s === 'string')) { - console.log(`export const ${name}: UncurryThis`); - } desc.value = uncurryThis(value); } + const name = `${prefix}${newKey}`; ReflectDefineProperty(dest, name, desc); if (varargsMethods.includes(name)) { ReflectDefineProperty(dest, `${name}Apply`, { @@ -148,7 +139,6 @@ function copyPrototype(src, dest, prefix, path = []) { encodeURIComponent, ].forEach((fn) => { primordials[fn.name] = fn; - console.log(`export const ${fn.name}: typeof globalThis.${fn.name};`); }); // Create copies of the namespace objects @@ -157,7 +147,7 @@ function copyPrototype(src, dest, prefix, path = []) { 'Math', 'Reflect', ].forEach((name) => { - copyPropsRenamed(global[name], primordials, name, [name]); + copyPropsRenamed(global[name], primordials, name); }); // Create copies of intrinsic objects @@ -200,9 +190,8 @@ function copyPrototype(src, dest, prefix, path = []) { ].forEach((name) => { const original = global[name]; primordials[name] = original; - console.log(`export const ${name}: typeof globalThis.${name};`); - copyPropsRenamed(original, primordials, name, [name]); - copyPrototype(original.prototype, primordials, `${name}Prototype`, [name, 'prototype']); + copyPropsRenamed(original, primordials, name); + copyPrototype(original.prototype, primordials, `${name}Prototype`); }); // Create copies of intrinsic objects that require a valid `this` to call @@ -213,149 +202,147 @@ function copyPrototype(src, dest, prefix, path = []) { ].forEach((name) => { const original = global[name]; primordials[name] = original; - console.log(`export const ${name}: typeof globalThis.${name};`); - copyPropsRenamedBound(original, primordials, name, [name]); - copyPrototype(original.prototype, primordials, `${name}Prototype`, [name, 'prototype']); + copyPropsRenamedBound(original, primordials, name); + copyPrototype(original.prototype, primordials, `${name}Prototype`); }); // Create copies of abstract intrinsic objects that are not directly exposed // on the global object. // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object -// [ -// { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, -// { name: 'ArrayIterator', original: { -// prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), -// } }, -// { name: 'StringIterator', original: { -// prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), -// } }, -// ].forEach(({ name, original }) => { -// primordials[name] = original; -// // The static %TypedArray% methods require a valid `this`, but can't be bound, -// // as they need a subclass constructor as the receiver: -// copyPrototype(original, primordials, name, [name]); -// copyPrototype(original.prototype, primordials, `${name}Prototype`, [name, 'prototype']); -// }); - -// /* eslint-enable node-core/prefer-primordials */ +[ + { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, + { name: 'ArrayIterator', original: { + prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), + } }, + { name: 'StringIterator', original: { + prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), + } }, +].forEach(({ name, original }) => { + primordials[name] = original; + // The static %TypedArray% methods require a valid `this`, but can't be bound, + // as they need a subclass constructor as the receiver: + copyPrototype(original, primordials, name); + copyPrototype(original.prototype, primordials, `${name}Prototype`); +}); -// const { -// ArrayPrototypeForEach, -// FunctionPrototypeCall, -// Map, -// ObjectFreeze, -// ObjectSetPrototypeOf, -// Set, -// SymbolIterator, -// WeakMap, -// WeakSet, -// } = primordials; +/* eslint-enable node-core/prefer-primordials */ -// // Because these functions are used by `makeSafe`, which is exposed -// // on the `primordials` object, it's important to use const references -// // to the primordials that they use: -// const createSafeIterator = (factory, next) => { -// class SafeIterator { -// constructor(iterable) { -// this._iterator = factory(iterable); -// } -// next() { -// return next(this._iterator); -// } -// [SymbolIterator]() { -// return this; -// } -// } -// ObjectSetPrototypeOf(SafeIterator.prototype, null); -// ObjectFreeze(SafeIterator.prototype); -// ObjectFreeze(SafeIterator); -// return SafeIterator; -// }; +const { + ArrayPrototypeForEach, + FunctionPrototypeCall, + Map, + ObjectFreeze, + ObjectSetPrototypeOf, + Set, + SymbolIterator, + WeakMap, + WeakSet, +} = primordials; -// primordials.SafeArrayIterator = createSafeIterator( -// primordials.ArrayPrototypeSymbolIterator, -// primordials.ArrayIteratorPrototypeNext -// ); -// primordials.SafeStringIterator = createSafeIterator( -// primordials.StringPrototypeSymbolIterator, -// primordials.StringIteratorPrototypeNext -// ); +// Because these functions are used by `makeSafe`, which is exposed +// on the `primordials` object, it's important to use const references +// to the primordials that they use: +const createSafeIterator = (factory, next) => { + class SafeIterator { + constructor(iterable) { + this._iterator = factory(iterable); + } + next() { + return next(this._iterator); + } + [SymbolIterator]() { + return this; + } + } + ObjectSetPrototypeOf(SafeIterator.prototype, null); + ObjectFreeze(SafeIterator.prototype); + ObjectFreeze(SafeIterator); + return SafeIterator; +}; -// const copyProps = (src, dest) => { -// ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => { -// if (!ReflectGetOwnPropertyDescriptor(dest, key)) { -// ReflectDefineProperty( -// dest, -// key, -// ReflectGetOwnPropertyDescriptor(src, key)); -// } -// }); -// }; +primordials.SafeArrayIterator = createSafeIterator( + primordials.ArrayPrototypeSymbolIterator, + primordials.ArrayIteratorPrototypeNext +); +primordials.SafeStringIterator = createSafeIterator( + primordials.StringPrototypeSymbolIterator, + primordials.StringIteratorPrototypeNext +); -// const makeSafe = (unsafe, safe) => { -// if (SymbolIterator in unsafe.prototype) { -// const dummy = new unsafe(); -// let next; // We can reuse the same `next` method. +const copyProps = (src, dest) => { + ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => { + if (!ReflectGetOwnPropertyDescriptor(dest, key)) { + ReflectDefineProperty( + dest, + key, + ReflectGetOwnPropertyDescriptor(src, key)); + } + }); +}; -// ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => { -// if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) { -// const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key); -// if ( -// typeof desc.value === 'function' && -// desc.value.length === 0 && -// SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {}) -// ) { -// const createIterator = uncurryThis(desc.value); -// next ??= uncurryThis(createIterator(dummy).next); -// const SafeIterator = createSafeIterator(createIterator, next); -// desc.value = function() { -// return new SafeIterator(this); -// }; -// } -// ReflectDefineProperty(safe.prototype, key, desc); -// } -// }); -// } else { -// copyProps(unsafe.prototype, safe.prototype); -// } -// copyProps(unsafe, safe); +const makeSafe = (unsafe, safe) => { + if (SymbolIterator in unsafe.prototype) { + const dummy = new unsafe(); + let next; // We can reuse the same `next` method. -// ObjectSetPrototypeOf(safe.prototype, null); -// ObjectFreeze(safe.prototype); -// ObjectFreeze(safe); -// return safe; -// }; -// primordials.makeSafe = makeSafe; + ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => { + if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) { + const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key); + if ( + typeof desc.value === 'function' && + desc.value.length === 0 && + SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {}) + ) { + const createIterator = uncurryThis(desc.value); + next ??= uncurryThis(createIterator(dummy).next); + const SafeIterator = createSafeIterator(createIterator, next); + desc.value = function() { + return new SafeIterator(this); + }; + } + ReflectDefineProperty(safe.prototype, key, desc); + } + }); + } else { + copyProps(unsafe.prototype, safe.prototype); + } + copyProps(unsafe, safe); -// // Subclass the constructors because we need to use their prototype -// // methods later. -// // Defining the `constructor` is necessary here to avoid the default -// // constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`. -// primordials.SafeMap = makeSafe( -// Map, -// class SafeMap extends Map { -// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor -// } -// ); -// primordials.SafeWeakMap = makeSafe( -// WeakMap, -// class SafeWeakMap extends WeakMap { -// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor -// } -// ); -// primordials.SafeSet = makeSafe( -// Set, -// class SafeSet extends Set { -// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor -// } -// ); -// primordials.SafeWeakSet = makeSafe( -// WeakSet, -// class SafeWeakSet extends WeakSet { -// constructor(i) { super(i); } // eslint-disable-line no-useless-constructor -// } -// ); + ObjectSetPrototypeOf(safe.prototype, null); + ObjectFreeze(safe.prototype); + ObjectFreeze(safe); + return safe; +}; +primordials.makeSafe = makeSafe; -// ObjectSetPrototypeOf(primordials, null); -// ObjectFreeze(primordials); +// Subclass the constructors because we need to use their prototype +// methods later. +// Defining the `constructor` is necessary here to avoid the default +// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`. +primordials.SafeMap = makeSafe( + Map, + class SafeMap extends Map { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } +); +primordials.SafeWeakMap = makeSafe( + WeakMap, + class SafeWeakMap extends WeakMap { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } +); +primordials.SafeSet = makeSafe( + Set, + class SafeSet extends Set { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } +); +primordials.SafeWeakSet = makeSafe( + WeakSet, + class SafeWeakSet extends WeakSet { + constructor(i) { super(i); } // eslint-disable-line no-useless-constructor + } +); +ObjectSetPrototypeOf(primordials, null); +ObjectFreeze(primordials); From 4abba0118a6893a9b1d132b0896c8aa4f606ace8 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Wed, 7 Apr 2021 11:08:25 -0500 Subject: [PATCH 6/8] nits and improvements --- lib/internal/bootstrap/loaders.js | 3 + lib/internal/errors.js | 6 +- tsconfig.json | 6 +- typings/internalBinding.d.ts | 441 ++++++++++++++++++++++++++++++ typings/primordials.d.ts | 22 +- 5 files changed, 473 insertions(+), 5 deletions(-) create mode 100644 typings/internalBinding.d.ts diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 4417a94181410b..25df41e5e6a0b8 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -152,6 +152,9 @@ const legacyWrapperList = new SafeSet([ } // Set up internalBinding() in the closure. +/** + * @type {InternalBinding} + */ let internalBinding; { const bindingObj = ObjectCreate(null); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 34c168ce38ab91..a7fec0d2c74680 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -352,7 +352,11 @@ function makeNodeErrorWithCode(Base, key) { }; } -// This function removes unnecessary frames from Node.js core errors. +/** + * This function removes unnecessary frames from Node.js core errors. + * @template {(...args: any[]) => any} T + * @type {(fn: T) => T} + */ function hideStackFrames(fn) { // We rename the functions that will be hidden to cut off the stacktrace // at the outermost one diff --git a/tsconfig.json b/tsconfig.json index 0993c65fa3a455..5d35e44222ddaa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,15 @@ { "include": ["lib","doc"], "exclude": ["src","tools","out"], - "files": ["./typings/primordials.d.ts"], + "files": [ + "./typings/internalBinding.d.ts", + "./typings/primordials.d.ts" + ], "compilerOptions": { "allowJs": true, "checkJs": false, "noEmit": true, + "lib": ["ESNext"], "target": "ESNext", "module": "CommonJS", "baseUrl": ".", diff --git a/typings/internalBinding.d.ts b/typings/internalBinding.d.ts new file mode 100644 index 00000000000000..d9ba4fd7a350a6 --- /dev/null +++ b/typings/internalBinding.d.ts @@ -0,0 +1,441 @@ +declare type TypedArray = Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray | Int16Array | Int32Array | Int8Array | BigInt64Array | Float32Array | Float64Array | BigUint64Array; +declare function InternalBinding(binding: 'types'): { + isAsyncFunction(value: unknown): value is (...args: unknown[]) => Promise, + isGeneratorFunction(value: unknown): value is GeneratorFunction, + isAnyArrayBuffer(value: unknown): value is (ArrayBuffer | SharedArrayBuffer), + isArrayBuffer(value: unknown): value is ArrayBuffer, + isArgumentsObject(value: unknown): value is ArrayLike, + isBoxedPrimitive(value: unknown): value is (BigInt | Boolean | Number | String | Symbol), + isDataView(value: unknown): value is DataView, + isExternal(value: unknown): value is Object, + isMap(value: unknown): value is Map, + isMapIterator: (value: unknown) => value is IterableIterator, + isModuleNamespaceObject: (value: unknown) => value is {[Symbol.toStringTag]: 'Module', [key: string]: any}, + isNativeError: (value: unknown) => Error, + isPromise: (value: unknown) => value is Promise, + isSet: (value: unknown) => value is Set, + isSetIterator: (value: unknown) => value is IterableIterator, + isWeakMap: (value: unknown) => value is WeakMap, + isWeakSet: (value: unknown) => value is WeakSet, + isRegExp: (value: unknown) => RegExp, + isDate: (value: unknown) => Date, + isTypedArray: (value: unknown) => value is TypedArray, + isStringObject: (value: unknown) => value is String, + isNumberObject: (value: unknown) => value is Number, + isBooleanObject: (value: unknown) => value is Boolean, + isBigIntObject: (value: unknown) => value is BigInt, +}; +declare function InternalBinding(binding: 'constants'): { + os: { + UV_UDP_REUSEADDR: 4, + dlopen: { + RTLD_LAZY: 1, + RTLD_NOW: 2, + RTLD_GLOBAL: 8, + RTLD_LOCAL: 4 + }, + errno:{ + E2BIG: 7, + EACCES: 13, + EADDRINUSE: 48, + EADDRNOTAVAIL: 49, + EAFNOSUPPORT: 47, + EAGAIN: 35, + EALREADY: 37, + EBADF: 9, + EBADMSG: 94, + EBUSY: 16, + ECANCELED: 89, + ECHILD: 10, + ECONNABORTED: 53, + ECONNREFUSED: 61, + ECONNRESET: 54, + EDEADLK: 11, + EDESTADDRREQ: 39, + EDOM: 33, + EDQUOT: 69, + EEXIST: 17, + EFAULT: 14, + EFBIG: 27, + EHOSTUNREACH: 65, + EIDRM: 90, + EILSEQ: 92, + EINPROGRESS: 36, + EINTR: 4, + EINVAL: 22, + EIO: 5, + EISCONN: 56, + EISDIR: 21, + ELOOP: 62, + EMFILE: 24, + EMLINK: 31, + EMSGSIZE: 40, + EMULTIHOP: 95, + ENAMETOOLONG: 63, + ENETDOWN: 50, + ENETRESET: 52, + ENETUNREACH: 51, + ENFILE: 23, + ENOBUFS: 55, + ENODATA: 96, + ENODEV: 19, + ENOENT: 2, + ENOEXEC: 8, + ENOLCK: 77, + ENOLINK: 97, + ENOMEM: 12, + ENOMSG: 91, + ENOPROTOOPT: 42, + ENOSPC: 28, + ENOSR: 98, + ENOSTR: 99, + ENOSYS: 78, + ENOTCONN: 57, + ENOTDIR: 20, + ENOTEMPTY: 66, + ENOTSOCK: 38, + ENOTSUP: 45, + ENOTTY: 25, + ENXIO: 6, + EOPNOTSUPP: 102, + EOVERFLOW: 84, + EPERM: 1, + EPIPE: 32, + EPROTO: 100, + EPROTONOSUPPORT: 43, + EPROTOTYPE: 41, + ERANGE: 34, + EROFS: 30, + ESPIPE: 29, + ESRCH: 3, + ESTALE: 70, + ETIME: 101, + ETIMEDOUT: 60, + ETXTBSY: 26, + EWOULDBLOCK: 35, + EXDEV: 18 + }, + signals: { + SIGHUP: 1, + SIGINT: 2, + SIGQUIT: 3, + SIGILL: 4, + SIGTRAP: 5, + SIGABRT: 6, + SIGIOT: 6, + SIGBUS: 10, + SIGFPE: 8, + SIGKILL: 9, + SIGUSR1: 30, + SIGSEGV: 11, + SIGUSR2: 31, + SIGPIPE: 13, + SIGALRM: 14, + SIGTERM: 15, + SIGCHLD: 20, + SIGCONT: 19, + SIGSTOP: 17, + SIGTSTP: 18, + SIGTTIN: 21, + SIGTTOU: 22, + SIGURG: 16, + SIGXCPU: 24, + SIGXFSZ: 25, + SIGVTALRM: 26, + SIGPROF: 27, + SIGWINCH: 28, + SIGIO: 23, + SIGINFO: 29, + SIGSYS: 12 + }, + priority: { + PRIORITY_LOW: 19, + PRIORITY_BELOW_NORMAL: 10, + PRIORITY_NORMAL: 0, + PRIORITY_ABOVE_NORMAL: -7, + PRIORITY_HIGH: -14, + PRIORITY_HIGHEST: -20 + } + }, + fs: { + UV_FS_SYMLINK_DIR: 1, + UV_FS_SYMLINK_JUNCTION: 2, + O_RDONLY: 0, + O_WRONLY: 1, + O_RDWR: 2, + UV_DIRENT_UNKNOWN: 0, + UV_DIRENT_FILE: 1, + UV_DIRENT_DIR: 2, + UV_DIRENT_LINK: 3, + UV_DIRENT_FIFO: 4, + UV_DIRENT_SOCKET: 5, + UV_DIRENT_CHAR: 6, + UV_DIRENT_BLOCK: 7, + S_IFMT: 61440, + S_IFREG: 32768, + S_IFDIR: 16384, + S_IFCHR: 8192, + S_IFBLK: 24576, + S_IFIFO: 4096, + S_IFLNK: 40960, + S_IFSOCK: 49152, + O_CREAT: 512, + O_EXCL: 2048, + UV_FS_O_FILEMAP: 0, + O_NOCTTY: 131072, + O_TRUNC: 1024, + O_APPEND: 8, + O_DIRECTORY: 1048576, + O_NOFOLLOW: 256, + O_SYNC: 128, + O_DSYNC: 4194304, + O_SYMLINK: 2097152, + O_NONBLOCK: 4, + S_IRWXU: 448, + S_IRUSR: 256, + S_IWUSR: 128, + S_IXUSR: 64, + S_IRWXG: 56, + S_IRGRP: 32, + S_IWGRP: 16, + S_IXGRP: 8, + S_IRWXO: 7, + S_IROTH: 4, + S_IWOTH: 2, + S_IXOTH: 1, + F_OK: 0, + R_OK: 4, + W_OK: 2, + X_OK: 1, + UV_FS_COPYFILE_EXCL: 1, + COPYFILE_EXCL: 1, + UV_FS_COPYFILE_FICLONE: 2, + COPYFILE_FICLONE: 2, + UV_FS_COPYFILE_FICLONE_FORCE: 4, + COPYFILE_FICLONE_FORCE: 4 + }, + crypto: { + OPENSSL_VERSION_NUMBER: 269488319, + SSL_OP_ALL: 2147485780, + SSL_OP_ALLOW_NO_DHE_KEX: 1024, + SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: 262144, + SSL_OP_CIPHER_SERVER_PREFERENCE: 4194304, + SSL_OP_CISCO_ANYCONNECT: 32768, + SSL_OP_COOKIE_EXCHANGE: 8192, + SSL_OP_CRYPTOPRO_TLSEXT_BUG: 2147483648, + SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: 2048, + SSL_OP_EPHEMERAL_RSA: 0, + SSL_OP_LEGACY_SERVER_CONNECT: 4, + SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: 0, + SSL_OP_MICROSOFT_SESS_ID_BUG: 0, + SSL_OP_MSIE_SSLV2_RSA_PADDING: 0, + SSL_OP_NETSCAPE_CA_DN_BUG: 0, + SSL_OP_NETSCAPE_CHALLENGE_BUG: 0, + SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: 0, + SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: 0, + SSL_OP_NO_COMPRESSION: 131072, + SSL_OP_NO_ENCRYPT_THEN_MAC: 524288, + SSL_OP_NO_QUERY_MTU: 4096, + SSL_OP_NO_RENEGOTIATION: 1073741824, + SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: 65536, + SSL_OP_NO_SSLv2: 0, + SSL_OP_NO_SSLv3: 33554432, + SSL_OP_NO_TICKET: 16384, + SSL_OP_NO_TLSv1: 67108864, + SSL_OP_NO_TLSv1_1: 268435456, + SSL_OP_NO_TLSv1_2: 134217728, + SSL_OP_NO_TLSv1_3: 536870912, + SSL_OP_PKCS1_CHECK_1: 0, + SSL_OP_PKCS1_CHECK_2: 0, + SSL_OP_PRIORITIZE_CHACHA: 2097152, + SSL_OP_SINGLE_DH_USE: 0, + SSL_OP_SINGLE_ECDH_USE: 0, + SSL_OP_SSLEAY_080_CLIENT_DH_BUG: 0, + SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: 0, + SSL_OP_TLS_BLOCK_PADDING_BUG: 0, + SSL_OP_TLS_D5_BUG: 0, + SSL_OP_TLS_ROLLBACK_BUG: 8388608, + ENGINE_METHOD_RSA: 1, + ENGINE_METHOD_DSA: 2, + ENGINE_METHOD_DH: 4, + ENGINE_METHOD_RAND: 8, + ENGINE_METHOD_EC: 2048, + ENGINE_METHOD_CIPHERS: 64, + ENGINE_METHOD_DIGESTS: 128, + ENGINE_METHOD_PKEY_METHS: 512, + ENGINE_METHOD_PKEY_ASN1_METHS: 1024, + ENGINE_METHOD_ALL: 65535, + ENGINE_METHOD_NONE: 0, + DH_CHECK_P_NOT_SAFE_PRIME: 2, + DH_CHECK_P_NOT_PRIME: 1, + DH_UNABLE_TO_CHECK_GENERATOR: 4, + DH_NOT_SUITABLE_GENERATOR: 8, + ALPN_ENABLED: 1, + RSA_PKCS1_PADDING: 1, + RSA_SSLV23_PADDING: 2, + RSA_NO_PADDING: 3, + RSA_PKCS1_OAEP_PADDING: 4, + RSA_X931_PADDING: 5, + RSA_PKCS1_PSS_PADDING: 6, + RSA_PSS_SALTLEN_DIGEST: -1, + RSA_PSS_SALTLEN_MAX_SIGN: -2, + RSA_PSS_SALTLEN_AUTO: -2, + defaultCoreCipherList: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA', + TLS1_VERSION: 769, + TLS1_1_VERSION: 770, + TLS1_2_VERSION: 771, + TLS1_3_VERSION: 772, + POINT_CONVERSION_COMPRESSED: 2, + POINT_CONVERSION_UNCOMPRESSED: 4, + POINT_CONVERSION_HYBRID: 6 + }, + zlib: { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_VERSION_ERROR: -6, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + ZLIB_VERNUM: 4784, + DEFLATE: 1, + INFLATE: 2, + GZIP: 3, + GUNZIP: 4, + DEFLATERAW: 5, + INFLATERAW: 6, + UNZIP: 7, + BROTLI_DECODE: 8, + BROTLI_ENCODE: 9, + Z_MIN_WINDOWBITS: 8, + Z_MAX_WINDOWBITS: 15, + Z_DEFAULT_WINDOWBITS: 15, + Z_MIN_CHUNK: 64, + Z_MAX_CHUNK: number, + Z_DEFAULT_CHUNK: 16384, + Z_MIN_MEMLEVEL: 1, + Z_MAX_MEMLEVEL: 9, + Z_DEFAULT_MEMLEVEL: 8, + Z_MIN_LEVEL: -1, + Z_MAX_LEVEL: 9, + Z_DEFAULT_LEVEL: -1, + BROTLI_OPERATION_PROCESS: 0, + BROTLI_OPERATION_FLUSH: 1, + BROTLI_OPERATION_FINISH: 2, + BROTLI_OPERATION_EMIT_METADATA: 3, + BROTLI_PARAM_MODE: 0, + BROTLI_MODE_GENERIC: 0, + BROTLI_MODE_TEXT: 1, + BROTLI_MODE_FONT: 2, + BROTLI_DEFAULT_MODE: 0, + BROTLI_PARAM_QUALITY: 1, + BROTLI_MIN_QUALITY: 0, + BROTLI_MAX_QUALITY: 11, + BROTLI_DEFAULT_QUALITY: 11, + BROTLI_PARAM_LGWIN: 2, + BROTLI_MIN_WINDOW_BITS: 10, + BROTLI_MAX_WINDOW_BITS: 24, + BROTLI_LARGE_MAX_WINDOW_BITS: 30, + BROTLI_DEFAULT_WINDOW: 22, + BROTLI_PARAM_LGBLOCK: 3, + BROTLI_MIN_INPUT_BLOCK_BITS: 16, + BROTLI_MAX_INPUT_BLOCK_BITS: 24, + BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, + BROTLI_PARAM_SIZE_HINT: 5, + BROTLI_PARAM_LARGE_WINDOW: 6, + BROTLI_PARAM_NPOSTFIX: 7, + BROTLI_PARAM_NDIRECT: 8, + BROTLI_DECODER_RESULT_ERROR: 0, + BROTLI_DECODER_RESULT_SUCCESS: 1, + BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2, + BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, + BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0, + BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, + BROTLI_DECODER_NO_ERROR: 0, + BROTLI_DECODER_SUCCESS: 1, + BROTLI_DECODER_NEEDS_MORE_INPUT: 2, + BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3, + BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, + BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2, + BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3, + BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, + BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5, + BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, + BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7, + BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, + BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9, + BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, + BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11, + BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, + BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13, + BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, + BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15, + BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, + BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19, + BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, + BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21, + BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, + BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25, + BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, + BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27, + BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, + BROTLI_DECODER_ERROR_UNREACHABLE: -31 + }, + trace: { + TRACE_EVENT_PHASE_BEGIN: 66, + TRACE_EVENT_PHASE_END: 69, + TRACE_EVENT_PHASE_COMPLETE: 88, + TRACE_EVENT_PHASE_INSTANT: 73, + TRACE_EVENT_PHASE_ASYNC_BEGIN: 83, + TRACE_EVENT_PHASE_ASYNC_STEP_INTO: 84, + TRACE_EVENT_PHASE_ASYNC_STEP_PAST: 112, + TRACE_EVENT_PHASE_ASYNC_END: 70, + TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: 98, + TRACE_EVENT_PHASE_NESTABLE_ASYNC_END: 101, + TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT: 110, + TRACE_EVENT_PHASE_FLOW_BEGIN: 115, + TRACE_EVENT_PHASE_FLOW_STEP: 116, + TRACE_EVENT_PHASE_FLOW_END: 102, + TRACE_EVENT_PHASE_METADATA: 77, + TRACE_EVENT_PHASE_COUNTER: 67, + TRACE_EVENT_PHASE_SAMPLE: 80, + TRACE_EVENT_PHASE_CREATE_OBJECT: 78, + TRACE_EVENT_PHASE_SNAPSHOT_OBJECT: 79, + TRACE_EVENT_PHASE_DELETE_OBJECT: 68, + TRACE_EVENT_PHASE_MEMORY_DUMP: 118, + TRACE_EVENT_PHASE_MARK: 82, + TRACE_EVENT_PHASE_CLOCK_SYNC: 99, + TRACE_EVENT_PHASE_ENTER_CONTEXT: 40, + TRACE_EVENT_PHASE_LEAVE_CONTEXT: 41, + TRACE_EVENT_PHASE_LINK_IDS: 61 + } +}; +declare function InternalBinding(binding: 'config'): { + isDebugBuild: boolean, + hasOpenSSL: boolean, + fipsMode: boolean, + hasIntl: boolean, + hasTracing: boolean, + hasNodeOptions: boolean, + hasInspector: boolean, + noBrowserGlobals: boolean, + bits: number, + hasDtrace: boolean +} \ No newline at end of file diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 946462ff473a67..45459d4843c133 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -1,9 +1,25 @@ -type UncurryThis any> = (self: ThisParameterType, ...args: Parameters) => ReturnType; +type UncurryThis unknown> = + (self: ThisParameterType, ...args: Parameters) => ReturnType; /** - * why + * Primordials are a way to safely use globals without fear of global mutation + * Generally, this means removing `this` parameter usage and instead using + * a regular parameter: + * + * @example + * + * ```js + * 'thing'.startsWith('hello'); + * ``` + * + * becomes + * + * ```js + * primordials.StringPrototypeStartsWith('thing', 'hello') + * ``` */ -declare namespace primordials {export const decodeURI: typeof globalThis.decodeURI; +declare namespace primordials { + export const decodeURI: typeof globalThis.decodeURI; export const decodeURIComponent: typeof globalThis.decodeURIComponent; export const encodeURI: typeof globalThis.encodeURI; export const encodeURIComponent: typeof globalThis.encodeURIComponent; From b636c8233335bb29031370edebe61a516828bb63 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Wed, 7 Apr 2021 12:20:50 -0500 Subject: [PATCH 7/8] Update typings/internalBinding.d.ts Co-authored-by: Antoine du Hamel --- typings/internalBinding.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/internalBinding.d.ts b/typings/internalBinding.d.ts index d9ba4fd7a350a6..598322d581ceac 100644 --- a/typings/internalBinding.d.ts +++ b/typings/internalBinding.d.ts @@ -438,4 +438,4 @@ declare function InternalBinding(binding: 'config'): { noBrowserGlobals: boolean, bits: number, hasDtrace: boolean -} \ No newline at end of file +} From 927aa17b32b58b6617c632c19cf1e3d7943f7920 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Wed, 7 Apr 2021 13:32:40 -0500 Subject: [PATCH 8/8] nits / make some mutations picked up --- lib/internal/per_context/primordials.js | 3 +++ typings/primordials.d.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 311b3c324cfced..f6f960eabdf316 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -280,6 +280,9 @@ const copyProps = (src, dest) => { }); }; +/** + * @type {typeof primordials.makeSafe} + */ const makeSafe = (unsafe, safe) => { if (SymbolIterator in unsafe.prototype) { const dummy = new unsafe(); diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 45459d4843c133..0436e92b1d9b53 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -1,5 +1,9 @@ type UncurryThis unknown> = (self: ThisParameterType, ...args: Parameters) => ReturnType; +type UncurryThisStaticApply unknown> = + (self: ThisParameterType, args: Parameters) => ReturnType; +type StaticApply unknown> = + (args: Parameters) => ReturnType; /** * Primordials are a way to safely use globals without fear of global mutation @@ -19,6 +23,12 @@ type UncurryThis unknown> = * ``` */ declare namespace primordials { + export function uncurryThis< + T extends (...args: unknown[]) => unknown + > (fn: T): + (self: ThisType, ...args: Parameters) => ReturnType; + export function makeSafe(unsafe: NewableFunction, safe: T): T; + export const decodeURI: typeof globalThis.decodeURI; export const decodeURIComponent: typeof globalThis.decodeURIComponent; export const encodeURI: typeof globalThis.encodeURI; @@ -49,6 +59,7 @@ declare namespace primordials { export const MathLog2: typeof Math.log2 export const MathLog10: typeof Math.log10 export const MathMax: typeof Math.max + export const MathMaxApply: StaticApply export const MathMin: typeof Math.min export const MathPow: typeof Math.pow export const MathRandom: typeof Math.random @@ -100,9 +111,11 @@ declare namespace primordials { export const ArrayPrototypeLastIndexOf: UncurryThis export const ArrayPrototypePop: UncurryThis export const ArrayPrototypePush: UncurryThis + export const ArrayPrototypePushApply: UncurryThisStaticApply export const ArrayPrototypeReverse: UncurryThis export const ArrayPrototypeShift: UncurryThis export const ArrayPrototypeUnshift: UncurryThis + export const ArrayPrototypeUnshiftApply: UncurryThisStaticApply export const ArrayPrototypeSlice: UncurryThis export const ArrayPrototypeSort: UncurryThis export const ArrayPrototypeSplice: UncurryThis