Skip to content

Commit

Permalink
Merge 4277453 into a357a18
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Apr 16, 2022
2 parents a357a18 + 4277453 commit 49123d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 12 additions & 3 deletions boa_engine/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ impl BuiltIn for BigInt {
)
.name(Self::NAME)
.length(Self::LENGTH)
.callable(true)
.constructor(true)
.method(Self::to_string, "toString", 0)
.method(Self::value_of, "valueOf", 0)
.static_method(Self::as_int_n, "asIntN", 2)
.static_method(Self::as_uint_n, "asUintN", 2)
.callable(true)
.constructor(true)
.property(
to_string_tag,
Self::NAME,
Expand All @@ -77,7 +77,16 @@ impl BigInt {
///
/// [spec]: https://tc39.es/ecma262/#sec-bigint-objects
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt
fn constructor(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If NewTarget is not undefined, throw a TypeError exception.
if !new_target.is_undefined() {
return context.throw_type_error("BigInt is not a constructor");
}

let value = args.get_or_undefined(0);

// 2. Let prim be ? ToPrimitive(value, number).
Expand Down
11 changes: 8 additions & 3 deletions boa_engine/src/builtins/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ impl BuiltIn for Symbol {
)
.name(Self::NAME)
.length(Self::LENGTH)
.callable(true)
.constructor(true)
.static_method(Self::for_, "for", 1)
.static_method(Self::key_for, "keyFor", 1)
.static_property("asyncIterator", symbol_async_iterator, attribute)
Expand All @@ -135,8 +137,6 @@ impl BuiltIn for Symbol {
None,
Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
)
.callable(true)
.constructor(false)
.property(
symbol_to_string_tag,
Self::NAME,
Expand Down Expand Up @@ -173,14 +173,19 @@ impl Symbol {
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
if new_target.is_undefined() {
// 1. If NewTarget is not undefined, throw a TypeError exception.
if !new_target.is_undefined() {
return context.throw_type_error("Symbol is not a constructor");
}

// 2. If description is undefined, let descString be undefined.
// 3. Else, let descString be ? ToString(description).
let description = match args.get(0) {
Some(value) if !value.is_undefined() => Some(value.to_string(context)?),
_ => None,
};

// 4. Return a new unique Symbol value whose [[Description]] value is descString.
Ok(JsSymbol::new(description).into())
}

Expand Down

0 comments on commit 49123d6

Please sign in to comment.