Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1 | // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5 | function createNonRegExp(calls) { |
| 6 | return { |
| 7 | get [Symbol.match]() { |
| 8 | calls.push("@@match"); |
| 9 | return undefined; |
| 10 | }, |
| 11 | get [Symbol.replace]() { |
| 12 | calls.push("@@replace"); |
| 13 | return undefined; |
| 14 | }, |
| 15 | get [Symbol.search]() { |
| 16 | calls.push("@@search"); |
| 17 | return undefined; |
| 18 | }, |
| 19 | get [Symbol.split]() { |
| 20 | calls.push("@@split"); |
| 21 | return undefined; |
| 22 | }, |
| 23 | [Symbol.toPrimitive]() { |
| 24 | calls.push("@@toPrimitive"); |
| 25 | return ""; |
| 26 | } |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | (function testStringMatchBrandCheck() { |
| 31 | var calls = []; |
| 32 | "".match(createNonRegExp(calls)); |
| 33 | assertEquals(["@@match", "@@toPrimitive"], calls); |
| 34 | })(); |
| 35 | |
| 36 | (function testStringSearchBrandCheck() { |
| 37 | var calls = []; |
| 38 | "".search(createNonRegExp(calls)); |
| 39 | assertEquals(["@@search", "@@toPrimitive"], calls); |
| 40 | })(); |
| 41 | |
| 42 | (function testStringSplitBrandCheck() { |
| 43 | var calls = []; |
| 44 | "".split(createNonRegExp(calls)); |
| 45 | assertEquals(["@@split", "@@toPrimitive"], calls); |
| 46 | })(); |
| 47 | |
| 48 | (function testStringReplaceBrandCheck() { |
| 49 | var calls = []; |
| 50 | "".replace(createNonRegExp(calls), ""); |
| 51 | assertEquals(["@@replace", "@@toPrimitive"], calls); |
| 52 | })(); |