chakra-9e2f198
var a = RegExp(1);
RegExp.prototype.toString.call(a);
var b = Object(1);
RegExp.prototype.toString.call(b);
./ChakraCore/out/Release/ch testcase.js
TypeError: RegExp.prototype.toString: 'this' is not a RegExp object
I checked the ES standard and found that the standard only stipulates that the this value of RegExp.prototype.toString must be an object, but chakra requires this value to be a regular object. May I know what is the reason?
According to ES2019 standard, the steps of RegExp.prototype.toString are as follows.
21.2.5.15RegExp.prototype.toString ( )
The ECMAScript standard reference is as follow:
http://www.ecma-international.org/ecma-262/10.0/index.html#sec-regexp.prototype.tostring
The source and flags getters both throw if the receiver is not a regex, which covers your a.
what happens with b if you comment out a?
When executing the above test case, Chakra throws TypeError: RegExp.prototype.toString:'this' is not a RegExp object in line 4 (b). After commenting out a, executing this code still throws TypeError. I also executed this test cases on other engines (such as v8, spider Monkey, JavascriptCore, etc.), and they all executed normally without causing any errors.
Thank you for the report!
The correct implementation is behind the flag ES6RegExPrototypeProperties if you run the test with -ES6RegExPrototypeProperties to enable the flag it should have the correct result.
Enabling that flag is part of #6390 I'm afraid ChakraCore's regexp engine is a weak point of sorts.
Most helpful comment
When executing the above test case, Chakra throws
TypeError: RegExp.prototype.toString:'this' is not a RegExp objectin line 4 (b). After commenting out a, executing this code still throws TypeError. I also executed this test cases on other engines (such as v8, spider Monkey, JavascriptCore, etc.), and they all executed normally without causing any errors.