Commit 0f249dd8 authored by peterwmwong's avatar peterwmwong Committed by Commit Bot

[builtins] Adjust String.prototype.matchAll as per spec changes...

[builtins] Adjust String.prototype.matchAll as per spec changes (https://github.com/tc39/proposal-string-matchall/pull/38)

- Removes IsRegExp check and special handling when false
- Removes MatchAllIterator
- Extracts previously inlined CreateRegExpStringIterator
- Update comments to match spec text and numbering

Bug: v8:6890
Change-Id: Ie81757a499acc77910f029835fb042e70d86d83d
Reviewed-on: https://chromium-review.googlesource.com/c/1317830
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57488}
parent ab9cd95b
This diff is collapsed.
...@@ -28,12 +28,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -28,12 +28,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
TNode<Object> RegExpCreate(TNode<Context> context, TNode<Map> initial_map, TNode<Object> RegExpCreate(TNode<Context> context, TNode<Map> initial_map,
TNode<Object> regexp_string, TNode<String> flags); TNode<Object> regexp_string, TNode<String> flags);
TNode<Object> MatchAllIterator(TNode<Context> context,
TNode<Context> native_context,
TNode<Object> regexp, TNode<String> string,
TNode<BoolT> is_fast_regexp,
char const* method_name);
protected: protected:
TNode<Smi> SmiZero(); TNode<Smi> SmiZero();
TNode<IntPtrT> IntPtrZero(); TNode<IntPtrT> IntPtrZero();
...@@ -146,6 +140,20 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -146,6 +140,20 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
TNode<String> replace_string); TNode<String> replace_string);
}; };
class RegExpMatchAllAssembler : public RegExpBuiltinsAssembler {
public:
explicit RegExpMatchAllAssembler(compiler::CodeAssemblerState* state)
: RegExpBuiltinsAssembler(state) {}
TNode<Object> CreateRegExpStringIterator(TNode<Context> native_context,
TNode<Object> regexp,
TNode<String> string,
TNode<Int32T> global,
TNode<Int32T> full_unicode);
void Generate(TNode<Context> context, TNode<Context> native_context,
TNode<Object> receiver, TNode<Object> maybe_string);
};
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -1511,12 +1511,10 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) { ...@@ -1511,12 +1511,10 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) {
RequireObjectCoercible(context, receiver, method_name); RequireObjectCoercible(context, receiver, method_name);
// 2. If regexp is neither undefined nor null, then // 2. If regexp is neither undefined nor null, then
Label return_match_all_iterator(this), Label tostring_and_create_regexp_string_iterator(this, Label::kDeferred);
tostring_and_return_match_all_iterator(this, Label::kDeferred);
TVARIABLE(BoolT, var_is_fast_regexp);
TVARIABLE(String, var_receiver_string); TVARIABLE(String, var_receiver_string);
GotoIf(IsNullOrUndefined(maybe_regexp), GotoIf(IsNullOrUndefined(maybe_regexp),
&tostring_and_return_match_all_iterator); &tostring_and_create_regexp_string_iterator);
{ {
// a. Let matcher be ? GetMethod(regexp, @@matchAll). // a. Let matcher be ? GetMethod(regexp, @@matchAll).
// b. If matcher is not undefined, then // b. If matcher is not undefined, then
...@@ -1526,8 +1524,10 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) { ...@@ -1526,8 +1524,10 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) {
// maybe_regexp is a fast regexp and receiver is a string. // maybe_regexp is a fast regexp and receiver is a string.
var_receiver_string = CAST(receiver); var_receiver_string = CAST(receiver);
CSA_ASSERT(this, IsString(var_receiver_string.value())); CSA_ASSERT(this, IsString(var_receiver_string.value()));
var_is_fast_regexp = Int32TrueConstant();
Goto(&return_match_all_iterator); RegExpMatchAllAssembler regexp_asm(state());
regexp_asm.Generate(context, native_context, maybe_regexp,
var_receiver_string.value());
}; };
auto if_generic_call = [=](Node* fn) { auto if_generic_call = [=](Node* fn) {
Callable call_callable = CodeFactory::Call(isolate()); Callable call_callable = CodeFactory::Call(isolate());
...@@ -1536,21 +1536,27 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) { ...@@ -1536,21 +1536,27 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) {
MaybeCallFunctionAtSymbol(context, maybe_regexp, receiver, MaybeCallFunctionAtSymbol(context, maybe_regexp, receiver,
isolate()->factory()->match_all_symbol(), isolate()->factory()->match_all_symbol(),
if_regexp_call, if_generic_call); if_regexp_call, if_generic_call);
Goto(&tostring_and_return_match_all_iterator); Goto(&tostring_and_create_regexp_string_iterator);
} }
BIND(&tostring_and_return_match_all_iterator); BIND(&tostring_and_create_regexp_string_iterator);
{ {
RegExpMatchAllAssembler regexp_asm(state());
// 3. Let S be ? ToString(O).
var_receiver_string = ToString_Inline(context, receiver); var_receiver_string = ToString_Inline(context, receiver);
var_is_fast_regexp = Int32FalseConstant();
Goto(&return_match_all_iterator); // 4. Let matcher be ? RegExpCreate(R, "g").
} TNode<Object> regexp = regexp_asm.RegExpCreate(
BIND(&return_match_all_iterator); context, native_context, maybe_regexp, StringConstant("g"));
{
// 3. Return ? MatchAllIterator(regexp, O). // 5. Let global be true.
RegExpBuiltinsAssembler regexp_asm(state()); // 6. Let fullUnicode be false.
TNode<Object> iterator = regexp_asm.MatchAllIterator( // 7. Return ! CreateRegExpStringIterator(matcher, S, global, fullUnicode).
context, native_context, maybe_regexp, var_receiver_string.value(), TNode<Int32T> global = Int32Constant(1);
var_is_fast_regexp.value(), method_name); TNode<Int32T> full_unicode = Int32Constant(0);
TNode<Object> iterator = regexp_asm.CreateRegExpStringIterator(
native_context, regexp, var_receiver_string.value(), global,
full_unicode);
Return(iterator); Return(iterator);
} }
} }
......
...@@ -625,13 +625,6 @@ ...@@ -625,13 +625,6 @@
'built-ins/Atomics/wait/cannot-suspend-throws': [SKIP], 'built-ins/Atomics/wait/cannot-suspend-throws': [SKIP],
'built-ins/Atomics/wait/undefined-index-defaults-to-zero': [SKIP], 'built-ins/Atomics/wait/undefined-index-defaults-to-zero': [SKIP],
# https://bugs.chromium.org/p/v8/issues/detail?id=6890#c12
'built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once': [FAIL],
'built-ins/RegExp/prototype/Symbol.matchAll/species-constructor': [FAIL],
'built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-global-throws': [FAIL],
'built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-unicode-throws': [FAIL],
'built-ins/String/prototype/matchAll/regexp-prototype-has-no-matchAll': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=8258 # https://bugs.chromium.org/p/v8/issues/detail?id=8258
'intl402/Locale/constructor-options-language-valid-undefined': [FAIL], 'intl402/Locale/constructor-options-language-valid-undefined': [FAIL],
'intl402/Locale/constructor-options-throwing-getters': [FAIL], 'intl402/Locale/constructor-options-throwing-getters': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment