mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Implement the ArrayBuffer.prototype.detached getter
This commit is contained in:
parent
8157bb601b
commit
bd0ccbe3c8
Notes:
sideshowbarker
2024-07-17 20:19:08 +09:00
Author: https://github.com/PrestonLTaylor Commit: https://github.com/SerenityOS/serenity/commit/bd0ccbe3c8 Pull-request: https://github.com/SerenityOS/serenity/pull/19710 Reviewed-by: https://github.com/linusg ✅
3 changed files with 17 additions and 0 deletions
|
@ -26,6 +26,7 @@ ThrowCompletionOr<void> ArrayBufferPrototype::initialize(Realm& realm)
|
|||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.slice, slice, 2, attr);
|
||||
define_native_accessor(realm, vm.names.byteLength, byte_length_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.detached, detached_getter, {}, Attribute::Configurable);
|
||||
|
||||
// 25.1.5.4 ArrayBuffer.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-arraybuffer.prototype-@@tostringtag
|
||||
define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.ArrayBuffer.as_string()), Attribute::Configurable);
|
||||
|
@ -148,4 +149,18 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::byte_length_getter)
|
|||
return Value(length);
|
||||
}
|
||||
|
||||
// 25.1.5.4 get ArrayBuffer.prototype.detached, https://tc39.es/proposal-arraybuffer-transfer/#sec-get-arraybuffer.prototype.detached
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::detached_getter)
|
||||
{
|
||||
// 1. Let O be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
|
||||
auto array_buffer_object = TRY(typed_this_value(vm));
|
||||
|
||||
// 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
|
||||
// FIXME: Check for shared buffer
|
||||
|
||||
// 4. Return IsDetachedBuffer(O).
|
||||
return Value(array_buffer_object->is_detached());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ private:
|
|||
|
||||
JS_DECLARE_NATIVE_FUNCTION(slice);
|
||||
JS_DECLARE_NATIVE_FUNCTION(byte_length_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(detached_getter);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -150,6 +150,7 @@ namespace JS {
|
|||
P(deleteProperty) \
|
||||
P(deref) \
|
||||
P(description) \
|
||||
P(detached) \
|
||||
P(difference) \
|
||||
P(dir) \
|
||||
P(direction) \
|
||||
|
|
Loading…
Reference in a new issue