aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ModuleLoader.cpp
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-03 15:31:55 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-03 15:31:55 -0700
commit08cf0d562ae81b4fb30aa5e599ca76056582ac5f (patch)
tree8385fce04c9bf7b4138ae3c3545aa330f388f456 /src/bun.js/bindings/ModuleLoader.cpp
parent9a2c3dea88b22351ecc85126b0c225bfefea71bf (diff)
downloadbun-08cf0d562ae81b4fb30aa5e599ca76056582ac5f.tar.gz
bun-08cf0d562ae81b4fb30aa5e599ca76056582ac5f.tar.zst
bun-08cf0d562ae81b4fb30aa5e599ca76056582ac5f.zip
Bunch of fixes (#3516)
* Fix #3497 * Fix #3497 * Run prettier * Fix package.json * remove this too * yeah * Fix missing tests * Use native for utf-8-validate * Add module ID names to builtins * Defer evaluation of ESM & CJS modules until link time * Use builtin name for exports in plugins * Add module IDs to builtins * Update JSC build with new flag * WebKit upgrade fixes * Update WebKit * prettier * Upgrade WebKit * bump * Update once again * Add visitAdditionalChildren, remove .fill() usage * Update process.test.js * Update fs.test.ts --------- Co-authored-by: dave caruso <me@paperdave.net> Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/ModuleLoader.cpp')
-rw-r--r--src/bun.js/bindings/ModuleLoader.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/bun.js/bindings/ModuleLoader.cpp b/src/bun.js/bindings/ModuleLoader.cpp
index 2e4dfa88e..2c8b95612 100644
--- a/src/bun.js/bindings/ModuleLoader.cpp
+++ b/src/bun.js/bindings/ModuleLoader.cpp
@@ -65,19 +65,25 @@ static JSC::JSInternalPromise* resolvedInternalPromise(JSC::JSGlobalObject* glob
}
// Converts an object from InternalModuleRegistry into { ...obj, default: obj }
-JSC::SyntheticSourceProvider::SyntheticSourceGenerator
-generateInternalModuleSourceCode(JSC::JSGlobalObject* globalObject, JSC::JSObject* object)
+static JSC::SyntheticSourceProvider::SyntheticSourceGenerator
+generateInternalModuleSourceCode(JSC::JSGlobalObject* globalObject, InternalModuleRegistry::Field moduleId)
{
- return [object](JSC::JSGlobalObject* lexicalGlobalObject,
+ return [moduleId](JSC::JSGlobalObject* lexicalGlobalObject,
JSC::Identifier moduleKey,
Vector<JSC::Identifier, 4>& exportNames,
JSC::MarkedArgumentBuffer& exportValues) -> void {
JSC::VM& vm = lexicalGlobalObject->vm();
- GlobalObject* globalObject = reinterpret_cast<GlobalObject*>(lexicalGlobalObject);
- JSC::EnsureStillAliveScope stillAlive(object);
-
+ GlobalObject* globalObject = jsCast<GlobalObject*>(lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* object = jsCast<JSObject*>(globalObject->internalModuleRegistry()->requireId(globalObject, vm, moduleId));
+ if (!object) {
+ return;
+ }
+ RETURN_IF_EXCEPTION(throwScope, {});
+
+ JSC::EnsureStillAliveScope stillAlive(object);
+
PropertyNameArray properties(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude);
object->getPropertyNames(globalObject, properties, DontEnumPropertiesMode::Exclude);
@@ -102,7 +108,8 @@ static OnLoadResult handleOnLoadObjectResult(Zig::GlobalObject* globalObject, JS
OnLoadResult result {};
result.type = OnLoadResultTypeObject;
JSC::VM& vm = globalObject->vm();
- if (JSC::JSValue exportsValue = object->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "exports"_s))) {
+ auto& builtinNames = WebCore::builtinNames(vm);
+ if (JSC::JSValue exportsValue = object->getIfPropertyExists(globalObject, builtinNames.exportsPublicName())) {
if (exportsValue.isObject()) {
result.value.object = exportsValue;
return result;
@@ -436,12 +443,14 @@ JSValue fetchCommonJSModule(
default: {
if (tag & SyntheticModuleType::InternalModuleRegistryFlag) {
constexpr auto mask = (SyntheticModuleType::InternalModuleRegistryFlag - 1);
+ auto result = globalObject->internalModuleRegistry()->requireId(globalObject, vm, static_cast<InternalModuleRegistry::Field>(tag & mask));
+ RETURN_IF_EXCEPTION(scope, {});
+
target->putDirect(
vm,
builtinNames.exportsPublicName(),
- globalObject->internalModuleRegistry()->requireId(globalObject, vm, static_cast<InternalModuleRegistry::Field>(tag & mask)),
+ result,
JSC::PropertyAttribute::ReadOnly | 0);
- RETURN_IF_EXCEPTION(scope, {});
RELEASE_AND_RETURN(scope, target);
} else {
RELEASE_AND_RETURN(scope, jsNumber(-1));
@@ -592,8 +601,7 @@ static JSValue fetchESMSourceCode(
default: {
if (tag & SyntheticModuleType::InternalModuleRegistryFlag) {
constexpr auto mask = (SyntheticModuleType::InternalModuleRegistryFlag - 1);
- auto* internalModule = jsCast<JSObject*>(globalObject->internalModuleRegistry()->requireId(globalObject, vm, static_cast<InternalModuleRegistry::Field>(tag & mask)));
- auto source = JSC::SourceCode(JSC::SyntheticSourceProvider::create(generateInternalModuleSourceCode(globalObject, internalModule), JSC::SourceOrigin(), WTFMove(moduleKey)));
+ auto source = JSC::SourceCode(JSC::SyntheticSourceProvider::create(generateInternalModuleSourceCode(globalObject, static_cast<InternalModuleRegistry::Field>(tag & mask)), JSC::SourceOrigin(URL(makeString("builtins://", moduleKey))), moduleKey));
return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source)));
} else {
auto&& provider = Zig::SourceProvider::create(globalObject, res->result.value, JSC::SourceProviderSourceType::Module, true);