chakra-1.11.8
var NISLFuzzingFunc = function(){
print(typeof Symbol());
print(Symbol().valueOf());
};
NISLFuzzingFunc();
./ChakraCore/out/Debug/ch testcase.js
symbol
TypeError: No implicit conversion of Symbol to String
symbol
Symbol()
According to ES2019 standard, the steps of Symbol.prototype.valueOf() are as follows.
19.4.3.4 Symbol.prototype.valueOf ()
The following steps are taken:
- Return ? thisSymbolValue(
this value).
And
The abstract operation thisSymbolValue(
value) performs the following steps:
- If Type(
value) is Symbol, returnvalue.
...
For this test case, this value is Symbol(), and it should be returned. So the final output should be Symbol(), but chakra threw a TypeError: No implicit conversion of Symbol to String.
Is my understanding wrong or chakra implementation incorrect?
http://www.ecma-international.org/ecma-262/10.0/index.html#sec-symbol.prototype.valueof
Thanks for the report, I've had a look and the behaviour of valueOf is not an issue here - it is returning the correct symbol.
The question comes in what print() does - only a string can be output to the console and a Symbol is not a string.
If you do print(Symbol().toString()); OR print(Symbol().valueOf().toString()) you'll get the output that you were expecting.
The print() method is not spec defined and is included in ch (the test harness) purely for displaying test results, so this isn't a bug or problem with chakracore itself - just a difference in how the test harness works.
For detail: print() within ch when given something that isn't a string uses the internal abstract operation ToString as defined here https://www.ecma-international.org/ecma-262/10.0/index.html#sec-tostring this operation throws a TypeError for symbols.
Most helpful comment
Thanks for the report, I've had a look and the behaviour of valueOf is not an issue here - it is returning the correct symbol.
The question comes in what
print()does - only a string can be output to the console and a Symbol is not a string.If you do
print(Symbol().toString());ORprint(Symbol().valueOf().toString())you'll get the output that you were expecting.The
print()method is not spec defined and is included in ch (the test harness) purely for displaying test results, so this isn't a bug or problem with chakracore itself - just a difference in how the test harness works.For detail: print() within ch when given something that isn't a string uses the internal abstract operation ToString as defined here https://www.ecma-international.org/ecma-262/10.0/index.html#sec-tostring this operation throws a TypeError for symbols.