v8/test/mjsunit/harmony/string-matchAll.js
Seth Brenith a9270e2bde Reland "[torque] Allow storing to bitfield structs that are stored in Smis"
This is a reland of 80843eda31

Original change's description:
> [torque] Allow storing to bitfield structs that are stored in Smis
> 
> This change:
> 1. Updates the Torque compiler to allow direct access to bitfields that
>    are packed within Smi values, which previously would have required a
>    separate untagging step,
> 2. Updates JSRegExpStringIterator to represent its flags in Torque,
> 3. Adds reduction cases in MachineOperatorReducer for when the input to
>    a branch or the left-hand side of a Word32Equals is based on a 64-bit
>    shift-and-mask operation which has been truncated to 32 bits, as is
>    the case in the code generated by step 1, and
> 4. Adds a reduction case in MachineOperatorReducer to remove an extra
>    Word64And operation added by step 1.
> 
> Bug: v8:7793
> Change-Id: Ib4ac2def6211b3cae6be25a8b2a644be5c7d6d3f
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2119225
> Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#67290}

Bug: v8:7793
Change-Id: I783b6ec080042fec0e922927f6675dede458a072
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2159731
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67305}
2020-04-22 10:34:46 +00:00

93 lines
2.3 KiB
JavaScript

// Copyright 2018 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.
(function TestReceiverNonString() {
const iter = 'a'.matchAll(/./g);
assertThrows(
() => iter.next.call(0),
TypeError
);
})();
(function TestAncestry() {
const iterProto = Object.getPrototypeOf('a'.matchAll(/./g));
const arrProto = Object.getPrototypeOf([][Symbol.iterator]());
assertSame(Object.getPrototypeOf(iterProto), Object.getPrototypeOf(arrProto));
})();
function TestNoMatch(string, regex_or_string) {
const next_result = string.matchAll(regex_or_string).next();
assertSame(undefined, next_result.value);
assertTrue(next_result.done);
}
TestNoMatch('a', /b/g);
TestNoMatch('a', 'b');
(function NonGlobalRegex() {
assertThrows(
() => { const iter = 'ab'.matchAll(/./); },
TypeError);
})();
function TestGlobalRegex(regex_or_string) {
const iter = 'ab'.matchAll(regex_or_string);
let next_result = iter.next();
assertEquals(['a'], next_result.value);
assertFalse(next_result.done);
next_result = iter.next();
assertEquals(['b'], next_result.value);
assertFalse(next_result.done);
next_result = iter.next();
assertSame(undefined, next_result.value);
assertTrue(next_result.done);
}
TestGlobalRegex(/./g);
TestGlobalRegex('.');
function TestEmptyGlobalRegExp(regex_or_string) {
const iter = 'd'.matchAll(regex_or_string);
let next_result = iter.next();
assertEquals([''], next_result.value);
assertFalse(next_result.done);
next_result = iter.next();
assertEquals([''], next_result.value);
assertFalse(next_result.done);
next_result = iter.next();
assertSame(undefined, next_result.value);
assertTrue(next_result.done);
}
TestEmptyGlobalRegExp(undefined);
TestEmptyGlobalRegExp(/(?:)/g);
TestEmptyGlobalRegExp('');
(function TestGlobalRegExpLastIndex() {
const regex = /./g;
const string = 'abc';
regex.exec(string);
assertSame(1, regex.lastIndex);
const iter = string.matchAll(regex);
// Verify an internal RegExp is created and mutations to the provided RegExp
// are not abservered.
regex.exec(string);
assertSame(2, regex.lastIndex);
let next_result = iter.next();
assertEquals(['b'], next_result.value);
assertFalse(next_result.done);
assertSame(2, regex.lastIndex);
})();