From 3c87fbfd37f36a409c704ea3f5e2701eb0126c44 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 11 May 2022 00:56:35 -0700 Subject: [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. --- src/javascript/jsc/bindings/ZigGlobalObject.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/javascript/jsc/bindings/ZigGlobalObject.cpp') 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); -- cgit v1.2.3