1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:47:34 +00:00

LibWeb/Infra: Port serialize_javascript_value_to_json_string() to String

This commit is contained in:
Linus Groh 2023-03-04 21:46:04 +00:00
parent 93ed1b59c8
commit 7800276c0f
2 changed files with 6 additions and 5 deletions

View file

@ -1,9 +1,10 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/String.h>
#include <LibJS/Runtime/AbstractOperations.h> #include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
@ -34,7 +35,7 @@ WebIDL::ExceptionOr<JS::Value> parse_json_bytes_to_javascript_value(JS::VM& vm,
} }
// https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-a-json-string // https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-a-json-string
WebIDL::ExceptionOr<DeprecatedString> serialize_javascript_value_to_json_string(JS::VM& vm, JS::Value value) WebIDL::ExceptionOr<String> serialize_javascript_value_to_json_string(JS::VM& vm, JS::Value value)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
@ -49,7 +50,7 @@ WebIDL::ExceptionOr<DeprecatedString> serialize_javascript_value_to_json_string(
VERIFY(result.is_string()); VERIFY(result.is_string());
// 4. Return result. // 4. Return result.
return TRY(result.as_string().deprecated_string()); return TRY(result.as_string().utf8_string());
} }
// https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-json-bytes // https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-json-bytes

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -14,7 +14,7 @@ namespace Web::Infra {
WebIDL::ExceptionOr<JS::Value> parse_json_string_to_javascript_value(JS::VM&, StringView); WebIDL::ExceptionOr<JS::Value> parse_json_string_to_javascript_value(JS::VM&, StringView);
WebIDL::ExceptionOr<JS::Value> parse_json_bytes_to_javascript_value(JS::VM&, ReadonlyBytes); WebIDL::ExceptionOr<JS::Value> parse_json_bytes_to_javascript_value(JS::VM&, ReadonlyBytes);
WebIDL::ExceptionOr<DeprecatedString> serialize_javascript_value_to_json_string(JS::VM&, JS::Value); WebIDL::ExceptionOr<String> serialize_javascript_value_to_json_string(JS::VM&, JS::Value);
WebIDL::ExceptionOr<ByteBuffer> serialize_javascript_value_to_json_bytes(JS::VM&, JS::Value); WebIDL::ExceptionOr<ByteBuffer> serialize_javascript_value_to_json_bytes(JS::VM&, JS::Value);
} }