mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
LibJS: Convert validate_typed_array() to ThrowCompletionOr
Also add spec step comments to it while we're here.
This commit is contained in:
parent
d7d73f9100
commit
3655aee543
Notes:
sideshowbarker
2024-07-18 03:06:16 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/3655aee5430 Pull-request: https://github.com/SerenityOS/serenity/pull/10340 Reviewed-by: https://github.com/IdanHo
@ -19,8 +19,8 @@ static void validate_integer_typed_array(GlobalObject& global_object, TypedArray
|
|||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
validate_typed_array(global_object, typed_array);
|
auto maybe_error = validate_typed_array(global_object, typed_array);
|
||||||
if (vm.exception())
|
if (maybe_error.is_error())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto type_name = typed_array.element_name();
|
auto type_name = typed_array.element_name();
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
#include <LibJS/Runtime/AbstractOperations.h>
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||||
|
#include <LibJS/Runtime/Completion.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/IteratorOperations.h>
|
#include <LibJS/Runtime/IteratorOperations.h>
|
||||||
#include <LibJS/Runtime/TypedArray.h>
|
#include <LibJS/Runtime/TypedArray.h>
|
||||||
@ -31,14 +32,24 @@ TypedArrayBase* typed_array_from(GlobalObject& global_object, Value typed_array_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 23.2.4.3 ValidateTypedArray ( O ), https://tc39.es/ecma262/#sec-validatetypedarray
|
// 23.2.4.3 ValidateTypedArray ( O ), https://tc39.es/ecma262/#sec-validatetypedarray
|
||||||
void validate_typed_array(GlobalObject& global_object, TypedArrayBase& typed_array)
|
ThrowCompletionOr<void> validate_typed_array(GlobalObject& global_object, TypedArrayBase& typed_array)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
|
// 1. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
|
||||||
if (!typed_array.is_typed_array())
|
if (!typed_array.is_typed_array())
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "TypedArray");
|
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOfType, "TypedArray");
|
||||||
else if (typed_array.viewed_array_buffer()->is_detached())
|
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
// 2. Assert: O has a [[ViewedArrayBuffer]] internal slot.
|
||||||
|
|
||||||
|
// 3. Let buffer be O.[[ViewedArrayBuffer]].
|
||||||
|
auto* buffer = typed_array.viewed_array_buffer();
|
||||||
|
|
||||||
|
// 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||||
|
if (buffer->is_detached())
|
||||||
|
return vm.throw_completion<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 22.2.5.1.3 InitializeTypedArrayFromArrayBuffer, https://tc39.es/ecma262/#sec-initializetypedarrayfromarraybuffer
|
// 22.2.5.1.3 InitializeTypedArrayFromArrayBuffer, https://tc39.es/ecma262/#sec-initializetypedarrayfromarraybuffer
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <LibJS/Runtime/AbstractOperations.h>
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||||
|
#include <LibJS/Runtime/Completion.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/PropertyDescriptor.h>
|
#include <LibJS/Runtime/PropertyDescriptor.h>
|
||||||
#include <LibJS/Runtime/PropertyName.h>
|
#include <LibJS/Runtime/PropertyName.h>
|
||||||
@ -20,7 +21,7 @@ namespace JS {
|
|||||||
class TypedArrayBase;
|
class TypedArrayBase;
|
||||||
|
|
||||||
TypedArrayBase* typed_array_from(GlobalObject&, Value);
|
TypedArrayBase* typed_array_from(GlobalObject&, Value);
|
||||||
void validate_typed_array(GlobalObject&, TypedArrayBase&);
|
ThrowCompletionOr<void> validate_typed_array(GlobalObject&, TypedArrayBase&);
|
||||||
|
|
||||||
class TypedArrayBase : public Object {
|
class TypedArrayBase : public Object {
|
||||||
JS_OBJECT(TypedArrayBase, Object);
|
JS_OBJECT(TypedArrayBase, Object);
|
||||||
|
@ -75,15 +75,11 @@ static TypedArrayBase* typed_array_from_this(GlobalObject& global_object)
|
|||||||
|
|
||||||
static TypedArrayBase* validate_typed_array_from_this(GlobalObject& global_object)
|
static TypedArrayBase* validate_typed_array_from_this(GlobalObject& global_object)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
auto* typed_array = typed_array_from_this(global_object);
|
auto* typed_array = typed_array_from_this(global_object);
|
||||||
if (!typed_array)
|
if (!typed_array)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
validate_typed_array(global_object, *typed_array);
|
TRY_OR_DISCARD(validate_typed_array(global_object, *typed_array));
|
||||||
if (vm.exception())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return typed_array;
|
return typed_array;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user