aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/CommonJSModuleRecord.cpp6
-rw-r--r--src/js/builtins/ImportMetaObject.ts11
-rw-r--r--src/js/out/WebCoreJSBuiltins.cpp4
3 files changed, 16 insertions, 5 deletions
diff --git a/src/bun.js/bindings/CommonJSModuleRecord.cpp b/src/bun.js/bindings/CommonJSModuleRecord.cpp
index a32d722d9..dc58e35aa 100644
--- a/src/bun.js/bindings/CommonJSModuleRecord.cpp
+++ b/src/bun.js/bindings/CommonJSModuleRecord.cpp
@@ -391,8 +391,12 @@ JSC::SourceCode createCommonJSModule(
// to pass to that and it isn't used directly much, so that
// seems harder to do correctly.
{
+ globalObject->clearGlobalScopeExtension();
+
JSWithScope* withScope = JSWithScope::create(vm, globalObject, globalObject->globalScope(), scopeExtensionObject);
- vm.interpreter.executeEval(executable, globalObject, withScope);
+ globalObject->setGlobalScopeExtension(withScope);
+ vm.interpreter.executeEval(executable, globalObject, globalObject->globalScope());
+ globalObject->clearGlobalScopeExtension();
if (UNLIKELY(catchScope.exception())) {
auto returnedException = catchScope.exception();
diff --git a/src/js/builtins/ImportMetaObject.ts b/src/js/builtins/ImportMetaObject.ts
index 2df0f0c98..7fc8b5fe8 100644
--- a/src/js/builtins/ImportMetaObject.ts
+++ b/src/js/builtins/ImportMetaObject.ts
@@ -33,8 +33,15 @@ export function loadCJS2ESM(this: ImportMetaObject, resolvedSpecifier: string) {
if (state === $promiseStatePending || (reactionsOrResult && $isPromise(reactionsOrResult))) {
throw new TypeError(`require() async module "${key}" is unsupported`);
} else if (state === $promiseStateRejected) {
- // TODO: use SyntaxError but preserve the specifier
- throw new TypeError(`${reactionsOrResult?.message ?? "An error occurred"} while parsing module \"${key}\"`);
+ if (!reactionsOrResult?.message) {
+ throw new TypeError(
+ `${
+ reactionsOrResult + "" ? reactionsOrResult : "An error occurred"
+ } occurred while parsing module \"${key}\"`,
+ );
+ }
+
+ throw reactionsOrResult;
}
entry.module = module = reactionsOrResult;
} else if (moduleRecordPromise && !module) {
diff --git a/src/js/out/WebCoreJSBuiltins.cpp b/src/js/out/WebCoreJSBuiltins.cpp
index b737640a8..f0df6a9e4 100644
--- a/src/js/out/WebCoreJSBuiltins.cpp
+++ b/src/js/out/WebCoreJSBuiltins.cpp
@@ -2188,9 +2188,9 @@ WEBCORE_FOREACH_STREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
const JSC::ConstructAbility s_importMetaObjectLoadCJS2ESMCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_importMetaObjectLoadCJS2ESMCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_importMetaObjectLoadCJS2ESMCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_importMetaObjectLoadCJS2ESMCodeLength = 1309;
+const int s_importMetaObjectLoadCJS2ESMCodeLength = 1337;
static const JSC::Intrinsic s_importMetaObjectLoadCJS2ESMCodeIntrinsic = JSC::NoIntrinsic;
-const char* const s_importMetaObjectLoadCJS2ESMCode = "(function (_){\"use strict\";var L=@Loader,w=@createFIFO(),x=_;while(x){var z=L.registry.@get(x);if(!z||!z.state||z.state<=@ModuleFetch)@fulfillModuleSync(x),z=L.registry.@get(x);var B=@getPromiseInternalField(z.fetch,@promiseFieldReactionsOrResult),D=L.parseModule(x,B),F=z.module;if(!F&&D&&@isPromise(D)){var G=@getPromiseInternalField(D,@promiseFieldReactionsOrResult),H=@getPromiseInternalField(D,@promiseFieldFlags),I=H&@promiseStateMask;if(I===@promiseStatePending||G&&@isPromise(G))@throwTypeError(`require() async module \"${x}\" is unsupported`);else if(I===@promiseStateRejected)@throwTypeError(`${G\?.message\?\?\"An error occurred\"} while parsing module \\\"${x}\\\"`);z.module=F=G}else if(D&&!F)z.module=F=D;@setStateToMax(z,@ModuleLink);var J=F.dependenciesMap,Q=L.requestedModules(F),T=@newArrayWithSize(Q.length);for(var U=0,V=Q.length;U<V;++U){var W=Q[U],X=W[0]===\"/\"\?W:L.resolve(W,x),Y=L.ensureRegistered(X);if(Y.state<@ModuleLink)w.push(X);@putByValDirect(T,U,Y),J.@set(W,Y)}z.dependencies=T,z.instantiate=@Promise.resolve(z),z.satisfy=@Promise.resolve(z),x=w.shift();while(x&&(L.registry.@get(x)\?.state\?\?@ModuleFetch)>=@ModuleLink)x=w.shift()}var Z=L.linkAndEvaluateModule(_,@undefined);if(Z&&@isPromise(Z))@throwTypeError(`require() async module \\\"${_}\\\" is unsupported`);return L.registry.@get(_)})\n";
+const char* const s_importMetaObjectLoadCJS2ESMCode = "(function (_){\"use strict\";var w=@Loader,x=@createFIFO(),z=_;while(z){var B=w.registry.@get(z);if(!B||!B.state||B.state<=@ModuleFetch)@fulfillModuleSync(z),B=w.registry.@get(z);var D=@getPromiseInternalField(B.fetch,@promiseFieldReactionsOrResult),F=w.parseModule(z,D),G=B.module;if(!G&&F&&@isPromise(F)){var H=@getPromiseInternalField(F,@promiseFieldReactionsOrResult),I=@getPromiseInternalField(F,@promiseFieldFlags),J=I&@promiseStateMask;if(J===@promiseStatePending||H&&@isPromise(H))@throwTypeError(`require() async module \"${z}\" is unsupported`);else if(J===@promiseStateRejected){if(!H\?.message)@throwTypeError(`${H+\"\"\?H:\"An error occurred\"} occurred while parsing module \\\"${z}\\\"`);throw H}B.module=G=H}else if(F&&!G)B.module=G=F;@setStateToMax(B,@ModuleLink);var L=G.dependenciesMap,Q=w.requestedModules(G),T=@newArrayWithSize(Q.length);for(var U=0,V=Q.length;U<V;++U){var W=Q[U],X=W[0]===\"/\"\?W:w.resolve(W,z),Y=w.ensureRegistered(X);if(Y.state<@ModuleLink)x.push(X);@putByValDirect(T,U,Y),L.@set(W,Y)}B.dependencies=T,B.instantiate=@Promise.resolve(B),B.satisfy=@Promise.resolve(B),z=x.shift();while(z&&(w.registry.@get(z)\?.state\?\?@ModuleFetch)>=@ModuleLink)z=x.shift()}var Z=w.linkAndEvaluateModule(_,@undefined);if(Z&&@isPromise(Z))@throwTypeError(`require() async module \\\"${_}\\\" is unsupported`);return w.registry.@get(_)})\n";
// requireESM
const JSC::ConstructAbility s_importMetaObjectRequireESMCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;