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 6643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6654 return static_cast<size_t>(obj->byte_length()->Number()); | 6654 return static_cast<size_t>(obj->byte_length()->Number()); |
6655 } | 6655 } |
6656 | 6656 |
6657 | 6657 |
6658 size_t v8::TypedArray::Length() { | 6658 size_t v8::TypedArray::Length() { |
6659 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); | 6659 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); |
6660 return static_cast<size_t>(obj->length_value()); | 6660 return static_cast<size_t>(obj->length_value()); |
6661 } | 6661 } |
6662 | 6662 |
6663 | 6663 |
6664 #define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \ | 6664 #define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \ |
6665 Local<Type##Array> Type##Array::New(Handle<ArrayBuffer> array_buffer, \ | 6665 Local<Type##Array> Type##Array::New(Handle<ArrayBuffer> array_buffer, \ |
6666 size_t byte_offset, size_t length) { \ | 6666 size_t byte_offset, size_t length) { \ |
6667 i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \ | 6667 i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \ |
6668 LOG_API(isolate, \ | 6668 LOG_API(isolate, \ |
6669 "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \ | 6669 "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \ |
6670 ENTER_V8(isolate); \ | 6670 ENTER_V8(isolate); \ |
6671 if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \ | 6671 if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \ |
6672 "v8::" #Type \ | 6672 "v8::" #Type \ |
6673 "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \ | 6673 "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \ |
6674 "length exceeds max allowed value")) { \ | 6674 "length exceeds max allowed value")) { \ |
6675 return Local<Type##Array>(); \ | 6675 return Local<Type##Array>(); \ |
6676 } \ | 6676 } \ |
6677 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \ | 6677 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \ |
6678 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \ | 6678 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \ |
6679 i::kExternal##Type##Array, buffer, byte_offset, length); \ | 6679 i::kExternal##Type##Array, buffer, byte_offset, length); \ |
6680 return Utils::ToLocal##Type##Array(obj); \ | 6680 return Utils::ToLocal##Type##Array(obj); \ |
| 6681 } \ |
| 6682 Local<Type##Array> Type##Array::New( \ |
| 6683 Handle<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, \ |
| 6684 size_t length) { \ |
| 6685 CHECK(i::FLAG_harmony_sharedarraybuffer); \ |
| 6686 i::Isolate* isolate = \ |
| 6687 Utils::OpenHandle(*shared_array_buffer)->GetIsolate(); \ |
| 6688 LOG_API(isolate, "v8::" #Type \ |
| 6689 "Array::New(Handle<SharedArrayBuffer>, size_t, size_t)"); \ |
| 6690 ENTER_V8(isolate); \ |
| 6691 if (!Utils::ApiCheck( \ |
| 6692 length <= static_cast<size_t>(i::Smi::kMaxValue), \ |
| 6693 "v8::" #Type \ |
| 6694 "Array::New(Handle<SharedArrayBuffer>, size_t, size_t)", \ |
| 6695 "length exceeds max allowed value")) { \ |
| 6696 return Local<Type##Array>(); \ |
| 6697 } \ |
| 6698 i::Handle<i::JSArrayBuffer> buffer = \ |
| 6699 Utils::OpenHandle(*shared_array_buffer); \ |
| 6700 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \ |
| 6701 i::kExternal##Type##Array, buffer, byte_offset, length); \ |
| 6702 return Utils::ToLocal##Type##Array(obj); \ |
6681 } | 6703 } |
6682 | 6704 |
6683 | 6705 |
6684 TYPED_ARRAYS(TYPED_ARRAY_NEW) | 6706 TYPED_ARRAYS(TYPED_ARRAY_NEW) |
6685 #undef TYPED_ARRAY_NEW | 6707 #undef TYPED_ARRAY_NEW |
6686 | 6708 |
6687 Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer, | 6709 Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer, |
6688 size_t byte_offset, size_t byte_length) { | 6710 size_t byte_offset, size_t byte_length) { |
6689 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); | 6711 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); |
6690 i::Isolate* isolate = buffer->GetIsolate(); | 6712 i::Isolate* isolate = buffer->GetIsolate(); |
6691 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); | 6713 LOG_API(isolate, "v8::DataView::New(Handle<ArrayBuffer>, size_t, size_t)"); |
6692 ENTER_V8(isolate); | 6714 ENTER_V8(isolate); |
6693 i::Handle<i::JSDataView> obj = | 6715 i::Handle<i::JSDataView> obj = |
6694 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length); | 6716 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length); |
| 6717 return Utils::ToLocal(obj); |
| 6718 } |
| 6719 |
| 6720 |
| 6721 Local<DataView> DataView::New(Handle<SharedArrayBuffer> shared_array_buffer, |
| 6722 size_t byte_offset, size_t byte_length) { |
| 6723 CHECK(i::FLAG_harmony_sharedarraybuffer); |
| 6724 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*shared_array_buffer); |
| 6725 i::Isolate* isolate = buffer->GetIsolate(); |
| 6726 LOG_API(isolate, |
| 6727 "v8::DataView::New(Handle<SharedArrayBuffer>, size_t, size_t)"); |
| 6728 ENTER_V8(isolate); |
| 6729 i::Handle<i::JSDataView> obj = |
| 6730 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length); |
6695 return Utils::ToLocal(obj); | 6731 return Utils::ToLocal(obj); |
6696 } | 6732 } |
6697 | 6733 |
6698 | 6734 |
6699 bool v8::SharedArrayBuffer::IsExternal() const { | 6735 bool v8::SharedArrayBuffer::IsExternal() const { |
6700 return Utils::OpenHandle(this)->is_external(); | 6736 return Utils::OpenHandle(this)->is_external(); |
6701 } | 6737 } |
6702 | 6738 |
6703 | 6739 |
6704 v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() { | 6740 v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() { |
(...skipping 18 matching lines...) Expand all Loading... |
6723 | 6759 |
6724 | 6760 |
6725 size_t v8::SharedArrayBuffer::ByteLength() const { | 6761 size_t v8::SharedArrayBuffer::ByteLength() const { |
6726 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); | 6762 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
6727 return static_cast<size_t>(obj->byte_length()->Number()); | 6763 return static_cast<size_t>(obj->byte_length()->Number()); |
6728 } | 6764 } |
6729 | 6765 |
6730 | 6766 |
6731 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate, | 6767 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate, |
6732 size_t byte_length) { | 6768 size_t byte_length) { |
| 6769 CHECK(i::FLAG_harmony_sharedarraybuffer); |
6733 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6770 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6734 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(size_t)"); | 6771 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(size_t)"); |
6735 ENTER_V8(i_isolate); | 6772 ENTER_V8(i_isolate); |
6736 i::Handle<i::JSArrayBuffer> obj = | 6773 i::Handle<i::JSArrayBuffer> obj = |
6737 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared); | 6774 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared); |
6738 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length, true, | 6775 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length, true, |
6739 i::SharedFlag::kShared); | 6776 i::SharedFlag::kShared); |
6740 return Utils::ToLocalShared(obj); | 6777 return Utils::ToLocalShared(obj); |
6741 } | 6778 } |
6742 | 6779 |
6743 | 6780 |
6744 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New( | 6781 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New( |
6745 Isolate* isolate, void* data, size_t byte_length, | 6782 Isolate* isolate, void* data, size_t byte_length, |
6746 ArrayBufferCreationMode mode) { | 6783 ArrayBufferCreationMode mode) { |
| 6784 CHECK(i::FLAG_harmony_sharedarraybuffer); |
6747 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6785 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6748 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)"); | 6786 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)"); |
6749 ENTER_V8(i_isolate); | 6787 ENTER_V8(i_isolate); |
6750 i::Handle<i::JSArrayBuffer> obj = | 6788 i::Handle<i::JSArrayBuffer> obj = |
6751 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared); | 6789 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared); |
6752 i::Runtime::SetupArrayBuffer(i_isolate, obj, | 6790 i::Runtime::SetupArrayBuffer(i_isolate, obj, |
6753 mode == ArrayBufferCreationMode::kExternalized, | 6791 mode == ArrayBufferCreationMode::kExternalized, |
6754 data, byte_length, i::SharedFlag::kShared); | 6792 data, byte_length, i::SharedFlag::kShared); |
6755 return Utils::ToLocalShared(obj); | 6793 return Utils::ToLocalShared(obj); |
6756 } | 6794 } |
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8386 Address callback_address = | 8424 Address callback_address = |
8387 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8425 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8388 VMState<EXTERNAL> state(isolate); | 8426 VMState<EXTERNAL> state(isolate); |
8389 ExternalCallbackScope call_scope(isolate, callback_address); | 8427 ExternalCallbackScope call_scope(isolate, callback_address); |
8390 callback(info); | 8428 callback(info); |
8391 } | 8429 } |
8392 | 8430 |
8393 | 8431 |
8394 } // namespace internal | 8432 } // namespace internal |
8395 } // namespace v8 | 8433 } // namespace v8 |
OLD | NEW |