Bug 272206 - Need to call flags and unicode getters in RegExp.prototype[Symbol.match]
Summary: Need to call flags and unicode getters in RegExp.prototype[Symbol.match]
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-04-04 20:56 PDT by Sosuke Suzuki
Modified: 2024-04-11 20:57 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sosuke Suzuki 2024-04-04 20:56:44 PDT
According to the spec[1], RegExp.prototype[Symbol.match] calls the flags getter and the unicode getter.
However, the current implementation does not work that way. This causes some test262 test cases to fail:

- test/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js
- test/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js
- test/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js

[1]: https://tc39.es/ecma262/#sec-regexp.prototype-@@match

poc:
```js
function shouldBe(actual, expected) {
    if (actual !== expected)
        throw new Error('bad value: ' + actual);
}

const re = /./;

let flagsCount = 0;
let unicodeCount = 0;

Object.defineProperties(re, {
    flags: {
        get() {
            flagsCount++;
            return '';
        }
    },
    unicode: {
        get() {
            unicodeCount++;
            return false;
        }
    }
});

for (let i = 0; i < 1e3; i++) {
    re[Symbol.match]('');
}
shouldBe(flagsCount, 1e3);
shouldBe(unicodeCount, 1e3);
```
Comment 1 Sosuke Suzuki 2024-04-04 20:59:39 PDT
Pull request: https://github.com/WebKit/WebKit/pull/26885
Comment 2 Radar WebKit Bug Importer 2024-04-11 20:57:14 PDT
<rdar://problem/126326970>