diff options
Diffstat (limited to 'src/js/builtins')
-rw-r--r-- | src/js/builtins/ProcessObjectInternals.ts | 4 | ||||
-rw-r--r-- | src/js/builtins/ReadableStream.ts | 3 | ||||
-rw-r--r-- | src/js/builtins/builtins.d.ts | 2 | ||||
-rw-r--r-- | src/js/builtins/codegen/index.ts | 22 |
4 files changed, 20 insertions, 11 deletions
diff --git a/src/js/builtins/ProcessObjectInternals.ts b/src/js/builtins/ProcessObjectInternals.ts index 8e2449a43..27cad80d0 100644 --- a/src/js/builtins/ProcessObjectInternals.ts +++ b/src/js/builtins/ProcessObjectInternals.ts @@ -35,9 +35,7 @@ export function binding(bindingName) { // TODO: make this less hacky. // This calls require("node:fs").constants // except, outside an ESM module. - const { constants: fs } = globalThis[globalThis.Symbol.for("Bun.lazy")]("createImportMeta", "node:process").require( - "node:fs", - ); + const { constants: fs } = $lazy("createImportMeta", "node:process").require("node:fs"); constants = { fs, zlib: {}, diff --git a/src/js/builtins/ReadableStream.ts b/src/js/builtins/ReadableStream.ts index 26b85fb6b..08131130d 100644 --- a/src/js/builtins/ReadableStream.ts +++ b/src/js/builtins/ReadableStream.ts @@ -161,8 +161,7 @@ export function consumeReadableStream(nativePtr, nativeType, inputStream) { } var Prototype = cached[nativeType]; if (Prototype === undefined) { - var [doRead, doError, doReadMany, doClose, onClose, deinit] = - globalThis[globalThis.Symbol.for("Bun.lazy")](nativeType); + var [doRead, doError, doReadMany, doClose, onClose, deinit] = $lazy(nativeType); Prototype = class NativeReadableStreamSink { handleError: any; diff --git a/src/js/builtins/builtins.d.ts b/src/js/builtins/builtins.d.ts index 9b32ea45e..57bde34a4 100644 --- a/src/js/builtins/builtins.d.ts +++ b/src/js/builtins/builtins.d.ts @@ -57,6 +57,7 @@ declare function $getPromiseInternalField<K extends PromiseFieldType, V>( promise: Promise<V>, key: K, ): PromiseFieldToValue<K, V>; +declare function $getInternalField(base: any, number: number): any; declare function $fulfillPromise(...args: any[]): TODO; declare function $evaluateCommonJSModule(...args: any[]): TODO; declare function $loadCJS2ESM(...args: any[]): TODO; @@ -110,6 +111,7 @@ declare function $putByIdDirectPrivate(obj: any, key: PropertyKey, value: any): declare function $putByValDirect(obj: any, key: PropertyKey, value: any): void; declare function $putByValWithThisSloppy(): TODO; declare function $putByValWithThisStrict(): TODO; +declare function $putInternalField(base: any, number: number, value: any): any; declare function $putPromiseInternalField<T extends PromiseFieldType, P extends Promise<any>>( promise: P, key: T, diff --git a/src/js/builtins/codegen/index.ts b/src/js/builtins/codegen/index.ts index a5d3c2dc8..5fbc15279 100644 --- a/src/js/builtins/codegen/index.ts +++ b/src/js/builtins/codegen/index.ts @@ -3,15 +3,23 @@ import path from "path"; import { sliceSourceCode } from "./builtin-parser"; import { applyGlobalReplacements, enums, globalsToPrefix } from "./replacements"; import { cap, fmtCPPString, low } from "./helpers"; -import { spawn, spawnSync } from "bun"; +import { spawn } from "bun"; async function createStaticHashtables() { const STATIC_HASH_TABLES = ["src/bun.js/bindings/Process.cpp"]; console.time("Creating static hash tables..."); - const create_hash_table = path.join( - import.meta.dir, - "../../../../bun-webkit/Source/JavaScriptCore/create_hash_table", - ); + const create_hash_table = [ + "src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table", + "bun-webkit/Source/JavaScriptCore/create_hash_table", + ] + .map(x => path.join(import.meta.dir, "../../../../" + x)) + .find(x => existsSync(x)); + if (!create_hash_table) { + console.warn( + "Could not find create_hash_table executable. Run `bun i` or clone webkit to build static hash tables", + ); + return; + } for (let cpp of STATIC_HASH_TABLES) { cpp = path.join(import.meta.dir, "../../../../", cpp); const { stdout, exited } = spawn({ @@ -49,6 +57,7 @@ const define = { "process.env.NODE_ENV": "development", "process.platform": process.platform, "process.arch": process.arch, + "$lazy": "___BUN_LAZY___", }; for (const name in enums) { @@ -226,7 +235,8 @@ $$capture_start$$(${fn.async ? "async " : ""}${ const finalReplacement = (fn.directives.sloppy ? captured : captured.replace(/function\s*\(.*?\)\s*{/, '$&"use strict";')) .replace(/^\((async )?function\(/, "($1function (") - .replace(/__intrinsic__/g, "@") + "\n"; + .replace(/__intrinsic__/g, "@") + .replace(/___BUN_LAZY___/g, "globalThis[globalThis.Symbol.for('Bun.lazy')]") + "\n"; bundledFunctions.push({ name: fn.name, |