Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: include/v8.h

Issue 1069883002: WIP SharedArrayBuffer implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/accessors.cc » ('j') | src/bootstrapper.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 3667 matching lines...) Expand 10 before | Expand all | Expand 10 after
3678 size_t byte_offset, size_t length); 3678 size_t byte_offset, size_t length);
3679 V8_INLINE static DataView* Cast(Value* obj); 3679 V8_INLINE static DataView* Cast(Value* obj);
3680 3680
3681 private: 3681 private:
3682 DataView(); 3682 DataView();
3683 static void CheckCast(Value* obj); 3683 static void CheckCast(Value* obj);
3684 }; 3684 };
3685 3685
3686 3686
3687 /** 3687 /**
3688 * TODO(binji): document
3689 * An instance of the built-in SharedArrayBuffer constructor (ES6 draft
3690 * 15.13.5).
3691 * This API is experimental and may change significantly.
3692 */
3693 class V8_EXPORT SharedArrayBuffer : public Object {
3694 public:
3695 /**
3696 * Allocator that V8 uses to allocate |SharedArrayBuffer|'s memory. The
3697 * allocator is a global V8 setting. It should be set with
3698 * V8::SetSharedArrayBufferAllocator prior to creation of a first
3699 * SharedArrayBuffer.
3700 *
3701 * This API is experimental and may change significantly.
3702 */
3703 class V8_EXPORT Allocator { // NOLINT
3704 public:
3705 virtual ~Allocator() {}
3706
3707 /**
3708 * Allocate |length| bytes. Return NULL if allocation is not successful.
3709 * Memory should be initialized to zeroes.
3710 */
3711 virtual void* Allocate(size_t length) = 0;
3712
3713 /**
3714 * Allocate |length| bytes. Return NULL if allocation is not successful.
3715 * Memory does not have to be initialized.
3716 */
3717 virtual void* AllocateUninitialized(size_t length) = 0;
3718 /**
3719 * Free the memory block of size |length|, pointed to by |data|.
3720 * That memory is guaranteed to be previously allocated by |Allocate|.
3721 */
3722 virtual void Free(void* data, size_t length) = 0;
3723 };
3724
3725 /**
3726 * The contents of an |SharedArrayBuffer|. Externalization of
3727 * |SharedArrayBuffer| returns an instance of this class, populated, with a
3728 * pointer to data and byte length.
3729 *
3730 * The Data pointer of SharedArrayBuffer::Contents is always allocated with
3731 * Allocator::Allocate that is set with V8::SetSharedArrayBufferAllocator.
3732 *
3733 * This API is experimental and may change significantly.
3734 */
3735 class V8_EXPORT Contents { // NOLINT
3736 public:
3737 Contents() : data_(NULL), byte_length_(0) {}
3738
3739 void* Data() const { return data_; }
3740 size_t ByteLength() const { return byte_length_; }
3741
3742 private:
3743 void* data_;
3744 size_t byte_length_;
3745
3746 friend class SharedArrayBuffer;
3747 };
3748
3749
3750 /**
3751 * Data length in bytes.
3752 */
3753 size_t ByteLength() const;
3754
3755 /**
3756 * Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
3757 * Allocated memory will be owned by a created SharedArrayBuffer and
3758 * will be deallocated when it is garbage-collected,
3759 * unless the object is externalized.
3760 */
3761 static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
3762
3763 /**
3764 * Create a new SharedArrayBuffer over an existing memory block.
3765 * The created array buffer is immediately in externalized state.
3766 * The memory block will not be reclaimed when a created SharedArrayBuffer
3767 * is garbage-collected.
3768 */
3769 static Local<SharedArrayBuffer> New(Isolate* isolate, void* data,
3770 size_t byte_length);
3771
3772 /**
3773 * Returns true if SharedArrayBuffer is extrenalized, that is, does not
3774 * own its memory block.
3775 */
3776 bool IsExternal() const;
3777
3778 /**
3779 * Make this SharedArrayBuffer external. The pointer to underlying memory
3780 * block and byte length are returned as |Contents| structure. After
3781 * SharedArrayBuffer had been etxrenalized, it does no longer owns the memory
3782 * block. The caller should take steps to free memory when it is no longer
3783 * needed.
3784 *
3785 * The memory block is guaranteed to be allocated with |Allocator::Allocate|
3786 * that has been set with V8::SetSharedArrayBufferAllocator.
3787 */
3788 Contents Externalize();
3789
3790 V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
3791
3792 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
3793
3794 private:
3795 SharedArrayBuffer();
3796 static void CheckCast(Value* obj);
3797 };
3798
3799
3800 /**
3801 * TODO(binji): document
3802 * A base class for an instance of TypedArray series of constructors
3803 * (ES6 draft 15.13.6).
3804 * This API is experimental and may change significantly.
3805 */
3806 class V8_EXPORT SharedTypedArray : public Object {
3807 public:
3808 /**
3809 * Returns underlying SharedArrayBuffer.
3810 */
3811 Local<SharedArrayBuffer> Buffer();
3812 /**
3813 * Byte offset in |Buffer|.
3814 */
3815 size_t ByteOffset();
3816 /**
3817 * Size of a view in bytes.
3818 */
3819 size_t ByteLength();
3820
3821 /**
3822 * Number of elements in this typed array
3823 * (e.g. for SharedInt16Array, |ByteLength|/2).
3824 */
3825 size_t Length();
3826
3827 V8_INLINE static SharedTypedArray* Cast(Value* obj);
3828
3829 private:
3830 SharedTypedArray();
3831 static void CheckCast(Value* obj);
3832 };
3833
3834
3835 /**
3836 * TODO(binji): document
3837 * An instance of Uint8Array constructor (ES6 draft 15.13.6).
3838 * This API is experimental and may change significantly.
3839 */
3840 class V8_EXPORT SharedUint8Array : public SharedTypedArray {
3841 public:
3842 static Local<SharedUint8Array> New(Handle<SharedArrayBuffer> array_buffer,
3843 size_t byte_offset, size_t length);
3844 V8_INLINE static SharedUint8Array* Cast(Value* obj);
3845
3846 private:
3847 SharedUint8Array();
3848 static void CheckCast(Value* obj);
3849 };
3850
3851
3852 /**
3853 * TODO(binji): document
3854 * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
3855 * This API is experimental and may change significantly.
3856 */
3857 class V8_EXPORT SharedUint8ClampedArray : public SharedTypedArray {
3858 public:
3859 static Local<SharedUint8ClampedArray> New(
3860 Handle<SharedArrayBuffer> array_buffer, size_t byte_offset,
3861 size_t length);
3862 V8_INLINE static SharedUint8ClampedArray* Cast(Value* obj);
3863
3864 private:
3865 SharedUint8ClampedArray();
3866 static void CheckCast(Value* obj);
3867 };
3868
3869 /**
3870 * TODO(binji): document
3871 * An instance of Int8Array constructor (ES6 draft 15.13.6).
3872 * This API is experimental and may change significantly.
3873 */
3874 class V8_EXPORT SharedInt8Array : public SharedTypedArray {
3875 public:
3876 static Local<SharedInt8Array> New(Handle<SharedArrayBuffer> array_buffer,
3877 size_t byte_offset, size_t length);
3878 V8_INLINE static SharedInt8Array* Cast(Value* obj);
3879
3880 private:
3881 SharedInt8Array();
3882 static void CheckCast(Value* obj);
3883 };
3884
3885
3886 /**
3887 * TODO(binji): document
3888 * An instance of Uint16Array constructor (ES6 draft 15.13.6).
3889 * This API is experimental and may change significantly.
3890 */
3891 class V8_EXPORT SharedUint16Array : public SharedTypedArray {
3892 public:
3893 static Local<SharedUint16Array> New(Handle<SharedArrayBuffer> array_buffer,
3894 size_t byte_offset, size_t length);
3895 V8_INLINE static SharedUint16Array* Cast(Value* obj);
3896
3897 private:
3898 SharedUint16Array();
3899 static void CheckCast(Value* obj);
3900 };
3901
3902
3903 /**
3904 * TODO(binji): document
3905 * An instance of Int16Array constructor (ES6 draft 15.13.6).
3906 * This API is experimental and may change significantly.
3907 */
3908 class V8_EXPORT SharedInt16Array : public SharedTypedArray {
3909 public:
3910 static Local<SharedInt16Array> New(Handle<SharedArrayBuffer> array_buffer,
3911 size_t byte_offset, size_t length);
3912 V8_INLINE static SharedInt16Array* Cast(Value* obj);
3913
3914 private:
3915 SharedInt16Array();
3916 static void CheckCast(Value* obj);
3917 };
3918
3919
3920 /**
3921 * TODO(binji): document
3922 * An instance of Uint32Array constructor (ES6 draft 15.13.6).
3923 * This API is experimental and may change significantly.
3924 */
3925 class V8_EXPORT SharedUint32Array : public SharedTypedArray {
3926 public:
3927 static Local<SharedUint32Array> New(Handle<SharedArrayBuffer> array_buffer,
3928 size_t byte_offset, size_t length);
3929 V8_INLINE static SharedUint32Array* Cast(Value* obj);
3930
3931 private:
3932 SharedUint32Array();
3933 static void CheckCast(Value* obj);
3934 };
3935
3936
3937 /**
3938 * TODO(binji): document
3939 * An instance of Int32Array constructor (ES6 draft 15.13.6).
3940 * This API is experimental and may change significantly.
3941 */
3942 class V8_EXPORT SharedInt32Array : public SharedTypedArray {
3943 public:
3944 static Local<SharedInt32Array> New(Handle<SharedArrayBuffer> array_buffer,
3945 size_t byte_offset, size_t length);
3946 V8_INLINE static SharedInt32Array* Cast(Value* obj);
3947
3948 private:
3949 SharedInt32Array();
3950 static void CheckCast(Value* obj);
3951 };
3952
3953
3954 /**
3955 * TODO(binji): document
3956 * An instance of Float32Array constructor (ES6 draft 15.13.6).
3957 * This API is experimental and may change significantly.
3958 */
3959 class V8_EXPORT SharedFloat32Array : public SharedTypedArray {
3960 public:
3961 static Local<SharedFloat32Array> New(Handle<SharedArrayBuffer> array_buffer,
3962 size_t byte_offset, size_t length);
3963 V8_INLINE static SharedFloat32Array* Cast(Value* obj);
3964
3965 private:
3966 SharedFloat32Array();
3967 static void CheckCast(Value* obj);
3968 };
3969
3970
3971 /**
3972 * TODO(binji): document
3973 * An instance of Float64Array constructor (ES6 draft 15.13.6).
3974 * This API is experimental and may change significantly.
3975 */
3976 class V8_EXPORT SharedFloat64Array : public SharedTypedArray {
3977 public:
3978 static Local<SharedFloat64Array> New(Handle<SharedArrayBuffer> array_buffer,
3979 size_t byte_offset, size_t length);
3980 V8_INLINE static SharedFloat64Array* Cast(Value* obj);
3981
3982 private:
3983 SharedFloat64Array();
3984 static void CheckCast(Value* obj);
3985 };
3986
3987
3988 /**
3688 * An instance of the built-in Date constructor (ECMA-262, 15.9). 3989 * An instance of the built-in Date constructor (ECMA-262, 15.9).
3689 */ 3990 */
3690 class V8_EXPORT Date : public Object { 3991 class V8_EXPORT Date : public Object {
3691 public: 3992 public:
3692 static V8_DEPRECATE_SOON("Use maybe version.", 3993 static V8_DEPRECATE_SOON("Use maybe version.",
3693 Local<Value> New(Isolate* isolate, double time)); 3994 Local<Value> New(Isolate* isolate, double time));
3694 static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context, 3995 static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
3695 double time); 3996 double time);
3696 3997
3697 /** 3998 /**
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after
5742 6043
5743 /** 6044 /**
5744 * Set allocator to use for ArrayBuffer memory. 6045 * Set allocator to use for ArrayBuffer memory.
5745 * The allocator should be set only once. The allocator should be set 6046 * The allocator should be set only once. The allocator should be set
5746 * before any code tha uses ArrayBuffers is executed. 6047 * before any code tha uses ArrayBuffers is executed.
5747 * This allocator is used in all isolates. 6048 * This allocator is used in all isolates.
5748 */ 6049 */
5749 static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator); 6050 static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator);
5750 6051
5751 /** 6052 /**
6053 * Set allocator to use for SharedArrayBuffer memory.
6054 * The allocator should be set only once. The allocator should be set
6055 * before any code tha uses SharedArrayBuffers is executed.
6056 * This allocator is used in all isolates.
6057 */
6058 static void SetSharedArrayBufferAllocator(
6059 SharedArrayBuffer::Allocator* allocator);
6060
6061 /**
5752 * Check if V8 is dead and therefore unusable. This is the case after 6062 * Check if V8 is dead and therefore unusable. This is the case after
5753 * fatal errors such as out-of-memory situations. 6063 * fatal errors such as out-of-memory situations.
5754 */ 6064 */
5755 V8_INLINE static V8_DEPRECATE_SOON("no alternative", bool IsDead()); 6065 V8_INLINE static V8_DEPRECATE_SOON("no alternative", bool IsDead());
5756 6066
5757 /** 6067 /**
5758 * Hand startup data to V8, in case the embedder has chosen to build 6068 * Hand startup data to V8, in case the embedder has chosen to build
5759 * V8 with external startup data. 6069 * V8 with external startup data.
5760 * 6070 *
5761 * Note: 6071 * Note:
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
6698 static const int kHeapObjectMapOffset = 0; 7008 static const int kHeapObjectMapOffset = 0;
6699 static const int kMapInstanceTypeAndBitFieldOffset = 7009 static const int kMapInstanceTypeAndBitFieldOffset =
6700 1 * kApiPointerSize + kApiIntSize; 7010 1 * kApiPointerSize + kApiIntSize;
6701 static const int kStringResourceOffset = 3 * kApiPointerSize; 7011 static const int kStringResourceOffset = 3 * kApiPointerSize;
6702 7012
6703 static const int kOddballKindOffset = 3 * kApiPointerSize; 7013 static const int kOddballKindOffset = 3 * kApiPointerSize;
6704 static const int kForeignAddressOffset = kApiPointerSize; 7014 static const int kForeignAddressOffset = kApiPointerSize;
6705 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 7015 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
6706 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; 7016 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
6707 static const int kContextHeaderSize = 2 * kApiPointerSize; 7017 static const int kContextHeaderSize = 2 * kApiPointerSize;
6708 static const int kContextEmbedderDataIndex = 76; 7018 static const int kContextEmbedderDataIndex = 95;
6709 static const int kFullStringRepresentationMask = 0x07; 7019 static const int kFullStringRepresentationMask = 0x07;
6710 static const int kStringEncodingMask = 0x4; 7020 static const int kStringEncodingMask = 0x4;
6711 static const int kExternalTwoByteRepresentationTag = 0x02; 7021 static const int kExternalTwoByteRepresentationTag = 0x02;
6712 static const int kExternalOneByteRepresentationTag = 0x06; 7022 static const int kExternalOneByteRepresentationTag = 0x06;
6713 7023
6714 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; 7024 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
6715 static const int kAmountOfExternalAllocatedMemoryOffset = 7025 static const int kAmountOfExternalAllocatedMemoryOffset =
6716 4 * kApiPointerSize; 7026 4 * kApiPointerSize;
6717 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = 7027 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
6718 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size; 7028 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
7764 8074
7765 8075
7766 DataView* DataView::Cast(v8::Value* value) { 8076 DataView* DataView::Cast(v8::Value* value) {
7767 #ifdef V8_ENABLE_CHECKS 8077 #ifdef V8_ENABLE_CHECKS
7768 CheckCast(value); 8078 CheckCast(value);
7769 #endif 8079 #endif
7770 return static_cast<DataView*>(value); 8080 return static_cast<DataView*>(value);
7771 } 8081 }
7772 8082
7773 8083
8084 SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) {
8085 #ifdef V8_ENABLE_CHECKS
8086 CheckCast(value);
8087 #endif
8088 return static_cast<SharedArrayBuffer*>(value);
8089 }
8090
8091
8092 SharedTypedArray* SharedTypedArray::Cast(v8::Value* value) {
8093 #ifdef V8_ENABLE_CHECKS
8094 CheckCast(value);
8095 #endif
8096 return static_cast<SharedTypedArray*>(value);
8097 }
8098
8099
8100 SharedUint8Array* SharedUint8Array::Cast(v8::Value* value) {
8101 #ifdef V8_ENABLE_CHECKS
8102 CheckCast(value);
8103 #endif
8104 return static_cast<SharedUint8Array*>(value);
8105 }
8106
8107
8108 SharedInt8Array* SharedInt8Array::Cast(v8::Value* value) {
8109 #ifdef V8_ENABLE_CHECKS
8110 CheckCast(value);
8111 #endif
8112 return static_cast<SharedInt8Array*>(value);
8113 }
8114
8115
8116 SharedUint16Array* SharedUint16Array::Cast(v8::Value* value) {
8117 #ifdef V8_ENABLE_CHECKS
8118 CheckCast(value);
8119 #endif
8120 return static_cast<SharedUint16Array*>(value);
8121 }
8122
8123
8124 SharedInt16Array* SharedInt16Array::Cast(v8::Value* value) {
8125 #ifdef V8_ENABLE_CHECKS
8126 CheckCast(value);
8127 #endif
8128 return static_cast<SharedInt16Array*>(value);
8129 }
8130
8131
8132 SharedUint32Array* SharedUint32Array::Cast(v8::Value* value) {
8133 #ifdef V8_ENABLE_CHECKS
8134 CheckCast(value);
8135 #endif
8136 return static_cast<SharedUint32Array*>(value);
8137 }
8138
8139
8140 SharedInt32Array* SharedInt32Array::Cast(v8::Value* value) {
8141 #ifdef V8_ENABLE_CHECKS
8142 CheckCast(value);
8143 #endif
8144 return static_cast<SharedInt32Array*>(value);
8145 }
8146
8147
8148 SharedFloat32Array* SharedFloat32Array::Cast(v8::Value* value) {
8149 #ifdef V8_ENABLE_CHECKS
8150 CheckCast(value);
8151 #endif
8152 return static_cast<SharedFloat32Array*>(value);
8153 }
8154
8155
8156 SharedFloat64Array* SharedFloat64Array::Cast(v8::Value* value) {
8157 #ifdef V8_ENABLE_CHECKS
8158 CheckCast(value);
8159 #endif
8160 return static_cast<SharedFloat64Array*>(value);
8161 }
8162
8163
8164 SharedUint8ClampedArray* SharedUint8ClampedArray::Cast(v8::Value* value) {
8165 #ifdef V8_ENABLE_CHECKS
8166 CheckCast(value);
8167 #endif
8168 return static_cast<SharedUint8ClampedArray*>(value);
8169 }
8170
8171
7774 Function* Function::Cast(v8::Value* value) { 8172 Function* Function::Cast(v8::Value* value) {
7775 #ifdef V8_ENABLE_CHECKS 8173 #ifdef V8_ENABLE_CHECKS
7776 CheckCast(value); 8174 CheckCast(value);
7777 #endif 8175 #endif
7778 return static_cast<Function*>(value); 8176 return static_cast<Function*>(value);
7779 } 8177 }
7780 8178
7781 8179
7782 External* External::Cast(v8::Value* value) { 8180 External* External::Cast(v8::Value* value) {
7783 #ifdef V8_ENABLE_CHECKS 8181 #ifdef V8_ENABLE_CHECKS
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
8069 */ 8467 */
8070 8468
8071 8469
8072 } // namespace v8 8470 } // namespace v8
8073 8471
8074 8472
8075 #undef TYPE_CHECK 8473 #undef TYPE_CHECK
8076 8474
8077 8475
8078 #endif // V8_H_ 8476 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/accessors.cc » ('j') | src/bootstrapper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698