Skip to content

Commit

Permalink
implemented get buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeloChecked committed Nov 28, 2023
1 parent 2c581bb commit 61106e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/typed_array/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl BuiltinTypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.buffer
fn buffer(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn buffer(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
Expand Down
6 changes: 6 additions & 0 deletions boa_engine/src/object/builtins/jstypedarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl JsTypedArray {
BuiltinTypedArray::at(&self.inner.clone().into(), &[index.into().into()], context)
}

/// Calls `TypedArray.prototype.buffer()`.
#[inline]
pub fn buffer(&self, context: &mut Context) -> JsResult<JsValue> {
BuiltinTypedArray::buffer(&self.inner.clone().into(), &[], context)
}

/// Returns `TypedArray.prototype.byteLength`.
#[inline]
pub fn byte_length(&self, context: &mut Context) -> JsResult<usize> {
Expand Down
6 changes: 6 additions & 0 deletions boa_examples/src/bin/jstypedarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ fn main() -> JsResult<()> {
assert_eq!(subarray4_6.get(0, context)?, JsValue::new(5.0));
assert_eq!(subarray4_6.get(1, context)?, JsValue::new(6.0));

// buffer
let array_buffer8 = JsArrayBuffer::new(8, context)?;
let array = JsUint8Array::from_array_buffer(array_buffer8, context)?;

assert!(array.buffer(context)?.as_object().unwrap().is_buffer());

context
.register_global_property(
js_string!("myUint8Array"),
Expand Down

0 comments on commit 61106e1

Please sign in to comment.