Chakracore: A question about Symbol().valueOf

Created on 8 Jun 2020  路  1Comment  路  Source: chakra-core/ChakraCore

Version

chakra-1.11.8

Test case
var NISLFuzzingFunc = function(){
    print(typeof Symbol());
    print(Symbol().valueOf());
}; 
NISLFuzzingFunc();
Execution steps
./ChakraCore/out/Debug/ch testcase.js
Output
symbol
TypeError: No implicit conversion of Symbol to String
Expected behavior
symbol
Symbol()
Description

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:

  1. Return ? thisSymbolValue(this value).

And

The abstract operation thisSymbolValue(value) performs the following steps:

  1. If Type(value) is Symbol, return value.
    ...

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?

Reference

http://www.ecma-international.org/ecma-262/10.0/index.html#sec-symbol.prototype.valueof

Question

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()); 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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings