| 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 3391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3402 // Because we use caching to speed up enumeration it is important | 3402 // Because we use caching to speed up enumeration it is important |
| 3403 // to never change the result of the basic enumeration function so | 3403 // to never change the result of the basic enumeration function so |
| 3404 // we clone the result. | 3404 // we clone the result. |
| 3405 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); | 3405 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3406 i::Handle<i::JSArray> result = | 3406 i::Handle<i::JSArray> result = |
| 3407 isolate->factory()->NewJSArrayWithElements(elms); | 3407 isolate->factory()->NewJSArrayWithElements(elms); |
| 3408 return Utils::ToLocal(scope.CloseAndEscape(result)); | 3408 return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 3409 } | 3409 } |
| 3410 | 3410 |
| 3411 | 3411 |
| 3412 static bool GetPredefinedToString( |
| 3413 i::Handle<i::String> tag, Local<String>* result) { |
| 3414 i::Isolate* i_isolate = tag->GetIsolate(); |
| 3415 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
| 3416 i::Factory* factory = i_isolate->factory(); |
| 3417 |
| 3418 if (i::String::Equals(tag, factory->Arguments_string())) { |
| 3419 *result = v8::String::NewFromUtf8(isolate, "[object ~Arguments]"); |
| 3420 } else if (i::String::Equals(tag, factory->Array_string())) { |
| 3421 *result = v8::String::NewFromUtf8(isolate, "[object ~Array]"); |
| 3422 } else if (i::String::Equals(tag, factory->Boolean_string())) { |
| 3423 *result = v8::String::NewFromUtf8(isolate, "[object ~Boolean]"); |
| 3424 } else if (i::String::Equals(tag, factory->Date_string())) { |
| 3425 *result = v8::String::NewFromUtf8(isolate, "[object ~Date]"); |
| 3426 } else if (i::String::Equals(tag, factory->Error_string())) { |
| 3427 *result = v8::String::NewFromUtf8(isolate, "[object ~Error]"); |
| 3428 } else if (i::String::Equals(tag, factory->Function_string())) { |
| 3429 *result = v8::String::NewFromUtf8(isolate, "[object ~Function]"); |
| 3430 } else if (i::String::Equals(tag, factory->Number_string())) { |
| 3431 *result = v8::String::NewFromUtf8(isolate, "[object ~Number]"); |
| 3432 } else if (i::String::Equals(tag, factory->RegExp_string())) { |
| 3433 *result = v8::String::NewFromUtf8(isolate, "[object ~RegExp]"); |
| 3434 } else if (i::String::Equals(tag, factory->String_string())) { |
| 3435 *result = v8::String::NewFromUtf8(isolate, "[object ~String]"); |
| 3436 } else { |
| 3437 return false; |
| 3438 } |
| 3439 return true; |
| 3440 } |
| 3441 |
| 3442 |
| 3412 Local<String> v8::Object::ObjectProtoToString() { | 3443 Local<String> v8::Object::ObjectProtoToString() { |
| 3413 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); | 3444 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3414 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 3445 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
| 3415 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", | 3446 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", |
| 3416 return Local<v8::String>()); | 3447 return Local<v8::String>()); |
| 3417 ENTER_V8(i_isolate); | 3448 ENTER_V8(i_isolate); |
| 3418 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3449 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3419 | 3450 |
| 3420 i::Handle<i::Object> name(self->class_name(), i_isolate); | 3451 i::Handle<i::Object> name(self->class_name(), i_isolate); |
| 3452 i::Handle<i::Object> tag; |
| 3421 | 3453 |
| 3422 // Native implementation of Object.prototype.toString (v8natives.js): | 3454 // Native implementation of Object.prototype.toString (v8natives.js): |
| 3423 // var c = %_ClassOf(this); | 3455 // var c = %_ClassOf(this); |
| 3424 // if (c === 'Arguments') c = 'Object'; | 3456 // if (c === 'Arguments') c = 'Object'; |
| 3425 // return "[object " + c + "]"; | 3457 // return "[object " + c + "]"; |
| 3426 | 3458 |
| 3427 if (!name->IsString()) { | 3459 if (!name->IsString()) { |
| 3428 return v8::String::NewFromUtf8(isolate, "[object ]"); | 3460 return v8::String::NewFromUtf8(isolate, "[object ]"); |
| 3429 } else { | 3461 } else { |
| 3430 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); | 3462 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
| 3431 if (i::String::Equals(class_name, | 3463 if (i::String::Equals(class_name, |
| 3432 i_isolate->factory()->Arguments_string())) { | 3464 i_isolate->factory()->Arguments_string())) { |
| 3433 return v8::String::NewFromUtf8(isolate, "[object Object]"); | 3465 return v8::String::NewFromUtf8(isolate, "[object Object]"); |
| 3434 } else { | 3466 } else { |
| 3467 if (internal::FLAG_harmony_tostring) { |
| 3468 i::Handle<i::Symbol> toStringTag = Utils::OpenHandle( |
| 3469 *Symbol::GetToStringTag(isolate)); |
| 3470 EXCEPTION_PREAMBLE(i_isolate); |
| 3471 has_pending_exception = !i::Runtime::GetObjectProperty( |
| 3472 i_isolate, self, toStringTag).ToHandle(&tag); |
| 3473 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>()); |
| 3474 |
| 3475 if (!tag->IsUndefined()) { |
| 3476 if (!tag->IsString()) |
| 3477 return v8::String::NewFromUtf8(isolate, "[object ???]"); |
| 3478 i::Handle<i::String> tag_name = i::Handle<i::String>::cast(tag); |
| 3479 if (!i::String::Equals(class_name, tag_name)) { |
| 3480 Local<String> result; |
| 3481 if (GetPredefinedToString(tag_name, &result)) |
| 3482 return result; |
| 3483 |
| 3484 class_name = tag_name; |
| 3485 } |
| 3486 } |
| 3487 } |
| 3435 const char* prefix = "[object "; | 3488 const char* prefix = "[object "; |
| 3436 Local<String> str = Utils::ToLocal(class_name); | 3489 Local<String> str = Utils::ToLocal(class_name); |
| 3437 const char* postfix = "]"; | 3490 const char* postfix = "]"; |
| 3438 | 3491 |
| 3439 int prefix_len = i::StrLength(prefix); | 3492 int prefix_len = i::StrLength(prefix); |
| 3440 int str_len = str->Utf8Length(); | 3493 int str_len = str->Utf8Length(); |
| 3441 int postfix_len = i::StrLength(postfix); | 3494 int postfix_len = i::StrLength(postfix); |
| 3442 | 3495 |
| 3443 int buf_len = prefix_len + str_len + postfix_len; | 3496 int buf_len = prefix_len + str_len + postfix_len; |
| 3444 i::ScopedVector<char> buf(buf_len); | 3497 i::ScopedVector<char> buf(buf_len); |
| (...skipping 2793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6238 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { | 6291 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { |
| 6239 return GetWellKnownSymbol(isolate, "Symbol.iterator"); | 6292 return GetWellKnownSymbol(isolate, "Symbol.iterator"); |
| 6240 } | 6293 } |
| 6241 | 6294 |
| 6242 | 6295 |
| 6243 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { | 6296 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { |
| 6244 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); | 6297 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); |
| 6245 } | 6298 } |
| 6246 | 6299 |
| 6247 | 6300 |
| 6301 Local<Symbol> v8::Symbol::GetToStringTag(Isolate* isolate) { |
| 6302 return GetWellKnownSymbol(isolate, "Symbol.toStringTag"); |
| 6303 } |
| 6304 |
| 6305 |
| 6248 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { | 6306 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { |
| 6249 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6307 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6250 LOG_API(i_isolate, "Private::New()"); | 6308 LOG_API(i_isolate, "Private::New()"); |
| 6251 ENTER_V8(i_isolate); | 6309 ENTER_V8(i_isolate); |
| 6252 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); | 6310 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
| 6253 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); | 6311 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); |
| 6254 Local<Symbol> result = Utils::ToLocal(symbol); | 6312 Local<Symbol> result = Utils::ToLocal(symbol); |
| 6255 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); | 6313 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); |
| 6256 } | 6314 } |
| 6257 | 6315 |
| (...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7707 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7765 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7708 Address callback_address = | 7766 Address callback_address = |
| 7709 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7767 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7710 VMState<EXTERNAL> state(isolate); | 7768 VMState<EXTERNAL> state(isolate); |
| 7711 ExternalCallbackScope call_scope(isolate, callback_address); | 7769 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7712 callback(info); | 7770 callback(info); |
| 7713 } | 7771 } |
| 7714 | 7772 |
| 7715 | 7773 |
| 7716 } } // namespace v8::internal | 7774 } } // namespace v8::internal |
| OLD | NEW |