Skip to content

Commit

Permalink
Revert of [errors] Improve NotGeneric error message (patchset #3 id:4…
Browse files Browse the repository at this point in the history
…0001 of https://codereview.chromium.org/2814043006/ )

Reason for revert:
Please schedule rebasing layout test first:
https://build.chromium.org/p/client.v8.fyi/builders/V8-Blink%20Linux%2064/builds/15036

https://github.com/v8/v8/wiki/Blink-layout-tests

Original issue's description:
> [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}
> Committed: https://chromium.googlesource.com/v8/v8/+/21b104e3b83569b52539ecaa83e68a3646065101

TBR=littledan@chromium.org,yangguo@chromium.org,jgruber@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:6206

Review-Url: https://codereview.chromium.org/2825123002
Cr-Commit-Position: refs/heads/master@{#44701}
  • Loading branch information
mi-ac authored and Commit bot committed Apr 18, 2017
1 parent 9cc6729 commit 5971023
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 54 deletions.
3 changes: 1 addition & 2 deletions src/builtins/builtins-function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ BUILTIN(FunctionPrototypeToString) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Function.prototype.toString"),
isolate->factory()->Function_string()));
"Function.prototype.toString")));
}

} // namespace internal
Expand Down
15 changes: 5 additions & 10 deletions src/builtins/builtins-number.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ BUILTIN(NumberPrototypeToExponential) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toExponential"),
isolate->factory()->Number_string()));
"Number.prototype.toExponential")));
}
double const value_number = value->Number();

Expand Down Expand Up @@ -73,8 +72,7 @@ BUILTIN(NumberPrototypeToFixed) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toFixed"),
isolate->factory()->Number_string()));
"Number.prototype.toFixed")));
}
double const value_number = value->Number();

Expand Down Expand Up @@ -116,8 +114,7 @@ BUILTIN(NumberPrototypeToLocaleString) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toLocaleString"),
isolate->factory()->Number_string()));
"Number.prototype.toLocaleString")));
}

// Turn the {value} into a String.
Expand All @@ -138,8 +135,7 @@ BUILTIN(NumberPrototypeToPrecision) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toPrecision"),
isolate->factory()->Number_string()));
"Number.prototype.toPrecision")));
}
double const value_number = value->Number();

Expand Down Expand Up @@ -183,8 +179,7 @@ BUILTIN(NumberPrototypeToString) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Number.prototype.toString"),
isolate->factory()->Number_string()));
"Number.prototype.toString")));
}
double const value_number = value->Number();

Expand Down
23 changes: 3 additions & 20 deletions src/code-stub-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2900,27 +2900,10 @@ Node* CodeStubAssembler::ToThisValue(Node* context, Node* value,

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.
CallRuntime(Runtime::kThrowTypeError, context,
SmiConstant(MessageTemplate::kNotGeneric),
CStringConstant(method_name), CStringConstant(primitive_name));
CallRuntime(Runtime::kThrowNotGeneric, context,
HeapConstant(factory()->NewStringFromAsciiChecked(method_name,
TENURED)));
Unreachable();
}

Expand Down
2 changes: 1 addition & 1 deletion src/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class ErrorUtils : public AllStatic {
T(NotConstructor, "% is not a constructor") \
T(NotDateObject, "this is not a Date object.") \
T(NotIntlObject, "% is not an i18n object.") \
T(NotGeneric, "% requires that 'this' be a %") \
T(NotGeneric, "% is not generic") \
T(NotIterable, "% is not iterable") \
T(NotPropertyName, "% is not a valid property name") \
T(NotTypedArray, "this is not a typed array.") \
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/runtime-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
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) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ namespace internal {
F(ThrowNonCallableInInstanceOfCheck, 0, 1) \
F(ThrowNonObjectInInstanceOfCheck, 0, 1) \
F(ThrowNotConstructor, 1, 1) \
F(ThrowNotGeneric, 1, 1) \
F(ThrowRangeError, -1 /* >= 1 */, 1) \
F(ThrowReferenceError, 1, 1) \
F(ThrowStackOverflow, 0, 1) \
Expand Down
42 changes: 21 additions & 21 deletions test/mjsunit/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,33 @@ test(function() {
}, "this is not a Date object.", TypeError);

// kNotGeneric
test(() => String.prototype.toString.call(1),
"String.prototype.toString requires that 'this' be a String",
TypeError);
test(function() {
String.prototype.toString.call(1);
}, "String.prototype.toString is not generic", TypeError);

test(() => String.prototype.valueOf.call(1),
"String.prototype.valueOf requires that 'this' be a String",
TypeError);
test(function() {
String.prototype.valueOf.call(1);
}, "String.prototype.valueOf is not generic", TypeError);

test(() => Boolean.prototype.toString.call(1),
"Boolean.prototype.toString requires that 'this' be a Boolean",
TypeError);
test(function() {
Boolean.prototype.toString.call(1);
}, "Boolean.prototype.toString is not generic", TypeError);

test(() => Boolean.prototype.valueOf.call(1),
"Boolean.prototype.valueOf requires that 'this' be a Boolean",
TypeError);
test(function() {
Boolean.prototype.valueOf.call(1);
}, "Boolean.prototype.valueOf is not generic", TypeError);

test(() => Number.prototype.toString.call({}),
"Number.prototype.toString requires that 'this' be a Number",
TypeError);
test(function() {
Number.prototype.toString.call({});
}, "Number.prototype.toString is not generic", TypeError);

test(() => Number.prototype.valueOf.call({}),
"Number.prototype.valueOf requires that 'this' be a Number",
TypeError);
test(function() {
Number.prototype.valueOf.call({});
}, "Number.prototype.valueOf is not generic", TypeError);

test(() => Function.prototype.toString.call(1),
"Function.prototype.toString requires that 'this' be a Function",
TypeError);
test(function() {
Function.prototype.toString.call(1);
}, "Function.prototype.toString is not generic", TypeError);

// kNotTypedArray
test(function() {
Expand Down

0 comments on commit 5971023

Please sign in to comment.