Bug 210671 - Web Inspector: REGRESSION(r242018): using `RegExp.prototype.test` with a global `RegExp` will ignore one potential match after each successful match
Summary: Web Inspector: REGRESSION(r242018): using `RegExp.prototype.test` with a glob...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on: 192527
Blocks:
  Show dependency treegraph
 
Reported: 2020-04-17 13:58 PDT by Devin Rousso
Modified: 2020-04-20 09:41 PDT (History)
5 users (show)

See Also:


Attachments
Patch (13.94 KB, patch)
2020-04-17 14:09 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (13.96 KB, patch)
2020-04-17 14:13 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2020-04-17 13:58:17 PDT
```
    let x = /script/gi;
    console.log(x.test("script")); // true
    console.log(x.test("script")); // false
    console.log(x.test("script")); // true
    console.log(x.test("script")); // false
```

this is due to the nature of `lastIndex`, which is set when using a global `RegExp` (see 12.a in <https://tc39.es/ecma262/#sec-regexpbuiltinexec>)
Comment 1 Devin Rousso 2020-04-17 14:09:39 PDT
Created attachment 396795 [details]
Patch
Comment 2 Devin Rousso 2020-04-17 14:13:56 PDT
Created attachment 396797 [details]
Patch

use better names :P
Comment 3 Radar WebKit Bug Importer 2020-04-17 14:17:52 PDT
<rdar://problem/61950043>
Comment 4 EWS 2020-04-17 15:33:10 PDT
Committed r260291: <https://trac.webkit.org/changeset/260291>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396797 [details].
Comment 5 BJ Burg 2020-04-20 09:41:48 PDT
(In reply to Devin Rousso from comment #0)
> ```
>     let x = /script/gi;
>     console.log(x.test("script")); // true
>     console.log(x.test("script")); // false
>     console.log(x.test("script")); // true
>     console.log(x.test("script")); // false
> ```
> 
> this is due to the nature of `lastIndex`, which is set when using a global
> `RegExp` (see 12.a in <https://tc39.es/ecma262/#sec-regexpbuiltinexec>)


Wut.