OLD | NEW |
---|---|
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 3361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3372 | 3372 |
3373 Local<String> v8::Object::ObjectProtoToString() { | 3373 Local<String> v8::Object::ObjectProtoToString() { |
3374 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); | 3374 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
3375 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 3375 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
3376 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", | 3376 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", |
3377 return Local<v8::String>()); | 3377 return Local<v8::String>()); |
3378 ENTER_V8(i_isolate); | 3378 ENTER_V8(i_isolate); |
3379 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3379 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3380 | 3380 |
3381 i::Handle<i::Object> name(self->class_name(), i_isolate); | 3381 i::Handle<i::Object> name(self->class_name(), i_isolate); |
3382 i::Handle<i::Object> tag; | |
3382 | 3383 |
3383 // Native implementation of Object.prototype.toString (v8natives.js): | 3384 // Native implementation of Object.prototype.toString (v8natives.js): |
3384 // var c = %_ClassOf(this); | 3385 // var c = %_ClassOf(this); |
3385 // if (c === 'Arguments') c = 'Object'; | 3386 // if (c === 'Arguments') c = 'Object'; |
3386 // return "[object " + c + "]"; | 3387 // return "[object " + c + "]"; |
3387 | 3388 |
3388 if (!name->IsString()) { | 3389 if (!name->IsString()) { |
3389 return v8::String::NewFromUtf8(isolate, "[object ]"); | 3390 return v8::String::NewFromUtf8(isolate, "[object ]"); |
3390 } else { | 3391 } else { |
3391 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); | 3392 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
3392 if (i::String::Equals(class_name, | 3393 if (i::String::Equals(class_name, |
3393 i_isolate->factory()->Arguments_string())) { | 3394 i_isolate->factory()->Arguments_string())) { |
3394 return v8::String::NewFromUtf8(isolate, "[object Object]"); | 3395 return v8::String::NewFromUtf8(isolate, "[object Object]"); |
3395 } else { | 3396 } else { |
3397 if (internal::FLAG_harmony_tostring) { | |
3398 i::Handle<i::Symbol> toStringTag = Utils::OpenHandle( | |
3399 *Symbol::GetToStringTag(isolate)); | |
3400 tag = i::Runtime::GetObjectProperty( | |
Dmitry Lomov (no reviews)
2014/10/18 15:16:48
This calls into Javascript, so needs EXCEPTION_PRE
| |
3401 i_isolate, self, toStringTag).ToHandleChecked(); | |
3402 | |
3403 if (!tag->IsUndefined()) { | |
3404 if (!tag->IsString()) { | |
3405 return v8::String::NewFromUtf8(isolate, "[object ???]"); | |
3406 } else { | |
3407 i::Handle<i::String> tag_name = i::Handle<i::String>::cast(tag); | |
3408 using namespace internal; | |
Dmitry Lomov (no reviews)
2014/10/18 15:16:48
Nit: remove 'using namespace internal' here, we us
| |
3409 if (!i::String::Equals(class_name, tag_name)) { | |
3410 if (i::String::Equals( | |
3411 tag_name, i_isolate->factory()->Arguments_string())) { | |
Dmitry Lomov (no reviews)
2014/10/18 15:16:48
Nit: introduce variable for i_isolate->factory()
| |
3412 return v8::String::NewFromUtf8(isolate, "[object ~Arguments]"); | |
3413 } else if (i::String::Equals( | |
3414 tag_name, i_isolate->factory()->Array_string())) { | |
3415 return v8::String::NewFromUtf8(isolate, "[object ~Array]"); | |
3416 } else if (i::String::Equals( | |
3417 tag_name, i_isolate->factory()->Boolean_string())) { | |
3418 return v8::String::NewFromUtf8(isolate, "[object ~Boolean]"); | |
3419 } else if (i::String::Equals( | |
3420 tag_name, i_isolate->factory()->Date_string())) { | |
3421 return v8::String::NewFromUtf8(isolate, "[object ~Date]"); | |
3422 } else if (i::String::Equals( | |
3423 tag_name, i_isolate->factory()->Error_string())) { | |
3424 return v8::String::NewFromUtf8(isolate, "[object ~Error]"); | |
3425 } else if (i::String::Equals( | |
3426 tag_name, i_isolate->factory()->Function_string())) { | |
3427 return v8::String::NewFromUtf8(isolate, "[object ~Function]"); | |
3428 } else if (i::String::Equals( | |
3429 tag_name, i_isolate->factory()->Number_string())) { | |
3430 return v8::String::NewFromUtf8(isolate, "[object ~Number]"); | |
3431 } else if (i::String::Equals( | |
3432 tag_name, i_isolate->factory()->RegExp_string())) { | |
3433 return v8::String::NewFromUtf8(isolate, "[object ~RegExp]"); | |
3434 } else if (i::String::Equals( | |
3435 tag_name, i_isolate->factory()->String_string())) { | |
3436 return v8::String::NewFromUtf8(isolate, "[object ~String]"); | |
3437 } else { | |
3438 class_name = tag_name; | |
3439 } | |
3440 } | |
3441 } | |
3442 } | |
3443 } | |
3396 const char* prefix = "[object "; | 3444 const char* prefix = "[object "; |
3397 Local<String> str = Utils::ToLocal(class_name); | 3445 Local<String> str = Utils::ToLocal(class_name); |
3398 const char* postfix = "]"; | 3446 const char* postfix = "]"; |
3399 | 3447 |
3400 int prefix_len = i::StrLength(prefix); | 3448 int prefix_len = i::StrLength(prefix); |
3401 int str_len = str->Utf8Length(); | 3449 int str_len = str->Utf8Length(); |
3402 int postfix_len = i::StrLength(postfix); | 3450 int postfix_len = i::StrLength(postfix); |
3403 | 3451 |
3404 int buf_len = prefix_len + str_len + postfix_len; | 3452 int buf_len = prefix_len + str_len + postfix_len; |
3405 i::ScopedVector<char> buf(buf_len); | 3453 i::ScopedVector<char> buf(buf_len); |
(...skipping 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6192 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { | 6240 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { |
6193 return GetWellKnownSymbol(isolate, "Symbol.iterator"); | 6241 return GetWellKnownSymbol(isolate, "Symbol.iterator"); |
6194 } | 6242 } |
6195 | 6243 |
6196 | 6244 |
6197 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { | 6245 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { |
6198 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); | 6246 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); |
6199 } | 6247 } |
6200 | 6248 |
6201 | 6249 |
6250 Local<Symbol> v8::Symbol::GetToStringTag(Isolate* isolate) { | |
6251 return GetWellKnownSymbol(isolate, "Symbol.toStringTag"); | |
6252 } | |
6253 | |
6254 | |
6202 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { | 6255 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { |
6203 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6256 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6204 LOG_API(i_isolate, "Private::New()"); | 6257 LOG_API(i_isolate, "Private::New()"); |
6205 ENTER_V8(i_isolate); | 6258 ENTER_V8(i_isolate); |
6206 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); | 6259 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
6207 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); | 6260 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); |
6208 Local<Symbol> result = Utils::ToLocal(symbol); | 6261 Local<Symbol> result = Utils::ToLocal(symbol); |
6209 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); | 6262 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); |
6210 } | 6263 } |
6211 | 6264 |
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7661 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7714 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7662 Address callback_address = | 7715 Address callback_address = |
7663 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7716 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7664 VMState<EXTERNAL> state(isolate); | 7717 VMState<EXTERNAL> state(isolate); |
7665 ExternalCallbackScope call_scope(isolate, callback_address); | 7718 ExternalCallbackScope call_scope(isolate, callback_address); |
7666 callback(info); | 7719 callback(info); |
7667 } | 7720 } |
7668 | 7721 |
7669 | 7722 |
7670 } } // namespace v8::internal | 7723 } } // namespace v8::internal |
OLD | NEW |