From fcd8b828644cc3cf2bd46bbfc0f6b90789d5dba2 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 1 Apr 2023 21:13:27 -0700 Subject: Add stubs for missing node builtins (#2534) * Stub `node:v8` * Stub `node:trace_events` * Stub `node:repl` * Stub `node:inspector` * Stub `node:http2` * Stub `node:diagnostics_channel` * Stub `node:dgram` * Stub `node:cluster` * Link stubs * cleanup * Clean up the test * Implement `node:vm` stub * Cleanup `v8` module stub * Add missing `promises` export to node:stream * Implement `node:stream/promise` * Implement `node:assert/strict` * cleanup * better errors * Increaase timeout * Update inspector.exports.js * Make the version consistent * Implement `process.binding("constants")` * Update runner.node.mjs --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/builtins/js/ProcessObjectInternals.js | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/bun.js/builtins/js/ProcessObjectInternals.js') diff --git a/src/bun.js/builtins/js/ProcessObjectInternals.js b/src/bun.js/builtins/js/ProcessObjectInternals.js index c1898d686..d9ab6d88a 100644 --- a/src/bun.js/builtins/js/ProcessObjectInternals.js +++ b/src/bun.js/builtins/js/ProcessObjectInternals.js @@ -23,6 +23,37 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +function binding(bindingName) { + "use strict"; + bindingName !== "constants" && + @throwTypeError( + 'process.binding() is not supported in Bun. If that breaks something, please file an issue and include a reproducible code sample.' + ); + + var cache = globalThis.Symbol.for("process.bindings.constants"); + var constants = globalThis[cache]; + if (!constants) { + // 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" + ) + constants = { + fs, + zlib: {}, + crypto: {}, + os: @Bun._Os().constants, + }; + globalThis[cache] = constants; + } + return constants; +} + function getStdioWriteStream(fd_, rawRequire) { var module = { path: "node:process", require: rawRequire }; var require = path => module.require(path); -- cgit v1.2.3