fix bugs found by exception scope verification (#20285)

Co-authored-by: 190n <7763597+190n@users.noreply.github.com>
This commit is contained in:
190n
2025-06-18 23:08:19 -07:00
committed by GitHub
parent aa37ecb7a5
commit 346e97dde2
98 changed files with 4263 additions and 933 deletions

View File

@@ -189,6 +189,7 @@ static Structure* createErrorStructure(JSC::VM& vm, JSGlobalObject* globalObject
JSObject* ErrorCodeCache::createError(VM& vm, Zig::GlobalObject* globalObject, ErrorCode code, JSValue message, JSValue options)
{
auto scope = DECLARE_CATCH_SCOPE(vm);
auto* cache = errorCache(globalObject);
const auto& data = errors[static_cast<size_t>(code)];
if (!cache->internalField(static_cast<unsigned>(code))) {
@@ -197,7 +198,15 @@ JSObject* ErrorCodeCache::createError(VM& vm, Zig::GlobalObject* globalObject, E
}
auto* structure = jsCast<Structure*>(cache->internalField(static_cast<unsigned>(code)).get());
return JSC::ErrorInstance::create(globalObject, structure, message, options, nullptr, JSC::RuntimeType::TypeNothing, data.type, true);
auto* created_error = JSC::ErrorInstance::create(globalObject, structure, message, options, nullptr, JSC::RuntimeType::TypeNothing, data.type, true);
if (auto* thrown_exception = scope.exception()) [[unlikely]] {
scope.clearException();
// TODO investigate what can throw here and whether it will throw non-objects
// (this is better than before where we would have returned nullptr from createError if any
// exception were thrown by ErrorInstance::create)
return jsCast<JSObject*>(thrown_exception->value());
}
return created_error;
}
JSObject* createError(VM& vm, Zig::GlobalObject* globalObject, ErrorCode code, const String& message)