diff options
author | 2023-09-07 04:58:44 -0700 | |
---|---|---|
committer | 2023-09-07 04:58:44 -0700 | |
commit | 57a06745a48093c25d0f4729ccea41a918d6427d (patch) | |
tree | ac2568d5c98918d6364d2a9667c164cd3f3b3867 /src/bun.js/modules/NodeModuleModule.h | |
parent | 4360ec83b4146e15344b304573795f084f86a7c2 (diff) | |
download | bun-57a06745a48093c25d0f4729ccea41a918d6427d.tar.gz bun-57a06745a48093c25d0f4729ccea41a918d6427d.tar.zst bun-57a06745a48093c25d0f4729ccea41a918d6427d.zip |
Progress for Next.js (#4468)
* L
* ipc
* asdfghjkl
* dfghjk
* it works!
* types
* patches for next.js
* sdfghj
* wsdfgn,./
* this
* yolo
* okay loser
* asdfghjk
* add some more APIs
* MESS
* sdfghjkl
* remove native events from streams
* stuff
* remove lazy(primordials) test
* debugging
* okay
* less fake extensions object
* fix `Buffer.toString()` args logic
* fix deserialize
* make tests work
* add test for `Buffer.toString` args
* Update server.zig
* remove test
* update test
* Update spawn-streaming-stdin.test.ts
* fix linux build
* Update fs.test.ts
* cli message improvements
* dfshaj
* Fix fs.watch bug maybe?
* remove
---------
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Diffstat (limited to 'src/bun.js/modules/NodeModuleModule.h')
-rw-r--r-- | src/bun.js/modules/NodeModuleModule.h | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/bun.js/modules/NodeModuleModule.h b/src/bun.js/modules/NodeModuleModule.h index 7c8f6ee14..b3c34eb5e 100644 --- a/src/bun.js/modules/NodeModuleModule.h +++ b/src/bun.js/modules/NodeModuleModule.h @@ -270,6 +270,40 @@ template <std::size_t N, class T> consteval std::size_t countof(T (&)[N]) { return N; } +JSC_DEFINE_CUSTOM_GETTER(get_resolveFilename, (JSGlobalObject * globalObject, + EncodedJSValue thisValue, + PropertyName propertyName)) { + auto override = static_cast<Zig::GlobalObject *>(globalObject) + ->m_nodeModuleOverriddenResolveFilename.get(); + if (override) { + return JSValue::encode(override); + } + // Instead of storing the original function on the global object and have + // those extra bytes, just have it be a property alias. + JSObject *thisObject = JSValue::decode(thisValue).getObject(); + if (!thisObject) + return JSValue::encode(jsUndefined()); + auto &vm = globalObject->vm(); + return JSValue::encode(thisObject->getDirect( + vm, Identifier::fromString(vm, "__resolveFilename"_s))); +} + +JSC_DEFINE_CUSTOM_SETTER(set_resolveFilename, + (JSGlobalObject * globalObject, + EncodedJSValue thisValue, EncodedJSValue value, + PropertyName propertyName)) { + auto valueJS = JSValue::decode(value); + if (valueJS.isCell()) { + if (auto fn = jsDynamicCast<JSFunction *>(valueJS.asCell())) { + static_cast<Zig::GlobalObject *>(globalObject) + ->m_nodeModuleOverriddenResolveFilename.set(globalObject->vm(), + globalObject, fn); + return true; + } + } + return false; +} + namespace Zig { DEFINE_NATIVE_MODULE(NodeModule) { @@ -303,6 +337,14 @@ DEFINE_NATIVE_MODULE(NodeModule) { put(Identifier::fromString(vm, "Module"_s), defaultObject); + defaultObject->putDirectCustomAccessor( + vm, JSC::Identifier::fromString(vm, "_resolveFilename"_s), + JSC::CustomGetterSetter::create(vm, get_resolveFilename, + set_resolveFilename), + JSC::PropertyAttribute::CustomAccessor | 0); + putNativeFn(Identifier::fromString(vm, "__resolveFilename"_s), + jsFunctionResolveFileName); + putNativeFn(Identifier::fromString(vm, "createRequire"_s), jsFunctionNodeModuleCreateRequire); putNativeFn(Identifier::fromString(vm, "paths"_s), @@ -314,8 +356,6 @@ DEFINE_NATIVE_MODULE(NodeModule) { putNativeFn(Identifier::fromString(vm, "SourceMap"_s), jsFunctionSourceMap); putNativeFn(Identifier::fromString(vm, "isBuiltin"_s), jsFunctionIsBuiltinModule); - putNativeFn(Identifier::fromString(vm, "_resolveFilename"_s), - jsFunctionResolveFileName); putNativeFn(Identifier::fromString(vm, "_nodeModulePaths"_s), Resolver__nodeModulePathsForJS); putNativeFn(Identifier::fromString(vm, "wrap"_s), jsFunctionWrap); |