| Index: src/api.cc
|
| diff --git a/src/api.cc b/src/api.cc
|
| index da1c0e74618c8e448a6705e8e1b5d5f7f2a2c06c..c882044870e2dc9a7b04187ae801ac20877302a4 100644
|
| --- a/src/api.cc
|
| +++ b/src/api.cc
|
| @@ -3493,71 +3493,43 @@ 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::HandleScope scope(i_isolate);
|
| + 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);
|
| -
|
| - 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;
|
| + 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);
|
| +
|
| + i::Handle<i::Object> fun_obj;
|
| + EXCEPTION_PREAMBLE(i_isolate);
|
| + has_pending_exception = !i::Runtime::GetObjectProperty(
|
| + i_isolate, builtin, key).ToHandle(&fun_obj);
|
| + EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
|
|
|
| - // Write postfix.
|
| - i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize);
|
| + if (!fun_obj->IsJSFunction()) return Local<v8::String>();
|
| + i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj);
|
|
|
| - // 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::Object> 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>());
|
| + if (!result->IsString()) return Local<v8::String>();
|
| + return Utils::ToLocal(
|
| + scope.CloseAndEscape(i::Handle<i::String>::cast(result)));
|
| }
|
|
|
|
|
|
|