ossy@webkit.org | 8f73aef | 2016-07-21 18:08:38 +0000 | [diff] [blame] | 1 | //@ runNoFTL |
mark.lam@apple.com | 2c87b1a | 2016-04-20 00:02:07 +0000 | [diff] [blame] | 2 | |
| 3 | function assert(testedValue, msg) { |
| 4 | if (!testedValue) |
| 5 | throw Error(msg); |
| 6 | } |
| 7 | |
| 8 | // String prototype with overridden @@search: test with string literal. |
| 9 | (function () { |
| 10 | let accesses = []; |
| 11 | var obj = ""; |
| 12 | Object.defineProperty(String.prototype, Symbol.search, { |
| 13 | value: function (str) { |
| 14 | accesses.push("Symbol(Symbol.search)"); |
| 15 | return /rch/[Symbol.search](str); |
| 16 | }, |
| 17 | writable: true, |
| 18 | configurable: true, |
| 19 | }); |
| 20 | |
| 21 | assert(accesses == "", "unexpected call to overridden props"); |
| 22 | let result = "searchme".search(obj); |
| 23 | assert(accesses == "Symbol(Symbol.search)", "Property accesses do not match expectation"); |
| 24 | assert(result === 3, "Unexpected result"); |
| 25 | |
| 26 | Object.defineProperty(String.prototype, Symbol.search, { value: undefined, writable: false, configurable: true }); |
| 27 | })(); |