diff --git a/src/bun.js/bindings/CommonJSModuleRecord.h b/src/bun.js/bindings/CommonJSModuleRecord.h index 33c9aac62463a8..d3f0fde00a1dae 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.h +++ b/src/bun.js/bindings/CommonJSModuleRecord.h @@ -1,7 +1,8 @@ #pragma once +#include "root.h" + #include "JavaScriptCore/JSGlobalObject.h" #include "JavaScriptCore/JSString.h" -#include "root.h" #include "headers-handwritten.h" #include "wtf/NakedPtr.h" diff --git a/src/bun.js/bindings/ImportMetaObject.cpp b/src/bun.js/bindings/ImportMetaObject.cpp index 2e145f17d591cb..19d4cab3243d23 100644 --- a/src/bun.js/bindings/ImportMetaObject.cpp +++ b/src/bun.js/bindings/ImportMetaObject.cpp @@ -102,7 +102,7 @@ static JSC::EncodedJSValue functionRequireResolve(JSC::JSGlobalObject* globalObj // require.resolve also supports a paths array // we only support a single path if (!fromValue.isUndefinedOrNull() && fromValue.isObject()) { - if (auto pathsObject = fromValue.getObject()->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "paths"_s))) { + if (auto pathsObject = fromValue.getObject()->getIfPropertyExists(globalObject, builtinNames(vm).pathsPublicName())) { if (pathsObject.isCell() && pathsObject.asCell()->type() == JSC::JSType::ArrayType) { auto pathsArray = JSC::jsCast(pathsObject); if (pathsArray->length() > 0) { @@ -209,7 +209,7 @@ extern "C" JSC::EncodedJSValue functionImportMeta__resolveSync(JSC::JSGlobalObje if (!fromValue.isUndefinedOrNull() && fromValue.isObject()) { - if (auto pathsObject = fromValue.getObject()->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "paths"_s))) { + if (auto pathsObject = fromValue.getObject()->getIfPropertyExists(globalObject, builtinNames(vm).pathsPublicName())) { if (pathsObject.isCell() && pathsObject.asCell()->type() == JSC::JSType::ArrayType) { auto pathsArray = JSC::jsCast(pathsObject); if (pathsArray->length() > 0) { @@ -358,7 +358,7 @@ JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, JSValue fromValue = callFrame->uncheckedArgument(1); if (!fromValue.isUndefinedOrNull() && fromValue.isObject()) { - if (JSValue pathsObject = fromValue.getObject()->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "paths"_s))) { + if (JSValue pathsObject = fromValue.getObject()->getIfPropertyExists(globalObject, builtinNames(vm).pathsPublicName())) { if (pathsObject.isCell() && pathsObject.asCell()->type() == JSC::JSType::ArrayType) { auto* pathsArray = JSC::jsCast(pathsObject); if (pathsArray->length() > 0) { diff --git a/src/bun.js/bindings/NodeVM.cpp b/src/bun.js/bindings/NodeVM.cpp index a6ea55e2ccf3ef..2053e36f0705f6 100644 --- a/src/bun.js/bindings/NodeVM.cpp +++ b/src/bun.js/bindings/NodeVM.cpp @@ -1,7 +1,7 @@ - #include "root.h" #include "JavaScriptCore/ExecutableInfo.h" +#include "BunClientData.h" #include "NodeVM.h" #include "JavaScriptCore/JSObjectInlines.h" #include "wtf/text/ExternalStringImpl.h" @@ -55,7 +55,7 @@ class ScriptOptions { } JSObject* options = asObject(optionsArg); - if (JSValue filenameOpt = options->getIfPropertyExists(globalObject, Identifier::fromString(vm, "filename"_s))) { + if (JSValue filenameOpt = options->getIfPropertyExists(globalObject, builtinNames(vm).filenamePublicName())) { if (filenameOpt.isString()) { opts.filename = filenameOpt.toWTFString(globalObject); any = true; diff --git a/src/bun.js/modules/NodeModuleModule.h b/src/bun.js/modules/NodeModuleModule.h index be6be2ee873985..d1994e4d0eb5e3 100644 --- a/src/bun.js/modules/NodeModuleModule.h +++ b/src/bun.js/modules/NodeModuleModule.h @@ -267,7 +267,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionResolveFileName, (JSC::JSGlobalObject * globa // weird thing. (fromValue.isObject()) { - if (auto idValue = fromValue.getObject()->getIfPropertyExists(globalObject, Identifier::fromString(vm, "filename"_s))) { + if (auto idValue = fromValue.getObject()->getIfPropertyExists(globalObject, builtinNames(vm).filenamePublicName())) { if (idValue.isString()) { fromValue = idValue; } @@ -334,21 +334,25 @@ struct Parent { Parent getParent(VM&vm, JSGlobalObject* global, JSValue maybe_parent) { Parent value { nullptr, nullptr }; - if (!maybe_parent.isCell()) { + + if (!maybe_parent) { return value; } - if (!maybe_parent.isObject()) { + + auto parent = maybe_parent.getObject(); + if (!parent) { return value; } - auto parent = maybe_parent.getObject(); + auto scope = DECLARE_THROW_SCOPE(vm); - JSValue paths = parent->get(global, Identifier::fromString(vm, "paths"_s)); + const auto& builtinNames = Bun::builtinNames(vm); + JSValue paths = parent->get(global, builtinNames.pathsPublicName()); RETURN_IF_EXCEPTION(scope, value); if (paths.isCell()) { value.paths = jsDynamicCast(paths); } - JSValue filename = parent->get(global, Identifier::fromString(vm, "filename"_s)); + JSValue filename = parent->get(global, builtinNames.filenamePublicName()); RETURN_IF_EXCEPTION(scope, value); if (filename.isString()) { value.filename = filename.toString(global); @@ -517,7 +521,7 @@ DEFINE_NATIVE_MODULE(NodeModule) { putNativeFn(Identifier::fromString(vm, "_resolveLookupPaths"_s), jsFunctionResolveLookupPaths); putNativeFn(Identifier::fromString(vm, "createRequire"_s), jsFunctionNodeModuleCreateRequire); - putNativeFn(Identifier::fromString(vm, "paths"_s), Resolver__nodeModulePathsForJS); + putNativeFn(builtinNames(vm).pathsPublicName(), Resolver__nodeModulePathsForJS); putNativeFn(Identifier::fromString(vm, "findSourceMap"_s), jsFunctionFindSourceMap); putNativeFn(Identifier::fromString(vm, "syncBuiltinExports"_s), jsFunctionSyncBuiltinExports); putNativeFn(Identifier::fromString(vm, "SourceMap"_s), jsFunctionSourceMap); diff --git a/src/js/builtins/BunBuiltinNames.h b/src/js/builtins/BunBuiltinNames.h index add726a63e3820..058f7415122179 100644 --- a/src/js/builtins/BunBuiltinNames.h +++ b/src/js/builtins/BunBuiltinNames.h @@ -94,7 +94,7 @@ using namespace JSC; macro(fetch) \ macro(fetchRequest) \ macro(file) \ - macro(filePath) \ + macro(filename) \ macro(fillFromJS) \ macro(finishConsumingStream) \ macro(flush) \ @@ -152,6 +152,7 @@ using namespace JSC; macro(password) \ macro(patch) \ macro(path) \ + macro(paths) \ macro(pathname) \ macro(pause) \ macro(pendingAbortRequest) \