mirror of
https://github.com/oven-sh/bun
synced 2026-02-18 06:41:50 +00:00
fix bugs found by exception scope verification (#20285)
Co-authored-by: 190n <7763597+190n@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user