Commit ae9c8c80 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[regexp] Improve String.prototype.matchAll error message

Currently if the argument to matchAll has a null or undefined .flags
property, the error message will read "String.prototype.matchAll called
on null or undefined", which is very confusing.

Drive-by fix: Remove the related and unused
MethodInvokedOnNullOrUndefined error.

Bug: v8:9895
Change-Id: I3644545282ac8d2156c7a51086e37a0ab7f97a78
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1874619
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64530}
parent 4a716fea
......@@ -1532,7 +1532,8 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) {
RegExpMatchAllAssembler regexp_asm(state());
{
Label fast(this), slow(this, Label::kDeferred),
throw_exception(this, Label::kDeferred), next(this);
throw_exception(this, Label::kDeferred),
throw_flags_exception(this, Label::kDeferred), next(this);
// 2. If regexp is neither undefined nor null, then
// a. Let isRegExp be ? IsRegExp(regexp).
......@@ -1559,7 +1560,9 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) {
TNode<Object> flags = GetProperty(context, heap_maybe_regexp,
isolate()->factory()->flags_string());
RequireObjectCoercible(context, flags, method_name);
// TODO(syg): Implement a RequireObjectCoercible with more flexible error
// messages.
GotoIf(IsNullOrUndefined(flags), &throw_flags_exception);
TNode<String> flags_string = ToString_Inline(context, flags);
TNode<String> global_char_string = StringConstant("g");
......@@ -1572,6 +1575,10 @@ TF_BUILTIN(StringPrototypeMatchAll, StringBuiltinsAssembler) {
BIND(&throw_exception);
ThrowTypeError(context, MessageTemplate::kRegExpGlobalInvokedOnNonGlobal);
BIND(&throw_flags_exception);
ThrowTypeError(context,
MessageTemplate::kStringMatchAllNullOrUndefinedFlags);
BIND(&next);
}
// a. Let matcher be ? GetMethod(regexp, @@matchAll).
......
......@@ -111,8 +111,6 @@ namespace internal {
T(MapperFunctionNonCallable, "flatMap mapper function is not callable") \
T(MethodCalledOnWrongObject, \
"Method % called on a non-object or on a wrong type of object.") \
T(MethodInvokedOnNullOrUndefined, \
"Method invoked on undefined or null value.") \
T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
T(NoAccess, "no access") \
T(NonCallableInInstanceOfCheck, \
......@@ -290,6 +288,9 @@ namespace internal {
T(StrictReadOnlyProperty, \
"Cannot assign to read only property '%' of % '%'") \
T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'") \
T(StringMatchAllNullOrUndefinedFlags, \
"The .flags property of the argument to String.prototype.matchAll cannot " \
"be null or undefined") \
T(SymbolIteratorInvalid, \
"Result of the Symbol.iterator method is not an object") \
T(SymbolAsyncIteratorInvalid, \
......
......@@ -296,7 +296,7 @@ bytecodes: [
B(Mov), R(context), R(16),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(17),
B(LdaConstant), U8(11),
B(Star), R(18),
......
......@@ -61,7 +61,7 @@ bytecodes: [
B(Mov), R(context), R(11),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(12),
B(LdaConstant), U8(5),
B(Star), R(13),
......@@ -191,7 +191,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(5),
B(Star), R(14),
......@@ -308,7 +308,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(6),
B(Star), R(15),
......
......@@ -93,7 +93,7 @@ bytecodes: [
B(Mov), R(context), R(15),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
......@@ -260,7 +260,7 @@ bytecodes: [
B(Mov), R(context), R(15),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
......@@ -443,7 +443,7 @@ bytecodes: [
B(Mov), R(context), R(15),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
......@@ -590,7 +590,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(7),
B(Star), R(14),
......
......@@ -58,7 +58,7 @@ bytecodes: [
B(Mov), R(context), R(10),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(11),
B(LdaConstant), U8(5),
B(Star), R(12),
......@@ -154,7 +154,7 @@ bytecodes: [
B(Mov), R(context), R(11),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(12),
B(LdaConstant), U8(5),
B(Star), R(13),
......@@ -261,7 +261,7 @@ bytecodes: [
B(Mov), R(context), R(10),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(11),
B(LdaConstant), U8(5),
B(Star), R(12),
......@@ -361,7 +361,7 @@ bytecodes: [
B(Mov), R(context), R(10),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(11),
B(LdaConstant), U8(7),
B(Star), R(12),
......
......@@ -61,7 +61,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(4),
B(Star), R(14),
......@@ -192,7 +192,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(9),
B(Star), R(15),
......@@ -300,7 +300,7 @@ bytecodes: [
B(Mov), R(context), R(11),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(12),
B(LdaConstant), U8(6),
B(Star), R(13),
......@@ -400,7 +400,7 @@ bytecodes: [
B(Mov), R(context), R(14),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(15),
B(LdaConstant), U8(6),
B(Star), R(16),
......@@ -510,7 +510,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(7),
B(Star), R(15),
......@@ -635,7 +635,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(10),
B(Star), R(14),
......@@ -744,7 +744,7 @@ bytecodes: [
B(Mov), R(context), R(14),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(15),
B(LdaConstant), U8(4),
B(Star), R(16),
......@@ -877,7 +877,7 @@ bytecodes: [
B(Mov), R(context), R(13),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(14),
B(LdaConstant), U8(5),
B(Star), R(15),
......
......@@ -176,7 +176,7 @@ bytecodes: [
B(Mov), R(context), R(12),
B(TestTypeOf), U8(6),
B(JumpIfTrue), U8(18),
B(Wide), B(LdaSmi), I16(160),
B(Wide), B(LdaSmi), I16(159),
B(Star), R(13),
B(LdaConstant), U8(11),
B(Star), R(14),
......
// Copyright 2019 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.
"foo".matchAll({[Symbol.match]: true});
*%(basename)s:5: TypeError: The .flags property of the argument to String.prototype.matchAll cannot be null or undefined
"foo".matchAll({[Symbol.match]: true});
^
TypeError: The .flags property of the argument to String.prototype.matchAll cannot be null or undefined
at String.matchAll (<anonymous>)
at *%(basename)s:5:7
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