Commit 21b104e3 authored by jgruber's avatar jgruber Committed by Commit bot

[errors] Improve NotGeneric error message

This changes the message from

"method_name is not generic"

to

"method_name requires that 'this' be a primitive_name object"

BUG=v8:6206

Review-Url: https://codereview.chromium.org/2814043006
Cr-Commit-Position: refs/heads/master@{#44683}
parent 228ffc08
...@@ -312,7 +312,8 @@ BUILTIN(FunctionPrototypeToString) { ...@@ -312,7 +312,8 @@ BUILTIN(FunctionPrototypeToString) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked( isolate->factory()->NewStringFromAsciiChecked(
"Function.prototype.toString"))); "Function.prototype.toString"),
isolate->factory()->Function_string()));
} }
} // namespace internal } // namespace internal
......
...@@ -29,7 +29,8 @@ BUILTIN(NumberPrototypeToExponential) { ...@@ -29,7 +29,8 @@ BUILTIN(NumberPrototypeToExponential) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked( isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toExponential"))); "Number.prototype.toExponential"),
isolate->factory()->Number_string()));
} }
double const value_number = value->Number(); double const value_number = value->Number();
...@@ -72,7 +73,8 @@ BUILTIN(NumberPrototypeToFixed) { ...@@ -72,7 +73,8 @@ BUILTIN(NumberPrototypeToFixed) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked( isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toFixed"))); "Number.prototype.toFixed"),
isolate->factory()->Number_string()));
} }
double const value_number = value->Number(); double const value_number = value->Number();
...@@ -114,7 +116,8 @@ BUILTIN(NumberPrototypeToLocaleString) { ...@@ -114,7 +116,8 @@ BUILTIN(NumberPrototypeToLocaleString) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked( isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toLocaleString"))); "Number.prototype.toLocaleString"),
isolate->factory()->Number_string()));
} }
// Turn the {value} into a String. // Turn the {value} into a String.
...@@ -135,7 +138,8 @@ BUILTIN(NumberPrototypeToPrecision) { ...@@ -135,7 +138,8 @@ BUILTIN(NumberPrototypeToPrecision) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked( isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toPrecision"))); "Number.prototype.toPrecision"),
isolate->factory()->Number_string()));
} }
double const value_number = value->Number(); double const value_number = value->Number();
...@@ -179,7 +183,8 @@ BUILTIN(NumberPrototypeToString) { ...@@ -179,7 +183,8 @@ BUILTIN(NumberPrototypeToString) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked( isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toString"))); "Number.prototype.toString"),
isolate->factory()->Number_string()));
} }
double const value_number = value->Number(); double const value_number = value->Number();
......
...@@ -2900,10 +2900,27 @@ Node* CodeStubAssembler::ToThisValue(Node* context, Node* value, ...@@ -2900,10 +2900,27 @@ Node* CodeStubAssembler::ToThisValue(Node* context, Node* value,
BIND(&done_throw); BIND(&done_throw);
{ {
const char* primitive_name = nullptr;
switch (primitive_type) {
case PrimitiveType::kBoolean:
primitive_name = "Boolean";
break;
case PrimitiveType::kNumber:
primitive_name = "Number";
break;
case PrimitiveType::kString:
primitive_name = "String";
break;
case PrimitiveType::kSymbol:
primitive_name = "Symbol";
break;
}
CHECK_NOT_NULL(primitive_name);
// The {value} is not a compatible receiver for this method. // The {value} is not a compatible receiver for this method.
CallRuntime(Runtime::kThrowNotGeneric, context, CallRuntime(Runtime::kThrowTypeError, context,
HeapConstant(factory()->NewStringFromAsciiChecked(method_name, SmiConstant(MessageTemplate::kNotGeneric),
TENURED))); CStringConstant(method_name), CStringConstant(primitive_name));
Unreachable(); Unreachable();
} }
......
...@@ -342,7 +342,7 @@ class ErrorUtils : public AllStatic { ...@@ -342,7 +342,7 @@ class ErrorUtils : public AllStatic {
T(NotConstructor, "% is not a constructor") \ T(NotConstructor, "% is not a constructor") \
T(NotDateObject, "this is not a Date object.") \ T(NotDateObject, "this is not a Date object.") \
T(NotIntlObject, "% is not an i18n object.") \ T(NotIntlObject, "% is not an i18n object.") \
T(NotGeneric, "% is not generic") \ T(NotGeneric, "% requires that 'this' be a %") \
T(NotIterable, "% is not iterable") \ T(NotIterable, "% is not iterable") \
T(NotPropertyName, "% is not a valid property name") \ T(NotPropertyName, "% is not a valid property name") \
T(NotTypedArray, "this is not a typed array.") \ T(NotTypedArray, "this is not a typed array.") \
......
...@@ -288,14 +288,6 @@ RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) { ...@@ -288,14 +288,6 @@ RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
isolate, NewTypeError(MessageTemplate::kNotConstructor, object)); isolate, NewTypeError(MessageTemplate::kNotConstructor, object));
} }
RUNTIME_FUNCTION(Runtime_ThrowNotGeneric) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 0);
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric, arg0));
}
RUNTIME_FUNCTION(Runtime_ThrowGeneratorRunning) { RUNTIME_FUNCTION(Runtime_ThrowGeneratorRunning) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(0, args.length()); DCHECK_EQ(0, args.length());
......
...@@ -322,7 +322,6 @@ namespace internal { ...@@ -322,7 +322,6 @@ namespace internal {
F(ThrowNonCallableInInstanceOfCheck, 0, 1) \ F(ThrowNonCallableInInstanceOfCheck, 0, 1) \
F(ThrowNonObjectInInstanceOfCheck, 0, 1) \ F(ThrowNonObjectInInstanceOfCheck, 0, 1) \
F(ThrowNotConstructor, 1, 1) \ F(ThrowNotConstructor, 1, 1) \
F(ThrowNotGeneric, 1, 1) \
F(ThrowRangeError, -1 /* >= 1 */, 1) \ F(ThrowRangeError, -1 /* >= 1 */, 1) \
F(ThrowReferenceError, 1, 1) \ F(ThrowReferenceError, 1, 1) \
F(ThrowStackOverflow, 0, 1) \ F(ThrowStackOverflow, 0, 1) \
......
...@@ -192,33 +192,33 @@ test(function() { ...@@ -192,33 +192,33 @@ test(function() {
}, "this is not a Date object.", TypeError); }, "this is not a Date object.", TypeError);
// kNotGeneric // kNotGeneric
test(function() { test(() => String.prototype.toString.call(1),
String.prototype.toString.call(1); "String.prototype.toString requires that 'this' be a String",
}, "String.prototype.toString is not generic", TypeError); TypeError);
test(function() { test(() => String.prototype.valueOf.call(1),
String.prototype.valueOf.call(1); "String.prototype.valueOf requires that 'this' be a String",
}, "String.prototype.valueOf is not generic", TypeError); TypeError);
test(function() { test(() => Boolean.prototype.toString.call(1),
Boolean.prototype.toString.call(1); "Boolean.prototype.toString requires that 'this' be a Boolean",
}, "Boolean.prototype.toString is not generic", TypeError); TypeError);
test(function() { test(() => Boolean.prototype.valueOf.call(1),
Boolean.prototype.valueOf.call(1); "Boolean.prototype.valueOf requires that 'this' be a Boolean",
}, "Boolean.prototype.valueOf is not generic", TypeError); TypeError);
test(function() { test(() => Number.prototype.toString.call({}),
Number.prototype.toString.call({}); "Number.prototype.toString requires that 'this' be a Number",
}, "Number.prototype.toString is not generic", TypeError); TypeError);
test(function() { test(() => Number.prototype.valueOf.call({}),
Number.prototype.valueOf.call({}); "Number.prototype.valueOf requires that 'this' be a Number",
}, "Number.prototype.valueOf is not generic", TypeError); TypeError);
test(function() { test(() => Function.prototype.toString.call(1),
Function.prototype.toString.call(1); "Function.prototype.toString requires that 'this' be a Function",
}, "Function.prototype.toString is not generic", TypeError); TypeError);
// kNotTypedArray // kNotTypedArray
test(function() { test(function() {
......
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