Skip to content

Commit

Permalink
Fix step 1 in Symbol constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Apr 16, 2022
1 parent e35ece0 commit 4277453
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions boa_engine/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ 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)
Expand Down
9 changes: 8 additions & 1 deletion 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 Down Expand Up @@ -171,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 4277453

Please sign in to comment.