mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibJS: Pre-allocate the out-of-memory error string on the VM
If we are out of memory, we can't try to allocate a string that could fail as well. When Error is converted to String, this would result in an endless OOM-throwing loop. Instead, pre-allocate the string on the VM, and use it to construct the Error. Note that as of this commit, the OOM string is still a DeprecatedString. This is just preporatory for Error's conversion to String.
This commit is contained in:
parent
93ad25fbe5
commit
4d10911f96
5 changed files with 42 additions and 31 deletions
|
@ -153,6 +153,18 @@ VM::VM(OwnPtr<CustomData> custom_data)
|
|||
m_well_known_symbol_##snake_name = Symbol::create(*this, String::from_utf8("Symbol." #SymbolName##sv).release_value_but_fixme_should_propagate_errors(), false);
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
m_error_messages[to_underlying(ErrorMessage::OutOfMemory)] = ErrorType::OutOfMemory.message();
|
||||
}
|
||||
|
||||
DeprecatedString const& VM::error_message(ErrorMessage type) const
|
||||
{
|
||||
VERIFY(type < ErrorMessage::__Count);
|
||||
|
||||
auto const& message = m_error_messages[to_underlying(type)];
|
||||
VERIFY(!message.is_empty());
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void VM::enable_default_host_import_module_dynamically_hook()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue