This commit is contained in:
Jarred Sumner
2024-07-29 17:19:47 -07:00
committed by GitHub
parent 5aeb4d9f79
commit c181cf45a7
4 changed files with 39 additions and 8 deletions

View File

@@ -418,17 +418,19 @@ extern "C" void Bun__onFulfillAsyncModule(
auto specifierValue = Bun::toJS(globalObject, *specifier);
if (auto entry = globalObject->esmRegistryMap()->get(globalObject, specifierValue)) {
if (res->result.value.commonJSExportsLen) {
if (entry.isObject()) {
if (auto isEvaluated = entry.getObject()->getIfPropertyExists(globalObject, Bun::builtinNames(vm).evaluatedPublicName())) {
if (isEvaluated.isTrue()) {
// it's a race! we lost.
// https://github.com/oven-sh/bun/issues/6946
return;
}
if (entry.isObject()) {
auto* object = entry.getObject();
if (auto state = object->getIfPropertyExists(globalObject, Bun::builtinNames(vm).statePublicName())) {
if (state.toInt32(globalObject) > JSC::JSModuleLoader::Status::Fetch) {
// it's a race! we lost.
// https://github.com/oven-sh/bun/issues/6946
// https://github.com/oven-sh/bun/issues/12910
return;
}
}
}
if (res->result.value.commonJSExportsLen) {
auto created = Bun::createCommonJSModule(jsCast<Zig::GlobalObject*>(globalObject), specifierValue, res->result.value);
if (created.has_value()) {
JSSourceCode* code = JSSourceCode::create(vm, WTFMove(created.value()));