Browse Source

Implement `Symbol.prototype.valueOf` (#1618)

pull/1619/head
hle0 3 years ago committed by GitHub
parent
commit
d3c5aea44e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      boa/src/builtins/symbol/mod.rs

21
boa/src/builtins/symbol/mod.rs

@ -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),
@ -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> {
// 1. Return ? thisSymbolValue(this value).
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.

Loading…
Cancel
Save