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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 virtual void Free(void* data, size_t) { free(data); } | 334 virtual void Free(void* data, size_t) { free(data); } |
335 }; | 335 }; |
336 | 336 |
337 } // namespace | 337 } // namespace |
338 | 338 |
339 | 339 |
340 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { | 340 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { |
341 i::Isolate* internal_isolate = new i::Isolate(true); | 341 i::Isolate* internal_isolate = new i::Isolate(true); |
342 ArrayBufferAllocator allocator; | 342 ArrayBufferAllocator allocator; |
343 internal_isolate->set_array_buffer_allocator(&allocator); | 343 internal_isolate->set_array_buffer_allocator(&allocator); |
| 344 internal_isolate->set_shared_array_buffer_allocator(&allocator); |
344 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); | 345 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); |
345 StartupData result = {NULL, 0}; | 346 StartupData result = {NULL, 0}; |
346 { | 347 { |
347 base::ElapsedTimer timer; | 348 base::ElapsedTimer timer; |
348 timer.Start(); | 349 timer.Start(); |
349 Isolate::Scope isolate_scope(isolate); | 350 Isolate::Scope isolate_scope(isolate); |
350 internal_isolate->Init(NULL); | 351 internal_isolate->Init(NULL); |
351 Persistent<Context> context; | 352 Persistent<Context> context; |
352 i::Snapshot::Metadata metadata; | 353 i::Snapshot::Metadata metadata; |
353 { | 354 { |
(...skipping 2316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2670 return Utils::OpenHandle(this)->IsSymbol(); | 2671 return Utils::OpenHandle(this)->IsSymbol(); |
2671 } | 2672 } |
2672 | 2673 |
2673 | 2674 |
2674 bool Value::IsArray() const { | 2675 bool Value::IsArray() const { |
2675 return Utils::OpenHandle(this)->IsJSArray(); | 2676 return Utils::OpenHandle(this)->IsJSArray(); |
2676 } | 2677 } |
2677 | 2678 |
2678 | 2679 |
2679 bool Value::IsArrayBuffer() const { | 2680 bool Value::IsArrayBuffer() const { |
2680 return Utils::OpenHandle(this)->IsJSArrayBuffer(); | 2681 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2682 return obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(); |
2681 } | 2683 } |
2682 | 2684 |
2683 | 2685 |
2684 bool Value::IsArrayBufferView() const { | 2686 bool Value::IsArrayBufferView() const { |
2685 return Utils::OpenHandle(this)->IsJSArrayBufferView(); | 2687 return Utils::OpenHandle(this)->IsJSArrayBufferView(); |
2686 } | 2688 } |
2687 | 2689 |
2688 | 2690 |
2689 bool Value::IsTypedArray() const { | 2691 bool Value::IsTypedArray() const { |
2690 return Utils::OpenHandle(this)->IsJSTypedArray(); | 2692 return Utils::OpenHandle(this)->IsJSTypedArray(); |
2691 } | 2693 } |
2692 | 2694 |
2693 | 2695 |
2694 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ | 2696 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ |
2695 bool Value::Is##Type##Array() const { \ | 2697 bool Value::Is##Type##Array() const { \ |
2696 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ | 2698 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ |
2697 return obj->IsJSTypedArray() && \ | 2699 return obj->IsJSTypedArray() && \ |
2698 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \ | 2700 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \ |
2699 } | 2701 } |
2700 | 2702 |
| 2703 |
2701 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY) | 2704 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY) |
2702 | 2705 |
2703 #undef VALUE_IS_TYPED_ARRAY | 2706 #undef VALUE_IS_TYPED_ARRAY |
2704 | 2707 |
2705 | 2708 |
2706 bool Value::IsDataView() const { | 2709 bool Value::IsDataView() const { |
2707 return Utils::OpenHandle(this)->IsJSDataView(); | 2710 return Utils::OpenHandle(this)->IsJSDataView(); |
2708 } | 2711 } |
2709 | 2712 |
2710 | 2713 |
| 2714 bool Value::IsSharedArrayBuffer() const { |
| 2715 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2716 return obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(); |
| 2717 } |
| 2718 |
| 2719 |
2711 bool Value::IsObject() const { | 2720 bool Value::IsObject() const { |
2712 return Utils::OpenHandle(this)->IsJSObject(); | 2721 return Utils::OpenHandle(this)->IsJSObject(); |
2713 } | 2722 } |
2714 | 2723 |
2715 | 2724 |
2716 bool Value::IsNumber() const { | 2725 bool Value::IsNumber() const { |
2717 return Utils::OpenHandle(this)->IsNumber(); | 2726 return Utils::OpenHandle(this)->IsNumber(); |
2718 } | 2727 } |
2719 | 2728 |
2720 | 2729 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3077 | 3086 |
3078 void v8::Promise::Resolver::CheckCast(Value* that) { | 3087 void v8::Promise::Resolver::CheckCast(Value* that) { |
3079 Utils::ApiCheck(that->IsPromise(), | 3088 Utils::ApiCheck(that->IsPromise(), |
3080 "v8::Promise::Resolver::Cast()", | 3089 "v8::Promise::Resolver::Cast()", |
3081 "Could not convert to promise resolver"); | 3090 "Could not convert to promise resolver"); |
3082 } | 3091 } |
3083 | 3092 |
3084 | 3093 |
3085 void v8::ArrayBuffer::CheckCast(Value* that) { | 3094 void v8::ArrayBuffer::CheckCast(Value* that) { |
3086 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 3095 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
3087 Utils::ApiCheck(obj->IsJSArrayBuffer(), | 3096 Utils::ApiCheck( |
3088 "v8::ArrayBuffer::Cast()", | 3097 obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(), |
3089 "Could not convert to ArrayBuffer"); | 3098 "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer"); |
3090 } | 3099 } |
3091 | 3100 |
3092 | 3101 |
3093 void v8::ArrayBufferView::CheckCast(Value* that) { | 3102 void v8::ArrayBufferView::CheckCast(Value* that) { |
3094 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 3103 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
3095 Utils::ApiCheck(obj->IsJSArrayBufferView(), | 3104 Utils::ApiCheck(obj->IsJSArrayBufferView(), |
3096 "v8::ArrayBufferView::Cast()", | 3105 "v8::ArrayBufferView::Cast()", |
3097 "Could not convert to ArrayBufferView"); | 3106 "Could not convert to ArrayBufferView"); |
3098 } | 3107 } |
3099 | 3108 |
(...skipping 22 matching lines...) Expand all Loading... |
3122 | 3131 |
3123 | 3132 |
3124 void v8::DataView::CheckCast(Value* that) { | 3133 void v8::DataView::CheckCast(Value* that) { |
3125 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 3134 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
3126 Utils::ApiCheck(obj->IsJSDataView(), | 3135 Utils::ApiCheck(obj->IsJSDataView(), |
3127 "v8::DataView::Cast()", | 3136 "v8::DataView::Cast()", |
3128 "Could not convert to DataView"); | 3137 "Could not convert to DataView"); |
3129 } | 3138 } |
3130 | 3139 |
3131 | 3140 |
| 3141 void v8::SharedArrayBuffer::CheckCast(Value* that) { |
| 3142 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 3143 Utils::ApiCheck( |
| 3144 obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(), |
| 3145 "v8::SharedArrayBuffer::Cast()", |
| 3146 "Could not convert to SharedArrayBuffer"); |
| 3147 } |
| 3148 |
| 3149 |
3132 void v8::Date::CheckCast(v8::Value* that) { | 3150 void v8::Date::CheckCast(v8::Value* that) { |
3133 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 3151 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
3134 i::Isolate* isolate = NULL; | 3152 i::Isolate* isolate = NULL; |
3135 if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate(); | 3153 if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate(); |
3136 Utils::ApiCheck(isolate != NULL && | 3154 Utils::ApiCheck(isolate != NULL && |
3137 obj->HasSpecificClassOf(isolate->heap()->Date_string()), | 3155 obj->HasSpecificClassOf(isolate->heap()->Date_string()), |
3138 "v8::Date::Cast()", | 3156 "v8::Date::Cast()", |
3139 "Could not convert to date"); | 3157 "Could not convert to date"); |
3140 } | 3158 } |
3141 | 3159 |
(...skipping 3154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6296 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); | 6314 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
6297 return static_cast<size_t>(obj->byte_length()->Number()); | 6315 return static_cast<size_t>(obj->byte_length()->Number()); |
6298 } | 6316 } |
6299 | 6317 |
6300 | 6318 |
6301 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) { | 6319 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) { |
6302 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6320 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6303 LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)"); | 6321 LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)"); |
6304 ENTER_V8(i_isolate); | 6322 ENTER_V8(i_isolate); |
6305 i::Handle<i::JSArrayBuffer> obj = | 6323 i::Handle<i::JSArrayBuffer> obj = |
6306 i_isolate->factory()->NewJSArrayBuffer(); | 6324 i_isolate->factory()->NewJSArrayBuffer(i::NOT_SHARED); |
6307 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length); | 6325 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length); |
6308 return Utils::ToLocal(obj); | 6326 return Utils::ToLocal(obj); |
6309 } | 6327 } |
6310 | 6328 |
6311 | 6329 |
6312 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data, | 6330 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data, |
6313 size_t byte_length, | 6331 size_t byte_length, |
6314 ArrayBufferCreationMode mode) { | 6332 ArrayBufferCreationMode mode) { |
6315 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6333 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6316 LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)"); | 6334 LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
6317 ENTER_V8(i_isolate); | 6335 ENTER_V8(i_isolate); |
6318 i::Handle<i::JSArrayBuffer> obj = | 6336 i::Handle<i::JSArrayBuffer> obj = |
6319 i_isolate->factory()->NewJSArrayBuffer(); | 6337 i_isolate->factory()->NewJSArrayBuffer(i::NOT_SHARED); |
6320 i::Runtime::SetupArrayBuffer(i_isolate, obj, | 6338 i::Runtime::SetupArrayBuffer(i_isolate, obj, |
6321 mode == ArrayBufferCreationMode::kExternalized, | 6339 mode == ArrayBufferCreationMode::kExternalized, |
6322 data, byte_length); | 6340 data, byte_length); |
6323 return Utils::ToLocal(obj); | 6341 return Utils::ToLocal(obj); |
6324 } | 6342 } |
6325 | 6343 |
6326 | 6344 |
6327 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { | 6345 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { |
6328 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); | 6346 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
6329 i::Handle<i::JSArrayBuffer> buffer; | 6347 i::Handle<i::JSArrayBuffer> buffer; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6415 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); | 6433 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); |
6416 i::Isolate* isolate = buffer->GetIsolate(); | 6434 i::Isolate* isolate = buffer->GetIsolate(); |
6417 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); | 6435 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); |
6418 ENTER_V8(isolate); | 6436 ENTER_V8(isolate); |
6419 i::Handle<i::JSDataView> obj = | 6437 i::Handle<i::JSDataView> obj = |
6420 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length); | 6438 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length); |
6421 return Utils::ToLocal(obj); | 6439 return Utils::ToLocal(obj); |
6422 } | 6440 } |
6423 | 6441 |
6424 | 6442 |
| 6443 bool v8::SharedArrayBuffer::IsExternal() const { |
| 6444 return Utils::OpenHandle(this)->is_external(); |
| 6445 } |
| 6446 |
| 6447 |
| 6448 v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() { |
| 6449 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this); |
| 6450 i::Isolate* isolate = self->GetIsolate(); |
| 6451 Utils::ApiCheck(!self->is_external(), "v8::SharedArrayBuffer::Externalize", |
| 6452 "SharedArrayBuffer already externalized"); |
| 6453 self->set_is_external(true); |
| 6454 isolate->heap()->UnregisterArrayBuffer(self->backing_store()); |
| 6455 return GetContents(); |
| 6456 } |
| 6457 |
| 6458 |
| 6459 v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() { |
| 6460 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this); |
| 6461 size_t byte_length = static_cast<size_t>(self->byte_length()->Number()); |
| 6462 Contents contents; |
| 6463 contents.data_ = self->backing_store(); |
| 6464 contents.byte_length_ = byte_length; |
| 6465 return contents; |
| 6466 } |
| 6467 |
| 6468 |
| 6469 size_t v8::SharedArrayBuffer::ByteLength() const { |
| 6470 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 6471 return static_cast<size_t>(obj->byte_length()->Number()); |
| 6472 } |
| 6473 |
| 6474 |
| 6475 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate, |
| 6476 size_t byte_length) { |
| 6477 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6478 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(size_t)"); |
| 6479 ENTER_V8(i_isolate); |
| 6480 i::Handle<i::JSArrayBuffer> obj = |
| 6481 i_isolate->factory()->NewJSArrayBuffer(i::SHARED); |
| 6482 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length, true, |
| 6483 i::SHARED); |
| 6484 return Utils::ToLocalShared(obj); |
| 6485 } |
| 6486 |
| 6487 |
| 6488 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New( |
| 6489 Isolate* isolate, void* data, size_t byte_length, |
| 6490 ArrayBufferCreationMode mode) { |
| 6491 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6492 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)"); |
| 6493 ENTER_V8(i_isolate); |
| 6494 i::Handle<i::JSArrayBuffer> obj = |
| 6495 i_isolate->factory()->NewJSArrayBuffer(i::SHARED); |
| 6496 i::Runtime::SetupArrayBuffer(i_isolate, obj, |
| 6497 mode == ArrayBufferCreationMode::kExternalized, |
| 6498 data, byte_length, i::SHARED); |
| 6499 return Utils::ToLocalShared(obj); |
| 6500 } |
| 6501 |
| 6502 |
6425 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { | 6503 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { |
6426 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6504 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6427 LOG_API(i_isolate, "Symbol::New()"); | 6505 LOG_API(i_isolate, "Symbol::New()"); |
6428 ENTER_V8(i_isolate); | 6506 ENTER_V8(i_isolate); |
6429 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); | 6507 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); |
6430 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); | 6508 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); |
6431 return Utils::ToLocal(result); | 6509 return Utils::ToLocal(result); |
6432 } | 6510 } |
6433 | 6511 |
6434 | 6512 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6761 | 6839 |
6762 | 6840 |
6763 Isolate* Isolate::New(const Isolate::CreateParams& params) { | 6841 Isolate* Isolate::New(const Isolate::CreateParams& params) { |
6764 i::Isolate* isolate = new i::Isolate(false); | 6842 i::Isolate* isolate = new i::Isolate(false); |
6765 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); | 6843 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); |
6766 if (params.array_buffer_allocator != NULL) { | 6844 if (params.array_buffer_allocator != NULL) { |
6767 isolate->set_array_buffer_allocator(params.array_buffer_allocator); | 6845 isolate->set_array_buffer_allocator(params.array_buffer_allocator); |
6768 } else { | 6846 } else { |
6769 isolate->set_array_buffer_allocator(i::V8::ArrayBufferAllocator()); | 6847 isolate->set_array_buffer_allocator(i::V8::ArrayBufferAllocator()); |
6770 } | 6848 } |
| 6849 if (params.shared_array_buffer_allocator) { |
| 6850 isolate->set_shared_array_buffer_allocator( |
| 6851 params.shared_array_buffer_allocator); |
| 6852 } else { |
| 6853 // Default to using the same allocator as the array_buffer_allocator. |
| 6854 isolate->set_shared_array_buffer_allocator( |
| 6855 isolate->array_buffer_allocator()); |
| 6856 } |
6771 if (params.snapshot_blob != NULL) { | 6857 if (params.snapshot_blob != NULL) { |
6772 isolate->set_snapshot_blob(params.snapshot_blob); | 6858 isolate->set_snapshot_blob(params.snapshot_blob); |
6773 } else { | 6859 } else { |
6774 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); | 6860 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); |
6775 } | 6861 } |
6776 if (params.entry_hook) { | 6862 if (params.entry_hook) { |
6777 isolate->set_function_entry_hook(params.entry_hook); | 6863 isolate->set_function_entry_hook(params.entry_hook); |
6778 } | 6864 } |
6779 if (params.code_event_handler) { | 6865 if (params.code_event_handler) { |
6780 isolate->InitializeLoggingAndCounters(); | 6866 isolate->InitializeLoggingAndCounters(); |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8079 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8165 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8080 Address callback_address = | 8166 Address callback_address = |
8081 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8167 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8082 VMState<EXTERNAL> state(isolate); | 8168 VMState<EXTERNAL> state(isolate); |
8083 ExternalCallbackScope call_scope(isolate, callback_address); | 8169 ExternalCallbackScope call_scope(isolate, callback_address); |
8084 callback(info); | 8170 callback(info); |
8085 } | 8171 } |
8086 | 8172 |
8087 | 8173 |
8088 } } // namespace v8::internal | 8174 } } // namespace v8::internal |
OLD | NEW |