mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 16:01:52 +00:00

PR-URL: https://github.com/nodejs/node/pull/17489 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
22 lines
836 B
JavaScript
22 lines
836 B
JavaScript
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const pattern = {};
|
|
pattern[Symbol.search] = function(string) {
|
|
return string.length;
|
|
};
|
|
// Check object coercible fails.
|
|
assertThrows(() => String.prototype.search.call(null, pattern),
|
|
TypeError);
|
|
// Override is called.
|
|
assertEquals(5, "abcde".search(pattern));
|
|
// Receiver is not converted to string if pattern has Symbol.match
|
|
const receiver = { toString(){ throw new Error(); }, length: 6 };
|
|
assertEquals(6, String.prototype.search.call(receiver, pattern));
|
|
// Non-callable override.
|
|
pattern[Symbol.search] = "dumdidum";
|
|
assertThrows(() => "abcde".search(pattern), TypeError);
|
|
|
|
assertEquals("[Symbol.search]", RegExp.prototype[Symbol.search].name);
|