Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: src/api.cc

Issue 936033002: Replace custom implementation of ObjectProtoToString with call to builtin Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 3475 matching lines...) Expand 10 before | Expand all | Expand 10 after
3486 // to never change the result of the basic enumeration function so 3486 // to never change the result of the basic enumeration function so
3487 // we clone the result. 3487 // we clone the result.
3488 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); 3488 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
3489 i::Handle<i::JSArray> result = 3489 i::Handle<i::JSArray> result =
3490 isolate->factory()->NewJSArrayWithElements(elms); 3490 isolate->factory()->NewJSArrayWithElements(elms);
3491 return Utils::ToLocal(scope.CloseAndEscape(result)); 3491 return Utils::ToLocal(scope.CloseAndEscape(result));
3492 } 3492 }
3493 3493
3494 3494
3495 Local<String> v8::Object::ObjectProtoToString() { 3495 Local<String> v8::Object::ObjectProtoToString() {
3496 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); 3496 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3497 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); 3497 i::Isolate* i_isolate = self->GetIsolate();
3498 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", 3498 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()",
3499 return Local<v8::String>()); 3499 return Local<v8::String>());
3500 ENTER_V8(i_isolate); 3500 ENTER_V8(i_isolate);
3501 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3501 i::HandleScope scope(i_isolate);
3502 3502 i::Context* context = i_isolate->context();
3503 i::Handle<i::Object> name(self->class_name(), i_isolate); 3503 if (context == NULL) return Local<String>();
3504 i::Handle<i::Object> tag; 3504 i::Context* native_context = context->native_context();
3505 if (native_context == NULL) return Local<String>();
3505 3506
3506 // Native implementation of Object.prototype.toString (v8natives.js): 3507 // Native implementation of Object.prototype.toString (v8natives.js):
3507 // var c = %_ClassOf(this); 3508 i::Handle<i::String> key = i_isolate->factory()->InternalizeOneByteString(
3508 // if (c === 'Arguments') c = 'Object'; 3509 STATIC_CHAR_VECTOR("DefaultObjectToString"));
3509 // return "[object " + c + "]"; 3510 i::Handle<i::GlobalObject> global =
3511 i::Handle<i::GlobalObject>(native_context->global_object(), i_isolate);
3512 i::Handle<i::JSBuiltinsObject> builtin =
3513 i::Handle<i::JSBuiltinsObject>(global->builtins(), i_isolate);
3510 3514
3511 if (!name->IsString()) { 3515 i::Handle<i::Object> fun_obj;
3512 return v8::String::NewFromUtf8(isolate, "[object ]"); 3516 EXCEPTION_PREAMBLE(i_isolate);
3513 } else { 3517 has_pending_exception = !i::Runtime::GetObjectProperty(
3514 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); 3518 i_isolate, builtin, key).ToHandle(&fun_obj);
3515 if (i::String::Equals(class_name, 3519 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
3516 i_isolate->factory()->Arguments_string())) {
3517 return v8::String::NewFromUtf8(isolate, "[object Object]");
3518 } else {
3519 if (internal::FLAG_harmony_tostring) {
3520 i::Handle<i::Symbol> toStringTag =
3521 Utils::OpenHandle(*Symbol::GetToStringTag(isolate));
3522 EXCEPTION_PREAMBLE(i_isolate);
3523 has_pending_exception =
3524 !i::Runtime::GetObjectProperty(i_isolate, self, toStringTag)
3525 .ToHandle(&tag);
3526 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
3527 3520
3528 if (tag->IsString()) { 3521 if (!fun_obj->IsJSFunction()) return Local<v8::String>();
3529 class_name = i::Handle<i::String>::cast(tag); 3522 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj);
3530 }
3531 }
3532 const char* prefix = "[object ";
3533 Local<String> str = Utils::ToLocal(class_name);
3534 const char* postfix = "]";
3535 3523
3536 int prefix_len = i::StrLength(prefix); 3524 i::Handle<i::Object> result;
3537 int str_len = str->Utf8Length(); 3525 i::Handle<i::Object>* args = NULL;
3538 int postfix_len = i::StrLength(postfix); 3526 int argc = 0;
3539 3527 has_pending_exception =
3540 int buf_len = prefix_len + str_len + postfix_len; 3528 !i::Execution::Call(i_isolate, fun, self, argc, args).ToHandle(&result);
3541 i::ScopedVector<char> buf(buf_len); 3529 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
3542 3530 if (!result->IsString()) return Local<v8::String>();
3543 // Write prefix. 3531 return Utils::ToLocal(
3544 char* ptr = buf.start(); 3532 scope.CloseAndEscape(i::Handle<i::String>::cast(result)));
3545 i::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize);
3546 ptr += prefix_len;
3547
3548 // Write real content.
3549 str->WriteUtf8(ptr, str_len);
3550 ptr += str_len;
3551
3552 // Write postfix.
3553 i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize);
3554
3555 // Copy the buffer into a heap-allocated string and return it.
3556 Local<String> result = v8::String::NewFromUtf8(
3557 isolate, buf.start(), String::kNormalString, buf_len);
3558 return result;
3559 }
3560 }
3561 } 3533 }
3562 3534
3563 3535
3564 Local<String> v8::Object::GetConstructorName() { 3536 Local<String> v8::Object::GetConstructorName() {
3565 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3537 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3566 ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", 3538 ON_BAILOUT(isolate, "v8::Object::GetConstructorName()",
3567 return Local<v8::String>()); 3539 return Local<v8::String>());
3568 ENTER_V8(isolate); 3540 ENTER_V8(isolate);
3569 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3541 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3570 i::Handle<i::String> name(self->constructor_name()); 3542 i::Handle<i::String> name(self->constructor_name());
(...skipping 4266 matching lines...) Expand 10 before | Expand all | Expand 10 after
7837 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7809 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7838 Address callback_address = 7810 Address callback_address =
7839 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7811 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7840 VMState<EXTERNAL> state(isolate); 7812 VMState<EXTERNAL> state(isolate);
7841 ExternalCallbackScope call_scope(isolate, callback_address); 7813 ExternalCallbackScope call_scope(isolate, callback_address);
7842 callback(info); 7814 callback(info);
7843 } 7815 }
7844 7816
7845 7817
7846 } } // namespace v8::internal 7818 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698