diff options
author | 2022-05-11 00:56:35 -0700 | |
---|---|---|
committer | 2022-05-11 00:56:35 -0700 | |
commit | 3c87fbfd37f36a409c704ea3f5e2701eb0126c44 (patch) | |
tree | 0f89aa932a7a15b12cf239895194990c6d898cff /src/javascript/jsc/bindings/ZigGlobalObject.cpp | |
parent | fd00950852c3f3bf49d9ce8f6a175753ad0167fd (diff) | |
download | bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.tar.gz bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.tar.zst bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.zip |
[bun.js] Implement `import.meta.require`
This allows synchronous dynamic loading of `.node`, `.json`, and `.toml` files.
It is not a CommonJS require, but it can be used that way so long as the content is not JavaScript.
Diffstat (limited to 'src/javascript/jsc/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/javascript/jsc/bindings/ZigGlobalObject.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index f42b2a5a2..a3c84bcfc 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -1173,7 +1173,7 @@ JSC::JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObje auto index = view.reverseFind('/', view.length()); if (index != WTF::notFound) { metaProperties->putDirect(vm, clientData->builtinNames().dirPublicName(), - JSC::jsSubstring(globalObject, keyString, 0, index)); + JSC::jsSubstring(globalObject, keyString, 0, index + 1)); metaProperties->putDirect( vm, clientData->builtinNames().filePublicName(), JSC::jsSubstring(globalObject, keyString, index + 1, keyString->length() - index - 1)); @@ -1191,6 +1191,9 @@ JSC::JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObje WTF::String("resolveSync"_s), functionImportMeta__resolveSync), JSC::PropertyAttribute::Function | 0); + metaProperties->putDirectBuiltinFunction(vm, globalObject, clientData->builtinNames().requirePublicName(), + jsZigGlobalObjectRequireCodeGenerator(vm), + JSC::PropertyAttribute::Builtin | 0); } metaProperties->putDirect(vm, clientData->builtinNames().pathPublicName(), key); |