diff options
Diffstat (limited to 'ext/node')
47 files changed, 495 insertions, 318 deletions
diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index 0fdaf4b4a..364468fb3 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -3,7 +3,33 @@ // deno-lint-ignore-file import { core, internals, primordials } from "ext:core/mod.js"; -const ops = core.ops; +const { + op_require_as_file_path, + op_require_break_on_next_statement, + op_require_init_paths, + op_require_is_deno_dir_package, + op_require_is_request_relative, + op_require_node_module_paths, + op_require_package_imports_resolve, + op_require_path_basename, + op_require_path_dirname, + op_require_path_is_absolute, + op_require_path_resolve, + op_require_proxy_path, + op_require_read_file, + op_require_read_package_scope, + op_require_real_path, + op_require_resolve_deno_dir, + op_require_resolve_exports, + op_require_resolve_lookup_paths, + op_require_stat, + op_require_try_self, + op_require_try_self_parent_path, +} = core.ensureFastOps(); +const { + op_napi_open, + op_require_read_closest_package_json, +} = core.ensureFastOps(true); const { ArrayIsArray, ArrayPrototypeIncludes, @@ -12,32 +38,33 @@ const { ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSplice, + Error, + JSONParse, + ObjectCreate, + ObjectEntries, ObjectGetOwnPropertyDescriptor, ObjectGetPrototypeOf, ObjectHasOwn, - ObjectSetPrototypeOf, ObjectKeys, - ObjectEntries, ObjectPrototype, - ObjectCreate, + ObjectSetPrototypeOf, Proxy, + RegExpPrototypeTest, + SafeArrayIterator, SafeMap, SafeWeakMap, - SafeArrayIterator, - JSONParse, String, + StringPrototypeCharCodeAt, StringPrototypeEndsWith, - StringPrototypeIndexOf, StringPrototypeIncludes, + StringPrototypeIndexOf, StringPrototypeMatch, StringPrototypeSlice, StringPrototypeSplit, StringPrototypeStartsWith, - StringPrototypeCharCodeAt, - RegExpPrototypeTest, - Error, TypeError, } = primordials; + import { nodeGlobals } from "ext:deno_node/00_globals.js"; import _httpAgent from "ext:deno_node/_http_agent.mjs"; @@ -248,11 +275,11 @@ function pathDirname(filepath) { } else if (filepath === "") { return "."; } - return ops.op_require_path_dirname(filepath); + return op_require_path_dirname(filepath); } function pathResolve(...args) { - return ops.op_require_path_resolve(args); + return op_require_path_resolve(args); } const nativeModulePolyfill = new SafeMap(); @@ -276,7 +303,7 @@ function stat(filename) { return result; } } - const result = ops.op_require_stat(filename); + const result = op_require_stat(filename); if (statCache !== null && result >= 0) { statCache.set(filename, result); } @@ -306,7 +333,7 @@ function tryPackage(requestPath, exts, isMain, originalPath) { requestPath, "package.json", ); - const pkg = ops.op_require_read_package_scope(packageJsonPath)?.main; + const pkg = op_require_read_package_scope(packageJsonPath)?.main; if (!pkg) { return tryExtensions( pathResolve(requestPath, "index"), @@ -360,7 +387,7 @@ function toRealPath(requestPath) { if (maybeCached) { return maybeCached; } - const rp = ops.op_require_real_path(requestPath); + const rp = op_require_real_path(requestPath); realpathCache.set(requestPath, rp); return rp; } @@ -379,7 +406,7 @@ function tryExtensions(p, exts, isMain) { // Find the longest (possibly multi-dot) extension registered in // Module._extensions function findLongestRegisteredExtension(filename) { - const name = ops.op_require_path_basename(filename); + const name = op_require_path_basename(filename); let currentExtension; let index; let startIndex = 0; @@ -513,7 +540,7 @@ function resolveExports( return false; } - return ops.op_require_resolve_exports( + return op_require_resolve_exports( usesLocalNodeModulesDir, modulesPath, request, @@ -524,7 +551,7 @@ function resolveExports( } Module._findPath = function (request, paths, isMain, parentPath) { - const absoluteRequest = ops.op_require_path_is_absolute(request); + const absoluteRequest = op_require_path_is_absolute(request); if (absoluteRequest) { paths = [""]; } else if (!paths || paths.length === 0) { @@ -568,10 +595,10 @@ Module._findPath = function (request, paths, isMain, parentPath) { if (usesLocalNodeModulesDir) { basePath = pathResolve(curPath, request); } else { - const isDenoDirPackage = ops.op_require_is_deno_dir_package( + const isDenoDirPackage = op_require_is_deno_dir_package( curPath, ); - const isRelative = ops.op_require_is_request_relative( + const isRelative = op_require_is_request_relative( request, ); basePath = (isDenoDirPackage && !isRelative) @@ -618,16 +645,16 @@ Module._findPath = function (request, paths, isMain, parentPath) { * @returns {string[]} List of module directories */ Module._nodeModulePaths = function (fromPath) { - return ops.op_require_node_module_paths(fromPath); + return op_require_node_module_paths(fromPath); }; Module._resolveLookupPaths = function (request, parent) { const paths = []; - if (ops.op_require_is_request_relative(request)) { + if (op_require_is_request_relative(request)) { ArrayPrototypePush( paths, - parent?.filename ? ops.op_require_path_dirname(parent.filename) : ".", + parent?.filename ? op_require_path_dirname(parent.filename) : ".", ); return paths; } @@ -635,7 +662,7 @@ Module._resolveLookupPaths = function (request, parent) { if ( !usesLocalNodeModulesDir && parent?.filename && parent.filename.length > 0 ) { - const denoDirPath = ops.op_require_resolve_deno_dir( + const denoDirPath = op_require_resolve_deno_dir( request, parent.filename, ); @@ -643,7 +670,7 @@ Module._resolveLookupPaths = function (request, parent) { ArrayPrototypePush(paths, denoDirPath); } } - const lookupPathsResult = ops.op_require_resolve_lookup_paths( + const lookupPathsResult = op_require_resolve_lookup_paths( request, parent?.paths, parent?.filename ?? "", @@ -765,7 +792,7 @@ Module._resolveFilename = function ( if (typeof options === "object" && options !== null) { if (ArrayIsArray(options.paths)) { - const isRelative = ops.op_require_is_request_relative( + const isRelative = op_require_is_request_relative( request, ); @@ -800,7 +827,7 @@ Module._resolveFilename = function ( if (parent?.filename) { if (request[0] === "#") { - const maybeResolved = ops.op_require_package_imports_resolve( + const maybeResolved = op_require_package_imports_resolve( parent.filename, request, ); @@ -811,12 +838,12 @@ Module._resolveFilename = function ( } // Try module self resolution first - const parentPath = ops.op_require_try_self_parent_path( + const parentPath = op_require_try_self_parent_path( !!parent, parent?.filename, parent?.id, ); - const selfResolved = ops.op_require_try_self(parentPath, request); + const selfResolved = op_require_try_self(parentPath, request); if (selfResolved) { const cacheKey = request + "\x00" + (paths.length === 1 ? paths[0] : ArrayPrototypeJoin(paths, "\x00")); @@ -832,7 +859,7 @@ Module._resolveFilename = function ( parentPath, ); if (filename) { - return ops.op_require_real_path(filename); + return op_require_real_path(filename); } const requireStack = []; for (let cursor = parent; cursor; cursor = moduleParentCache.get(cursor)) { @@ -876,7 +903,7 @@ Module.prototype.load = function (filename) { // Canonicalize the path so it's not pointing to the symlinked directory // in `node_modules` directory of the referrer. - this.filename = ops.op_require_real_path(filename); + this.filename = op_require_real_path(filename); this.paths = Module._nodeModulePaths( pathDirname(this.filename), ); @@ -989,7 +1016,7 @@ Module.prototype._compile = function (content, filename) { if (hasInspectBrk && !hasBrokenOnInspectBrk) { hasBrokenOnInspectBrk = true; - ops.op_require_break_on_next_statement(); + op_require_break_on_next_statement(); } const { @@ -1032,10 +1059,10 @@ Module.prototype._compile = function (content, filename) { }; Module._extensions[".js"] = function (module, filename) { - const content = ops.op_require_read_file(filename); + const content = op_require_read_file(filename); if (StringPrototypeEndsWith(filename, ".js")) { - const pkg = ops.op_require_read_closest_package_json(filename); + const pkg = op_require_read_closest_package_json(filename); if (pkg && pkg.exists && pkg.typ === "module") { throw createRequireEsmError( filename, @@ -1070,7 +1097,7 @@ function stripBOM(content) { // Native extension for .json Module._extensions[".json"] = function (module, filename) { - const content = ops.op_require_read_file(filename); + const content = op_require_read_file(filename); try { module.exports = JSONParse(stripBOM(content)); @@ -1085,11 +1112,11 @@ Module._extensions[".node"] = function (module, filename) { if (filename.endsWith("fsevents.node")) { throw new Error("Using fsevents module is currently not supported"); } - module.exports = ops.op_napi_open(filename, globalThis); + module.exports = op_napi_open(filename, globalThis); }; function createRequireFromPath(filename) { - const proxyPath = ops.op_require_proxy_path(filename); + const proxyPath = op_require_proxy_path(filename); const mod = new Module(proxyPath); mod.filename = proxyPath; mod.paths = Module._nodeModulePaths(mod.path); @@ -1152,14 +1179,14 @@ function createRequire(filenameOrUrl) { `The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ${filenameOrUrl}`, ); } - const filename = ops.op_require_as_file_path(fileUrlStr); + const filename = op_require_as_file_path(fileUrlStr); return createRequireFromPath(filename); } Module.createRequire = createRequire; Module._initPaths = function () { - const paths = ops.op_require_init_paths(); + const paths = op_require_init_paths(); modulePaths = paths; Module.globalPaths = ArrayPrototypeSlice(modulePaths); }; diff --git a/ext/node/polyfills/02_init.js b/ext/node/polyfills/02_init.js index 186a51d5f..7d433fe0c 100644 --- a/ext/node/polyfills/02_init.js +++ b/ext/node/polyfills/02_init.js @@ -2,8 +2,9 @@ // deno-lint-ignore-file -const internals = globalThis.__bootstrap.internals; +import { internals } from "ext:core/mod.js"; const requireImpl = internals.requireImpl; + import { nodeGlobals } from "ext:deno_node/00_globals.js"; import "node:module"; diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js index bdde3cc40..26628dde9 100644 --- a/ext/node/polyfills/_brotli.js +++ b/ext/node/polyfills/_brotli.js @@ -3,15 +3,23 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_brotli_compress, + op_brotli_compress_async, + op_brotli_compress_stream, + op_brotli_compress_stream_end, + op_brotli_decompress, + op_brotli_decompress_async, + op_brotli_decompress_stream, + op_create_brotli_compress, + op_create_brotli_decompress, +} = core.ensureFastOps(); + import { zlib as constants } from "ext:deno_node/internal_binding/constants.ts"; import { TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { Transform } from "node:stream"; import { Buffer } from "node:buffer"; -const { core } = globalThis.__bootstrap; -const { ops } = core; -const { - op_brotli_compress_async, -} = core.ensureFastOps(); const enc = new TextEncoder(); const toU8 = (input) => { @@ -44,7 +52,7 @@ export class BrotliDecompress extends Transform { transform(chunk, _encoding, callback) { const input = toU8(chunk); const output = new Uint8Array(1024); - const avail = ops.op_brotli_decompress_stream(context, input, output); + const avail = op_brotli_decompress_stream(context, input, output); this.push(output.slice(0, avail)); callback(); }, @@ -54,7 +62,7 @@ export class BrotliDecompress extends Transform { }, }); - this.#context = ops.op_create_brotli_decompress(); + this.#context = op_create_brotli_decompress(); const context = this.#context; } } @@ -68,20 +76,20 @@ export class BrotliCompress extends Transform { transform(chunk, _encoding, callback) { const input = toU8(chunk); const output = new Uint8Array(brotliMaxCompressedSize(input.length)); - const avail = ops.op_brotli_compress_stream(context, input, output); + const avail = op_brotli_compress_stream(context, input, output); this.push(output.slice(0, avail)); callback(); }, flush(callback) { const output = new Uint8Array(1024); - const avail = ops.op_brotli_compress_stream_end(context, output); + const avail = op_brotli_compress_stream_end(context, output); this.push(output.slice(0, avail)); callback(); }, }); const params = Object.values(options?.params ?? {}); - this.#context = ops.op_create_brotli_compress(params); + this.#context = op_create_brotli_compress(params); const context = this.#context; } } @@ -138,17 +146,17 @@ export function brotliCompressSync( const output = new Uint8Array(brotliMaxCompressedSize(buf.length)); const { quality, lgwin, mode } = oneOffCompressOptions(options); - const len = ops.op_brotli_compress(buf, output, quality, lgwin, mode); + const len = op_brotli_compress(buf, output, quality, lgwin, mode); return Buffer.from(output.subarray(0, len)); } export function brotliDecompress(input) { const buf = toU8(input); - return ops.op_brotli_decompress_async(buf) + return op_brotli_decompress_async(buf) .then((result) => callback(null, Buffer.from(result))) .catch((err) => callback(err)); } export function brotliDecompressSync(input) { - return Buffer.from(ops.op_brotli_decompress(toU8(input))); + return Buffer.from(op_brotli_decompress(toU8(input))); } diff --git a/ext/node/polyfills/_fs/_fs_cp.js b/ext/node/polyfills/_fs/_fs_cp.js index 245e3c76b..283b4f542 100644 --- a/ext/node/polyfills/_fs/_fs_cp.js +++ b/ext/node/polyfills/_fs/_fs_cp.js @@ -2,22 +2,24 @@ // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_cp, + op_node_cp_sync, +} = core.ensureFastOps(); + import { getValidatedPath, validateCpOptions, } from "ext:deno_node/internal/fs/utils.mjs"; import { promisify } from "ext:deno_node/internal/util.mjs"; -const core = globalThis.__bootstrap.core; -const ops = core.ops; -const { op_node_cp } = core.ensureFastOps(); - export function cpSync(src, dest, options) { validateCpOptions(options); const srcPath = getValidatedPath(src, "src"); const destPath = getValidatedPath(dest, "dest"); - ops.op_node_cp_sync(srcPath, destPath); + op_node_cp_sync(srcPath, destPath); } export function cp(src, dest, options, callback) { diff --git a/ext/node/polyfills/_fs/_fs_exists.ts b/ext/node/polyfills/_fs/_fs_exists.ts index f930013fe..3c22fc5b8 100644 --- a/ext/node/polyfills/_fs/_fs_exists.ts +++ b/ext/node/polyfills/_fs/_fs_exists.ts @@ -2,7 +2,12 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -const core = globalThis.__bootstrap.core; + +import { core } from "ext:core/mod.js"; +const { + op_node_fs_exists_sync, +} = core.ensureFastOps(); + import { pathFromURL } from "ext:deno_web/00_infra.js"; type ExistsCallback = (exists: boolean) => void; @@ -35,5 +40,5 @@ Object.defineProperty(exists, kCustomPromisifiedSymbol, { */ export function existsSync(path: string | URL): boolean { path = path instanceof URL ? pathFromURL(path) : path; - return core.ops.op_node_fs_exists_sync(path); + return op_node_fs_exists_sync(path); } diff --git a/ext/node/polyfills/_next_tick.ts b/ext/node/polyfills/_next_tick.ts index e2b04a513..5915c750e 100644 --- a/ext/node/polyfills/_next_tick.ts +++ b/ext/node/polyfills/_next_tick.ts @@ -4,12 +4,12 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; + import { validateFunction } from "ext:deno_node/internal/validators.mjs"; import { _exiting } from "ext:deno_node/_process/exiting.ts"; import { FixedQueue } from "ext:deno_node/internal/fixed_queue.ts"; -const { core } = globalThis.__bootstrap; - interface Tock { callback: (...args: Array<unknown>) => void; args: Array<unknown>; diff --git a/ext/node/polyfills/_process/process.ts b/ext/node/polyfills/_process/process.ts index 510126e91..4fae1bc1b 100644 --- a/ext/node/polyfills/_process/process.ts +++ b/ext/node/polyfills/_process/process.ts @@ -8,6 +8,7 @@ // They have to be split this way to prevent a circular dependency import { core } from "ext:core/mod.js"; + import { nextTick as _nextTick } from "ext:deno_node/_next_tick.ts"; import { _exiting } from "ext:deno_node/_process/exiting.ts"; import * as fs from "ext:deno_fs/30_fs.js"; diff --git a/ext/node/polyfills/_util/_util_callbackify.ts b/ext/node/polyfills/_util/_util_callbackify.ts index 582a16077..0ea4d0881 100644 --- a/ext/node/polyfills/_util/_util_callbackify.ts +++ b/ext/node/polyfills/_util/_util_callbackify.ts @@ -24,7 +24,6 @@ // These are simplified versions of the "real" errors in Node. import { primordials } from "ext:core/mod.js"; -import { nextTick } from "ext:deno_node/_next_tick.ts"; const { ArrayPrototypePop, Error, @@ -36,6 +35,8 @@ const { TypeError, } = primordials; +import { nextTick } from "ext:deno_node/_next_tick.ts"; + class NodeFalsyValueRejectionError extends Error { public reason: unknown; public code = "ERR_FALSY_VALUE_REJECTION"; diff --git a/ext/node/polyfills/_util/async.ts b/ext/node/polyfills/_util/async.ts index 6d65c402a..cc116412c 100644 --- a/ext/node/polyfills/_util/async.ts +++ b/ext/node/polyfills/_util/async.ts @@ -3,12 +3,13 @@ // (with some modifications) import { primordials } from "ext:core/mod.js"; -import { clearTimeout, setTimeout } from "ext:deno_web/02_timers.js"; const { Promise, PromiseReject, } = primordials; +import { clearTimeout, setTimeout } from "ext:deno_web/02_timers.js"; + /** Resolve a Promise after a given amount of milliseconds. */ export function delay( ms: number, diff --git a/ext/node/polyfills/_util/os.ts b/ext/node/polyfills/_util/os.ts index 239419d91..8a3d9edf4 100644 --- a/ext/node/polyfills/_util/os.ts +++ b/ext/node/polyfills/_util/os.ts @@ -1,7 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { core } from "ext:core/mod.js"; -const ops = core.ops; +const { + op_node_build_os, +} = core.ensureFastOps(true); export type OSType = | "windows" @@ -11,7 +13,7 @@ export type OSType = | "freebsd" | "openbsd"; -export const osType: OSType = ops.op_node_build_os(); +export const osType: OSType = op_node_build_os(); export const isWindows = osType === "windows"; export const isLinux = osType === "linux" || osType === "android"; diff --git a/ext/node/polyfills/_util/std_asserts.ts b/ext/node/polyfills/_util/std_asserts.ts index f25904251..78b749f54 100644 --- a/ext/node/polyfills/_util/std_asserts.ts +++ b/ext/node/polyfills/_util/std_asserts.ts @@ -2,13 +2,6 @@ // vendored from std/assert/mod.ts import { primordials } from "ext:core/mod.js"; -import { URLPrototype } from "ext:deno_url/00_url.js"; -import { red } from "ext:deno_node/_util/std_fmt_colors.ts"; -import { - buildMessage, - diff, - diffstr, -} from "ext:deno_node/_util/std_testing_diff.ts"; const { DatePrototype, ArrayPrototypeJoin, @@ -37,6 +30,14 @@ const { WeakRefPrototypeDeref, } = primordials; +import { URLPrototype } from "ext:deno_url/00_url.js"; +import { red } from "ext:deno_node/_util/std_fmt_colors.ts"; +import { + buildMessage, + diff, + diffstr, +} from "ext:deno_node/_util/std_testing_diff.ts"; + const FORMAT_PATTERN = new SafeRegExp(/(?=["\\])/g); /** Converts the input into a string. Objects, Sets and Maps are sorted so as to diff --git a/ext/node/polyfills/_util/std_testing_diff.ts b/ext/node/polyfills/_util/std_testing_diff.ts index 878e21f0b..74e396b0c 100644 --- a/ext/node/polyfills/_util/std_testing_diff.ts +++ b/ext/node/polyfills/_util/std_testing_diff.ts @@ -2,15 +2,6 @@ // This file was vendored from std/testing/_diff.ts import { primordials } from "ext:core/mod.js"; -import { - bgGreen, - bgRed, - bold, - gray, - green, - red, - white, -} from "ext:deno_node/_util/std_fmt_colors.ts"; const { ArrayFrom, ArrayPrototypeFilter, @@ -23,19 +14,29 @@ const { ArrayPrototypeReverse, ArrayPrototypeShift, ArrayPrototypeSlice, - ArrayPrototypeSplice, ArrayPrototypeSome, + ArrayPrototypeSplice, ArrayPrototypeUnshift, + MathMin, + ObjectFreeze, SafeArrayIterator, SafeRegExp, - StringPrototypeSplit, StringPrototypeReplace, + StringPrototypeSplit, StringPrototypeTrim, - MathMin, - ObjectFreeze, Uint32Array, } = primordials; +import { + bgGreen, + bgRed, + bold, + gray, + green, + red, + white, +} from "ext:deno_node/_util/std_fmt_colors.ts"; + interface FarthestPoint { y: number; id: number; diff --git a/ext/node/polyfills/_zlib_binding.mjs b/ext/node/polyfills/_zlib_binding.mjs index 9cece7feb..f5e7a1218 100644 --- a/ext/node/polyfills/_zlib_binding.mjs +++ b/ext/node/polyfills/_zlib_binding.mjs @@ -43,9 +43,14 @@ export const DEFLATERAW = 5; export const INFLATERAW = 6; export const UNZIP = 7; -const { core } = globalThis.__bootstrap; -const { ops } = core; +import { core } from "ext:core/mod.js"; const { + op_zlib_close, + op_zlib_close_if_pending, + op_zlib_init, + op_zlib_new, + op_zlib_reset, + op_zlib_write, op_zlib_write_async, } = core.ensureFastOps(); @@ -55,11 +60,11 @@ class Zlib { #handle; constructor(mode) { - this.#handle = ops.op_zlib_new(mode); + this.#handle = op_zlib_new(mode); } close() { - ops.op_zlib_close(this.#handle); + op_zlib_close(this.#handle); } writeSync( @@ -71,7 +76,7 @@ class Zlib { out_off, out_len, ) { - const err = ops.op_zlib_write( + const err = op_zlib_write( this.#handle, flush, input, @@ -145,7 +150,7 @@ class Zlib { strategy, dictionary, ) { - const err = ops.op_zlib_init( + const err = op_zlib_init( this.#handle, level, windowBits, @@ -164,7 +169,7 @@ class Zlib { } reset() { - const err = ops.op_zlib_reset(this.#handle); + const err = op_zlib_reset(this.#handle); if (err != Z_OK) { this.#error("Failed to reset stream", err); } @@ -172,7 +177,7 @@ class Zlib { #error(message, err) { this.onerror(message, err); - ops.op_zlib_close_if_pending(this.#handle); + op_zlib_close_if_pending(this.#handle); } } diff --git a/ext/node/polyfills/child_process.ts b/ext/node/polyfills/child_process.ts index ac3a0043f..0f45230d9 100644 --- a/ext/node/polyfills/child_process.ts +++ b/ext/node/polyfills/child_process.ts @@ -6,6 +6,14 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core, internals } from "ext:core/mod.js"; +const { + op_node_child_ipc_pipe, +} = core.ensureFastOps(); +const { + op_npm_process_state, +} = core.ensureFastOps(true); + import { ChildProcess, ChildProcessOptions, @@ -48,9 +56,6 @@ import { kEmptyObject, } from "ext:deno_node/internal/util.mjs"; -const { core } = globalThis.__bootstrap; -const ops = core.ops; - const MAX_BUFFER = 1024 * 1024; type ForkOptions = ChildProcessOptions; @@ -151,8 +156,7 @@ export function fork( options.shell = false; Object.assign(options.env ??= {}, { - DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE: core.ops - .op_npm_process_state(), + DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE: op_npm_process_state(), }); return spawn(options.execPath, args, options); @@ -824,13 +828,12 @@ export function execFileSync( } function setupChildProcessIpcChannel() { - const fd = ops.op_node_child_ipc_pipe(); + const fd = op_node_child_ipc_pipe(); if (typeof fd != "number" || fd < 0) return; setupChannel(process, fd); } -globalThis.__bootstrap.internals.__setupChildProcessIpcChannel = - setupChildProcessIpcChannel; +internals.__setupChildProcessIpcChannel = setupChildProcessIpcChannel; export default { fork, diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 40ae2c02d..fe5896534 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -3,9 +3,13 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -// import { ReadableStreamPrototype } from "ext:deno_web/06_streams.js"; +import { core } from "ext:core/mod.js"; +const { + op_fetch_response_upgrade, + op_fetch_send, + op_node_http_request, +} = core.ensureFastOps(); -const core = globalThis.__bootstrap.core; import { TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { setTimeout } from "ext:deno_web/02_timers.js"; import { @@ -60,10 +64,6 @@ import { timerId } from "ext:deno_web/03_abort_signal.js"; import { clearTimeout as webClearTimeout } from "ext:deno_web/02_timers.js"; import { resourceForReadableStream } from "ext:deno_web/06_streams.js"; import { TcpConn } from "ext:deno_net/01_net.js"; -const { - op_fetch_response_upgrade, - op_fetch_send, -} = core.ensureFastOps(); enum STATUS_CODES { /** RFC 7231, 6.2.1 */ @@ -606,7 +606,7 @@ class ClientRequest extends OutgoingMessage { this._bodyWriteRid = resourceForReadableStream(readable); } - this._req = core.ops.op_node_http_request( + this._req = op_node_http_request( this.method, url, headers, diff --git a/ext/node/polyfills/http2.ts b/ext/node/polyfills/http2.ts index f8698a803..43b6fe4f1 100644 --- a/ext/node/polyfills/http2.ts +++ b/ext/node/polyfills/http2.ts @@ -5,6 +5,18 @@ // deno-lint-ignore-file prefer-primordials import { core } from "ext:core/mod.js"; +const { + op_http2_connect, + op_http2_client_get_response, + op_http2_client_get_response_body_chunk, + op_http2_client_get_response_trailers, + op_http2_client_request, + op_http2_client_reset_stream, + op_http2_client_send_data, + op_http2_client_send_trailers, + op_http2_poll_client_connection, +} = core.ensureFastOps(); + import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts"; import { EventEmitter } from "node:events"; import { Buffer } from "node:buffer"; @@ -43,18 +55,6 @@ import { } from "ext:deno_node/internal/errors.ts"; import { _checkIsHttpToken } from "ext:deno_node/_http_common.ts"; -const { - op_http2_connect, - op_http2_client_get_response, - op_http2_client_get_response_body_chunk, - op_http2_client_get_response_trailers, - op_http2_client_request, - op_http2_client_reset_stream, - op_http2_client_send_data, - op_http2_client_send_trailers, - op_http2_poll_client_connection, -} = core.ensureFastOps(); - const kSession = Symbol("session"); const kAlpnProtocol = Symbol("alpnProtocol"); const kAuthority = Symbol("authority"); diff --git a/ext/node/polyfills/internal/buffer.mjs b/ext/node/polyfills/internal/buffer.mjs index 4d50fe80f..5c76a21a5 100644 --- a/ext/node/polyfills/internal/buffer.mjs +++ b/ext/node/polyfills/internal/buffer.mjs @@ -5,6 +5,8 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; + import { TextDecoder, TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { codes } from "ext:deno_node/internal/error_codes.ts"; import { encodings } from "ext:deno_node/internal_binding/string_decoder.ts"; @@ -35,8 +37,6 @@ import { import { atob, btoa } from "ext:deno_web/05_base64.js"; import { Blob } from "ext:deno_web/09_file.js"; -const { core } = globalThis.__bootstrap; - export { atob, Blob, btoa }; const utf8Encoder = new TextEncoder(); diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index 4b4eaefcd..cf935cfd4 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -7,6 +7,22 @@ // deno-lint-ignore-file prefer-primordials import { core, internals } from "ext:core/mod.js"; +const { + op_node_ipc_read, + op_node_ipc_write, +} = core.ensureFastOps(); +import { + ArrayIsArray, + ArrayPrototypeFilter, + ArrayPrototypeJoin, + ArrayPrototypePush, + ArrayPrototypeSlice, + ArrayPrototypeSort, + ArrayPrototypeUnshift, + ObjectHasOwn, + StringPrototypeToUpperCase, +} from "ext:deno_node/internal/primordials.mjs"; + import { assert } from "ext:deno_node/_util/asserts.ts"; import { EventEmitter } from "node:events"; import { os } from "ext:deno_node/internal_binding/constants.ts"; @@ -30,27 +46,10 @@ import { validateObject, validateString, } from "ext:deno_node/internal/validators.mjs"; -import { - ArrayIsArray, - ArrayPrototypeFilter, - ArrayPrototypeJoin, - ArrayPrototypePush, - ArrayPrototypeSlice, - ArrayPrototypeSort, - ArrayPrototypeUnshift, - ObjectHasOwn, - StringPrototypeToUpperCase, -} from "ext:deno_node/internal/primordials.mjs"; import { kEmptyObject } from "ext:deno_node/internal/util.mjs"; import { getValidatedPath } from "ext:deno_node/internal/fs/utils.mjs"; import process from "node:process"; -const core = globalThis.__bootstrap.core; -const { - op_node_ipc_read, - op_node_ipc_write, -} = core.ensureFastOps(); - export function mapValues<T, O>( record: Readonly<Record<string, T>>, transformer: (value: T) => O, diff --git a/ext/node/polyfills/internal/constants.ts b/ext/node/polyfills/internal/constants.ts index 59f326883..521cea987 100644 --- a/ext/node/polyfills/internal/constants.ts +++ b/ext/node/polyfills/internal/constants.ts @@ -1,8 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright Joyent and Node contributors. All rights reserved. MIT license. -const { ops } = globalThis.__bootstrap.core; -const isWindows = ops.op_node_build_os() === "windows"; +import { isWindows } from "ext:deno_node/_util/os.ts"; // Alphabet chars. export const CHAR_UPPERCASE_A = 65; /* A */ diff --git a/ext/node/polyfills/internal/crypto/_randomFill.mjs b/ext/node/polyfills/internal/crypto/_randomFill.mjs index 7f66cfb4b..cb61e27ef 100644 --- a/ext/node/polyfills/internal/crypto/_randomFill.mjs +++ b/ext/node/polyfills/internal/crypto/_randomFill.mjs @@ -3,17 +3,18 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_generate_secret, + op_node_generate_secret_async, +} = core.ensureFastOps(true); + import { MAX_SIZE as kMaxUint32, } from "ext:deno_node/internal/crypto/_randomBytes.ts"; import { Buffer } from "node:buffer"; import { isAnyArrayBuffer, isArrayBufferView } from "node:util/types"; import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts"; -const { core } = globalThis.__bootstrap; -const { ops } = core; -const { - op_node_generate_secret_async, -} = core.ensureFastOps(); const kBufferMaxLength = 0x7fffffff; @@ -87,7 +88,7 @@ export function randomFillSync(buf, offset = 0, size) { } const bytes = new Uint8Array(buf.buffer ? buf.buffer : buf, offset, size); - ops.op_node_generate_secret(bytes); + op_node_generate_secret(bytes); return buf; } diff --git a/ext/node/polyfills/internal/crypto/_randomInt.ts b/ext/node/polyfills/internal/crypto/_randomInt.ts index aba5a9b26..072d74c11 100644 --- a/ext/node/polyfills/internal/crypto/_randomInt.ts +++ b/ext/node/polyfills/internal/crypto/_randomInt.ts @@ -4,7 +4,9 @@ // deno-lint-ignore-file prefer-primordials import { core } from "ext:core/mod.js"; -const ops = core.ops; +const { + op_node_random_int, +} = core.ensureFastOps(); export default function randomInt(max: number): number; export default function randomInt(min: number, max: number): number; @@ -49,7 +51,7 @@ export default function randomInt( min = Math.ceil(min); max = Math.floor(max); - const result = ops.op_node_random_int(min, max); + const result = op_node_random_int(min, max); if (cb) { cb(null, result); diff --git a/ext/node/polyfills/internal/crypto/cipher.ts b/ext/node/polyfills/internal/crypto/cipher.ts index 164d6d11d..fdbdb6fd4 100644 --- a/ext/node/polyfills/internal/crypto/cipher.ts +++ b/ext/node/polyfills/internal/crypto/cipher.ts @@ -4,6 +4,24 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + encode, +} = core; +const { + op_node_cipheriv_encrypt, + op_node_cipheriv_final, + op_node_cipheriv_set_aad, + op_node_create_cipheriv, + op_node_create_decipheriv, + op_node_decipheriv_decrypt, + op_node_decipheriv_final, + op_node_decipheriv_set_aad, + op_node_private_decrypt, + op_node_private_encrypt, + op_node_public_encrypt, +} = core.ensureFastOps(); + import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts"; import { validateInt32, @@ -35,8 +53,6 @@ export function isStringOrBuffer(val) { Buffer.isBuffer(val); } -const { ops, encode } = globalThis.__bootstrap.core; - const NO_TAG = new Uint8Array(); export type CipherCCMTypes = @@ -168,7 +184,7 @@ export class Cipheriv extends Transform implements Cipher { ...options, }); this.#cache = new BlockModeCache(false); - this.#context = ops.op_node_create_cipheriv(cipher, toU8(key), toU8(iv)); + this.#context = op_node_create_cipheriv(cipher, toU8(key), toU8(iv)); this.#needsBlockCache = !(cipher == "aes-128-gcm" || cipher == "aes-256-gcm"); if (this.#context == 0) { @@ -178,7 +194,7 @@ export class Cipheriv extends Transform implements Cipher { final(encoding: string = getDefaultEncoding()): Buffer | string { const buf = new Buffer(16); - const maybeTag = ops.op_node_cipheriv_final( + const maybeTag = op_node_cipheriv_final( this.#context, this.#cache.cache, buf, @@ -200,7 +216,7 @@ export class Cipheriv extends Transform implements Cipher { plaintextLength: number; }, ): this { - ops.op_node_cipheriv_set_aad(this.#context, buffer); + op_node_cipheriv_set_aad(this.#context, buffer); return this; } @@ -223,7 +239,7 @@ export class Cipheriv extends Transform implements Cipher { let output; if (!this.#needsBlockCache) { output = Buffer.allocUnsafe(buf.length); - ops.op_node_cipheriv_encrypt(this.#context, buf, output); + op_node_cipheriv_encrypt(this.#context, buf, output); return outputEncoding === "buffer" ? output : output.toString(outputEncoding); @@ -236,7 +252,7 @@ export class Cipheriv extends Transform implements Cipher { output = Buffer.alloc(0); } else { output = Buffer.allocUnsafe(input.length); - ops.op_node_cipheriv_encrypt(this.#context, input, output); + op_node_cipheriv_encrypt(this.#context, input, output); } return outputEncoding === "buffer" ? output @@ -311,7 +327,7 @@ export class Decipheriv extends Transform implements Cipher { ...options, }); this.#cache = new BlockModeCache(true); - this.#context = ops.op_node_create_decipheriv(cipher, toU8(key), toU8(iv)); + this.#context = op_node_create_decipheriv(cipher, toU8(key), toU8(iv)); this.#needsBlockCache = !(cipher == "aes-128-gcm" || cipher == "aes-256-gcm"); if (this.#context == 0) { @@ -321,7 +337,7 @@ export class Decipheriv extends Transform implements Cipher { final(encoding: string = getDefaultEncoding()): Buffer | string { let buf = new Buffer(16); - ops.op_node_decipheriv_final( + op_node_decipheriv_final( this.#context, this.#cache.cache, buf, @@ -342,7 +358,7 @@ export class Decipheriv extends Transform implements Cipher { plaintextLength: number; }, ): this { - ops.op_node_decipheriv_set_aad(this.#context, buffer); + op_node_decipheriv_set_aad(this.#context, buffer); return this; } @@ -369,7 +385,7 @@ export class Decipheriv extends Transform implements Cipher { let output; if (!this.#needsBlockCache) { output = Buffer.allocUnsafe(buf.length); - ops.op_node_decipheriv_decrypt(this.#context, buf, output); + op_node_decipheriv_decrypt(this.#context, buf, output); return outputEncoding === "buffer" ? output : output.toString(outputEncoding); @@ -381,7 +397,7 @@ export class Decipheriv extends Transform implements Cipher { output = Buffer.alloc(0); } else { output = new Buffer(input.length); - ops.op_node_decipheriv_decrypt(this.#context, input, output); + op_node_decipheriv_decrypt(this.#context, input, output); } return outputEncoding === "buffer" ? output @@ -432,7 +448,7 @@ export function privateEncrypt( const padding = privateKey.padding || 1; buffer = getArrayBufferOrView(buffer, "buffer"); - return ops.op_node_private_encrypt(data, buffer, padding); + return op_node_private_encrypt(data, buffer, padding); } export function privateDecrypt( @@ -443,7 +459,7 @@ export function privateDecrypt( const padding = privateKey.padding || 1; buffer = getArrayBufferOrView(buffer, "buffer"); - return ops.op_node_private_decrypt(data, buffer, padding); + return op_node_private_decrypt(data, buffer, padding); } export function publicEncrypt( @@ -454,7 +470,7 @@ export function publicEncrypt( const padding = publicKey.padding || 1; buffer = getArrayBufferOrView(buffer, "buffer"); - return ops.op_node_public_encrypt(data, buffer, padding); + return op_node_public_encrypt(data, buffer, padding); } export function prepareKey(key) { diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts index 315c37278..fbcdab185 100644 --- a/ext/node/polyfills/internal/crypto/diffiehellman.ts +++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts @@ -4,6 +4,18 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_dh_compute_secret, + op_node_dh_generate2, + op_node_ecdh_compute_secret, + op_node_ecdh_generate_keys, + op_node_ecdh_compute_public_key, +} = core.ensureFastOps(); +const { + op_node_gen_prime, +} = core.ensureFastOps(true); + import { notImplemented } from "ext:deno_node/_utils.ts"; import { isAnyArrayBuffer, @@ -33,8 +45,6 @@ import type { import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts"; import type { BufferEncoding } from "ext:deno_node/_global.d.ts"; -const { ops } = Deno.core; - const DH_GENERATOR = 2; export class DiffieHellman { @@ -92,7 +102,7 @@ export class DiffieHellman { } this.#prime = Buffer.from( - ops.op_node_gen_prime(this.#primeLength).buffer, + op_node_gen_prime(this.#primeLength).buffer, ); } @@ -173,7 +183,7 @@ export class DiffieHellman { buf = Buffer.from(otherPublicKey.buffer); } - const sharedSecret = ops.op_node_dh_compute_secret( + const sharedSecret = op_node_dh_compute_secret( this.#prime, this.#privateKey, buf, @@ -190,7 +200,7 @@ export class DiffieHellman { generateKeys(encoding: BinaryToTextEncoding): string; generateKeys(_encoding?: BinaryToTextEncoding): Buffer | string { const generator = this.#checkGenerator(); - const [privateKey, publicKey] = ops.op_node_dh_generate2( + const [privateKey, publicKey] = op_node_dh_generate2( this.#prime, this.#primeLength ?? 0, generator, @@ -1215,7 +1225,7 @@ export class ECDH { ): Buffer | string { const secretBuf = Buffer.alloc(this.#curve.sharedSecretSize); - ops.op_node_ecdh_compute_secret( + op_node_ecdh_compute_secret( this.#curve.name, this.#privbuf, otherPublicKey, @@ -1231,7 +1241,7 @@ export class ECDH { encoding?: BinaryToTextEncoding, _format?: ECDHKeyFormat, ): Buffer | string { - ops.op_node_ecdh_generate_keys( + op_node_ecdh_generate_keys( this.#curve.name, this.#pubbuf, this.#privbuf, @@ -1273,7 +1283,7 @@ export class ECDH { this.#privbuf = privateKey; this.#pubbuf = Buffer.alloc(this.#curve.publicKeySize); - ops.op_node_ecdh_compute_public_key( + op_node_ecdh_compute_public_key( this.#curve.name, this.#privbuf, this.#pubbuf, diff --git a/ext/node/polyfills/internal/crypto/hash.ts b/ext/node/polyfills/internal/crypto/hash.ts index 6188e59d6..8d56f601e 100644 --- a/ext/node/polyfills/internal/crypto/hash.ts +++ b/ext/node/polyfills/internal/crypto/hash.ts @@ -4,6 +4,17 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_create_hash, + op_node_get_hashes, + op_node_hash_clone, + op_node_hash_digest_hex, + op_node_hash_digest, + op_node_hash_update_str, + op_node_hash_update, +} = core.ensureFastOps(); + import { TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { Buffer } from "node:buffer"; import { Transform } from "node:stream"; @@ -23,8 +34,6 @@ import { prepareSecretKey, } from "ext:deno_node/internal/crypto/keys.ts"; -const { ops } = globalThis.__bootstrap.core; - // TODO(@littledivy): Use Result<T, E> instead of boolean when // https://bugs.chromium.org/p/v8/issues/detail?id=13600 is fixed. function unwrapErr(ok: boolean) { @@ -65,7 +74,7 @@ export class Hash extends Transform { ) { super({ transform(chunk: string, _encoding: string, callback: () => void) { - ops.op_node_hash_update(context, coerceToBytes(chunk)); + op_node_hash_update(context, coerceToBytes(chunk)); callback(); }, flush(callback: () => void) { @@ -75,7 +84,7 @@ export class Hash extends Transform { }); if (typeof algorithm === "string") { - this.#context = ops.op_node_create_hash( + this.#context = op_node_create_hash( algorithm.toLowerCase(), ); if (this.#context === 0) { @@ -89,7 +98,7 @@ export class Hash extends Transform { } copy(): Hash { - return new Hash(ops.op_node_clone_hash(this.#context)); + return new Hash(op_node_hash_clone(this.#context)); } /** @@ -97,9 +106,9 @@ export class Hash extends Transform { */ update(data: string | ArrayBuffer, _encoding?: string): this { if (typeof data === "string") { - unwrapErr(ops.op_node_hash_update_str(this.#context, data)); + unwrapErr(op_node_hash_update_str(this.#context, data)); } else { - unwrapErr(ops.op_node_hash_update(this.#context, coerceToBytes(data))); + unwrapErr(op_node_hash_update(this.#context, coerceToBytes(data))); } return this; @@ -114,10 +123,10 @@ export class Hash extends Transform { */ digest(encoding?: string): Buffer | string { if (encoding === "hex") { - return ops.op_node_hash_digest_hex(this.#context); + return op_node_hash_digest_hex(this.#context); } - const digest = ops.op_node_hash_digest(this.#context); + const digest = op_node_hash_digest(this.#context); if (encoding === undefined) { return Buffer.from(digest); } @@ -237,7 +246,7 @@ export function createHash(algorithm: string, opts?: TransformOptions) { * @returns Array of hash algorithm names. */ export function getHashes() { - return ops.op_node_get_hashes(); + return op_node_get_hashes(); } export default { diff --git a/ext/node/polyfills/internal/crypto/hkdf.ts b/ext/node/polyfills/internal/crypto/hkdf.ts index 50b64001f..8e09f6388 100644 --- a/ext/node/polyfills/internal/crypto/hkdf.ts +++ b/ext/node/polyfills/internal/crypto/hkdf.ts @@ -4,6 +4,12 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_hkdf, + op_node_hkdf_async, +} = core.ensureFastOps(); + import { validateFunction, validateInteger, @@ -31,12 +37,6 @@ import { isArrayBufferView, } from "ext:deno_node/internal/util/types.ts"; -const { core } = globalThis.__bootstrap; -const { ops } = core; -const { - op_node_hkdf_async, -} = core.ensureFastOps(); - const validateParameters = hideStackFrames((hash, key, salt, info, length) => { validateString(hash, "digest"); key = new Uint8Array(prepareKey(key)); @@ -134,7 +134,7 @@ export function hkdfSync( const okm = new Uint8Array(length); try { - ops.op_node_hkdf(hash, key, salt, info, okm); + op_node_hkdf(hash, key, salt, info, okm); } catch (e) { throw new ERR_CRYPTO_INVALID_DIGEST(e); } diff --git a/ext/node/polyfills/internal/crypto/keygen.ts b/ext/node/polyfills/internal/crypto/keygen.ts index d11399caf..7b6c58d59 100644 --- a/ext/node/polyfills/internal/crypto/keygen.ts +++ b/ext/node/polyfills/internal/crypto/keygen.ts @@ -29,18 +29,27 @@ import { import { Buffer } from "node:buffer"; import { KeyFormat, KeyType } from "ext:deno_node/internal/crypto/types.ts"; -const { core } = globalThis.__bootstrap; -const { ops } = core; +import { core } from "ext:core/mod.js"; const { + op_node_dh_generate, op_node_dh_generate_async, + op_node_dh_generate_group, op_node_dh_generate_group_async, + op_node_dsa_generate, op_node_dsa_generate_async, + op_node_ec_generate, op_node_ec_generate_async, - op_node_generate_rsa_async, - op_node_generate_secret_async, + op_node_ed25519_generate, op_node_ed25519_generate_async, + op_node_generate_rsa, + op_node_generate_rsa_async, + op_node_x25519_generate, op_node_x25519_generate_async, } = core.ensureFastOps(); +const { + op_node_generate_secret, + op_node_generate_secret_async, +} = core.ensureFastOps(true); function validateGenerateKey( type: "hmac" | "aes", @@ -75,7 +84,7 @@ export function generateKeySync( const { length } = options; const key = new Uint8Array(Math.floor(length / 8)); - ops.op_node_generate_secret(key); + op_node_generate_secret(key); return new SecretKeyObject(setOwnedKey(key)); } @@ -804,7 +813,7 @@ function createJob(mode, type, options) { if (type === "rsa") { if (mode === kSync) { - return ops.op_node_generate_rsa( + return op_node_generate_rsa( modulusLength, publicExponent, ); @@ -859,7 +868,7 @@ function createJob(mode, type, options) { } if (mode === kSync) { - return ops.op_node_generate_rsa( + return op_node_generate_rsa( modulusLength, publicExponent, ); @@ -883,7 +892,7 @@ function createJob(mode, type, options) { } if (mode === kSync) { - return ops.op_node_dsa_generate(modulusLength, divisorLength); + return op_node_dsa_generate(modulusLength, divisorLength); } return op_node_dsa_generate_async( modulusLength, @@ -905,20 +914,20 @@ function createJob(mode, type, options) { } if (mode === kSync) { - return ops.op_node_ec_generate(namedCurve); + return op_node_ec_generate(namedCurve); } else { return op_node_ec_generate_async(namedCurve); } } case "ed25519": { if (mode === kSync) { - return ops.op_node_ed25519_generate(); + return op_node_ed25519_generate(); } return op_node_ed25519_generate_async(); } case "x25519": { if (mode === kSync) { - return ops.op_node_x25519_generate(); + return op_node_x25519_generate(); } return op_node_x25519_generate_async(); } @@ -944,7 +953,7 @@ function createJob(mode, type, options) { validateString(group, "options.group"); if (mode === kSync) { - return ops.op_node_dh_generate_group(group); + return op_node_dh_generate_group(group); } else { return op_node_dh_generate_group_async(group); } @@ -971,7 +980,7 @@ function createJob(mode, type, options) { const g = generator == null ? 2 : generator; if (mode === kSync) { - return ops.op_node_dh_generate(prime, primeLength ?? 0, g); + return op_node_dh_generate(prime, primeLength ?? 0, g); } else { return op_node_dh_generate_async( prime, diff --git a/ext/node/polyfills/internal/crypto/keys.ts b/ext/node/polyfills/internal/crypto/keys.ts index 0f2c7f985..f1da42daf 100644 --- a/ext/node/polyfills/internal/crypto/keys.ts +++ b/ext/node/polyfills/internal/crypto/keys.ts @@ -4,6 +4,11 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_create_private_key, +} = core.ensureFastOps(); + import { kHandle, kKeyObject, @@ -39,9 +44,6 @@ import { forgivingBase64UrlEncode as encodeToBase64Url, } from "ext:deno_web/00_infra.js"; -const { core } = globalThis.__bootstrap; -const { ops } = core; - export const getArrayBufferOrView = hideStackFrames( ( buffer, @@ -234,7 +236,7 @@ export function createPrivateKey( key: PrivateKeyInput | string | Buffer | JsonWebKeyInput, ): PrivateKeyObject { const { data, format, type } = prepareAsymmetricKey(key); - const details = ops.op_node_create_private_key(data, format, type); + const details = op_node_create_private_key(data, format, type); const handle = setOwnedKey(copyBuffer(data)); return new PrivateKeyObject(handle, details); } diff --git a/ext/node/polyfills/internal/crypto/pbkdf2.ts b/ext/node/polyfills/internal/crypto/pbkdf2.ts index e365ef3f0..47c66043c 100644 --- a/ext/node/polyfills/internal/crypto/pbkdf2.ts +++ b/ext/node/polyfills/internal/crypto/pbkdf2.ts @@ -3,13 +3,15 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_pbkdf2, + op_node_pbkdf2_async, +} = core.ensureFastOps(); + import { Buffer } from "node:buffer"; import { HASH_DATA } from "ext:deno_node/internal/crypto/types.ts"; -const { core } = globalThis.__bootstrap; -const { ops } = core; -const { op_node_pbkdf2_async } = core.ensureFastOps(); - export const MAX_ALLOC = Math.pow(2, 30) - 1; export type NormalizedAlgorithms = @@ -51,7 +53,7 @@ export function pbkdf2Sync( } const DK = new Uint8Array(keylen); - if (!ops.op_node_pbkdf2(password, salt, iterations, digest, DK)) { + if (!op_node_pbkdf2(password, salt, iterations, digest, DK)) { throw new Error("Invalid digest"); } diff --git a/ext/node/polyfills/internal/crypto/random.ts b/ext/node/polyfills/internal/crypto/random.ts index 450754734..52f6db272 100644 --- a/ext/node/polyfills/internal/crypto/random.ts +++ b/ext/node/polyfills/internal/crypto/random.ts @@ -4,6 +4,22 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core, primordials } from "ext:core/mod.js"; +const { + op_node_check_prime, + op_node_check_prime_async, + op_node_check_prime_bytes, + op_node_check_prime_bytes_async, + op_node_gen_prime_async, +} = core.ensureFastOps(); +const { + op_node_gen_prime, +} = core.ensureFastOps(true); +const { + StringPrototypePadStart, + StringPrototypeToString, +} = primordials; + import { notImplemented } from "ext:deno_node/_utils.ts"; import randomBytes from "ext:deno_node/internal/crypto/_randomBytes.ts"; import randomFill, { @@ -32,17 +48,6 @@ export { } from "ext:deno_node/internal/crypto/_randomFill.mjs"; export { default as randomInt } from "ext:deno_node/internal/crypto/_randomInt.ts"; -import { primordials } from "ext:core/mod.js"; -const { StringPrototypePadStart, StringPrototypeToString } = primordials; - -const { core } = globalThis.__bootstrap; -const { ops } = core; -const { - op_node_gen_prime_async, - op_node_check_prime_bytes_async, - op_node_check_prime_async, -} = Deno.core.ensureFastOps(); - export type LargeNumberLike = | ArrayBufferView | SharedArrayBuffer @@ -129,7 +134,7 @@ export function checkPrimeSync( validateInt32(checks, "options.checks", 0); if (typeof candidate === "bigint") { - return ops.op_node_check_prime(candidate, checks); + return op_node_check_prime(candidate, checks); } else if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { throw new ERR_INVALID_ARG_TYPE( "candidate", @@ -144,7 +149,7 @@ export function checkPrimeSync( ); } - return ops.op_node_check_prime_bytes(candidate, checks); + return op_node_check_prime_bytes(candidate, checks); } export interface GeneratePrimeOptions { @@ -186,7 +191,7 @@ export function generatePrimeSync( bigint, } = validateRandomPrimeJob(size, options); - const prime = ops.op_node_gen_prime(size); + const prime = op_node_gen_prime(size); if (bigint) return arrayBufferToUnsignedBigInt(prime.buffer); return prime.buffer; } diff --git a/ext/node/polyfills/internal/crypto/scrypt.ts b/ext/node/polyfills/internal/crypto/scrypt.ts index 49dd815c6..7de5a3ab8 100644 --- a/ext/node/polyfills/internal/crypto/scrypt.ts +++ b/ext/node/polyfills/internal/crypto/scrypt.ts @@ -29,9 +29,9 @@ SOFTWARE. import { Buffer } from "node:buffer"; import { HASH_DATA } from "ext:deno_node/internal/crypto/types.ts"; -const { core } = globalThis.__bootstrap; -const { ops } = core; +import { core } from "ext:core/mod.js"; const { + op_node_scrypt_sync, op_node_scrypt_async, } = core.ensureFastOps(); @@ -78,7 +78,7 @@ export function scryptSync( } const buf = Buffer.alloc(keylen); - ops.op_node_scrypt_sync( + op_node_scrypt_sync( password, salt, keylen, diff --git a/ext/node/polyfills/internal/crypto/sig.ts b/ext/node/polyfills/internal/crypto/sig.ts index 066857d51..fb303e4e2 100644 --- a/ext/node/polyfills/internal/crypto/sig.ts +++ b/ext/node/polyfills/internal/crypto/sig.ts @@ -4,6 +4,12 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_sign, + op_node_verify, +} = core.ensureFastOps(); + import { notImplemented } from "ext:deno_node/_utils.ts"; import { validateFunction, @@ -28,9 +34,6 @@ import { KeyFormat, KeyType } from "ext:deno_node/internal/crypto/types.ts"; import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts"; import { ERR_CRYPTO_SIGN_KEY_REQUIRED } from "ext:deno_node/internal/errors.ts"; -const { core } = globalThis.__bootstrap; -const { ops } = core; - export type DSAEncoding = "der" | "ieee-p1363"; export interface SigningOptions { @@ -81,7 +84,7 @@ export class SignImpl extends Writable { encoding?: BinaryToTextEncoding, ): Buffer | string { const { data, format, type } = prepareAsymmetricKey(privateKey); - const ret = Buffer.from(ops.op_node_sign( + const ret = Buffer.from(op_node_sign( this.hash.digest(), this.#digestType, data!, @@ -157,7 +160,7 @@ export class VerifyImpl extends Writable { "crypto.Verify.prototype.verify with non BinaryLike input", ); } - return ops.op_node_verify( + return op_node_verify( this.hash.digest(), this.#digestType, keyData!, diff --git a/ext/node/polyfills/internal/crypto/x509.ts b/ext/node/polyfills/internal/crypto/x509.ts index 07037bd4a..380deefc3 100644 --- a/ext/node/polyfills/internal/crypto/x509.ts +++ b/ext/node/polyfills/internal/crypto/x509.ts @@ -4,6 +4,22 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_x509_ca, + op_node_x509_check_email, + op_node_x509_fingerprint, + op_node_x509_fingerprint256, + op_node_x509_fingerprint512, + op_node_x509_get_issuer, + op_node_x509_get_serial_number, + op_node_x509_get_subject, + op_node_x509_get_valid_from, + op_node_x509_get_valid_to, + op_node_x509_key_usage, + op_node_x509_parse, +} = core.ensureFastOps(); + import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts"; import { Buffer } from "node:buffer"; import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts"; @@ -12,8 +28,6 @@ import { validateString } from "ext:deno_node/internal/validators.mjs"; import { notImplemented } from "ext:deno_node/_utils.ts"; import { BinaryLike } from "ext:deno_node/internal/crypto/types.ts"; -const { ops } = globalThis.__bootstrap.core; - // deno-lint-ignore no-explicit-any export type PeerCertificate = any; @@ -56,11 +70,11 @@ export class X509Certificate { ); } - this.#handle = ops.op_node_x509_parse(buffer); + this.#handle = op_node_x509_parse(buffer); } get ca(): boolean { - return ops.op_node_x509_ca(this.#handle); + return op_node_x509_ca(this.#handle); } checkEmail( @@ -68,7 +82,7 @@ export class X509Certificate { _options?: Pick<X509CheckOptions, "subject">, ): string | undefined { validateString(email, "email"); - if (ops.op_node_x509_check_email(this.#handle, email)) { + if (op_node_x509_check_email(this.#handle, email)) { return email; } } @@ -90,15 +104,15 @@ export class X509Certificate { } get fingerprint(): string { - return ops.op_node_x509_fingerprint(this.#handle); + return op_node_x509_fingerprint(this.#handle); } get fingerprint256(): string { - return ops.op_node_x509_fingerprint256(this.#handle); + return op_node_x509_fingerprint256(this.#handle); } get fingerprint512(): string { - return ops.op_node_x509_fingerprint512(this.#handle); + return op_node_x509_fingerprint512(this.#handle); } get infoAccess(): string | undefined { @@ -108,7 +122,7 @@ export class X509Certificate { } get issuer(): string { - return ops.op_node_x509_get_issuer(this.#handle); + return op_node_x509_get_issuer(this.#handle); } get issuerCertificate(): X509Certificate | undefined { @@ -116,7 +130,7 @@ export class X509Certificate { } get keyUsage(): string[] | undefined { - const flags = ops.op_node_x509_key_usage(this.#handle); + const flags = op_node_x509_key_usage(this.#handle); if (flags === 0) return undefined; const result: string[] = []; if (flags & 0x01) result.push("DigitalSignature"); @@ -144,11 +158,11 @@ export class X509Certificate { } get serialNumber(): string { - return ops.op_node_x509_get_serial_number(this.#handle); + return op_node_x509_get_serial_number(this.#handle); } get subject(): string { - return ops.op_node_x509_get_subject(this.#handle); + return op_node_x509_get_subject(this.#handle); } get subjectAltName(): string | undefined { @@ -168,11 +182,11 @@ export class X509Certificate { } get validFrom(): string { - return ops.op_node_x509_get_valid_from(this.#handle); + return op_node_x509_get_valid_from(this.#handle); } get validTo(): string { - return ops.op_node_x509_get_valid_to(this.#handle); + return op_node_x509_get_valid_to(this.#handle); } verify(_publicKey: KeyObject): boolean { diff --git a/ext/node/polyfills/internal/process/report.ts b/ext/node/polyfills/internal/process/report.ts index 2d81b4ce8..c4a1ff561 100644 --- a/ext/node/polyfills/internal/process/report.ts +++ b/ext/node/polyfills/internal/process/report.ts @@ -1,8 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { arch, versions } from "ext:deno_node/_process/process.ts"; -import { cpus, hostname, networkInterfaces } from "node:os"; - import { primordials } from "ext:core/mod.js"; const { Error, @@ -13,6 +10,9 @@ const { DatePrototypeGetTime, } = primordials; +import { arch, versions } from "ext:deno_node/_process/process.ts"; +import { cpus, hostname, networkInterfaces } from "node:os"; + function writeReport(_filename: string, _err: typeof Error) { return ""; } diff --git a/ext/node/polyfills/internal/validators.mjs b/ext/node/polyfills/internal/validators.mjs index e728d40ad..89527a84c 100644 --- a/ext/node/polyfills/internal/validators.mjs +++ b/ext/node/polyfills/internal/validators.mjs @@ -4,17 +4,17 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -import { codes } from "ext:deno_node/internal/error_codes.ts"; -import { hideStackFrames } from "ext:deno_node/internal/hide_stack_frames.ts"; -import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts"; -import { normalizeEncoding } from "ext:deno_node/internal/normalize_encoding.mjs"; - import { primordials } from "ext:core/mod.js"; const { ArrayPrototypeIncludes, ArrayPrototypeJoin, } = primordials; +import { codes } from "ext:deno_node/internal/error_codes.ts"; +import { hideStackFrames } from "ext:deno_node/internal/hide_stack_frames.ts"; +import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts"; +import { normalizeEncoding } from "ext:deno_node/internal/normalize_encoding.mjs"; + /** * @param {number} value * @returns {boolean} diff --git a/ext/node/polyfills/internal_binding/_libuv_winerror.ts b/ext/node/polyfills/internal_binding/_libuv_winerror.ts index a62b27a7f..105adfb55 100644 --- a/ext/node/polyfills/internal_binding/_libuv_winerror.ts +++ b/ext/node/polyfills/internal_binding/_libuv_winerror.ts @@ -1,7 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -const { ops } = globalThis.__bootstrap.core; +import { core } from "ext:core/mod.js"; +const { + op_node_sys_to_uv_error, +} = core.ensureFastOps(); export function uvTranslateSysError(sysErrno: number): string { - return ops.op_node_sys_to_uv_error(sysErrno); + return op_node_sys_to_uv_error(sysErrno); } diff --git a/ext/node/polyfills/internal_binding/constants.ts b/ext/node/polyfills/internal_binding/constants.ts index 69a2dffeb..4a6a90608 100644 --- a/ext/node/polyfills/internal_binding/constants.ts +++ b/ext/node/polyfills/internal_binding/constants.ts @@ -1,4 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +import { core } from "ext:core/mod.js"; +const { + op_node_build_os, +} = core.ensureFastOps(true); + let os: { dlopen: { RTLD_DEEPBIND?: number; @@ -196,8 +202,7 @@ let os: { UV_UDP_REUSEADDR: number; }; -const core = globalThis.__bootstrap.core; -const buildOs = core.ops.op_node_build_os(); +const buildOs = op_node_build_os(); if (buildOs === "darwin") { os = { UV_UDP_REUSEADDR: 4, diff --git a/ext/node/polyfills/internal_binding/stream_wrap.ts b/ext/node/polyfills/internal_binding/stream_wrap.ts index 352bc6a43..87371bf7a 100644 --- a/ext/node/polyfills/internal_binding/stream_wrap.ts +++ b/ext/node/polyfills/internal_binding/stream_wrap.ts @@ -30,6 +30,12 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_can_write_vectored, + op_raw_write_vectored, +} = core.ensureFastOps(); + import { TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { Buffer } from "node:buffer"; import { notImplemented } from "ext:deno_node/_utils.ts"; @@ -40,9 +46,6 @@ import { } from "ext:deno_node/internal_binding/async_wrap.ts"; import { codeMap } from "ext:deno_node/internal_binding/uv.ts"; -import { core } from "ext:core/mod.js"; -const { ops } = core; - interface Reader { read(p: Uint8Array): Promise<number | null>; } @@ -204,13 +207,13 @@ export class LibuvStreamWrap extends HandleWrap { // Fast case optimization: two chunks, and all buffers. if ( chunks.length === 2 && allBuffers && supportsWritev && - ops.op_can_write_vectored(rid) + op_can_write_vectored(rid) ) { // String chunks. if (typeof chunks[0] === "string") chunks[0] = Buffer.from(chunks[0]); if (typeof chunks[1] === "string") chunks[1] = Buffer.from(chunks[1]); - ops.op_raw_write_vectored( + op_raw_write_vectored( rid, chunks[0], chunks[1], diff --git a/ext/node/polyfills/internal_binding/udp_wrap.ts b/ext/node/polyfills/internal_binding/udp_wrap.ts index 209c84a23..b78f2a077 100644 --- a/ext/node/polyfills/internal_binding/udp_wrap.ts +++ b/ext/node/polyfills/internal_binding/udp_wrap.ts @@ -24,7 +24,11 @@ // deno-lint-ignore-file prefer-primordials import { core } from "ext:core/mod.js"; -const ops = core.ops; +const { + op_node_unstable_net_listen_udp, + op_node_unstable_net_listen_unixpacket, +} = core.ensureFastOps(); + import { AsyncWrap, providerType, @@ -41,8 +45,8 @@ import * as net from "ext:deno_net/01_net.js"; import { isLinux, isWindows } from "ext:deno_node/_util/os.ts"; const DenoListenDatagram = net.createListenDatagram( - ops.op_node_unstable_net_listen_udp, - ops.op_node_unstable_net_listen_unixpacket, + op_node_unstable_net_listen_udp, + op_node_unstable_net_listen_unixpacket, ); type MessageType = string | Uint8Array | Buffer | DataView; diff --git a/ext/node/polyfills/internal_binding/util.ts b/ext/node/polyfills/internal_binding/util.ts index 721d0964f..b4bcdaef4 100644 --- a/ext/node/polyfills/internal_binding/util.ts +++ b/ext/node/polyfills/internal_binding/util.ts @@ -29,11 +29,13 @@ // deno-lint-ignore-file prefer-primordials import { core } from "ext:core/mod.js"; -const ops = core.ops; +const { + op_node_guess_handle_type, +} = core.ensureFastOps(); const handleTypes = ["TCP", "TTY", "UDP", "FILE", "PIPE", "UNKNOWN"]; export function guessHandleType(fd: number): string { - const type = ops.op_node_guess_handle_type(fd); + const type = op_node_guess_handle_type(fd); return handleTypes[type]; } diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts index 5d354b38b..f95ea1cc8 100644 --- a/ext/node/polyfills/os.ts +++ b/ext/node/polyfills/os.ts @@ -23,7 +23,14 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -const core = globalThis.__bootstrap.core; +import { core } from "ext:core/mod.js"; +const { + op_cpus, + op_node_os_get_priority, + op_node_os_set_priority, + op_node_os_username, +} = core.ensureFastOps(); + import { validateIntegerRange } from "ext:deno_node/_utils.ts"; import process from "node:process"; import { isWindows, osType } from "ext:deno_node/_util/os.ts"; @@ -32,8 +39,6 @@ import { os } from "ext:deno_node/internal_binding/constants.ts"; import { osUptime } from "ext:runtime/30_os.js"; import { Buffer } from "ext:deno_node/internal/buffer.mjs"; -const ops = core.ops; - export const constants = os; interface CPUTimes { @@ -133,7 +138,7 @@ export function arch(): string { (machine as any)[Symbol.toPrimitive] = (): string => machine(); export function cpus(): CPUCoreInfo[] { - return ops.op_cpus(); + return op_cpus(); } /** @@ -164,7 +169,7 @@ export function freemem(): number { /** Not yet implemented */ export function getPriority(pid = 0): number { validateIntegerRange(pid, "pid"); - return core.ops.op_node_os_get_priority(pid); + return op_node_os_get_priority(pid); } /** Returns the string path of the current user's home directory. */ @@ -270,7 +275,7 @@ export function setPriority(pid: number, priority?: number) { validateIntegerRange(pid, "pid"); validateIntegerRange(priority, "priority", -20, 19); - core.ops.op_node_os_set_priority(pid, priority); + op_node_os_set_priority(pid, priority); } /** Returns the operating system's default directory for temporary files as a string. */ @@ -350,7 +355,7 @@ export function userInfo( throw new ERR_OS_NO_HOMEDIR(); } let shell = isWindows ? (Deno.env.get("SHELL") || null) : null; - let username = core.ops.op_node_os_username(); + let username = op_node_os_username(); if (options?.encoding === "buffer") { _homedir = _homedir ? Buffer.from(_homedir) : _homedir; diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index 752486af4..3d5009b90 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -4,9 +4,15 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -const internals = globalThis.__bootstrap.internals; -const { core } = globalThis.__bootstrap; -const { ops } = core; +import { core, internals } from "ext:core/mod.js"; +const { + op_process_abort, + op_geteuid, +} = core.ensureFastOps(); +const { + op_set_exit_code, +} = core.ensureFastOps(true); + import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts"; import { EventEmitter } from "node:events"; import Module from "node:module"; @@ -99,7 +105,7 @@ export const exit = (code?: number | string) => { }; export const abort = () => { - ops.op_process_abort(); + op_process_abort(); }; function addReadOnlyProcessAlias( @@ -440,7 +446,7 @@ class Process extends EventEmitter { globalProcessExitCode = code; code = parseInt(code) || 0; if (!isNaN(code)) { - ops.op_set_exit_code(code); + op_set_exit_code(code); } } @@ -676,7 +682,7 @@ class Process extends EventEmitter { /** This method is removed on Windows */ geteuid?(): number { - return ops.op_geteuid(); + return op_geteuid(); } // TODO(kt3k): Implement this when we added -e option to node compat mode diff --git a/ext/node/polyfills/punycode.ts b/ext/node/polyfills/punycode.ts index 3c3e18242..53bec2e5e 100644 --- a/ext/node/polyfills/punycode.ts +++ b/ext/node/polyfills/punycode.ts @@ -1,23 +1,29 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { ucs2 } from "ext:deno_node/internal/idna.ts"; +import { core } from "ext:core/mod.js"; +const { + op_node_idna_domain_to_unicode, + op_node_idna_punycode_decode, + op_node_idna_punycode_encode, + op_node_idna_domain_to_ascii, +} = core.ensureFastOps(); -const { ops } = globalThis.__bootstrap.core; +import { ucs2 } from "ext:deno_node/internal/idna.ts"; function toASCII(domain) { - return ops.op_node_idna_domain_to_ascii(domain); + return op_node_idna_domain_to_ascii(domain); } function toUnicode(domain) { - return ops.op_node_idna_domain_to_unicode(domain); + return op_node_idna_domain_to_unicode(domain); } function decode(domain) { - return ops.op_node_idna_punycode_decode(domain); + return op_node_idna_punycode_decode(domain); } function encode(domain) { - return ops.op_node_idna_punycode_encode(domain); + return op_node_idna_punycode_encode(domain); } export { decode, encode, toASCII, toUnicode, ucs2 }; diff --git a/ext/node/polyfills/tty.js b/ext/node/polyfills/tty.js index a08d1ae37..86fd34d7c 100644 --- a/ext/node/polyfills/tty.js +++ b/ext/node/polyfills/tty.js @@ -1,11 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { primordials } from "ext:core/mod.js"; +const { + Error, +} = primordials; + import { ERR_INVALID_FD } from "ext:deno_node/internal/errors.ts"; import { LibuvStreamWrap } from "ext:deno_node/internal_binding/stream_wrap.ts"; import { providerType } from "ext:deno_node/internal_binding/async_wrap.ts"; import { Socket } from "node:net"; import { setReadStream } from "ext:deno_node/_process/streams.mjs"; -const { Error } = globalThis.__bootstrap.primordials; // Returns true when the given numeric fd is associated with a TTY and false otherwise. function isatty(fd) { diff --git a/ext/node/polyfills/util.ts b/ext/node/polyfills/util.ts index eb03bd272..3d449f8dc 100644 --- a/ext/node/polyfills/util.ts +++ b/ext/node/polyfills/util.ts @@ -1,21 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { promisify } from "ext:deno_node/internal/util.mjs"; -import { callbackify } from "ext:deno_node/_util/_util_callbackify.ts"; -import { debuglog } from "ext:deno_node/internal/util/debuglog.ts"; -import { - format, - formatWithOptions, - inspect, - stripVTControlCharacters, -} from "ext:deno_node/internal/util/inspect.mjs"; -import { codes } from "ext:deno_node/internal/error_codes.ts"; -import types from "node:util/types"; -import { Buffer } from "node:buffer"; -import { isDeepStrictEqual } from "ext:deno_node/internal/util/comparisons.ts"; -import process from "node:process"; -import { validateString } from "ext:deno_node/internal/validators.mjs"; -import { parseArgs } from "ext:deno_node/internal/util/parse_args/parse_args.js"; import { primordials } from "ext:core/mod.js"; const { ArrayIsArray, @@ -43,6 +27,23 @@ const { StringPrototypeToWellFormed, } = primordials; +import { promisify } from "ext:deno_node/internal/util.mjs"; +import { callbackify } from "ext:deno_node/_util/_util_callbackify.ts"; +import { debuglog } from "ext:deno_node/internal/util/debuglog.ts"; +import { + format, + formatWithOptions, + inspect, + stripVTControlCharacters, +} from "ext:deno_node/internal/util/inspect.mjs"; +import { codes } from "ext:deno_node/internal/error_codes.ts"; +import types from "node:util/types"; +import { Buffer } from "node:buffer"; +import { isDeepStrictEqual } from "ext:deno_node/internal/util/comparisons.ts"; +import process from "node:process"; +import { validateString } from "ext:deno_node/internal/validators.mjs"; +import { parseArgs } from "ext:deno_node/internal/util/parse_args/parse_args.js"; + export { callbackify, debuglog, diff --git a/ext/node/polyfills/v8.ts b/ext/node/polyfills/v8.ts index 251cead62..4c01bc9ad 100644 --- a/ext/node/polyfills/v8.ts +++ b/ext/node/polyfills/v8.ts @@ -4,12 +4,16 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -import { notImplemented } from "ext:deno_node/_utils.ts"; +import { core } from "ext:core/mod.js"; +const { + op_v8_cached_data_version_tag, + op_v8_get_heap_statistics, +} = core.ensureFastOps(); -const { ops } = globalThis.__bootstrap.core; +import { notImplemented } from "ext:deno_node/_utils.ts"; export function cachedDataVersionTag() { - return ops.op_v8_cached_data_version_tag(); + return op_v8_cached_data_version_tag(); } export function getHeapCodeStatistics() { notImplemented("v8.getHeapCodeStatistics"); @@ -24,7 +28,7 @@ export function getHeapSpaceStatistics() { const buffer = new Float64Array(14); export function getHeapStatistics() { - ops.op_v8_get_heap_statistics(buffer); + op_v8_get_heap_statistics(buffer); return { total_heap_size: buffer[0], diff --git a/ext/node/polyfills/vm.ts b/ext/node/polyfills/vm.ts index 221770ffe..ef817456a 100644 --- a/ext/node/polyfills/vm.ts +++ b/ext/node/polyfills/vm.ts @@ -3,10 +3,11 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file no-explicit-any prefer-primordials +import { core } from "ext:core/mod.js"; import { notImplemented } from "ext:deno_node/_utils.ts"; - -const { core } = globalThis.__bootstrap; -const ops = core.ops; +const { + op_vm_run_in_new_context, +} = core.ensureFastOps(); export class Script { code: string; @@ -32,7 +33,7 @@ export class Script { "Script.runInNewContext options are currently not supported", ); } - return ops.op_vm_run_in_new_context(this.code, contextObject); + return op_vm_run_in_new_context(this.code, contextObject); } createCachedData() { @@ -64,7 +65,7 @@ export function runInNewContext( if (options) { console.warn("vm.runInNewContext options are currently not supported"); } - return ops.op_vm_run_in_new_context(code, contextObject); + return op_vm_run_in_new_context(code, contextObject); } export function runInThisContext( diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 1e3d41435..4092cac51 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -4,6 +4,11 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core, internals } from "ext:core/mod.js"; +const { + op_require_read_closest_package_json, +} = core.ensureFastOps(true); + import { isAbsolute, resolve } from "node:path"; import { notImplemented } from "ext:deno_node/_utils.ts"; import { EventEmitter, once } from "node:events"; @@ -12,7 +17,6 @@ import { MessageChannel, MessagePort } from "ext:deno_web/13_message_port.js"; let environmentData = new Map(); let threads = 0; -const { core } = globalThis.__bootstrap; export interface WorkerOptions { // only for typings @@ -120,7 +124,7 @@ class _Worker extends EventEmitter { specifier = resolve(specifier); let pkg; try { - pkg = core.ops.op_require_read_closest_package_json(specifier); + pkg = op_require_read_closest_package_json(specifier); } catch (_) { // empty catch block when package json might not be present } @@ -203,7 +207,7 @@ type ParentPort = typeof self & NodeEventTarget; // deno-lint-ignore no-explicit-any let parentPort: ParentPort = null as any; -globalThis.__bootstrap.internals.__initWorkerThreads = () => { +internals.__initWorkerThreads = () => { isMainThread = // deno-lint-ignore no-explicit-any (globalThis as any).name !== PRIVATE_WORKER_THREAD_NAME; |