Browse Source

Change `ArrayBuffer` `byteLength` to accessor property (#2010)

This Pull Request fixes `byteLength` for `ArrayBuffer`. It should be an accessor property rather than a method, per the spec.

It changes the following:

- Removes `byteLength` method for `ArrayBuffer` built-in.
- Add `byteLength` accessor property for `ArrayBuffer`.
- Change `byte_length` function name to `get_byte_length`, to match other function names used for accessor properties.
pull/2014/head
lupd 2 years ago
parent
commit
e6d12f835c
  1. 14
      boa_engine/src/builtins/array_buffer/mod.rs

14
boa_engine/src/builtins/array_buffer/mod.rs

@ -37,11 +37,17 @@ impl BuiltIn for ArrayBuffer {
fn init(context: &mut Context) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let flag_attributes = Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE;
let get_species = FunctionBuilder::native(context, Self::get_species)
.name("get [Symbol.species]")
.constructor(false)
.build();
let get_byte_length = FunctionBuilder::native(context, Self::get_byte_length)
.name("get byteLength")
.build();
ConstructorBuilder::with_standard_constructor(
context,
Self::constructor,
@ -49,6 +55,7 @@ impl BuiltIn for ArrayBuffer {
)
.name(Self::NAME)
.length(Self::LENGTH)
.accessor("byteLength", Some(get_byte_length), None, flag_attributes)
.static_accessor(
WellKnownSymbols::species(),
Some(get_species),
@ -56,7 +63,6 @@ impl BuiltIn for ArrayBuffer {
Attribute::CONFIGURABLE,
)
.static_method(Self::is_view, "isView", 1)
.method(Self::byte_length, "byteLength", 0)
.method(Self::slice, "slice", 2)
.property(
WellKnownSymbols::to_string_tag(),
@ -133,7 +139,11 @@ impl ArrayBuffer {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-get-arraybuffer.prototype.bytelength
fn byte_length(this: &JsValue, _args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn get_byte_length(
this: &JsValue,
_args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
let obj = if let Some(obj) = this.as_object() {

Loading…
Cancel
Save