LibJS: Implement the ArrayBuffer.prototype.detached getter

This commit is contained in:
PrestonLTaylor 2023-06-29 21:24:40 +01:00 committed by Linus Groh
parent 8157bb601b
commit bd0ccbe3c8
Notes: sideshowbarker 2024-07-17 20:19:08 +09:00
3 changed files with 17 additions and 0 deletions

View file

@ -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());
}
}

View file

@ -23,6 +23,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(slice);
JS_DECLARE_NATIVE_FUNCTION(byte_length_getter);
JS_DECLARE_NATIVE_FUNCTION(detached_getter);
};
}

View file

@ -150,6 +150,7 @@ namespace JS {
P(deleteProperty) \
P(deref) \
P(description) \
P(detached) \
P(difference) \
P(dir) \
P(direction) \