Chromium Code Reviews| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } // namespace internal | 152 } // namespace internal |
| 153 | 153 |
| 154 | 154 |
| 155 // --- Handles --- | 155 // --- Handles --- |
| 156 | 156 |
| 157 #define TYPE_CHECK(T, S) \ | 157 #define TYPE_CHECK(T, S) \ |
| 158 while (false) { \ | 158 while (false) { \ |
| 159 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ | 159 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ |
| 160 } | 160 } |
| 161 | 161 |
| 162 | |
| 163 /** | 162 /** |
| 164 * An object reference managed by the v8 garbage collector. | 163 * An object reference managed by the v8 garbage collector. |
| 165 * | 164 * |
| 166 * All objects returned from v8 have to be tracked by the garbage | 165 * All objects returned from v8 have to be tracked by the garbage |
| 167 * collector so that it knows that the objects are still alive. Also, | 166 * collector so that it knows that the objects are still alive. Also, |
| 168 * because the garbage collector may move objects, it is unsafe to | 167 * because the garbage collector may move objects, it is unsafe to |
| 169 * point directly to an object. Instead, all objects are stored in | 168 * point directly to an object. Instead, all objects are stored in |
| 170 * handles which are known by the garbage collector and updated | 169 * handles which are known by the garbage collector and updated |
| 171 * whenever an object moves. Handles should always be passed by value | 170 * whenever an object moves. Handles should always be passed by value |
| 172 * (except in cases like out-parameters) and they should never be | 171 * (except in cases like out-parameters) and they should never be |
| 173 * allocated on the heap. | 172 * allocated on the heap. |
| 174 * | 173 * |
| 175 * There are two types of handles: local and persistent handles. | 174 * There are two types of handles: local and persistent handles. |
| 175 * | |
| 176 * Local handles are light-weight and transient and typically used in | 176 * Local handles are light-weight and transient and typically used in |
| 177 * local operations. They are managed by HandleScopes. Persistent | 177 * local operations. They are managed by HandleScopes, which means that a |
| 178 * handles can be used when storing objects across several independent | 178 * HandleScope must exist on the stack when they are created, and that they are |
|
Franzi
2017/03/29 08:40:45
I would change the wording a little bit:
They are
Anna Henningsen
2017/03/29 18:02:41
Done.
| |
| 179 * operations and have to be explicitly deallocated when they're no | 179 * only valid inside of the HandleScope active during their creation. |
| 180 * For passing a local handle to an outer HandleScope, a EscapableHandleScope | |
|
Franzi
2017/03/29 08:40:45
an EscapableH....
Anna Henningsen
2017/03/29 18:02:41
Done.
| |
| 181 * and its Escape() method need to be used. | |
|
Franzi
2017/03/29 08:40:45
Must instead of need
Anna Henningsen
2017/03/29 18:02:41
Done.
| |
| 182 * | |
| 183 * Persistent handles can be used when storing objects across several | |
| 184 * independent operations and have to be explicitly deallocated when they're no | |
| 180 * longer used. | 185 * longer used. |
| 181 * | 186 * |
| 182 * It is safe to extract the object stored in the handle by | 187 * It is safe to extract the object stored in the handle by |
| 183 * dereferencing the handle (for instance, to extract the Object* from | 188 * dereferencing the handle (for instance, to extract the Object* from |
| 184 * a Local<Object>); the value will still be governed by a handle | 189 * a Local<Object>); the value will still be governed by a handle |
| 185 * behind the scenes and the same rules apply to these values as to | 190 * behind the scenes and the same rules apply to these values as to |
| 186 * their handles. | 191 * their handles. |
| 187 */ | 192 */ |
| 188 template <class T> | 193 template <class T> |
| 189 class Local { | 194 class Local { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 template <class S> | 252 template <class S> |
| 248 V8_INLINE bool operator!=(const Local<S>& that) const { | 253 V8_INLINE bool operator!=(const Local<S>& that) const { |
| 249 return !operator==(that); | 254 return !operator==(that); |
| 250 } | 255 } |
| 251 | 256 |
| 252 template <class S> V8_INLINE bool operator!=( | 257 template <class S> V8_INLINE bool operator!=( |
| 253 const Persistent<S>& that) const { | 258 const Persistent<S>& that) const { |
| 254 return !operator==(that); | 259 return !operator==(that); |
| 255 } | 260 } |
| 256 | 261 |
| 262 /** | |
| 263 * Casts a handle to a subclass, e.g. Local<Value> to Local<Object>. | |
|
Franzi
2017/03/29 08:40:45
We are probably not consistent in this doc, but I'
Anna Henningsen
2017/03/29 18:02:41
Done.
| |
| 264 * This is only valid if the handle actually refers to a value of the | |
|
Franzi
2017/03/29 08:40:45
valid? The method throws otherwise, right?
Anna Henningsen
2017/03/29 18:02:41
With V8_ENABLE_CHECKS it crashes, otherwise it fai
| |
| 265 * target type. | |
| 266 */ | |
| 257 template <class S> V8_INLINE static Local<T> Cast(Local<S> that) { | 267 template <class S> V8_INLINE static Local<T> Cast(Local<S> that) { |
| 258 #ifdef V8_ENABLE_CHECKS | 268 #ifdef V8_ENABLE_CHECKS |
| 259 // If we're going to perform the type check then we have to check | 269 // If we're going to perform the type check then we have to check |
| 260 // that the handle isn't empty before doing the checked cast. | 270 // that the handle isn't empty before doing the checked cast. |
| 261 if (that.IsEmpty()) return Local<T>(); | 271 if (that.IsEmpty()) return Local<T>(); |
| 262 #endif | 272 #endif |
| 263 return Local<T>(T::Cast(*that)); | 273 return Local<T>(T::Cast(*that)); |
| 264 } | 274 } |
| 265 | 275 |
| 276 /** | |
| 277 * Calling this is equivalent to Local<S>::Cast(). | |
|
Franzi
2017/03/29 08:40:45
How about
Alias for ...?
Anna Henningsen
2017/03/29 18:02:41
It seems a bit odd to me to call a bound method an
| |
| 278 * In particular, this is only valid if the handle actually refers to a value | |
| 279 * of the target type. | |
| 280 */ | |
| 266 template <class S> | 281 template <class S> |
| 267 V8_INLINE Local<S> As() const { | 282 V8_INLINE Local<S> As() const { |
| 268 return Local<S>::Cast(*this); | 283 return Local<S>::Cast(*this); |
| 269 } | 284 } |
| 270 | 285 |
| 271 /** | 286 /** |
| 272 * Create a local handle for the content of another handle. | 287 * Create a local handle for the content of another handle. |
| 273 * The referee is kept alive by the local handle even when | 288 * The referee is kept alive by the local handle even when |
| 274 * the original handle is destroyed/disposed. | 289 * the original handle is destroyed/disposed. |
| 275 */ | 290 */ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 public: | 347 public: |
| 333 V8_INLINE MaybeLocal() : val_(nullptr) {} | 348 V8_INLINE MaybeLocal() : val_(nullptr) {} |
| 334 template <class S> | 349 template <class S> |
| 335 V8_INLINE MaybeLocal(Local<S> that) | 350 V8_INLINE MaybeLocal(Local<S> that) |
| 336 : val_(reinterpret_cast<T*>(*that)) { | 351 : val_(reinterpret_cast<T*>(*that)) { |
| 337 TYPE_CHECK(T, S); | 352 TYPE_CHECK(T, S); |
| 338 } | 353 } |
| 339 | 354 |
| 340 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } | 355 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } |
| 341 | 356 |
| 357 /** | |
| 358 * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty, | |
| 359 * |false| is returned and |out| is left untouched. | |
| 360 */ | |
| 342 template <class S> | 361 template <class S> |
| 343 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { | 362 V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { |
| 344 out->val_ = IsEmpty() ? nullptr : this->val_; | 363 out->val_ = IsEmpty() ? nullptr : this->val_; |
| 345 return !IsEmpty(); | 364 return !IsEmpty(); |
| 346 } | 365 } |
| 347 | 366 |
| 348 // Will crash if the MaybeLocal<> is empty. | 367 /** |
| 368 * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty, | |
| 369 * V8 will crash the process. | |
| 370 */ | |
| 349 V8_INLINE Local<T> ToLocalChecked(); | 371 V8_INLINE Local<T> ToLocalChecked(); |
| 350 | 372 |
| 373 /** | |
| 374 * Converts this MaybeLocal<> to a Local<>, using a default value if this | |
| 375 * MaybeLocal<> is empty. | |
| 376 */ | |
| 351 template <class S> | 377 template <class S> |
| 352 V8_INLINE Local<S> FromMaybe(Local<S> default_value) const { | 378 V8_INLINE Local<S> FromMaybe(Local<S> default_value) const { |
| 353 return IsEmpty() ? default_value : Local<S>(val_); | 379 return IsEmpty() ? default_value : Local<S>(val_); |
| 354 } | 380 } |
| 355 | 381 |
| 356 private: | 382 private: |
| 357 T* val_; | 383 T* val_; |
| 358 }; | 384 }; |
| 359 | 385 |
| 360 | 386 /** |
| 361 // Eternal handles are set-once handles that live for the life of the isolate. | 387 * Eternal handles are set-once handles that live for the lifetime of the |
| 388 * isolate. | |
| 389 */ | |
| 362 template <class T> class Eternal { | 390 template <class T> class Eternal { |
| 363 public: | 391 public: |
| 364 V8_INLINE Eternal() : val_(nullptr) {} | 392 V8_INLINE Eternal() : val_(nullptr) {} |
| 365 template <class S> | 393 template <class S> |
| 366 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) { | 394 V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : val_(nullptr) { |
| 367 Set(isolate, handle); | 395 Set(isolate, handle); |
| 368 } | 396 } |
| 369 // Can only be safely called if already set. | 397 // Can only be safely called if already set. |
| 370 V8_INLINE Local<T> Get(Isolate* isolate) const; | 398 V8_INLINE Local<T> Get(Isolate* isolate) const; |
| 371 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } | 399 V8_INLINE bool IsEmpty() const { return val_ == nullptr; } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 // will pass the first two internal fields back to the callback, kFinalizer | 459 // will pass the first two internal fields back to the callback, kFinalizer |
| 432 // will pass a void* parameter back, but is invoked before the object is | 460 // will pass a void* parameter back, but is invoked before the object is |
| 433 // actually collected, so it can be resurrected. In the last case, it is not | 461 // actually collected, so it can be resurrected. In the last case, it is not |
| 434 // possible to request a second pass callback. | 462 // possible to request a second pass callback. |
| 435 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; | 463 enum class WeakCallbackType { kParameter, kInternalFields, kFinalizer }; |
| 436 | 464 |
| 437 /** | 465 /** |
| 438 * An object reference that is independent of any handle scope. Where | 466 * An object reference that is independent of any handle scope. Where |
| 439 * a Local handle only lives as long as the HandleScope in which it was | 467 * a Local handle only lives as long as the HandleScope in which it was |
| 440 * allocated, a PersistentBase handle remains valid until it is explicitly | 468 * allocated, a PersistentBase handle remains valid until it is explicitly |
| 441 * disposed. | 469 * disposed using Reset(). |
| 442 * | 470 * |
| 443 * A persistent handle contains a reference to a storage cell within | 471 * A persistent handle contains a reference to a storage cell within |
| 444 * the v8 engine which holds an object value and which is updated by | 472 * the V8 engine which holds an object value and which is updated by |
| 445 * the garbage collector whenever the object is moved. A new storage | 473 * the garbage collector whenever the object is moved. A new storage |
| 446 * cell can be created using the constructor or PersistentBase::Reset and | 474 * cell can be created using the constructor or PersistentBase::Reset and |
| 447 * existing handles can be disposed using PersistentBase::Reset. | 475 * existing handles can be disposed using PersistentBase::Reset. |
| 448 * | 476 * |
| 449 */ | 477 */ |
| 450 template <class T> class PersistentBase { | 478 template <class T> class PersistentBase { |
| 451 public: | 479 public: |
| 452 /** | 480 /** |
| 453 * If non-empty, destroy the underlying storage cell | 481 * If non-empty, destroy the underlying storage cell |
| 454 * IsEmpty() will return true after this call. | 482 * IsEmpty() will return true after this call. |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 EscapableHandleScope(const EscapableHandleScope&) = delete; | 920 EscapableHandleScope(const EscapableHandleScope&) = delete; |
| 893 void operator=(const EscapableHandleScope&) = delete; | 921 void operator=(const EscapableHandleScope&) = delete; |
| 894 void* operator new(size_t size); | 922 void* operator new(size_t size); |
| 895 void operator delete(void*, size_t); | 923 void operator delete(void*, size_t); |
| 896 | 924 |
| 897 private: | 925 private: |
| 898 internal::Object** Escape(internal::Object** escape_value); | 926 internal::Object** Escape(internal::Object** escape_value); |
| 899 internal::Object** escape_slot_; | 927 internal::Object** escape_slot_; |
| 900 }; | 928 }; |
| 901 | 929 |
| 930 /** | |
| 931 * A SealHandleScope acts like a handle scope in which no handle allocations | |
| 932 * are allowed, which can be useful for debugging handle leaks. | |
|
Franzi
2017/03/29 08:40:45
allowed. It can be useful...
Anna Henningsen
2017/03/29 18:02:41
Done.
| |
| 933 * Handles can be allocated within inner normal HandleScopes. | |
| 934 */ | |
| 902 class V8_EXPORT SealHandleScope { | 935 class V8_EXPORT SealHandleScope { |
| 903 public: | 936 public: |
| 904 SealHandleScope(Isolate* isolate); | 937 SealHandleScope(Isolate* isolate); |
| 905 ~SealHandleScope(); | 938 ~SealHandleScope(); |
| 906 | 939 |
| 907 SealHandleScope(const SealHandleScope&) = delete; | 940 SealHandleScope(const SealHandleScope&) = delete; |
| 908 void operator=(const SealHandleScope&) = delete; | 941 void operator=(const SealHandleScope&) = delete; |
| 909 void* operator new(size_t size); | 942 void* operator new(size_t size); |
| 910 void operator delete(void*, size_t); | 943 void operator delete(void*, size_t); |
| 911 | 944 |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1356 Local<Context> context, StreamedSource* source, | 1389 Local<Context> context, StreamedSource* source, |
| 1357 Local<String> full_source_string, const ScriptOrigin& origin); | 1390 Local<String> full_source_string, const ScriptOrigin& origin); |
| 1358 | 1391 |
| 1359 /** | 1392 /** |
| 1360 * Return a version tag for CachedData for the current V8 version & flags. | 1393 * Return a version tag for CachedData for the current V8 version & flags. |
| 1361 * | 1394 * |
| 1362 * This value is meant only for determining whether a previously generated | 1395 * This value is meant only for determining whether a previously generated |
| 1363 * CachedData instance is still valid; the tag has no other meaing. | 1396 * CachedData instance is still valid; the tag has no other meaing. |
| 1364 * | 1397 * |
| 1365 * Background: The data carried by CachedData may depend on the exact | 1398 * Background: The data carried by CachedData may depend on the exact |
| 1366 * V8 version number or currently compiler flags. This means when | 1399 * V8 version number or current compiler flags. This means that when |
| 1367 * persisting CachedData, the embedder must take care to not pass in | 1400 * persisting CachedData, the embedder must take care to not pass in |
| 1368 * data from another V8 version, or the same version with different | 1401 * data from another V8 version, or the same version with different |
| 1369 * features enabled. | 1402 * features enabled. |
| 1370 * | 1403 * |
| 1371 * The easiest way to do so is to clear the embedder's cache on any | 1404 * The easiest way to do so is to clear the embedder's cache on any |
| 1372 * such change. | 1405 * such change. |
| 1373 * | 1406 * |
| 1374 * Alternatively, this tag can be stored alongside the cached data and | 1407 * Alternatively, this tag can be stored alongside the cached data and |
| 1375 * compared when it is being used. | 1408 * compared when it is being used. |
| 1376 */ | 1409 */ |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1676 * WARNING: This API is under development, and changes (including incompatible | 1709 * WARNING: This API is under development, and changes (including incompatible |
| 1677 * changes to the API or wire format) may occur without notice until this | 1710 * changes to the API or wire format) may occur without notice until this |
| 1678 * warning is removed. | 1711 * warning is removed. |
| 1679 */ | 1712 */ |
| 1680 class V8_EXPORT ValueSerializer { | 1713 class V8_EXPORT ValueSerializer { |
| 1681 public: | 1714 public: |
| 1682 class V8_EXPORT Delegate { | 1715 class V8_EXPORT Delegate { |
| 1683 public: | 1716 public: |
| 1684 virtual ~Delegate() {} | 1717 virtual ~Delegate() {} |
| 1685 | 1718 |
| 1686 /* | 1719 /** |
| 1687 * Handles the case where a DataCloneError would be thrown in the structured | 1720 * Handles the case where a DataCloneError would be thrown in the structured |
| 1688 * clone spec. Other V8 embedders may throw some other appropriate exception | 1721 * clone spec. Other V8 embedders may throw some other appropriate exception |
| 1689 * type. | 1722 * type. |
| 1690 */ | 1723 */ |
| 1691 virtual void ThrowDataCloneError(Local<String> message) = 0; | 1724 virtual void ThrowDataCloneError(Local<String> message) = 0; |
| 1692 | 1725 |
| 1693 /* | 1726 /** |
| 1694 * The embedder overrides this method to write some kind of host object, if | 1727 * The embedder overrides this method to write some kind of host object, if |
| 1695 * possible. If not, a suitable exception should be thrown and | 1728 * possible. If not, a suitable exception should be thrown and |
| 1696 * Nothing<bool>() returned. | 1729 * Nothing<bool>() returned. |
| 1697 */ | 1730 */ |
| 1698 virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object); | 1731 virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object); |
| 1699 | 1732 |
| 1700 /* | 1733 /** |
| 1701 * Called when the ValueSerializer is going to serialize a | 1734 * Called when the ValueSerializer is going to serialize a |
| 1702 * SharedArrayBuffer object. The embedder must return an ID for the | 1735 * SharedArrayBuffer object. The embedder must return an ID for the |
| 1703 * object, using the same ID if this SharedArrayBuffer has already been | 1736 * object, using the same ID if this SharedArrayBuffer has already been |
| 1704 * serialized in this buffer. When deserializing, this ID will be passed to | 1737 * serialized in this buffer. When deserializing, this ID will be passed to |
| 1705 * ValueDeserializer::TransferSharedArrayBuffer as |transfer_id|. | 1738 * ValueDeserializer::TransferSharedArrayBuffer as |transfer_id|. |
| 1706 * | 1739 * |
| 1707 * If the object cannot be serialized, an | 1740 * If the object cannot be serialized, an |
| 1708 * exception should be thrown and Nothing<uint32_t>() returned. | 1741 * exception should be thrown and Nothing<uint32_t>() returned. |
| 1709 */ | 1742 */ |
| 1710 virtual Maybe<uint32_t> GetSharedArrayBufferId( | 1743 virtual Maybe<uint32_t> GetSharedArrayBufferId( |
| 1711 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer); | 1744 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer); |
| 1712 | 1745 |
| 1713 virtual Maybe<uint32_t> GetWasmModuleTransferId( | 1746 virtual Maybe<uint32_t> GetWasmModuleTransferId( |
| 1714 Isolate* isolate, Local<WasmCompiledModule> module); | 1747 Isolate* isolate, Local<WasmCompiledModule> module); |
| 1715 /* | 1748 /** |
| 1716 * Allocates memory for the buffer of at least the size provided. The actual | 1749 * Allocates memory for the buffer of at least the size provided. The actual |
| 1717 * size (which may be greater or equal) is written to |actual_size|. If no | 1750 * size (which may be greater or equal) is written to |actual_size|. If no |
| 1718 * buffer has been allocated yet, nullptr will be provided. | 1751 * buffer has been allocated yet, nullptr will be provided. |
| 1719 * | 1752 * |
| 1720 * If the memory cannot be allocated, nullptr should be returned. | 1753 * If the memory cannot be allocated, nullptr should be returned. |
| 1721 * |actual_size| will be ignored. It is assumed that |old_buffer| is still | 1754 * |actual_size| will be ignored. It is assumed that |old_buffer| is still |
| 1722 * valid in this case and has not been modified. | 1755 * valid in this case and has not been modified. |
| 1723 */ | 1756 */ |
| 1724 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size, | 1757 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size, |
| 1725 size_t* actual_size); | 1758 size_t* actual_size); |
| 1726 | 1759 |
| 1727 /* | 1760 /** |
| 1728 * Frees a buffer allocated with |ReallocateBufferMemory|. | 1761 * Frees a buffer allocated with |ReallocateBufferMemory|. |
| 1729 */ | 1762 */ |
| 1730 virtual void FreeBufferMemory(void* buffer); | 1763 virtual void FreeBufferMemory(void* buffer); |
| 1731 }; | 1764 }; |
| 1732 | 1765 |
| 1733 explicit ValueSerializer(Isolate* isolate); | 1766 explicit ValueSerializer(Isolate* isolate); |
| 1734 ValueSerializer(Isolate* isolate, Delegate* delegate); | 1767 ValueSerializer(Isolate* isolate, Delegate* delegate); |
| 1735 ~ValueSerializer(); | 1768 ~ValueSerializer(); |
| 1736 | 1769 |
| 1737 /* | 1770 /** |
| 1738 * Writes out a header, which includes the format version. | 1771 * Writes out a header, which includes the format version. |
| 1739 */ | 1772 */ |
| 1740 void WriteHeader(); | 1773 void WriteHeader(); |
| 1741 | 1774 |
| 1742 /* | 1775 /** |
| 1743 * Serializes a JavaScript value into the buffer. | 1776 * Serializes a JavaScript value into the buffer. |
| 1744 */ | 1777 */ |
| 1745 V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context, | 1778 V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context, |
| 1746 Local<Value> value); | 1779 Local<Value> value); |
| 1747 | 1780 |
| 1748 /* | 1781 /** |
| 1749 * Returns the stored data. This serializer should not be used once the buffer | 1782 * Returns the stored data. This serializer should not be used once the buffer |
| 1750 * is released. The contents are undefined if a previous write has failed. | 1783 * is released. The contents are undefined if a previous write has failed. |
| 1751 */ | 1784 */ |
| 1752 V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer()); | 1785 V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer()); |
| 1753 | 1786 |
| 1754 /* | 1787 /** |
| 1755 * Returns the stored data (allocated using the delegate's | 1788 * Returns the stored data (allocated using the delegate's |
| 1756 * AllocateBufferMemory) and its size. This serializer should not be used once | 1789 * AllocateBufferMemory) and its size. This serializer should not be used once |
| 1757 * the buffer is released. The contents are undefined if a previous write has | 1790 * the buffer is released. The contents are undefined if a previous write has |
| 1758 * failed. | 1791 * failed. |
| 1759 */ | 1792 */ |
| 1760 V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release(); | 1793 V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release(); |
| 1761 | 1794 |
| 1762 /* | 1795 /** |
| 1763 * Marks an ArrayBuffer as havings its contents transferred out of band. | 1796 * Marks an ArrayBuffer as havings its contents transferred out of band. |
| 1764 * Pass the corresponding ArrayBuffer in the deserializing context to | 1797 * Pass the corresponding ArrayBuffer in the deserializing context to |
| 1765 * ValueDeserializer::TransferArrayBuffer. | 1798 * ValueDeserializer::TransferArrayBuffer. |
| 1766 */ | 1799 */ |
| 1767 void TransferArrayBuffer(uint32_t transfer_id, | 1800 void TransferArrayBuffer(uint32_t transfer_id, |
| 1768 Local<ArrayBuffer> array_buffer); | 1801 Local<ArrayBuffer> array_buffer); |
| 1769 | 1802 |
| 1770 /* | 1803 /** |
| 1771 * Similar to TransferArrayBuffer, but for SharedArrayBuffer. | 1804 * Similar to TransferArrayBuffer, but for SharedArrayBuffer. |
| 1772 */ | 1805 */ |
| 1773 V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId", | 1806 V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId", |
| 1774 void TransferSharedArrayBuffer( | 1807 void TransferSharedArrayBuffer( |
| 1775 uint32_t transfer_id, | 1808 uint32_t transfer_id, |
| 1776 Local<SharedArrayBuffer> shared_array_buffer)); | 1809 Local<SharedArrayBuffer> shared_array_buffer)); |
| 1777 | 1810 |
| 1778 /* | 1811 /** |
| 1779 * Indicate whether to treat ArrayBufferView objects as host objects, | 1812 * Indicate whether to treat ArrayBufferView objects as host objects, |
| 1780 * i.e. pass them to Delegate::WriteHostObject. This should not be | 1813 * i.e. pass them to Delegate::WriteHostObject. This should not be |
| 1781 * called when no Delegate was passed. | 1814 * called when no Delegate was passed. |
| 1782 * | 1815 * |
| 1783 * The default is not to treat ArrayBufferViews as host objects. | 1816 * The default is not to treat ArrayBufferViews as host objects. |
| 1784 */ | 1817 */ |
| 1785 void SetTreatArrayBufferViewsAsHostObjects(bool mode); | 1818 void SetTreatArrayBufferViewsAsHostObjects(bool mode); |
| 1786 | 1819 |
| 1787 /* | 1820 /** |
| 1788 * Write raw data in various common formats to the buffer. | 1821 * Write raw data in various common formats to the buffer. |
| 1789 * Note that integer types are written in base-128 varint format, not with a | 1822 * Note that integer types are written in base-128 varint format, not with a |
| 1790 * binary copy. For use during an override of Delegate::WriteHostObject. | 1823 * binary copy. For use during an override of Delegate::WriteHostObject. |
| 1791 */ | 1824 */ |
| 1792 void WriteUint32(uint32_t value); | 1825 void WriteUint32(uint32_t value); |
| 1793 void WriteUint64(uint64_t value); | 1826 void WriteUint64(uint64_t value); |
| 1794 void WriteDouble(double value); | 1827 void WriteDouble(double value); |
| 1795 void WriteRawBytes(const void* source, size_t length); | 1828 void WriteRawBytes(const void* source, size_t length); |
| 1796 | 1829 |
| 1797 private: | 1830 private: |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1809 * WARNING: This API is under development, and changes (including incompatible | 1842 * WARNING: This API is under development, and changes (including incompatible |
| 1810 * changes to the API or wire format) may occur without notice until this | 1843 * changes to the API or wire format) may occur without notice until this |
| 1811 * warning is removed. | 1844 * warning is removed. |
| 1812 */ | 1845 */ |
| 1813 class V8_EXPORT ValueDeserializer { | 1846 class V8_EXPORT ValueDeserializer { |
| 1814 public: | 1847 public: |
| 1815 class V8_EXPORT Delegate { | 1848 class V8_EXPORT Delegate { |
| 1816 public: | 1849 public: |
| 1817 virtual ~Delegate() {} | 1850 virtual ~Delegate() {} |
| 1818 | 1851 |
| 1819 /* | 1852 /** |
| 1820 * The embedder overrides this method to read some kind of host object, if | 1853 * The embedder overrides this method to read some kind of host object, if |
| 1821 * possible. If not, a suitable exception should be thrown and | 1854 * possible. If not, a suitable exception should be thrown and |
| 1822 * MaybeLocal<Object>() returned. | 1855 * MaybeLocal<Object>() returned. |
| 1823 */ | 1856 */ |
| 1824 virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate); | 1857 virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate); |
| 1825 | 1858 |
| 1826 /* | 1859 /** |
| 1827 * Get a WasmCompiledModule given a transfer_id previously provided | 1860 * Get a WasmCompiledModule given a transfer_id previously provided |
| 1828 * by ValueSerializer::GetWasmModuleTransferId | 1861 * by ValueSerializer::GetWasmModuleTransferId |
| 1829 */ | 1862 */ |
| 1830 virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId( | 1863 virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId( |
| 1831 Isolate* isolate, uint32_t transfer_id); | 1864 Isolate* isolate, uint32_t transfer_id); |
| 1832 }; | 1865 }; |
| 1833 | 1866 |
| 1834 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size); | 1867 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size); |
| 1835 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size, | 1868 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size, |
| 1836 Delegate* delegate); | 1869 Delegate* delegate); |
| 1837 ~ValueDeserializer(); | 1870 ~ValueDeserializer(); |
| 1838 | 1871 |
| 1839 /* | 1872 /** |
| 1840 * Reads and validates a header (including the format version). | 1873 * Reads and validates a header (including the format version). |
| 1841 * May, for example, reject an invalid or unsupported wire format. | 1874 * May, for example, reject an invalid or unsupported wire format. |
| 1842 */ | 1875 */ |
| 1843 V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context); | 1876 V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context); |
| 1844 | 1877 |
| 1845 /* | 1878 /** |
| 1846 * Deserializes a JavaScript value from the buffer. | 1879 * Deserializes a JavaScript value from the buffer. |
| 1847 */ | 1880 */ |
| 1848 V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context); | 1881 V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context); |
| 1849 | 1882 |
| 1850 /* | 1883 /** |
| 1851 * Accepts the array buffer corresponding to the one passed previously to | 1884 * Accepts the array buffer corresponding to the one passed previously to |
| 1852 * ValueSerializer::TransferArrayBuffer. | 1885 * ValueSerializer::TransferArrayBuffer. |
| 1853 */ | 1886 */ |
| 1854 void TransferArrayBuffer(uint32_t transfer_id, | 1887 void TransferArrayBuffer(uint32_t transfer_id, |
| 1855 Local<ArrayBuffer> array_buffer); | 1888 Local<ArrayBuffer> array_buffer); |
| 1856 | 1889 |
| 1857 /* | 1890 /** |
| 1858 * Similar to TransferArrayBuffer, but for SharedArrayBuffer. | 1891 * Similar to TransferArrayBuffer, but for SharedArrayBuffer. |
| 1859 * The id is not necessarily in the same namespace as unshared ArrayBuffer | 1892 * The id is not necessarily in the same namespace as unshared ArrayBuffer |
| 1860 * objects. | 1893 * objects. |
| 1861 */ | 1894 */ |
| 1862 void TransferSharedArrayBuffer(uint32_t id, | 1895 void TransferSharedArrayBuffer(uint32_t id, |
| 1863 Local<SharedArrayBuffer> shared_array_buffer); | 1896 Local<SharedArrayBuffer> shared_array_buffer); |
| 1864 | 1897 |
| 1865 /* | 1898 /** |
| 1866 * Must be called before ReadHeader to enable support for reading the legacy | 1899 * Must be called before ReadHeader to enable support for reading the legacy |
| 1867 * wire format (i.e., which predates this being shipped). | 1900 * wire format (i.e., which predates this being shipped). |
| 1868 * | 1901 * |
| 1869 * Don't use this unless you need to read data written by previous versions of | 1902 * Don't use this unless you need to read data written by previous versions of |
| 1870 * blink::ScriptValueSerializer. | 1903 * blink::ScriptValueSerializer. |
| 1871 */ | 1904 */ |
| 1872 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format); | 1905 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format); |
| 1873 | 1906 |
| 1874 /* | 1907 /** |
| 1875 * Expect inline wasm in the data stream (rather than in-memory transfer) | 1908 * Expect inline wasm in the data stream (rather than in-memory transfer) |
| 1876 */ | 1909 */ |
| 1877 void SetExpectInlineWasm(bool allow_inline_wasm); | 1910 void SetExpectInlineWasm(bool allow_inline_wasm); |
| 1878 | 1911 |
| 1879 /* | 1912 /** |
| 1880 * Reads the underlying wire format version. Likely mostly to be useful to | 1913 * Reads the underlying wire format version. Likely mostly to be useful to |
| 1881 * legacy code reading old wire format versions. Must be called after | 1914 * legacy code reading old wire format versions. Must be called after |
| 1882 * ReadHeader. | 1915 * ReadHeader. |
| 1883 */ | 1916 */ |
| 1884 uint32_t GetWireFormatVersion() const; | 1917 uint32_t GetWireFormatVersion() const; |
| 1885 | 1918 |
| 1886 /* | 1919 /** |
| 1887 * Reads raw data in various common formats to the buffer. | 1920 * Reads raw data in various common formats to the buffer. |
| 1888 * Note that integer types are read in base-128 varint format, not with a | 1921 * Note that integer types are read in base-128 varint format, not with a |
| 1889 * binary copy. For use during an override of Delegate::ReadHostObject. | 1922 * binary copy. For use during an override of Delegate::ReadHostObject. |
| 1890 */ | 1923 */ |
| 1891 V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value); | 1924 V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value); |
| 1892 V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value); | 1925 V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value); |
| 1893 V8_WARN_UNUSED_RESULT bool ReadDouble(double* value); | 1926 V8_WARN_UNUSED_RESULT bool ReadDouble(double* value); |
| 1894 V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data); | 1927 V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data); |
| 1895 | 1928 |
| 1896 private: | 1929 private: |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2301 * unique. | 2334 * unique. |
| 2302 */ | 2335 */ |
| 2303 int GetIdentityHash(); | 2336 int GetIdentityHash(); |
| 2304 | 2337 |
| 2305 V8_INLINE static Name* Cast(Value* obj); | 2338 V8_INLINE static Name* Cast(Value* obj); |
| 2306 | 2339 |
| 2307 private: | 2340 private: |
| 2308 static void CheckCast(Value* obj); | 2341 static void CheckCast(Value* obj); |
| 2309 }; | 2342 }; |
| 2310 | 2343 |
| 2311 | 2344 /** |
| 2345 * A flag describing different modes of string creation. | |
| 2346 * The |kInternalized| flag acts as a hint that the string should be created | |
|
Franzi
2017/03/29 08:40:45
There's Doxygen syntax for enums. Can we use that?
Anna Henningsen
2017/03/29 18:02:41
Done, assuming you meant adding doc comments to th
| |
| 2347 * in the old generation heap space and be deduplicated if an identical string | |
| 2348 * already exists. | |
| 2349 * | |
| 2350 * Aside from performance implications there are no differences between the two | |
| 2351 * creation modes. | |
| 2352 */ | |
| 2312 enum class NewStringType { kNormal, kInternalized }; | 2353 enum class NewStringType { kNormal, kInternalized }; |
| 2313 | 2354 |
| 2314 | 2355 |
| 2315 /** | 2356 /** |
| 2316 * A JavaScript string value (ECMA-262, 4.3.17). | 2357 * A JavaScript string value (ECMA-262, 4.3.17). |
| 2317 */ | 2358 */ |
| 2318 class V8_EXPORT String : public Name { | 2359 class V8_EXPORT String : public Name { |
| 2319 public: | 2360 public: |
| 2320 static const int kMaxLength = (1 << 28) - 16; | 2361 static const int kMaxLength = (1 << 28) - 16; |
| 2321 | 2362 |
| 2322 enum Encoding { | 2363 enum Encoding { |
| 2323 UNKNOWN_ENCODING = 0x1, | 2364 UNKNOWN_ENCODING = 0x1, |
| 2324 TWO_BYTE_ENCODING = 0x0, | 2365 TWO_BYTE_ENCODING = 0x0, |
| 2325 ONE_BYTE_ENCODING = 0x8 | 2366 ONE_BYTE_ENCODING = 0x8 |
| 2326 }; | 2367 }; |
| 2327 /** | 2368 /** |
| 2328 * Returns the number of characters in this string. | 2369 * Returns the number of characters (UTF-16 code units) in this string. |
| 2329 */ | 2370 */ |
| 2330 int Length() const; | 2371 int Length() const; |
| 2331 | 2372 |
| 2332 /** | 2373 /** |
| 2333 * Returns the number of bytes in the UTF-8 encoded | 2374 * Returns the number of bytes in the UTF-8 encoded |
| 2334 * representation of this string. | 2375 * representation of this string. |
| 2335 */ | 2376 */ |
| 2336 int Utf8Length() const; | 2377 int Utf8Length() const; |
| 2337 | 2378 |
| 2338 /** | 2379 /** |
| 2339 * Returns whether this string is known to contain only one byte data. | 2380 * Returns whether this string is known to contain only one byte data, |
| 2381 * i.e. ISO-8859-1 code points. | |
| 2340 * Does not read the string. | 2382 * Does not read the string. |
| 2341 * False negatives are possible. | 2383 * False negatives are possible. |
| 2342 */ | 2384 */ |
| 2343 bool IsOneByte() const; | 2385 bool IsOneByte() const; |
| 2344 | 2386 |
| 2345 /** | 2387 /** |
| 2346 * Returns whether this string contain only one byte data. | 2388 * Returns whether this string contain only one byte data, |
| 2389 * i.e. ISO-8859-1 code points. | |
| 2347 * Will read the entire string in some cases. | 2390 * Will read the entire string in some cases. |
| 2348 */ | 2391 */ |
| 2349 bool ContainsOnlyOneByte() const; | 2392 bool ContainsOnlyOneByte() const; |
| 2350 | 2393 |
| 2351 /** | 2394 /** |
| 2352 * Write the contents of the string to an external buffer. | 2395 * Write the contents of the string to an external buffer. |
| 2353 * If no arguments are given, expects the buffer to be large | 2396 * If no arguments are given, expects the buffer to be large |
| 2354 * enough to hold the entire string and NULL terminator. Copies | 2397 * enough to hold the entire string and NULL terminator. Copies |
| 2355 * the contents of the string and the NULL terminator into the | 2398 * the contents of the string and the NULL terminator into the |
| 2356 * buffer. | 2399 * buffer. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2643 // Disallow copying and assigning. | 2686 // Disallow copying and assigning. |
| 2644 Utf8Value(const Utf8Value&) = delete; | 2687 Utf8Value(const Utf8Value&) = delete; |
| 2645 void operator=(const Utf8Value&) = delete; | 2688 void operator=(const Utf8Value&) = delete; |
| 2646 | 2689 |
| 2647 private: | 2690 private: |
| 2648 char* str_; | 2691 char* str_; |
| 2649 int length_; | 2692 int length_; |
| 2650 }; | 2693 }; |
| 2651 | 2694 |
| 2652 /** | 2695 /** |
| 2653 * Converts an object to a two-byte string. | 2696 * Converts an object to a two-byte (UTF-16-encoded) string. |
| 2654 * If conversion to a string fails (eg. due to an exception in the toString() | 2697 * If conversion to a string fails (eg. due to an exception in the toString() |
| 2655 * method of the object) then the length() method returns 0 and the * operator | 2698 * method of the object) then the length() method returns 0 and the * operator |
| 2656 * returns NULL. | 2699 * returns NULL. |
| 2657 */ | 2700 */ |
| 2658 class V8_EXPORT Value { | 2701 class V8_EXPORT Value { |
| 2659 public: | 2702 public: |
| 2660 explicit Value(Local<v8::Value> obj); | 2703 explicit Value(Local<v8::Value> obj); |
| 2661 ~Value(); | 2704 ~Value(); |
| 2662 uint16_t* operator*() { return str_; } | 2705 uint16_t* operator*() { return str_; } |
| 2663 const uint16_t* operator*() const { return str_; } | 2706 const uint16_t* operator*() const { return str_; } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2678 void VerifyExternalStringResource(ExternalStringResource* val) const; | 2721 void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 2679 static void CheckCast(v8::Value* obj); | 2722 static void CheckCast(v8::Value* obj); |
| 2680 }; | 2723 }; |
| 2681 | 2724 |
| 2682 | 2725 |
| 2683 /** | 2726 /** |
| 2684 * A JavaScript symbol (ECMA-262 edition 6) | 2727 * A JavaScript symbol (ECMA-262 edition 6) |
| 2685 */ | 2728 */ |
| 2686 class V8_EXPORT Symbol : public Name { | 2729 class V8_EXPORT Symbol : public Name { |
| 2687 public: | 2730 public: |
| 2688 // Returns the print name string of the symbol, or undefined if none. | 2731 /** |
| 2732 * Returns the print name string of the symbol, or undefined if none. | |
| 2733 */ | |
| 2689 Local<Value> Name() const; | 2734 Local<Value> Name() const; |
| 2690 | 2735 |
| 2691 // Create a symbol. If name is not empty, it will be used as the description. | 2736 /** |
| 2737 * Create a symbol. If name is not empty, it will be used as the description. | |
| 2738 */ | |
| 2692 static Local<Symbol> New(Isolate* isolate, | 2739 static Local<Symbol> New(Isolate* isolate, |
| 2693 Local<String> name = Local<String>()); | 2740 Local<String> name = Local<String>()); |
| 2694 | 2741 |
| 2695 // Access global symbol registry. | 2742 /** |
| 2696 // Note that symbols created this way are never collected, so | 2743 * Access global symbol registry. |
| 2697 // they should only be used for statically fixed properties. | 2744 * Note that symbols created this way are never collected, so |
| 2698 // Also, there is only one global name space for the names used as keys. | 2745 * they should only be used for statically fixed properties. |
| 2699 // To minimize the potential for clashes, use qualified names as keys. | 2746 * Also, there is only one global name space for the names used as keys. |
| 2747 * To minimize the potential for clashes, use qualified names as keys. | |
| 2748 */ | |
| 2700 static Local<Symbol> For(Isolate *isolate, Local<String> name); | 2749 static Local<Symbol> For(Isolate *isolate, Local<String> name); |
| 2701 | 2750 |
| 2702 // Retrieve a global symbol. Similar to |For|, but using a separate | 2751 /** |
| 2703 // registry that is not accessible by (and cannot clash with) JavaScript code. | 2752 * Retrieve a global symbol. Similar to |For|, but using a separate |
| 2753 * registry that is not accessible by (and cannot clash with) JavaScript code. | |
| 2754 */ | |
| 2704 static Local<Symbol> ForApi(Isolate *isolate, Local<String> name); | 2755 static Local<Symbol> ForApi(Isolate *isolate, Local<String> name); |
| 2705 | 2756 |
| 2706 // Well-known symbols | 2757 // Well-known symbols |
| 2707 static Local<Symbol> GetIterator(Isolate* isolate); | 2758 static Local<Symbol> GetIterator(Isolate* isolate); |
| 2708 static Local<Symbol> GetUnscopables(Isolate* isolate); | 2759 static Local<Symbol> GetUnscopables(Isolate* isolate); |
| 2709 static Local<Symbol> GetToPrimitive(Isolate* isolate); | 2760 static Local<Symbol> GetToPrimitive(Isolate* isolate); |
| 2710 static Local<Symbol> GetToStringTag(Isolate* isolate); | 2761 static Local<Symbol> GetToStringTag(Isolate* isolate); |
| 2711 static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate); | 2762 static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate); |
| 2712 | 2763 |
| 2713 V8_INLINE static Symbol* Cast(Value* obj); | 2764 V8_INLINE static Symbol* Cast(Value* obj); |
| 2714 | 2765 |
| 2715 private: | 2766 private: |
| 2716 Symbol(); | 2767 Symbol(); |
| 2717 static void CheckCast(Value* obj); | 2768 static void CheckCast(Value* obj); |
| 2718 }; | 2769 }; |
| 2719 | 2770 |
| 2720 | 2771 |
| 2721 /** | 2772 /** |
| 2722 * A private symbol | 2773 * A private symbol |
| 2723 * | 2774 * |
| 2724 * This is an experimental feature. Use at your own risk. | 2775 * This is an experimental feature. Use at your own risk. |
| 2725 */ | 2776 */ |
| 2726 class V8_EXPORT Private : public Data { | 2777 class V8_EXPORT Private : public Data { |
| 2727 public: | 2778 public: |
| 2728 // Returns the print name string of the private symbol, or undefined if none. | 2779 /** |
| 2780 * Returns the print name string of the private symbol, or undefined if none. | |
| 2781 */ | |
| 2729 Local<Value> Name() const; | 2782 Local<Value> Name() const; |
| 2730 | 2783 |
| 2731 // Create a private symbol. If name is not empty, it will be the description. | 2784 /** |
| 2785 * Create a private symbol. If name is not empty, it will be the description. | |
| 2786 */ | |
| 2732 static Local<Private> New(Isolate* isolate, | 2787 static Local<Private> New(Isolate* isolate, |
| 2733 Local<String> name = Local<String>()); | 2788 Local<String> name = Local<String>()); |
| 2734 | 2789 |
| 2735 // Retrieve a global private symbol. If a symbol with this name has not | 2790 /** |
| 2736 // been retrieved in the same isolate before, it is created. | 2791 * Retrieve a global private symbol. If a symbol with this name has not |
| 2737 // Note that private symbols created this way are never collected, so | 2792 * been retrieved in the same isolate before, it is created. |
| 2738 // they should only be used for statically fixed properties. | 2793 * Note that private symbols created this way are never collected, so |
| 2739 // Also, there is only one global name space for the names used as keys. | 2794 * they should only be used for statically fixed properties. |
| 2740 // To minimize the potential for clashes, use qualified names as keys, | 2795 * Also, there is only one global name space for the names used as keys. |
| 2741 // e.g., "Class#property". | 2796 * To minimize the potential for clashes, use qualified names as keys, |
| 2797 * e.g., "Class#property". | |
| 2798 */ | |
| 2742 static Local<Private> ForApi(Isolate* isolate, Local<String> name); | 2799 static Local<Private> ForApi(Isolate* isolate, Local<String> name); |
| 2743 | 2800 |
| 2744 private: | 2801 private: |
| 2745 Private(); | 2802 Private(); |
| 2746 }; | 2803 }; |
| 2747 | 2804 |
| 2748 | 2805 |
| 2749 /** | 2806 /** |
| 2750 * A JavaScript number value (ECMA-262, 4.3.20) | 2807 * A JavaScript number value (ECMA-262, 4.3.20) |
| 2751 */ | 2808 */ |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4056 | 4113 |
| 4057 /** | 4114 /** |
| 4058 * Free the memory block of size |length|, pointed to by |data|. | 4115 * Free the memory block of size |length|, pointed to by |data|. |
| 4059 * That memory is guaranteed to be previously allocated by |Allocate|. | 4116 * That memory is guaranteed to be previously allocated by |Allocate|. |
| 4060 */ | 4117 */ |
| 4061 virtual void Free(void* data, size_t length) = 0; | 4118 virtual void Free(void* data, size_t length) = 0; |
| 4062 | 4119 |
| 4063 /** | 4120 /** |
| 4064 * malloc/free based convenience allocator. | 4121 * malloc/free based convenience allocator. |
| 4065 * | 4122 * |
| 4066 * Caller takes ownership. | 4123 * Caller takes ownership, i.e. the returned object needs to be freed using |
| 4124 * |delete allocator| once it is no longer in use. | |
| 4067 */ | 4125 */ |
| 4068 static Allocator* NewDefaultAllocator(); | 4126 static Allocator* NewDefaultAllocator(); |
| 4069 }; | 4127 }; |
| 4070 | 4128 |
| 4071 /** | 4129 /** |
| 4072 * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| | 4130 * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
| 4073 * returns an instance of this class, populated, with a pointer to data | 4131 * returns an instance of this class, populated, with a pointer to data |
| 4074 * and byte length. | 4132 * and byte length. |
| 4075 * | 4133 * |
| 4076 * The Data pointer of ArrayBuffer::Contents is always allocated with | 4134 * The Data pointer of ArrayBuffer::Contents is always allocated with |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 4100 * Create a new ArrayBuffer. Allocate |byte_length| bytes. | 4158 * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 4101 * Allocated memory will be owned by a created ArrayBuffer and | 4159 * Allocated memory will be owned by a created ArrayBuffer and |
| 4102 * will be deallocated when it is garbage-collected, | 4160 * will be deallocated when it is garbage-collected, |
| 4103 * unless the object is externalized. | 4161 * unless the object is externalized. |
| 4104 */ | 4162 */ |
| 4105 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); | 4163 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); |
| 4106 | 4164 |
| 4107 /** | 4165 /** |
| 4108 * Create a new ArrayBuffer over an existing memory block. | 4166 * Create a new ArrayBuffer over an existing memory block. |
| 4109 * The created array buffer is by default immediately in externalized state. | 4167 * The created array buffer is by default immediately in externalized state. |
| 4110 * The memory block will not be reclaimed when a created ArrayBuffer | 4168 * In externalized state, the memory block will not be reclaimed when a |
| 4111 * is garbage-collected. | 4169 * created ArrayBuffer is garbage-collected. |
| 4170 * In internalized state, the memory block will be released using | |
| 4171 * |Allocator::Free| once all ArrayBuffers referencing it are collected by | |
| 4172 * the garbage collector. | |
| 4112 */ | 4173 */ |
| 4113 static Local<ArrayBuffer> New( | 4174 static Local<ArrayBuffer> New( |
| 4114 Isolate* isolate, void* data, size_t byte_length, | 4175 Isolate* isolate, void* data, size_t byte_length, |
| 4115 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); | 4176 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); |
| 4116 | 4177 |
| 4117 /** | 4178 /** |
| 4118 * Returns true if ArrayBuffer is externalized, that is, does not | 4179 * Returns true if ArrayBuffer is externalized, that is, does not |
| 4119 * own its memory block. | 4180 * own its memory block. |
| 4120 */ | 4181 */ |
| 4121 bool IsExternal() const; | 4182 bool IsExternal() const; |
| (...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6050 public: | 6111 public: |
| 6051 HeapStatistics(); | 6112 HeapStatistics(); |
| 6052 size_t total_heap_size() { return total_heap_size_; } | 6113 size_t total_heap_size() { return total_heap_size_; } |
| 6053 size_t total_heap_size_executable() { return total_heap_size_executable_; } | 6114 size_t total_heap_size_executable() { return total_heap_size_executable_; } |
| 6054 size_t total_physical_size() { return total_physical_size_; } | 6115 size_t total_physical_size() { return total_physical_size_; } |
| 6055 size_t total_available_size() { return total_available_size_; } | 6116 size_t total_available_size() { return total_available_size_; } |
| 6056 size_t used_heap_size() { return used_heap_size_; } | 6117 size_t used_heap_size() { return used_heap_size_; } |
| 6057 size_t heap_size_limit() { return heap_size_limit_; } | 6118 size_t heap_size_limit() { return heap_size_limit_; } |
| 6058 size_t malloced_memory() { return malloced_memory_; } | 6119 size_t malloced_memory() { return malloced_memory_; } |
| 6059 size_t peak_malloced_memory() { return peak_malloced_memory_; } | 6120 size_t peak_malloced_memory() { return peak_malloced_memory_; } |
| 6121 | |
| 6122 /** | |
| 6123 * Returns a 0/1 boolean, which signifies whether the |--zap_code_space| | |
| 6124 * option is enabled or not, which makes V8 overwrite heap garbage with a bit | |
| 6125 * pattern. | |
| 6126 */ | |
| 6060 size_t does_zap_garbage() { return does_zap_garbage_; } | 6127 size_t does_zap_garbage() { return does_zap_garbage_; } |
| 6061 | 6128 |
| 6062 private: | 6129 private: |
| 6063 size_t total_heap_size_; | 6130 size_t total_heap_size_; |
| 6064 size_t total_heap_size_executable_; | 6131 size_t total_heap_size_executable_; |
| 6065 size_t total_physical_size_; | 6132 size_t total_physical_size_; |
| 6066 size_t total_available_size_; | 6133 size_t total_available_size_; |
| 6067 size_t used_heap_size_; | 6134 size_t used_heap_size_; |
| 6068 size_t heap_size_limit_; | 6135 size_t heap_size_limit_; |
| 6069 size_t malloced_memory_; | 6136 size_t malloced_memory_; |
| (...skipping 1770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7840 * e.g. because a previous API call threw an exception that hasn't been caught | 7907 * e.g. because a previous API call threw an exception that hasn't been caught |
| 7841 * yet, or because a TerminateExecution exception was thrown. In that case, a | 7908 * yet, or because a TerminateExecution exception was thrown. In that case, a |
| 7842 * "Nothing" value is returned. | 7909 * "Nothing" value is returned. |
| 7843 */ | 7910 */ |
| 7844 template <class T> | 7911 template <class T> |
| 7845 class Maybe { | 7912 class Maybe { |
| 7846 public: | 7913 public: |
| 7847 V8_INLINE bool IsNothing() const { return !has_value_; } | 7914 V8_INLINE bool IsNothing() const { return !has_value_; } |
| 7848 V8_INLINE bool IsJust() const { return has_value_; } | 7915 V8_INLINE bool IsJust() const { return has_value_; } |
| 7849 | 7916 |
| 7850 // Will crash if the Maybe<> is nothing. | 7917 /** |
| 7918 * An alias for |FromJust|. Will crash if the Maybe<> is nothing. | |
| 7919 */ | |
| 7851 V8_INLINE T ToChecked() const { return FromJust(); } | 7920 V8_INLINE T ToChecked() const { return FromJust(); } |
| 7852 | 7921 |
| 7922 /** | |
| 7923 * Converts this Maybe<> to a value of type T. If this Maybe<> is | |
| 7924 * nothing (empty), |false| is returned and |out| is left untouched. | |
| 7925 */ | |
| 7853 V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const { | 7926 V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const { |
| 7854 if (V8_LIKELY(IsJust())) *out = value_; | 7927 if (V8_LIKELY(IsJust())) *out = value_; |
| 7855 return IsJust(); | 7928 return IsJust(); |
| 7856 } | 7929 } |
| 7857 | 7930 |
| 7858 // Will crash if the Maybe<> is nothing. | 7931 /** |
| 7932 * Converts this Maybe<> to a value of type T. If this Maybe<> is | |
| 7933 * nothing (empty), V8 will crash the process. | |
| 7934 */ | |
| 7859 V8_INLINE T FromJust() const { | 7935 V8_INLINE T FromJust() const { |
| 7860 if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); | 7936 if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); |
| 7861 return value_; | 7937 return value_; |
| 7862 } | 7938 } |
| 7863 | 7939 |
| 7940 /** | |
| 7941 * Converts this Maybe<> to a value of type T, using a default value if this | |
| 7942 * Maybe<> is nothing (empty). | |
| 7943 */ | |
| 7864 V8_INLINE T FromMaybe(const T& default_value) const { | 7944 V8_INLINE T FromMaybe(const T& default_value) const { |
| 7865 return has_value_ ? value_ : default_value; | 7945 return has_value_ ? value_ : default_value; |
| 7866 } | 7946 } |
| 7867 | 7947 |
| 7868 V8_INLINE bool operator==(const Maybe& other) const { | 7948 V8_INLINE bool operator==(const Maybe& other) const { |
| 7869 return (IsJust() == other.IsJust()) && | 7949 return (IsJust() == other.IsJust()) && |
| 7870 (!IsJust() || FromJust() == other.FromJust()); | 7950 (!IsJust() || FromJust() == other.FromJust()); |
| 7871 } | 7951 } |
| 7872 | 7952 |
| 7873 V8_INLINE bool operator!=(const Maybe& other) const { | 7953 V8_INLINE bool operator!=(const Maybe& other) const { |
| (...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9903 */ | 9983 */ |
| 9904 | 9984 |
| 9905 | 9985 |
| 9906 } // namespace v8 | 9986 } // namespace v8 |
| 9907 | 9987 |
| 9908 | 9988 |
| 9909 #undef TYPE_CHECK | 9989 #undef TYPE_CHECK |
| 9910 | 9990 |
| 9911 | 9991 |
| 9912 #endif // INCLUDE_V8_H_ | 9992 #endif // INCLUDE_V8_H_ |
| OLD | NEW |