Skip to content

Commit

Permalink
fixe set_view_value check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimpruda committed Oct 14, 2021
1 parent dd98b10 commit 0fe8246
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions boa/src/builtins/dataview/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use crate::{
builtins::{array_buffer::SharedMemoryOrder, typed_array::TypedArrayName, BuiltIn, JsArgs},
context::StandardObjects,
object::{
use crate::{Context, JsResult, builtins::{array_buffer::SharedMemoryOrder, typed_array::TypedArrayName, BuiltIn, JsArgs}, context::StandardObjects, object::{
internal_methods::get_prototype_from_constructor, ConstructorBuilder, FunctionBuilder,
JsObject, ObjectData,
},
property::Attribute,
value::JsValue,
Context, JsResult,
};
}, property::Attribute, symbol::WellKnownSymbols, value::JsValue};
use gc::{Finalize, Trace};

#[derive(Debug, Clone, Trace, Finalize)]
Expand Down Expand Up @@ -47,9 +40,11 @@ impl BuiltIn for DataView {
)
.name(Self::NAME)
.length(Self::LENGTH)

.accessor("buffer", Some(get_buffer), None, flag_attributes)
.accessor("byteLength", Some(get_byte_length), None, flag_attributes)
.accessor("byteOffset", Some(get_byte_offset), None, flag_attributes)

.method(Self::get_big_int64, "getBigInt64", 1)
.method(Self::get_big_uint64, "getBigUint64", 1)
.method(Self::get_float32, "getFloat32", 1)
Expand All @@ -70,6 +65,13 @@ impl BuiltIn for DataView {
.method(Self::set_uint8, "setUint8", 2)
.method(Self::set_uint16, "setUint16", 2)
.method(Self::set_uint32, "setUint32", 2)

.property(
WellKnownSymbols::to_string_tag(),
Self::NAME,
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)

.build();

dataview_object.into()
Expand Down Expand Up @@ -509,13 +511,13 @@ impl DataView {
// 3. Let getIndex be ? ToIndex(requestIndex).
let get_index = request_index.to_index(context)?;

// 4. If ! IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
// 5. Otherwise, let numberValue be ? ToNumber(value).
let number_value = if value.is_bigint() | value.is_number() {
let number_value = if !value.is_bigint() & !value.is_number() {
return context.throw_type_error("value is not a Number or a BigInt");
} else if t.is_big_int_element_type() & !value.is_bigint() {
// 4. If ! IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
return context.throw_type_error("value must be a BigInt");
} else if !t.is_big_int_element_type() & !value.is_number() {
// 5. Otherwise, let numberValue be ? ToNumber(value).
return context.throw_type_error("value must be a number");
} else {
value.to_owned()
Expand Down

0 comments on commit 0fe8246

Please sign in to comment.