aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-02-14 22:24:11 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-02-14 22:24:11 -0800
commit5598ea69f23683c593715764ed1a7d75c1092e8e (patch)
tree480e649b5426c77ebcb1b747409d13a1cf2b51bf
parent4dc6bf1b099a2a7425a5ff313cff9a9c828f6cd3 (diff)
downloadbun-5598ea69f23683c593715764ed1a7d75c1092e8e.tar.gz
bun-5598ea69f23683c593715764ed1a7d75c1092e8e.tar.zst
bun-5598ea69f23683c593715764ed1a7d75c1092e8e.zip
don't break esbuild
-rw-r--r--src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp2
-rw-r--r--src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp4
-rw-r--r--src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp48
-rw-r--r--src/bun.js/builtins/js/ImportMetaObject.js2
-rw-r--r--src/bun.js/module_loader.zig29
-rw-r--r--src/bun.js/undici.exports.js33
-rw-r--r--test/bun.js/disabled-module.test.js7
7 files changed, 50 insertions, 75 deletions
diff --git a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp
index b1409f455..8fb7fb19c 100644
--- a/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp
+++ b/src/bun.js/builtins/WebCoreJSBuiltinInternals.cpp
@@ -44,8 +44,8 @@ namespace Zig { class GlobalObject; }
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/HeapInlines.h>
#include <JavaScriptCore/JSCJSValueInlines.h>
+#include <JavaScriptCore/JSObjectInlines.h>
#include <JavaScriptCore/SlotVisitorInlines.h>
-#include <JavaScriptCore/StructureInlines.h>
namespace WebCore {
diff --git a/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp b/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp
index a6a62ed62..d014618c3 100644
--- a/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp
+++ b/src/bun.js/builtins/cpp/ImportMetaObjectBuiltins.cpp
@@ -168,7 +168,7 @@ const char* const s_importMetaObjectLoadCJS2ESMCode =
const JSC::ConstructAbility s_importMetaObjectRequireESMCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectRequireESMCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectRequireESMCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_importMetaObjectRequireESMCodeLength = 626;
+const int s_importMetaObjectRequireESMCodeLength = 616;
static const JSC::Intrinsic s_importMetaObjectRequireESMCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_importMetaObjectRequireESMCode =
"(function (resolved) {\n" \
@@ -184,7 +184,7 @@ const char* const s_importMetaObjectRequireESMCode =
" }\n" \
" var exports = @Loader.getModuleNamespaceObject(entry.module);\n" \
" var commonJS = exports.default;\n" \
- " var cjs = commonJS && commonJS[@commonJSSymbol];\n" \
+ " var cjs = commonJS?.[@commonJSSymbol];\n" \
" if (cjs === 0) {\n" \
" return commonJS;\n" \
" } else if (cjs && @isCallable(commonJS)) {\n" \
diff --git a/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp
index c5ffdff09..574d18f20 100644
--- a/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp
+++ b/src/bun.js/builtins/cpp/ProcessObjectInternalsBuiltins.cpp
@@ -51,12 +51,12 @@ namespace WebCore {
const JSC::ConstructAbility s_processObjectInternalsGetStdioWriteStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_processObjectInternalsGetStdioWriteStreamCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_processObjectInternalsGetStdioWriteStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_processObjectInternalsGetStdioWriteStreamCodeLength = 9968;
+const int s_processObjectInternalsGetStdioWriteStreamCodeLength = 9767;
static const JSC::Intrinsic s_processObjectInternalsGetStdioWriteStreamCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_processObjectInternalsGetStdioWriteStreamCode =
"(function (fd_, rawRequire) {\n" \
" var module = { path: \"node:process\", require: rawRequire };\n" \
- " var require = (path) => module.require(path);\n" \
+ " var require = path => module.require(path);\n" \
"\n" \
" function createStdioWriteStream(fd_) {\n" \
" var { Duplex, eos, destroy } = require(\"node:stream\");\n" \
@@ -103,20 +103,11 @@ const char* const s_processObjectInternalsGetStdioWriteStreamCode =
" _destroy(err, callback) {\n" \
" if (!err && this.#onClose !== null) {\n" \
" var AbortError = class AbortError extends Error {\n" \
- " constructor(\n" \
- " message = \"The operation was aborted\",\n" \
- " options = void 0,\n" \
- " ) {\n" \
+ " constructor(message = \"The operation was aborted\", options = void 0) {\n" \
" if (options !== void 0 && typeof options !== \"object\") {\n" \
- " throw new Error(\n" \
- " `Invalid AbortError options:\\n" \
+ " throw new Error(`Invalid AbortError options:\\n" \
"\\n" \
- "${JSON.stringify(\n" \
- " options,\n" \
- " null,\n" \
- " 2,\n" \
- " )}`,\n" \
- " );\n" \
+ "${JSON.stringify(options, null, 2)}`);\n" \
" }\n" \
" super(message, options);\n" \
" this.code = \"ABORT_ERR\";\n" \
@@ -158,7 +149,7 @@ const char* const s_processObjectInternalsGetStdioWriteStreamCode =
" }\n" \
" });\n" \
"\n" \
- " eos(stream, (err) => {\n" \
+ " eos(stream, err => {\n" \
" this.#writable = false;\n" \
" if (err) {\n" \
" destroy(stream, err);\n" \
@@ -197,7 +188,7 @@ const char* const s_processObjectInternalsGetStdioWriteStreamCode =
" this.push(null);\n" \
" });\n" \
"\n" \
- " eos(readStream, (err) => {\n" \
+ " eos(readStream, err => {\n" \
" this.#readable = false;\n" \
" if (err) {\n" \
" destroy(readStream, err);\n" \
@@ -230,12 +221,7 @@ const char* const s_processObjectInternalsGetStdioWriteStreamCode =
" if (!encoding) return true;\n" \
"\n" \
" var normalied = encoding.toLowerCase();\n" \
- " return (\n" \
- " normalied === \"utf8\" ||\n" \
- " normalied === \"utf-8\" ||\n" \
- " normalied === \"buffer\" ||\n" \
- " normalied === \"binary\"\n" \
- " );\n" \
+ " return normalied === \"utf8\" || normalied === \"utf-8\" || normalied === \"buffer\" || normalied === \"binary\";\n" \
" }\n" \
"\n" \
" var FastStdioWriteStream = class StdioWriteStream extends EventEmitter {\n" \
@@ -389,7 +375,7 @@ const char* const s_processObjectInternalsGetStdioWriteStreamCode =
" this.#performCallback(callback);\n" \
" this.emit(\"drain\");\n" \
" },\n" \
- " (err) => this.#performCallback(callback, err),\n" \
+ " err => this.#performCallback(callback, err),\n" \
" );\n" \
" return false;\n" \
" }\n" \
@@ -472,12 +458,12 @@ const char* const s_processObjectInternalsGetStdioWriteStreamCode =
const JSC::ConstructAbility s_processObjectInternalsGetStdinStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_processObjectInternalsGetStdinStreamCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_processObjectInternalsGetStdinStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_processObjectInternalsGetStdinStreamCodeLength = 4415;
+const int s_processObjectInternalsGetStdinStreamCodeLength = 4305;
static const JSC::Intrinsic s_processObjectInternalsGetStdinStreamCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_processObjectInternalsGetStdinStreamCode =
"(function (fd_, rawRequire, Bun) {\n" \
" var module = { path: \"node:process\", require: rawRequire };\n" \
- " var require = (path) => module.require(path);\n" \
+ " var require = path => module.require(path);\n" \
"\n" \
" var { Duplex, eos, destroy } = require(\"node:stream\");\n" \
"\n" \
@@ -526,15 +512,9 @@ const char* const s_processObjectInternalsGetStdinStreamCode =
" var AbortError = class AbortError extends Error {\n" \
" constructor(message = \"The operation was aborted\", options = void 0) {\n" \
" if (options !== void 0 && typeof options !== \"object\") {\n" \
- " throw new Error(\n" \
- " `Invalid AbortError options:\\n" \
+ " throw new Error(`Invalid AbortError options:\\n" \
"\\n" \
- "${JSON.stringify(\n" \
- " options,\n" \
- " null,\n" \
- " 2,\n" \
- " )}`,\n" \
- " );\n" \
+ "${JSON.stringify(options, null, 2)}`);\n" \
" }\n" \
" super(message, options);\n" \
" this.code = \"ABORT_ERR\";\n" \
@@ -652,7 +632,7 @@ const char* const s_processObjectInternalsGetStdinStreamCode =
" }\n" \
" });\n" \
"\n" \
- " eos(writeStream, (err) => {\n" \
+ " eos(writeStream, err => {\n" \
" this.#writable = false;\n" \
" if (err) {\n" \
" destroy(writeStream, err);\n" \
diff --git a/src/bun.js/builtins/js/ImportMetaObject.js b/src/bun.js/builtins/js/ImportMetaObject.js
index e785723c3..82701554d 100644
--- a/src/bun.js/builtins/js/ImportMetaObject.js
+++ b/src/bun.js/builtins/js/ImportMetaObject.js
@@ -148,7 +148,7 @@ function requireESM(resolved) {
}
var exports = @Loader.getModuleNamespaceObject(entry.module);
var commonJS = exports.default;
- var cjs = commonJS && commonJS[@commonJSSymbol];
+ var cjs = commonJS?.[@commonJSSymbol];
if (cjs === 0) {
return commonJS;
} else if (cjs && @isCallable(commonJS)) {
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index 8b557377b..c2c49c423 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -2027,32 +2027,9 @@ pub const ModuleLoader = struct {
.source_code = ZigString.init(
\\const symbol = Symbol.for("CommonJS");
\\const lazy = globalThis[Symbol.for("Bun.lazy")];
- \\// creating this triggers a watchpoint in JSC, so lets delay doing that.
- \\var masqueradesAsUndefined, hasMasqueradedAsUndefined;
- \\const target = {[symbol]: 0};
- \\const proxy = new Proxy(target, {
- \\ get: function (target, prop) {
- \\ if (prop in target) {
- \\ return target[prop];
- \\ }
- \\
- \\ if (!hasMasqueradedAsUndefined) {
- \\ masqueradesAsUndefined = lazy("masqueradesAsUndefined");
- \\ hasMasqueradedAsUndefined = true;
- \\ }
- \\
- \\ return masqueradesAsUndefined;
- \\ },
- \\ set: function (target, prop, value) {
- \\ target[prop] = value;
- \\ return true;
- \\ },
- \\ has: function (target, prop) {
- \\ return prop in target;
- \\ },
- \\});
- \\
- \\export default proxy;
+ \\var masqueradesAsUndefined = lazy("masqueradesAsUndefined");
+ \\masqueradesAsUndefined[symbol] = 0;
+ \\export default masqueradesAsUndefined;
\\
),
.specifier = ZigString.init(specifier),
diff --git a/src/bun.js/undici.exports.js b/src/bun.js/undici.exports.js
index 70d7ebcae..2021d71d2 100644
--- a/src/bun.js/undici.exports.js
+++ b/src/bun.js/undici.exports.js
@@ -1,3 +1,5 @@
+const { EventEmitter } = import.meta.require("events");
+
export var fetch = Bun.fetch;
export var Response = globalThis.Response;
export var Headers = globalThis.Headers;
@@ -20,7 +22,7 @@ function notImplemented() {
throw new Error("Not implemented in bun");
}
export function request() {
- throw new Error("Not implemented in bun");
+ throw new Error("TODO: Not implemented in bun yet!");
}
export function stream() {
throw new Error("Not implemented in bun");
@@ -59,13 +61,24 @@ export function Undici() {
throw new Error("Not implemented in bun");
}
-Undici.Dispatcher =
- Undici.Pool =
- Undici.BalancedPool =
- Undici.Client =
- Undici.buildConnector =
+class Dispatcher extends EventEmitter {}
+class Agent extends Dispatcher {}
+class Pool extends Dispatcher {}
+class BalancedPool extends Dispatcher {}
+class Client extends Dispatcher {
+ request() {
+ throw new Error("Not implemented in bun");
+ }
+}
+
+Undici.Dispatcher = Dispatcher;
+Undici.Pool = Pool;
+Undici.BalancedPool = BalancedPool;
+Undici.Client = Client;
+Undici.Agent = Agent;
+
+Undici.buildConnector =
Undici.errors =
- Undici.Agent =
Undici.setGlobalDispatcher =
Undici.getGlobalDispatcher =
Undici.request =
@@ -100,5 +113,11 @@ export default {
MockPool,
MockAgent,
mockErrors,
+ Dispatcher,
+ Pool,
+ BalancedPool,
+ Client,
+ Agent,
Undici,
+ [Symbol.for("CommonJS")]: 0,
};
diff --git a/test/bun.js/disabled-module.test.js b/test/bun.js/disabled-module.test.js
index 5eb0db898..43b08731d 100644
--- a/test/bun.js/disabled-module.test.js
+++ b/test/bun.js/disabled-module.test.js
@@ -1,9 +1,8 @@
-import { describe, it, expect, beforeEach, afterEach, test } from "bun:test";
+import { expect, test } from "bun:test";
test("not implemented yet module masquerades as undefined and throws an error", () => {
const worker_threads = import.meta.require("worker_threads");
- expect(typeof worker_threads).toBe("object");
- expect(typeof worker_threads.foo).toBe("undefined");
- expect(() => worker_threads.foo()).toThrow("Not implemented yet in Bun :(");
+ expect(typeof worker_threads).toBe("undefined");
+ expect(typeof worker_threads.getEnvironmentData).toBe("undefined");
});