blob: 0beb57a5368607af0ead51fb3f1d334c2c41b664 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001// Copyright 2015 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 Murdoch097c5b22016-05-18 11:27:45 +01005var pattern = {
6 [Symbol.replace]: (string, newValue) => string + newValue
7};
8// Check object coercible fails.
9assertThrows(() => String.prototype.replace.call(null, pattern, "x"),
10 TypeError);
11// Override is called.
12assertEquals("abcdex", "abcde".replace(pattern, "x"));
13// Non-callable override.
14pattern[Symbol.replace] = "dumdidum";
15assertThrows(() => "abcde".replace(pattern, "x"), TypeError);
16
17assertEquals("[Symbol.replace]", RegExp.prototype[Symbol.replace].name);