Remove duplicate C++ implementation of Object.prototype.toString

The only caller was the API, and it can just as easily use the
TurboFan version.

R=franzih@chromium.org

Review-Url: https://codereview.chromium.org/2603493002
Cr-Commit-Position: refs/heads/master@{#41962}
This commit is contained in:
adamk 2016-12-27 10:28:47 -08:00 committed by Commit bot
parent 23019c4ec0
commit c5dd44c331
3 changed files with 6 additions and 96 deletions

View File

@ -4475,12 +4475,14 @@ MaybeLocal<Array> v8::Object::GetOwnPropertyNames(Local<Context> context,
MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) {
PREPARE_FOR_EXECUTION(context, Object, ObjectProtoToString, String);
auto obj = Utils::OpenHandle(this);
Local<String> result;
auto self = Utils::OpenHandle(this);
Local<Value> result;
has_pending_exception =
!ToLocal<String>(i::JSObject::ObjectProtoToString(isolate, obj), &result);
!ToLocal<Value>(i::Execution::Call(isolate, isolate->object_to_string(),
self, 0, nullptr),
&result);
RETURN_ON_FAILED_EXECUTION(String);
RETURN_ESCAPED(result);
RETURN_ESCAPED(Local<String>::Cast(result));
}

View File

@ -16290,94 +16290,6 @@ bool JSObject::WasConstructedFromApiFunction() {
return is_api_object;
}
MaybeHandle<String> Object::ObjectProtoToString(Isolate* isolate,
Handle<Object> object) {
if (*object == isolate->heap()->undefined_value()) {
return isolate->factory()->undefined_to_string();
}
if (*object == isolate->heap()->null_value()) {
return isolate->factory()->null_to_string();
}
Handle<JSReceiver> receiver =
Object::ToObject(isolate, object).ToHandleChecked();
// For proxies, we must check IsArray() before get(toStringTag) to comply
// with the specification
Maybe<bool> is_array = Nothing<bool>();
InstanceType instance_type = receiver->map()->instance_type();
if (instance_type == JS_PROXY_TYPE) {
is_array = Object::IsArray(receiver);
MAYBE_RETURN(is_array, MaybeHandle<String>());
}
Handle<String> tag;
Handle<Object> to_string_tag;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, to_string_tag,
JSReceiver::GetProperty(receiver,
isolate->factory()->to_string_tag_symbol()),
String);
if (to_string_tag->IsString()) {
tag = Handle<String>::cast(to_string_tag);
} else {
switch (instance_type) {
case JS_API_OBJECT_TYPE:
case JS_SPECIAL_API_OBJECT_TYPE:
tag = handle(receiver->class_name(), isolate);
break;
case JS_ARGUMENTS_TYPE:
return isolate->factory()->arguments_to_string();
case JS_ARRAY_TYPE:
return isolate->factory()->array_to_string();
case JS_BOUND_FUNCTION_TYPE:
case JS_FUNCTION_TYPE:
return isolate->factory()->function_to_string();
case JS_ERROR_TYPE:
return isolate->factory()->error_to_string();
case JS_DATE_TYPE:
return isolate->factory()->date_to_string();
case JS_REGEXP_TYPE:
return isolate->factory()->regexp_to_string();
case JS_PROXY_TYPE: {
if (is_array.FromJust()) {
return isolate->factory()->array_to_string();
}
if (receiver->IsCallable()) {
return isolate->factory()->function_to_string();
}
return isolate->factory()->object_to_string();
}
case JS_VALUE_TYPE: {
Object* value = JSValue::cast(*receiver)->value();
if (value->IsString()) {
return isolate->factory()->string_to_string();
}
if (value->IsNumber()) {
return isolate->factory()->number_to_string();
}
if (value->IsBoolean()) {
return isolate->factory()->boolean_to_string();
}
if (value->IsSymbol()) {
return isolate->factory()->object_to_string();
}
UNREACHABLE();
tag = handle(receiver->class_name(), isolate);
break;
}
default:
return isolate->factory()->object_to_string();
}
}
IncrementalStringBuilder builder(isolate);
builder.AppendCString("[object ");
builder.AppendString(tag);
builder.AppendCharacter(']');
return builder.Finish();
}
const char* Symbol::PrivateSymbolToName() const {
Heap* heap = GetIsolate()->heap();
#define SYMBOL_CHECK_AND_PRINT(name) \

View File

@ -1496,10 +1496,6 @@ class Object {
inline void VerifyApiCallResultType();
// ES6 19.1.3.6 Object.prototype.toString
MUST_USE_RESULT static MaybeHandle<String> ObjectProtoToString(
Isolate* isolate, Handle<Object> object);
// Prints this object without details.
void ShortPrint(FILE* out = stdout);