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 28 matching lines...) Expand all Loading... | |
39 #include "src/property-details.h" | 39 #include "src/property-details.h" |
40 #include "src/prototype.h" | 40 #include "src/prototype.h" |
41 #include "src/runtime/runtime.h" | 41 #include "src/runtime/runtime.h" |
42 #include "src/runtime-profiler.h" | 42 #include "src/runtime-profiler.h" |
43 #include "src/sampler.h" | 43 #include "src/sampler.h" |
44 #include "src/scanner-character-streams.h" | 44 #include "src/scanner-character-streams.h" |
45 #include "src/simulator.h" | 45 #include "src/simulator.h" |
46 #include "src/snapshot.h" | 46 #include "src/snapshot.h" |
47 #include "src/unicode-inl.h" | 47 #include "src/unicode-inl.h" |
48 #include "src/v8threads.h" | 48 #include "src/v8threads.h" |
49 #include "src/vector.h" | |
49 #include "src/version.h" | 50 #include "src/version.h" |
50 #include "src/vm-state-inl.h" | 51 #include "src/vm-state-inl.h" |
51 | 52 |
52 | 53 |
53 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) | 54 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
54 | 55 |
55 #define ENTER_V8(isolate) \ | 56 #define ENTER_V8(isolate) \ |
56 i::VMState<v8::OTHER> __state__((isolate)) | 57 i::VMState<v8::OTHER> __state__((isolate)) |
57 | 58 |
58 namespace v8 { | 59 namespace v8 { |
(...skipping 3313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3372 | 3373 |
3373 Local<String> v8::Object::ObjectProtoToString() { | 3374 Local<String> v8::Object::ObjectProtoToString() { |
3374 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); | 3375 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
3375 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); | 3376 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
3376 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", | 3377 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", |
3377 return Local<v8::String>()); | 3378 return Local<v8::String>()); |
3378 ENTER_V8(i_isolate); | 3379 ENTER_V8(i_isolate); |
3379 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3380 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3380 | 3381 |
3381 i::Handle<i::Object> name(self->class_name(), i_isolate); | 3382 i::Handle<i::Object> name(self->class_name(), i_isolate); |
3383 i::Handle<i::Object> tag; | |
3382 | 3384 |
3383 // Native implementation of Object.prototype.toString (v8natives.js): | 3385 // Native implementation of Object.prototype.toString (v8natives.js): |
3384 // var c = %_ClassOf(this); | 3386 // var c = %_ClassOf(this); |
3385 // if (c === 'Arguments') c = 'Object'; | 3387 // if (c === 'Arguments') c = 'Object'; |
3386 // return "[object " + c + "]"; | 3388 // return "[object " + c + "]"; |
3387 | 3389 |
3388 if (!name->IsString()) { | 3390 if (!name->IsString()) { |
3389 return v8::String::NewFromUtf8(isolate, "[object ]"); | 3391 return v8::String::NewFromUtf8(isolate, "[object ]"); |
3390 } else { | 3392 } else { |
3391 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); | 3393 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
3392 if (i::String::Equals(class_name, | 3394 if (i::String::Equals(class_name, |
3393 i_isolate->factory()->Arguments_string())) { | 3395 i_isolate->factory()->Arguments_string())) { |
3394 return v8::String::NewFromUtf8(isolate, "[object Object]"); | 3396 return v8::String::NewFromUtf8(isolate, "[object Object]"); |
3395 } else { | 3397 } else { |
3398 if (internal::FLAG_harmony_tostring) { | |
3399 i::Handle<i::Symbol> toStringTag = Utils::OpenHandle( | |
3400 *Symbol::GetToStringTag(isolate)); | |
3401 tag = i::Runtime::GetObjectProperty( | |
3402 i_isolate, self, toStringTag).ToHandleChecked(); | |
3403 | |
3404 if (!tag->IsUndefined()) { | |
3405 if (!tag->IsString()) { | |
3406 return v8::String::NewFromUtf8(isolate, "[object ???]"); | |
3407 } else { | |
3408 i::Handle<i::String> tag_name = i::Handle<i::String>::cast(tag); | |
3409 using namespace internal; | |
3410 if (!i::String::Equals(class_name, tag_name)) { | |
3411 if (tag_name->IsUtf8EqualTo(CStrVector("Arguments"))) { | |
3412 return v8::String::NewFromUtf8(isolate, "[object ~Arguments]"); | |
caitp (gmail)
2014/10/17 22:00:49
I'm not sure if it's worth doing this linearly, or
Dmitry Lomov (no reviews)
2014/10/18 08:41:49
Instead of IsUtf8EqualTo with a new string constan
| |
3413 } else if (tag_name->IsUtf8EqualTo(CStrVector("Array"))) { | |
3414 return v8::String::NewFromUtf8(isolate, "[object ~Array]"); | |
3415 } else if (tag_name->IsUtf8EqualTo(CStrVector("Boolean"))) { | |
3416 return v8::String::NewFromUtf8(isolate, "[object ~Boolean]"); | |
3417 } else if (tag_name->IsUtf8EqualTo(CStrVector("Date"))) { | |
3418 return v8::String::NewFromUtf8(isolate, "[object ~Date]"); | |
3419 } else if (tag_name->IsUtf8EqualTo(CStrVector("Error"))) { | |
3420 return v8::String::NewFromUtf8(isolate, "[object ~Error]"); | |
3421 } else if (tag_name->IsUtf8EqualTo(CStrVector("Function"))) { | |
3422 return v8::String::NewFromUtf8(isolate, "[object ~Function]"); | |
3423 } else if (tag_name->IsUtf8EqualTo(CStrVector("Number"))) { | |
3424 return v8::String::NewFromUtf8(isolate, "[object ~Number]"); | |
3425 } else if (tag_name->IsUtf8EqualTo(CStrVector("RegExp"))) { | |
3426 return v8::String::NewFromUtf8(isolate, "[object ~RegExp]"); | |
3427 } else if (tag_name->IsUtf8EqualTo(CStrVector("String"))) { | |
3428 return v8::String::NewFromUtf8(isolate, "[object ~String]"); | |
3429 } else { | |
3430 class_name = tag_name; | |
3431 } | |
3432 } | |
3433 } | |
3434 } | |
3435 } | |
3396 const char* prefix = "[object "; | 3436 const char* prefix = "[object "; |
3397 Local<String> str = Utils::ToLocal(class_name); | 3437 Local<String> str = Utils::ToLocal(class_name); |
3398 const char* postfix = "]"; | 3438 const char* postfix = "]"; |
3399 | 3439 |
3400 int prefix_len = i::StrLength(prefix); | 3440 int prefix_len = i::StrLength(prefix); |
3401 int str_len = str->Utf8Length(); | 3441 int str_len = str->Utf8Length(); |
3402 int postfix_len = i::StrLength(postfix); | 3442 int postfix_len = i::StrLength(postfix); |
3403 | 3443 |
3404 int buf_len = prefix_len + str_len + postfix_len; | 3444 int buf_len = prefix_len + str_len + postfix_len; |
3405 i::ScopedVector<char> buf(buf_len); | 3445 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) { | 6232 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { |
6193 return GetWellKnownSymbol(isolate, "Symbol.iterator"); | 6233 return GetWellKnownSymbol(isolate, "Symbol.iterator"); |
6194 } | 6234 } |
6195 | 6235 |
6196 | 6236 |
6197 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { | 6237 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { |
6198 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); | 6238 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); |
6199 } | 6239 } |
6200 | 6240 |
6201 | 6241 |
6242 Local<Symbol> v8::Symbol::GetToStringTag(Isolate* isolate) { | |
6243 return GetWellKnownSymbol(isolate, "Symbol.toStringTag"); | |
6244 } | |
6245 | |
6246 | |
6202 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { | 6247 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { |
6203 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6248 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6204 LOG_API(i_isolate, "Private::New()"); | 6249 LOG_API(i_isolate, "Private::New()"); |
6205 ENTER_V8(i_isolate); | 6250 ENTER_V8(i_isolate); |
6206 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); | 6251 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
6207 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); | 6252 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); |
6208 Local<Symbol> result = Utils::ToLocal(symbol); | 6253 Local<Symbol> result = Utils::ToLocal(symbol); |
6209 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); | 6254 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); |
6210 } | 6255 } |
6211 | 6256 |
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7661 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7706 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7662 Address callback_address = | 7707 Address callback_address = |
7663 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7708 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7664 VMState<EXTERNAL> state(isolate); | 7709 VMState<EXTERNAL> state(isolate); |
7665 ExternalCallbackScope call_scope(isolate, callback_address); | 7710 ExternalCallbackScope call_scope(isolate, callback_address); |
7666 callback(info); | 7711 callback(info); |
7667 } | 7712 } |
7668 | 7713 |
7669 | 7714 |
7670 } } // namespace v8::internal | 7715 } } // namespace v8::internal |
OLD | NEW |