Skip to content

Commit

Permalink
Change ArrayBuffer byteLength to accessor property (#2010)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lupd authored and Razican committed Jun 8, 2022
1 parent 36369d9 commit 6ac64b8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions boa_engine/src/builtins/array_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,32 @@ 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,
context.intrinsics().constructors().array_buffer().clone(),
)
.name(Self::NAME)
.length(Self::LENGTH)
.accessor("byteLength", Some(get_byte_length), None, flag_attributes)
.static_accessor(
WellKnownSymbols::species(),
Some(get_species),
None,
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(),
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 6ac64b8

Please sign in to comment.