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 3333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3344 Promise(); | 3344 Promise(); |
3345 static void CheckCast(Value* obj); | 3345 static void CheckCast(Value* obj); |
3346 }; | 3346 }; |
3347 | 3347 |
3348 | 3348 |
3349 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT | 3349 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
3350 // The number of required internal fields can be defined by embedder. | 3350 // The number of required internal fields can be defined by embedder. |
3351 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 | 3351 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
3352 #endif | 3352 #endif |
3353 | 3353 |
| 3354 |
| 3355 enum class ArrayBufferCreationMode { kInternalized, kExternalized }; |
| 3356 |
| 3357 |
3354 /** | 3358 /** |
3355 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). | 3359 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
3356 * This API is experimental and may change significantly. | 3360 * This API is experimental and may change significantly. |
3357 */ | 3361 */ |
3358 class V8_EXPORT ArrayBuffer : public Object { | 3362 class V8_EXPORT ArrayBuffer : public Object { |
3359 public: | 3363 public: |
3360 /** | 3364 /** |
3361 * Allocator that V8 uses to allocate |ArrayBuffer|'s memory. | 3365 * Allocator that V8 uses to allocate |ArrayBuffer|'s memory. |
3362 * The allocator is a global V8 setting. It should be set with | 3366 * The allocator is a global V8 setting. It should be set with |
3363 * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer. | 3367 * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3419 /** | 3423 /** |
3420 * Create a new ArrayBuffer. Allocate |byte_length| bytes. | 3424 * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
3421 * Allocated memory will be owned by a created ArrayBuffer and | 3425 * Allocated memory will be owned by a created ArrayBuffer and |
3422 * will be deallocated when it is garbage-collected, | 3426 * will be deallocated when it is garbage-collected, |
3423 * unless the object is externalized. | 3427 * unless the object is externalized. |
3424 */ | 3428 */ |
3425 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); | 3429 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); |
3426 | 3430 |
3427 /** | 3431 /** |
3428 * Create a new ArrayBuffer over an existing memory block. | 3432 * Create a new ArrayBuffer over an existing memory block. |
3429 * The created array buffer is immediately in externalized state. | 3433 * The created array buffer is by default immediately in externalized state. |
3430 * The memory block will not be reclaimed when a created ArrayBuffer | 3434 * The memory block will not be reclaimed when a created ArrayBuffer |
3431 * is garbage-collected. | 3435 * is garbage-collected. |
3432 */ | 3436 */ |
3433 static Local<ArrayBuffer> New(Isolate* isolate, void* data, | 3437 static Local<ArrayBuffer> New( |
3434 size_t byte_length); | 3438 Isolate* isolate, void* data, size_t byte_length, |
| 3439 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); |
3435 | 3440 |
3436 /** | 3441 /** |
3437 * Returns true if ArrayBuffer is extrenalized, that is, does not | 3442 * Returns true if ArrayBuffer is extrenalized, that is, does not |
3438 * own its memory block. | 3443 * own its memory block. |
3439 */ | 3444 */ |
3440 bool IsExternal() const; | 3445 bool IsExternal() const; |
3441 | 3446 |
3442 /** | 3447 /** |
3443 * Returns true if this ArrayBuffer may be neutered. | 3448 * Returns true if this ArrayBuffer may be neutered. |
3444 */ | 3449 */ |
(...skipping 11 matching lines...) Expand all Loading... |
3456 * Make this ArrayBuffer external. The pointer to underlying memory block | 3461 * Make this ArrayBuffer external. The pointer to underlying memory block |
3457 * and byte length are returned as |Contents| structure. After ArrayBuffer | 3462 * and byte length are returned as |Contents| structure. After ArrayBuffer |
3458 * had been etxrenalized, it does no longer owns the memory block. The caller | 3463 * had been etxrenalized, it does no longer owns the memory block. The caller |
3459 * should take steps to free memory when it is no longer needed. | 3464 * should take steps to free memory when it is no longer needed. |
3460 * | 3465 * |
3461 * The memory block is guaranteed to be allocated with |Allocator::Allocate| | 3466 * The memory block is guaranteed to be allocated with |Allocator::Allocate| |
3462 * that has been set with V8::SetArrayBufferAllocator. | 3467 * that has been set with V8::SetArrayBufferAllocator. |
3463 */ | 3468 */ |
3464 Contents Externalize(); | 3469 Contents Externalize(); |
3465 | 3470 |
| 3471 /** |
| 3472 * Get a pointer to the ArrayBuffer's underlying memory block without |
| 3473 * externalizing it. If the ArrayBuffer is not externalized, this pointer |
| 3474 * will become invalid as soon as the ArrayBuffer became garbage collected. |
| 3475 * |
| 3476 * The embedder should make sure to hold a strong reference to the |
| 3477 * ArrayBuffer while accessing this pointer. |
| 3478 * |
| 3479 * The memory block is guaranteed to be allocated with |Allocator::Allocate|. |
| 3480 */ |
| 3481 Contents GetContents(); |
| 3482 |
3466 V8_INLINE static ArrayBuffer* Cast(Value* obj); | 3483 V8_INLINE static ArrayBuffer* Cast(Value* obj); |
3467 | 3484 |
3468 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; | 3485 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
3469 | 3486 |
3470 private: | 3487 private: |
3471 ArrayBuffer(); | 3488 ArrayBuffer(); |
3472 static void CheckCast(Value* obj); | 3489 static void CheckCast(Value* obj); |
3473 }; | 3490 }; |
3474 | 3491 |
3475 | 3492 |
(...skipping 4655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8131 */ | 8148 */ |
8132 | 8149 |
8133 | 8150 |
8134 } // namespace v8 | 8151 } // namespace v8 |
8135 | 8152 |
8136 | 8153 |
8137 #undef TYPE_CHECK | 8154 #undef TYPE_CHECK |
8138 | 8155 |
8139 | 8156 |
8140 #endif // V8_H_ | 8157 #endif // V8_H_ |
OLD | NEW |