mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-09 12:42:54 +00:00
IDLGenerators: Throw TypeError if IDL ByteString contains element > 255
This commit is contained in:
parent
6dc61f895d
commit
19a5780f0c
Notes:
github-actions[bot]
2024-11-21 20:51:11 +00:00
Author: https://github.com/tcl3
Commit: 19a5780f0c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2485
Reviewed-by: https://github.com/trflynn89 ✅
3 changed files with 41 additions and 7 deletions
|
@ -225,6 +225,33 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, String
|
|||
return clean_up_on_return(stored_realm, relevant_realm, completion, callback.operation_returns_promise);
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#ref-for-idl-ByteString%E2%91%A7
|
||||
JS::ThrowCompletionOr<String> to_byte_string(JS::VM& vm, JS::Value value)
|
||||
{
|
||||
// 1. Let x be ? ToString(V).
|
||||
auto x = TRY(value.to_string(vm));
|
||||
|
||||
// 2. If the value of any element of x is greater than 255, then throw a TypeError.
|
||||
for (auto character : x.code_points()) {
|
||||
if (character > 0xFF)
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidCodePoint);
|
||||
}
|
||||
|
||||
// 3. Return an IDL ByteString value whose length is the length of x, and where the value of each element is the value of the corresponding element of x.
|
||||
// FIXME: This should return a ByteString.
|
||||
return x;
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<String> to_string(JS::VM& vm, JS::Value value)
|
||||
{
|
||||
return value.to_string(vm);
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<String> to_usv_string(JS::VM& vm, JS::Value value)
|
||||
{
|
||||
return value.to_well_formed_string(vm);
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#invoke-a-callback-function
|
||||
// https://whatpr.org/webidl/1437.html#invoke-a-callback-function
|
||||
JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Value> this_argument, GC::MarkedVector<JS::Value> args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue