Bug 210671

Summary: Web Inspector: REGRESSION(r242018): using `RegExp.prototype.test` with a global `RegExp` will ignore one potential match after each successful match
Product: WebKit Reporter: Devin Rousso <hi>
Component: Web InspectorAssignee: Devin Rousso <hi>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, hi, inspector-bugzilla-changes, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: All   
OS: All   
Bug Depends on: 192527    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch none

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.