chakra-core / ChakraCore

ChakraCore is an open source Javascript engine with a C API.
MIT License
9.13k stars 1.2k forks source link

Support for regexp symbols like Symbol.split not enabled by default #5510

Closed sunlili closed 4 years ago

sunlili commented 6 years ago

Hello, The following code behaves strangely (inconsistent with other engines).

function testToUint32InSplit() {
  var re;
  function toDictMode() {
    re.x = 42;
    delete re.x;
    return "def";
  }

  re *= /./g  // Needs to be global to trigger lastIndex accesses.
  return testToStringInReplace(toDictMode(new String('a'), 'length'), 1);
}

function testToStringInReplace() {
  var re;
  function toDictMode() {
    re.x = 42;
    delete re.x;
    return 42;
  }

  re = /./g;  // Needs to be global to trigger lastIndex accesses.
  return re[Symbol.split]("abc", { valueOf: toDictMode });
}

testToUint32InSplit();
testToStringInReplace();

print("BT_FLAG");

In ChakraCore, the output is TypeError: Object doesn't support property or method 'undefined'

However, in V8 and SpiderMonkey, output is BT_FLAG

BT group 2018.7.24

MSLaguana commented 6 years ago

This is because by default chakracore does not enable support for some of the regex symbols, like Symbol.split. If you specify the -ES6RegexSymbols flag then it turns on that support, and this test case behaves as expected.

rhuanjl commented 4 years ago

Consolidating as part of #6390