Reviewers: Dmitry Lomov (chromium), fqian,

Message:
@fqian: my understanding is that this change shouldn't regress Blink
implementation of V8Window::toStringMethodCustom [1]. Please confirm that as you
are the author of the FIXME comment for that code.

[1]
https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp&q=V8Window::toStringMethodCustom&sq=package:chromium&type=cs&l=214


Description:
Replace custom implementation of ObjectProtoToString with call to builtin

The implementation in api.cc seems to just repeat what is written in
v8natives.js and harmony-tostring.js I replaced it with call to the
corresponding builtin.

BUG=None

Please review this at https://codereview.chromium.org/936033002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+24, -58 lines):
  M src/api.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index da1c0e74618c8e448a6705e8e1b5d5f7f2a2c06c..7a173b3ec421583e100b2659d3b0d0ce3942f8c7 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3493,71 +3493,37 @@ Local<Array> v8::Object::GetOwnPropertyNames() {


 Local<String> v8::Object::ObjectProtoToString() {
-  i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
-  Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
+  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
+  i::Isolate* i_isolate = self->GetIsolate();
   ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()",
              return Local<v8::String>());
   ENTER_V8(i_isolate);
-  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
-
-  i::Handle<i::Object> name(self->class_name(), i_isolate);
-  i::Handle<i::Object> tag;
+  i::Context* context = i_isolate->context();
+  if (context == NULL) return Local<String>();
+  i::Context* native_context = context->native_context();
+  if (native_context == NULL) return Local<String>();

   // Native implementation of Object.prototype.toString (v8natives.js):
-  //   var c = %_ClassOf(this);
-  //   if (c === 'Arguments') c  = 'Object';
-  //   return "[object " + c + "]";
-
-  if (!name->IsString()) {
-    return v8::String::NewFromUtf8(isolate, "[object ]");
-  } else {
-    i::Handle<i::String> class_name = i::Handle<i::String>::cast(name);
-    if (i::String::Equals(class_name,
-                          i_isolate->factory()->Arguments_string())) {
-      return v8::String::NewFromUtf8(isolate, "[object Object]");
-    } else {
-      if (internal::FLAG_harmony_tostring) {
-        i::Handle<i::Symbol> toStringTag =
-            Utils::OpenHandle(*Symbol::GetToStringTag(isolate));
-        EXCEPTION_PREAMBLE(i_isolate);
-        has_pending_exception =
-            !i::Runtime::GetObjectProperty(i_isolate, self, toStringTag)
-                 .ToHandle(&tag);
-        EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
-
-        if (tag->IsString()) {
-          class_name = i::Handle<i::String>::cast(tag);
-        }
-      }
-      const char* prefix = "[object ";
-      Local<String> str = Utils::ToLocal(class_name);
-      const char* postfix = "]";
-
-      int prefix_len = i::StrLength(prefix);
-      int str_len = str->Utf8Length();
-      int postfix_len = i::StrLength(postfix);
+ i::Handle<i::String> key = i_isolate->factory()->InternalizeOneByteString(
+      STATIC_CHAR_VECTOR("DefaultObjectToString"));
+  i::Handle<i::GlobalObject> global =
+ i::Handle<i::GlobalObject>(native_context->global_object(), i_isolate);
+  i::Handle<i::JSBuiltinsObject> builtin =
+      i::Handle<i::JSBuiltinsObject>(global->builtins(), i_isolate);

-      int buf_len = prefix_len + str_len + postfix_len;
-      i::ScopedVector<char> buf(buf_len);
-
-      // Write prefix.
-      char* ptr = buf.start();
-      i::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize);
-      ptr += prefix_len;
-
-      // Write real content.
-      str->WriteUtf8(ptr, str_len);
-      ptr += str_len;
-
-      // Write postfix.
-      i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize);
+  i::Handle<i::JSFunction> fun;
+  EXCEPTION_PREAMBLE(i_isolate);
+  has_pending_exception =
+ !i::Runtime::GetObjectProperty(i_isolate, builtin, key).ToHandle(&fun);
+  EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());

-      // Copy the buffer into a heap-allocated string and return it.
-      Local<String> result = v8::String::NewFromUtf8(
-          isolate, buf.start(), String::kNormalString, buf_len);
-      return result;
-    }
-  }
+  i::Handle<i::String> result;
+  i::Handle<i::Object>* args = NULL;
+  int argc = 0;
+  has_pending_exception =
+ !i::Execution::Call(i_isolate, fun, self, argc, args).ToHandle(&result);
+  EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
+  return Utils::ToLocal(result);
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to