v8/test/mjsunit/regexp-linear-flag.js
Shu-yu Guo 81e7e2f437 [regexp] Implement the /d flag for RegExp indices
This CL implements the upcoming spec change:
https://github.com/tc39/proposal-regexp-match-indices/pull/49

A new JSRegExpResultWithIndices subclass is introduced with a separate map and
an extra slot for storing the indices. If /d is passed, exec() constructs a
JSRegExpResultWithIndices and eagerly builds indices.

The existing re-execution logic is removed.

Bug: v8:9548
Change-Id: Ic11853e7521017af5e8bd583c7b82bb672821132
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2616873
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72306}
2021-01-26 04:14:10 +00:00

43 lines
1.6 KiB
JavaScript

// Copyright 2020 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.
// Flags: --allow-natives-syntax
// Flags: --enable-experimental-regexp-engine
// Flags: --no-default-to-experimental-regexp-engine
// Flags: --no-force-slow-path
// We shouldn't assign the experimental engine to regexps without 'l' flag.
assertNotEquals("EXPERIMENTAL", %RegexpTypeTag(/asdf/));
assertNotEquals("EXPERIMENTAL", %RegexpTypeTag(/123|asdf/));
assertNotEquals("EXPERIMENTAL", %RegexpTypeTag(/(a*)*x/));
assertNotEquals("EXPERIMENTAL", %RegexpTypeTag(/(a*)\1/));
// We should assign the experimental engine to regexps with 'l' flag.
assertEquals("EXPERIMENTAL", %RegexpTypeTag(/asdf/l));
assertEquals("EXPERIMENTAL", %RegexpTypeTag(/123|asdf/l));
assertEquals("EXPERIMENTAL", %RegexpTypeTag(/(a*)*x/l));
// We should throw if a regexp with 'l' flag can't be handled by the
// experimental engine.
assertThrows(() => /(a*)\1/l, SyntaxError);
// The flags field of a regexp should be sorted.
assertEquals("glmsy", (/asdf/lymsg).flags);
// The 'linear' member should be set according to the linear flag.
assertTrue((/asdf/lymsg).linear);
assertFalse((/asdf/ymsg).linear);
// The new fields installed on the regexp prototype map shouldn't make
// unmodified regexps slow.
assertTrue(%RegexpIsUnmodified(/asdf/));
assertTrue(%RegexpIsUnmodified(/asdf/l));
// Redefined .linear should reflect in flags.
{
let re = /./;
Object.defineProperty(re, "linear", { get: function() { return true; } });
assertEquals("l", re.flags);
}