| 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 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3283 // Because we use caching to speed up enumeration it is important | 3283 // Because we use caching to speed up enumeration it is important |
| 3284 // to never change the result of the basic enumeration function so | 3284 // to never change the result of the basic enumeration function so |
| 3285 // we clone the result. | 3285 // we clone the result. |
| 3286 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); | 3286 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3287 i::Handle<i::JSArray> result = | 3287 i::Handle<i::JSArray> result = |
| 3288 isolate->factory()->NewJSArrayWithElements(elms); | 3288 isolate->factory()->NewJSArrayWithElements(elms); |
| 3289 return Utils::ToLocal(scope.CloseAndEscape(result)); | 3289 return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 3290 } | 3290 } |
| 3291 | 3291 |
| 3292 | 3292 |
| 3293 static bool GetPredefinedToString(i::Handle<i::String> tag, | |
| 3294 Local<String>* result) { | |
| 3295 i::Isolate* i_isolate = tag->GetIsolate(); | |
| 3296 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | |
| 3297 i::Factory* factory = i_isolate->factory(); | |
| 3298 | |
| 3299 if (i::String::Equals(tag, factory->Arguments_string())) { | |
| 3300 *result = v8::String::NewFromUtf8(isolate, "[object ~Arguments]"); | |
| 3301 } else if (i::String::Equals(tag, factory->Array_string())) { | |
| 3302 *result = v8::String::NewFromUtf8(isolate, "[object ~Array]"); | |
| 3303 } else if (i::String::Equals(tag, factory->Boolean_string())) { | |
| 3304 *result = v8::String::NewFromUtf8(isolate, "[object ~Boolean]"); | |
| 3305 } else if (i::String::Equals(tag, factory->Date_string())) { | |
| 3306 *result = v8::String::NewFromUtf8(isolate, "[object ~Date]"); | |
| 3307 } else if (i::String::Equals(tag, factory->Error_string())) { | |
| 3308 *result = v8::String::NewFromUtf8(isolate, "[object ~Error]"); | |
| 3309 } else if (i::String::Equals(tag, factory->Function_string())) { | |
| 3310 *result = v8::String::NewFromUtf8(isolate, "[object ~Function]"); | |
| 3311 } else if (i::String::Equals(tag, factory->Number_string())) { | |
| 3312 *result = v8::String::NewFromUtf8(isolate, "[object ~Number]"); | |
| 3313 } else if (i::String::Equals(tag, factory->RegExp_string())) { | |
| 3314 *result = v8::String::NewFromUtf8(isolate, "[object ~RegExp]"); | |
| 3315 } else if (i::String::Equals(tag, factory->String_string())) { | |
| 3316 *result = v8::String::NewFromUtf8(isolate, "[object ~String]"); | |
| 3317 } else { | |
| 3318 return false; | |
| 3319 } | |
| 3320 return true; | |
| 3321 } | |
| 3322 | |
| 3323 | |
| 3324 Local<String> v8::Object::ObjectProtoToString() { | 3293 Local<String> v8::Object::ObjectProtoToString() { |
| 3325 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); | 3294 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3326 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 3295 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
| 3327 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", | 3296 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", |
| 3328 return Local<v8::String>()); | 3297 return Local<v8::String>()); |
| 3329 ENTER_V8(i_isolate); | 3298 ENTER_V8(i_isolate); |
| 3330 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3299 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3331 | 3300 |
| 3332 i::Handle<i::Object> name(self->class_name(), i_isolate); | 3301 i::Handle<i::Object> name(self->class_name(), i_isolate); |
| 3333 i::Handle<i::Object> tag; | 3302 i::Handle<i::Object> tag; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3347 } else { | 3316 } else { |
| 3348 if (internal::FLAG_harmony_tostring) { | 3317 if (internal::FLAG_harmony_tostring) { |
| 3349 i::Handle<i::Symbol> toStringTag = | 3318 i::Handle<i::Symbol> toStringTag = |
| 3350 Utils::OpenHandle(*Symbol::GetToStringTag(isolate)); | 3319 Utils::OpenHandle(*Symbol::GetToStringTag(isolate)); |
| 3351 EXCEPTION_PREAMBLE(i_isolate); | 3320 EXCEPTION_PREAMBLE(i_isolate); |
| 3352 has_pending_exception = | 3321 has_pending_exception = |
| 3353 !i::Runtime::GetObjectProperty(i_isolate, self, toStringTag) | 3322 !i::Runtime::GetObjectProperty(i_isolate, self, toStringTag) |
| 3354 .ToHandle(&tag); | 3323 .ToHandle(&tag); |
| 3355 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>()); | 3324 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>()); |
| 3356 | 3325 |
| 3357 if (!tag->IsUndefined()) { | 3326 if (tag->IsString()) { |
| 3358 if (!tag->IsString()) | 3327 class_name = i::Handle<i::String>::cast(tag); |
| 3359 return v8::String::NewFromUtf8(isolate, "[object ???]"); | |
| 3360 i::Handle<i::String> tag_name = i::Handle<i::String>::cast(tag); | |
| 3361 if (!i::String::Equals(class_name, tag_name)) { | |
| 3362 Local<String> result; | |
| 3363 if (GetPredefinedToString(tag_name, &result)) return result; | |
| 3364 | |
| 3365 class_name = tag_name; | |
| 3366 } | |
| 3367 } | 3328 } |
| 3368 } | 3329 } |
| 3369 const char* prefix = "[object "; | 3330 const char* prefix = "[object "; |
| 3370 Local<String> str = Utils::ToLocal(class_name); | 3331 Local<String> str = Utils::ToLocal(class_name); |
| 3371 const char* postfix = "]"; | 3332 const char* postfix = "]"; |
| 3372 | 3333 |
| 3373 int prefix_len = i::StrLength(prefix); | 3334 int prefix_len = i::StrLength(prefix); |
| 3374 int str_len = str->Utf8Length(); | 3335 int str_len = str->Utf8Length(); |
| 3375 int postfix_len = i::StrLength(postfix); | 3336 int postfix_len = i::StrLength(postfix); |
| 3376 | 3337 |
| (...skipping 4297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7674 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7635 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7675 Address callback_address = | 7636 Address callback_address = |
| 7676 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7637 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7677 VMState<EXTERNAL> state(isolate); | 7638 VMState<EXTERNAL> state(isolate); |
| 7678 ExternalCallbackScope call_scope(isolate, callback_address); | 7639 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7679 callback(info); | 7640 callback(info); |
| 7680 } | 7641 } |
| 7681 | 7642 |
| 7682 | 7643 |
| 7683 } } // namespace v8::internal | 7644 } } // namespace v8::internal |
| OLD | NEW |