mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:47:35 +00:00
LibJS+LibWeb: Move the macro to convert ENOMEM to an exception to LibJS
Move the macro to LibJS and change it to return a throw completion instead of a WebIDL exception. This will let us use this macro within LibJS to handle OOM conditions.
This commit is contained in:
parent
ba97f6a0d3
commit
d8044c5358
15 changed files with 118 additions and 93 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibTextCodec/Decoder.h>
|
||||
#include <LibWeb/Infra/JSON.h>
|
||||
|
@ -54,14 +55,12 @@ WebIDL::ExceptionOr<DeprecatedString> serialize_javascript_value_to_json_string(
|
|||
// https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-json-bytes
|
||||
WebIDL::ExceptionOr<ByteBuffer> serialize_javascript_value_to_json_bytes(JS::VM& vm, JS::Value value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let string be the result of serializing a JavaScript value to a JSON string given value.
|
||||
auto string = TRY(serialize_javascript_value_to_json_string(vm, value));
|
||||
|
||||
// 2. Return the result of running UTF-8 encode on string.
|
||||
// NOTE: LibJS strings are stored as UTF-8.
|
||||
return TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(string.bytes()));
|
||||
return TRY_OR_THROW_OOM(vm, ByteBuffer::copy(string.bytes()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue