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 /** \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 3276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3287 Promise(); | 3287 Promise(); |
3288 static void CheckCast(Value* obj); | 3288 static void CheckCast(Value* obj); |
3289 }; | 3289 }; |
3290 | 3290 |
3291 | 3291 |
3292 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT | 3292 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
3293 // The number of required internal fields can be defined by embedder. | 3293 // The number of required internal fields can be defined by embedder. |
3294 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 | 3294 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
3295 #endif | 3295 #endif |
3296 | 3296 |
| 3297 |
| 3298 enum class ArrayBufferCreationMode { kInternalized, kExternalized }; |
| 3299 |
| 3300 |
3297 /** | 3301 /** |
3298 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). | 3302 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
3299 * This API is experimental and may change significantly. | 3303 * This API is experimental and may change significantly. |
3300 */ | 3304 */ |
3301 class V8_EXPORT ArrayBuffer : public Object { | 3305 class V8_EXPORT ArrayBuffer : public Object { |
3302 public: | 3306 public: |
3303 /** | 3307 /** |
3304 * Allocator that V8 uses to allocate |ArrayBuffer|'s memory. | 3308 * Allocator that V8 uses to allocate |ArrayBuffer|'s memory. |
3305 * The allocator is a global V8 setting. It should be set with | 3309 * The allocator is a global V8 setting. It should be set with |
3306 * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer. | 3310 * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3362 /** | 3366 /** |
3363 * Create a new ArrayBuffer. Allocate |byte_length| bytes. | 3367 * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
3364 * Allocated memory will be owned by a created ArrayBuffer and | 3368 * Allocated memory will be owned by a created ArrayBuffer and |
3365 * will be deallocated when it is garbage-collected, | 3369 * will be deallocated when it is garbage-collected, |
3366 * unless the object is externalized. | 3370 * unless the object is externalized. |
3367 */ | 3371 */ |
3368 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); | 3372 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); |
3369 | 3373 |
3370 /** | 3374 /** |
3371 * Create a new ArrayBuffer over an existing memory block. | 3375 * Create a new ArrayBuffer over an existing memory block. |
3372 * The created array buffer is immediately in externalized state. | 3376 * The created array buffer is by default immediately in externalized state. |
3373 * The memory block will not be reclaimed when a created ArrayBuffer | 3377 * The memory block will not be reclaimed when a created ArrayBuffer |
3374 * is garbage-collected. | 3378 * is garbage-collected. |
3375 */ | 3379 */ |
3376 static Local<ArrayBuffer> New(Isolate* isolate, void* data, | 3380 static Local<ArrayBuffer> New( |
3377 size_t byte_length); | 3381 Isolate* isolate, void* data, size_t byte_length, |
| 3382 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); |
3378 | 3383 |
3379 /** | 3384 /** |
3380 * Returns true if ArrayBuffer is extrenalized, that is, does not | 3385 * Returns true if ArrayBuffer is extrenalized, that is, does not |
3381 * own its memory block. | 3386 * own its memory block. |
3382 */ | 3387 */ |
3383 bool IsExternal() const; | 3388 bool IsExternal() const; |
3384 | 3389 |
3385 /** | 3390 /** |
3386 * Returns true if this ArrayBuffer may be neutered. | 3391 * Returns true if this ArrayBuffer may be neutered. |
3387 */ | 3392 */ |
(...skipping 11 matching lines...) Expand all Loading... |
3399 * Make this ArrayBuffer external. The pointer to underlying memory block | 3404 * Make this ArrayBuffer external. The pointer to underlying memory block |
3400 * and byte length are returned as |Contents| structure. After ArrayBuffer | 3405 * and byte length are returned as |Contents| structure. After ArrayBuffer |
3401 * had been etxrenalized, it does no longer owns the memory block. The caller | 3406 * had been etxrenalized, it does no longer owns the memory block. The caller |
3402 * should take steps to free memory when it is no longer needed. | 3407 * should take steps to free memory when it is no longer needed. |
3403 * | 3408 * |
3404 * The memory block is guaranteed to be allocated with |Allocator::Allocate| | 3409 * The memory block is guaranteed to be allocated with |Allocator::Allocate| |
3405 * that has been set with V8::SetArrayBufferAllocator. | 3410 * that has been set with V8::SetArrayBufferAllocator. |
3406 */ | 3411 */ |
3407 Contents Externalize(); | 3412 Contents Externalize(); |
3408 | 3413 |
| 3414 /** |
| 3415 * Get a pointer to the ArrayBuffer's underlying memory block without |
| 3416 * externalizing it. If the ArrayBuffer is not externalized, this pointer |
| 3417 * will become invalid as soon as the ArrayBuffer became garbage collected. |
| 3418 * |
| 3419 * The embedder should make sure to hold a strong reference to the |
| 3420 * ArrayBuffer while accessing this pointer. |
| 3421 * |
| 3422 * The memory block is guaranteed to be allocated with |Allocator::Allocate|. |
| 3423 */ |
| 3424 Contents GetContents(); |
| 3425 |
3409 V8_INLINE static ArrayBuffer* Cast(Value* obj); | 3426 V8_INLINE static ArrayBuffer* Cast(Value* obj); |
3410 | 3427 |
3411 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; | 3428 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
3412 | 3429 |
3413 private: | 3430 private: |
3414 ArrayBuffer(); | 3431 ArrayBuffer(); |
3415 static void CheckCast(Value* obj); | 3432 static void CheckCast(Value* obj); |
3416 }; | 3433 }; |
3417 | 3434 |
3418 | 3435 |
(...skipping 4612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8031 */ | 8048 */ |
8032 | 8049 |
8033 | 8050 |
8034 } // namespace v8 | 8051 } // namespace v8 |
8035 | 8052 |
8036 | 8053 |
8037 #undef TYPE_CHECK | 8054 #undef TYPE_CHECK |
8038 | 8055 |
8039 | 8056 |
8040 #endif // V8_H_ | 8057 #endif // V8_H_ |
OLD | NEW |