v8/test/mjsunit/es6/string-search.js
peterwmwong 183eb36b88 [builtins] Port String.prototype.{search, match} to CSA
- Expose fast paths for RegExpPrototypeMatchBody/RegExpPrototypeSearchBody as TFS builtins
- Add StringPrototypeMatch and StringPrototypeSearch TFJ builtins
  - Add StringMatchSearchAssembler to ensure same search/match behavior
- Remove functionality from string.js

A quick benchmark shows gains of 20-30% for unoptimized code and 0-20% for optimized code.
https://github.com/peterwmwong/v8-perf/blob/master/string-search-match/README.md

Bug: v8:5049
Change-Id: I0fffee6e94e62ecae049c9e5798da52d67ae1823
Reviewed-on: https://chromium-review.googlesource.com/707824
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48452}
2017-10-11 12:05:22 +00:00

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);