diff options
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 14 | ||||
-rw-r--r-- | src/bun.js/module_loader.zig | 42 |
2 files changed, 55 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index bcb462d42..0f4fe92e2 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -1137,6 +1137,15 @@ enum ReadableStreamTag : int32_t { Bytes = 4, }; +JSC_DEFINE_HOST_FUNCTION(functionCallNotImplemented, + (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) +{ + auto& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + throwTypeError(globalObject, scope, "Not implemented yet in Bun :("_s); + return JSC::JSValue::encode(JSC::JSValue {}); +} + // we're trying out a new way to do this lazy loading static JSC_DEFINE_HOST_FUNCTION(functionLazyLoad, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) @@ -1156,6 +1165,7 @@ JSC: static NeverDestroyed<const String> bunStreamString(MAKE_STATIC_STRING_IMPL("bun:stream")); static NeverDestroyed<const String> noopString(MAKE_STATIC_STRING_IMPL("noop")); static NeverDestroyed<const String> createImportMeta(MAKE_STATIC_STRING_IMPL("createImportMeta")); + static NeverDestroyed<const String> masqueradesAsUndefined(MAKE_STATIC_STRING_IMPL("masqueradesAsUndefined")); JSC::JSValue moduleName = callFrame->argument(0); if (moduleName.isNumber()) { @@ -1235,6 +1245,10 @@ JSC: return JSValue::encode(obj); } + if (string == masqueradesAsUndefined) { + return JSValue::encode(InternalFunction::createFunctionThatMasqueradesAsUndefined(vm, globalObject, 0, String(), functionCallNotImplemented)); + } + if (UNLIKELY(string == noopString)) { auto* obj = constructEmptyObject(globalObject); obj->putDirectCustomAccessor(vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "getterSetter"_s)), JSC::CustomGetterSetter::create(vm, noop_getter, noop_setter), 0); diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 0bd379e63..8b557377b 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -2021,6 +2021,44 @@ pub const ModuleLoader = struct { .hash = 0, }; } + } else if (DisabledModule.has(specifier)) { + return ResolvedSource{ + .allocator = null, + .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; + \\ + ), + .specifier = ZigString.init(specifier), + .source_url = ZigString.init(specifier), + .hash = 0, + }; } return null; @@ -2209,11 +2247,11 @@ pub const HardcodedModule = enum { .{ .{ "assert", "node:assert" }, .{ "buffer", "node:buffer" }, - .{ "bun", "bun" }, .{ "bun:ffi", "bun:ffi" }, .{ "bun:jsc", "bun:jsc" }, .{ "bun:sqlite", "bun:sqlite" }, .{ "bun:wrap", "bun:wrap" }, + .{ "bun", "bun" }, .{ "child_process", "node:child_process" }, .{ "crypto", "node:crypto" }, .{ "depd", "depd" }, @@ -2262,6 +2300,7 @@ pub const HardcodedModule = enum { .{ "node:util", "node:util" }, .{ "node:util/types", "node:util/types" }, .{ "node:wasi", "node:wasi" }, + .{ "node:worker_threads", "node:worker_threads" }, .{ "node:zlib", "node:zlib" }, .{ "os", "node:os" }, .{ "path", "node:path" }, @@ -2287,6 +2326,7 @@ pub const HardcodedModule = enum { .{ "util", "node:util" }, .{ "util/types", "node:util/types" }, .{ "wasi", "node:wasi" }, + .{ "worker_threads", "node:worker_threads" }, .{ "ws", "ws" }, .{ "ws/lib/websocket", "ws" }, .{ "zlib", "node:zlib" }, |