[message] Improve IteratorSymbolNonCallable error message

Add the receiver to the IteratorSymbolNonCallable error
message.

Bug: v8:12918
Change-Id: Ib863a357474282ec3723cc4e7e012052979ca2d6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3813069
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#82308}
This commit is contained in:
jameslahm 2022-08-09 21:53:56 +08:00 committed by V8 LUCI CQ
parent 78f8cb235a
commit 7e95d21172
16 changed files with 104 additions and 54 deletions

View File

@ -179,7 +179,9 @@ ArrayFrom(js-implicit context: NativeContext, receiver: JSAny)(...arguments):
// 14. Return A.
return a;
} label IteratorNotCallable(_value: JSAny) deferred {
ThrowTypeError(MessageTemplate::kIteratorSymbolNonCallable);
ThrowTypeError(
MessageTemplate::kFirstArgumentIteratorSymbolNonCallable,
'%Array%.from');
}
}
}

View File

@ -375,7 +375,7 @@ extern enum MessageTemplate {
kProtoObjectOrNull,
kInvalidOffset,
kInvalidTypedArrayLength,
kIteratorSymbolNonCallable,
kFirstArgumentIteratorSymbolNonCallable,
kIteratorValueNotAnObject,
kNotIterable,
kReduceNoInitial,

View File

@ -420,7 +420,7 @@ void CallOrConstructBuiltinsAssembler::CallOrConstructWithSpread(
BIND(&if_iterator_fn_not_callable);
message_id = SmiConstant(
static_cast<int>(MessageTemplate::kIteratorSymbolNonCallable)),
static_cast<int>(MessageTemplate::kSpreadIteratorSymbolNonCallable)),
Goto(&throw_spread_error);
BIND(&if_iterator_is_null_or_undefined);

View File

@ -345,7 +345,8 @@ transitioning macro TypedArrayCreateByLength(implicit context: Context)(
transitioning macro ConstructByJSReceiver(implicit context: Context)(
obj: JSReceiver): never
labels IfConstructByArrayLike(JSReceiver, uintptr) {
labels IfConstructByArrayLike(JSReceiver, uintptr),
IfIteratorNotCallable(JSAny) {
try {
// TODO(v8:8906): Use iterator::GetIteratorMethod() once it supports
// labels.
@ -364,8 +365,6 @@ transitioning macro ConstructByJSReceiver(implicit context: Context)(
goto IfConstructByArrayLike(obj, length);
} label IfInvalidLength(length: Number) {
ThrowRangeError(MessageTemplate::kInvalidTypedArrayLength, length);
} label IfIteratorNotCallable(_value: JSAny) deferred {
ThrowTypeError(MessageTemplate::kIteratorSymbolNonCallable);
}
}
@ -389,7 +388,8 @@ transitioning builtin CreateTypedArray(
ConstructByTypedArray(typedArray) otherwise IfConstructByArrayLike;
}
case (obj: JSReceiver): {
ConstructByJSReceiver(obj) otherwise IfConstructByArrayLike;
ConstructByJSReceiver(obj) otherwise IfConstructByArrayLike,
IfIteratorNotCallable;
}
// The first argument was a number or fell through and is treated as
// a number. https://tc39.github.io/ecma262/#sec-typedarray-length
@ -410,6 +410,10 @@ transitioning builtin CreateTypedArray(
// 56 for constructorName.
const elementsInfo = GetTypedArrayElementsInfo(map);
return ConstructByArrayLike(map, arrayLike, length, elementsInfo);
} label IfIteratorNotCallable(_value: JSAny) deferred {
ThrowTypeError(
MessageTemplate::kFirstArgumentIteratorSymbolNonCallable,
'TypedArray\'s constructor');
}
}

View File

@ -151,7 +151,9 @@ TypedArrayFrom(js-implicit context: NativeContext, receiver: JSAny)(
ThrowRangeError(MessageTemplate::kInvalidTypedArrayLength, length);
}
} label IteratorNotCallable(_value: JSAny) deferred {
ThrowTypeError(MessageTemplate::kIteratorSymbolNonCallable);
ThrowTypeError(
MessageTemplate::kFirstArgumentIteratorSymbolNonCallable,
kBuiltinNameFrom);
}
const finalLengthNum = Convert<Number>(finalLength);

View File

@ -120,8 +120,11 @@ namespace internal {
T(InvalidUnit, "Invalid unit argument for %() '%'") \
T(IterableYieldedNonString, "Iterable yielded % which is not a string") \
T(IteratorResultNotAnObject, "Iterator result % is not an object") \
T(IteratorSymbolNonCallable, \
T(SpreadIteratorSymbolNonCallable, \
"Spread syntax requires ...iterable[Symbol.iterator] to be a function") \
T(FirstArgumentIteratorSymbolNonCallable, \
"% requires that the property of the first argument, " \
"items[Symbol.iterator], when exists, be a function") \
T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \
T(LanguageID, "Language ID should be string or object.") \
T(LocaleNotEmpty, \

View File

@ -0,0 +1,7 @@
// Copyright 2022 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 x = {
[Symbol.iterator]: 1
};
Uint8Array.from(x);

View File

@ -0,0 +1,6 @@
*%(basename)s:7: TypeError: %%TypedArray%%.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function
Uint8Array.from(x);
^
TypeError: %%TypedArray%%.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function
at Function.from (<anonymous>)
at *%(basename)s:7:12

View File

@ -0,0 +1,7 @@
// Copyright 2022 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 x = {
[Symbol.iterator]: 1
};
new Uint8Array(x);

View File

@ -0,0 +1,6 @@
*%(basename)s:7: TypeError: TypedArray's constructor requires that the property of the first argument, items[Symbol.iterator], when exists, be a function
new Uint8Array(x);
^
TypeError: TypedArray's constructor requires that the property of the first argument, items[Symbol.iterator], when exists, be a function
at new Uint8Array (<anonymous>)
at *%(basename)s:7:1

View File

@ -0,0 +1,7 @@
// Copyright 2022 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 x = {
[Symbol.iterator]: 1
};
Array.from(x);

View File

@ -0,0 +1,6 @@
*%(basename)s:7: TypeError: %%Array%%.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function
Array.from(x);
^
TypeError: %%Array%%.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function
at Function.from (<anonymous>)
at *%(basename)s:7:7

View File

@ -83,7 +83,7 @@ bytecodes: [
/* 48 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0),
/* 53 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 58 E> */ B(GetKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(303),
B(Wide), B(LdaSmi), I16(304),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
@ -115,7 +115,7 @@ bytecodes: [
/* 41 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0),
/* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 51 E> */ B(GetKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(302),
B(Wide), B(LdaSmi), I16(303),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
@ -149,7 +149,7 @@ bytecodes: [
B(Star2),
B(LdaImmutableCurrentContextSlot), U8(3),
/* 58 E> */ B(GetKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(303),
B(Wide), B(LdaSmi), I16(304),
B(Star3),
B(LdaConstant), U8(0),
B(Star4),
@ -181,7 +181,7 @@ bytecodes: [
/* 41 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0),
/* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 51 E> */ B(GetKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(302),
B(Wide), B(LdaSmi), I16(303),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),

View File

@ -58,7 +58,7 @@ bytecodes: [
B(Star2),
B(LdaImmutableCurrentContextSlot), U8(3),
/* 54 E> */ B(GetKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(301),
B(Wide), B(LdaSmi), I16(302),
B(Star3),
B(LdaConstant), U8(0),
B(Star4),
@ -91,7 +91,7 @@ bytecodes: [
/* 44 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0),
/* 49 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 54 E> */ B(GetKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(301),
B(Wide), B(LdaSmi), I16(302),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),

View File

@ -24,7 +24,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(1),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
@ -61,13 +61,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
/* 61 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(301),
B(Wide), B(LdaSmi), I16(302),
B(Star2),
B(LdaConstant), U8(1),
B(Star3),
@ -99,13 +99,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 61 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(301),
B(Wide), B(LdaSmi), I16(302),
B(Star1),
B(LdaConstant), U8(1),
B(Star2),
@ -145,7 +145,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
@ -167,7 +167,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star3),
B(LdaConstant), U8(0),
B(Star4),
@ -182,7 +182,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
@ -216,13 +216,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 65 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(303),
B(Wide), B(LdaSmi), I16(304),
B(Star1),
B(LdaConstant), U8(1),
B(Star2),
@ -253,13 +253,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 58 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(302),
B(Wide), B(LdaSmi), I16(303),
B(Star1),
B(LdaConstant), U8(1),
B(Star2),
@ -292,13 +292,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(295),
B(Wide), B(LdaSmi), I16(296),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
/* 65 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(303),
B(Wide), B(LdaSmi), I16(304),
B(Star2),
B(LdaConstant), U8(1),
B(Star3),
@ -327,7 +327,7 @@ bytecode array length: 19
bytecodes: [
/* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 51 E> */ B(GetKeyedProperty), R(this), U8(0),
B(Wide), B(LdaSmi), I16(302),
B(Wide), B(LdaSmi), I16(303),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),

View File

@ -543,30 +543,30 @@ KNOWN_OBJECTS = {
("old_space", 0x04a2d): "RegExpMultipleCache",
("old_space", 0x04e35): "SingleCharacterStringTable",
("old_space", 0x0523d): "BuiltinsConstantsTable",
("old_space", 0x05681): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x056a5): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x056c9): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x056ed): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x05711): "AsyncGeneratorYieldResolveSharedFun",
("old_space", 0x05735): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x05759): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x0577d): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x057a1): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x057c5): "PromiseAllResolveElementSharedFun",
("old_space", 0x057e9): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x0580d): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x05831): "PromiseAnyRejectElementSharedFun",
("old_space", 0x05855): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05879): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x0589d): "PromiseCatchFinallySharedFun",
("old_space", 0x058c1): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x058e5): "PromiseThenFinallySharedFun",
("old_space", 0x05909): "PromiseThrowerFinallySharedFun",
("old_space", 0x0592d): "PromiseValueThunkFinallySharedFun",
("old_space", 0x05951): "ProxyRevokeSharedFun",
("old_space", 0x05975): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x05999): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x059bd): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
("old_space", 0x05689): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x056ad): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x056d1): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x056f5): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x05719): "AsyncGeneratorYieldResolveSharedFun",
("old_space", 0x0573d): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x05761): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x05785): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x057a9): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x057cd): "PromiseAllResolveElementSharedFun",
("old_space", 0x057f1): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x05815): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x05839): "PromiseAnyRejectElementSharedFun",
("old_space", 0x0585d): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05881): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x058a5): "PromiseCatchFinallySharedFun",
("old_space", 0x058c9): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x058ed): "PromiseThenFinallySharedFun",
("old_space", 0x05911): "PromiseThrowerFinallySharedFun",
("old_space", 0x05935): "PromiseValueThunkFinallySharedFun",
("old_space", 0x05959): "ProxyRevokeSharedFun",
("old_space", 0x0597d): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x059a1): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x059c5): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
}
# Lower 32 bits of first page addresses for various heap spaces.