Skip to content

Commit

Permalink
fix Symbol.prototype.valueOf (boa-dev#1617)
Browse files Browse the repository at this point in the history
Signed-off-by: hle0 <91701075+hle0@users.noreply.github.com>
  • Loading branch information
hle0 committed Oct 3, 2021
1 parent 5029a23 commit 70182a6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions boa/src/builtins/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl BuiltIn for Symbol {
.static_property("toStringTag", symbol_to_string_tag.clone(), attribute)
.static_property("unscopables", symbol_unscopables, attribute)
.method(Self::to_string, "toString", 0)
.method(Self::value_of, "valueOf", 0)
.accessor(
"description",
Some(get_description),
Expand Down Expand Up @@ -212,6 +213,26 @@ impl Symbol {
Ok(symbol.to_string().into())
}

/// `Symbol.prototype.valueOf()`
///
/// This method returns a `Symbol` that is the primitive value of the specified `Symbol` object.
///
/// More information:
/// - [MDN documentation][mdn]
/// - [ECMAScript reference][spec]
///
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf
/// [spec]: https://tc39.es/ecma262/#sec-symbol.prototype.valueof
pub(crate) fn value_of(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue> {
// valueOf a symbol is itself
let symbol = Self::this_symbol_value(this, context)?;
Ok(JsValue::Symbol(symbol))
}

/// `get Symbol.prototype.description`
///
/// This accessor returns the description of the `Symbol` object.
Expand Down

0 comments on commit 70182a6

Please sign in to comment.