diff options
author | 2023-06-01 18:04:09 -0700 | |
---|---|---|
committer | 2023-06-01 18:04:09 -0700 | |
commit | 3e84f18cc03a6bab898235ff2a9827b47a83aac9 (patch) | |
tree | 160b0bd3cf1b707bf68f500f0a82e85807a0fa99 /src/bun.js/bindings/ZigGlobalObject.cpp | |
parent | 42606d6aed323fa24b6783b24624e9f57cb9ef9d (diff) | |
download | bun-3e84f18cc03a6bab898235ff2a9827b47a83aac9.tar.gz bun-3e84f18cc03a6bab898235ff2a9827b47a83aac9.tar.zst bun-3e84f18cc03a6bab898235ff2a9827b47a83aac9.zip |
Implement `__dirname` and `__filename`, allow direct eval in CommonJS (#3164)
* Implement `__dirname` and `__filename`, allow direct eval in CommonJS
* Fixup dirname and add test
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 2a6be49b2..0a453a9c8 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -2619,7 +2619,7 @@ void GlobalObject::finishCreation(VM& vm) JSC::Structure* structure = globalObject->structureCache().emptyObjectStructureForPrototype( globalObject, globalObject->objectPrototype(), - 3); + 5); JSC::PropertyOffset offset; auto& vm = globalObject->vm(); @@ -2640,6 +2640,20 @@ void GlobalObject::finishCreation(VM& vm) structure = structure->addPropertyTransition( vm, structure, + JSC::Identifier::fromString(vm, "__dirname"_s), + 0, + offset); + + structure = structure->addPropertyTransition( + vm, + structure, + JSC::Identifier::fromString(vm, "__filename"_s), + 0, + offset); + + structure = structure->addPropertyTransition( + vm, + structure, JSC::Identifier::fromString(vm, "require"_s), JSC::PropertyAttribute::Function | JSC::PropertyAttribute::Builtin | 0, offset); |