From c5dd44c33174c64cf7a5dcab0a65e8517d2c0e26 Mon Sep 17 00:00:00 2001 From: adamk Date: Tue, 27 Dec 2016 10:28:47 -0800 Subject: [PATCH] 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} --- src/api.cc | 10 +++--- src/objects.cc | 88 -------------------------------------------------- src/objects.h | 4 --- 3 files changed, 6 insertions(+), 96 deletions(-) diff --git a/src/api.cc b/src/api.cc index ba4fbb8dc9..ba10ebdc5b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4475,12 +4475,14 @@ MaybeLocal v8::Object::GetOwnPropertyNames(Local context, MaybeLocal v8::Object::ObjectProtoToString(Local context) { PREPARE_FOR_EXECUTION(context, Object, ObjectProtoToString, String); - auto obj = Utils::OpenHandle(this); - Local result; + auto self = Utils::OpenHandle(this); + Local result; has_pending_exception = - !ToLocal(i::JSObject::ObjectProtoToString(isolate, obj), &result); + !ToLocal(i::Execution::Call(isolate, isolate->object_to_string(), + self, 0, nullptr), + &result); RETURN_ON_FAILED_EXECUTION(String); - RETURN_ESCAPED(result); + RETURN_ESCAPED(Local::Cast(result)); } diff --git a/src/objects.cc b/src/objects.cc index 0df16fb8c5..fb860a8f5b 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -16290,94 +16290,6 @@ bool JSObject::WasConstructedFromApiFunction() { return is_api_object; } -MaybeHandle Object::ObjectProtoToString(Isolate* isolate, - Handle 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 receiver = - Object::ToObject(isolate, object).ToHandleChecked(); - - // For proxies, we must check IsArray() before get(toStringTag) to comply - // with the specification - Maybe is_array = Nothing(); - InstanceType instance_type = receiver->map()->instance_type(); - if (instance_type == JS_PROXY_TYPE) { - is_array = Object::IsArray(receiver); - MAYBE_RETURN(is_array, MaybeHandle()); - } - - Handle tag; - Handle 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::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) \ diff --git a/src/objects.h b/src/objects.h index 44ba7428cc..af4cbe894d 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1496,10 +1496,6 @@ class Object { inline void VerifyApiCallResultType(); - // ES6 19.1.3.6 Object.prototype.toString - MUST_USE_RESULT static MaybeHandle ObjectProtoToString( - Isolate* isolate, Handle object); - // Prints this object without details. void ShortPrint(FILE* out = stdout);