From 70182a64947a4101c6f1f29a269944764d1416a5 Mon Sep 17 00:00:00 2001 From: hle0 <91701075+hle0@users.noreply.github.com> Date: Sun, 3 Oct 2021 00:29:37 +0000 Subject: [PATCH 1/2] fix Symbol.prototype.valueOf (#1617) Signed-off-by: hle0 <91701075+hle0@users.noreply.github.com> --- boa/src/builtins/symbol/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index 6b9c3b4d55b..80057969c2d 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/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 { + // 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. From a3e67b5dae366e29d7796b36cb422ad1dd772d1d Mon Sep 17 00:00:00 2001 From: hle0 <91701075+hle0@users.noreply.github.com> Date: Sat, 2 Oct 2021 22:08:16 -0400 Subject: [PATCH 2/2] Revise fix for Symbol.prototype.valueOf (#1617) Include steps from ECMAScript spec --- boa/src/builtins/symbol/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index 80057969c2d..482a7e0eb7b 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/boa/src/builtins/symbol/mod.rs @@ -228,7 +228,7 @@ impl Symbol { _: &[JsValue], context: &mut Context, ) -> JsResult { - // valueOf a symbol is itself + // 1. Return ? thisSymbolValue(this value). let symbol = Self::this_symbol_value(this, context)?; Ok(JsValue::Symbol(symbol)) }