Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Fix Symbol and BigInt constructors #2032

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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