|
| 1 | +// Test the telemetry added in Bug 1950211 |
| 2 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 0); |
| 3 | + |
| 4 | +"abc".match(/b/); |
| 5 | +"abc".match({ [Symbol.match]: () => [] }); |
| 6 | +"abc".match("b"); |
| 7 | +"abc".match(42); |
| 8 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 0); |
| 9 | +Number.prototype[Symbol.match] = () => []; |
| 10 | +"abc".match(42); |
| 11 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 1); |
| 12 | +delete Number.prototype[Symbol.match]; |
| 13 | + |
| 14 | +"abc".matchAll(/b/g); |
| 15 | +"abc".matchAll({ [Symbol.matchAll]: () => [] }); |
| 16 | +"abc".matchAll("b"); |
| 17 | +"abc".matchAll(42); |
| 18 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 1); |
| 19 | +Number.prototype[Symbol.matchAll] = () => []; |
| 20 | +"abc".matchAll(42); |
| 21 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 2); |
| 22 | +delete Number.prototype[Symbol.matchAll]; |
| 23 | + |
| 24 | +"abc".replace(/b/, "d"); |
| 25 | +"abc".replace({ [Symbol.replace]: () => "" }); |
| 26 | +"abc".replace("b", "d"); |
| 27 | +"abc".replace(42, "d"); |
| 28 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 2); |
| 29 | +Number.prototype[Symbol.replace] = () => ""; |
| 30 | +"abc".replace(42, "d"); |
| 31 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 3); |
| 32 | +delete Number.prototype[Symbol.replace]; |
| 33 | + |
| 34 | +"abc".replaceAll(/b/g, "d"); |
| 35 | +"abc".replaceAll({ [Symbol.replace]: () => "" }); |
| 36 | +"abc".replaceAll("b", "d"); |
| 37 | +"abc".replaceAll(42, "d"); |
| 38 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 3); |
| 39 | +Number.prototype[Symbol.replace] = () => ""; |
| 40 | +"abc".replaceAll(42, "d"); |
| 41 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 4); |
| 42 | +delete Number.prototype[Symbol.replace]; |
| 43 | + |
| 44 | +"abc".search(/b/); |
| 45 | +"abc".search({ [Symbol.search]: () => -1 }); |
| 46 | +"abc".search("b"); |
| 47 | +"abc".search(42); |
| 48 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 4); |
| 49 | +Number.prototype[Symbol.search] = () => -1; |
| 50 | +"abc".search(42); |
| 51 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 5); |
| 52 | +delete Number.prototype[Symbol.search]; |
| 53 | + |
| 54 | +"abc".split(/b/); |
| 55 | +"abc".split({ [Symbol.split]: () => [] }); |
| 56 | +"abc".split("b"); |
| 57 | +"abc".split(42); |
| 58 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 5); |
| 59 | +Number.prototype[Symbol.split] = () => []; |
| 60 | +"abc".split(42); |
| 61 | +assertEq(getUseCounterResults().RegExpSymbolProtocolOnPrimitive, 6); |
| 62 | +delete Number.prototype[Symbol.split]; |
0 commit comments