| 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. That 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 |
| 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, an EscapableHandleScope |
| 181 * and its Escape() method must be used. |
| 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 * Cast a handle to a subclass, e.g. Local<Value> to Local<Object>. |
| 264 * This is only valid if the handle actually refers to a value of the |
| 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(). |
| 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. It can be useful for debugging handle leaks. |
| 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 |
| 2344 /** |
| 2345 * A flag describing different modes of string creation. |
| 2346 * |
| 2347 * Aside from performance implications there are no differences between the two |
| 2348 * creation modes. |
| 2349 */ |
| 2350 enum class NewStringType { |
| 2351 /** |
| 2352 * Create a new string, always allocating new storage memory. |
| 2353 */ |
| 2354 kNormal, |
| 2311 | 2355 |
| 2312 enum class NewStringType { kNormal, kInternalized }; | 2356 /** |
| 2313 | 2357 * Acts as a hint that the string should be created in the |
| 2358 * old generation heap space and be deduplicated if an identical string |
| 2359 * already exists. |
| 2360 */ |
| 2361 kInternalized |
| 2362 }; |
| 2314 | 2363 |
| 2315 /** | 2364 /** |
| 2316 * A JavaScript string value (ECMA-262, 4.3.17). | 2365 * A JavaScript string value (ECMA-262, 4.3.17). |
| 2317 */ | 2366 */ |
| 2318 class V8_EXPORT String : public Name { | 2367 class V8_EXPORT String : public Name { |
| 2319 public: | 2368 public: |
| 2320 static const int kMaxLength = (1 << 28) - 16; | 2369 static const int kMaxLength = (1 << 28) - 16; |
| 2321 | 2370 |
| 2322 enum Encoding { | 2371 enum Encoding { |
| 2323 UNKNOWN_ENCODING = 0x1, | 2372 UNKNOWN_ENCODING = 0x1, |
| 2324 TWO_BYTE_ENCODING = 0x0, | 2373 TWO_BYTE_ENCODING = 0x0, |
| 2325 ONE_BYTE_ENCODING = 0x8 | 2374 ONE_BYTE_ENCODING = 0x8 |
| 2326 }; | 2375 }; |
| 2327 /** | 2376 /** |
| 2328 * Returns the number of characters in this string. | 2377 * Returns the number of characters (UTF-16 code units) in this string. |
| 2329 */ | 2378 */ |
| 2330 int Length() const; | 2379 int Length() const; |
| 2331 | 2380 |
| 2332 /** | 2381 /** |
| 2333 * Returns the number of bytes in the UTF-8 encoded | 2382 * Returns the number of bytes in the UTF-8 encoded |
| 2334 * representation of this string. | 2383 * representation of this string. |
| 2335 */ | 2384 */ |
| 2336 int Utf8Length() const; | 2385 int Utf8Length() const; |
| 2337 | 2386 |
| 2338 /** | 2387 /** |
| 2339 * Returns whether this string is known to contain only one byte data. | 2388 * Returns whether this string is known to contain only one byte data, |
| 2389 * i.e. ISO-8859-1 code points. |
| 2340 * Does not read the string. | 2390 * Does not read the string. |
| 2341 * False negatives are possible. | 2391 * False negatives are possible. |
| 2342 */ | 2392 */ |
| 2343 bool IsOneByte() const; | 2393 bool IsOneByte() const; |
| 2344 | 2394 |
| 2345 /** | 2395 /** |
| 2346 * Returns whether this string contain only one byte data. | 2396 * Returns whether this string contain only one byte data, |
| 2397 * i.e. ISO-8859-1 code points. |
| 2347 * Will read the entire string in some cases. | 2398 * Will read the entire string in some cases. |
| 2348 */ | 2399 */ |
| 2349 bool ContainsOnlyOneByte() const; | 2400 bool ContainsOnlyOneByte() const; |
| 2350 | 2401 |
| 2351 /** | 2402 /** |
| 2352 * Write the contents of the string to an external buffer. | 2403 * Write the contents of the string to an external buffer. |
| 2353 * If no arguments are given, expects the buffer to be large | 2404 * If no arguments are given, expects the buffer to be large |
| 2354 * enough to hold the entire string and NULL terminator. Copies | 2405 * enough to hold the entire string and NULL terminator. Copies |
| 2355 * the contents of the string and the NULL terminator into the | 2406 * the contents of the string and the NULL terminator into the |
| 2356 * buffer. | 2407 * buffer. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2643 // Disallow copying and assigning. | 2694 // Disallow copying and assigning. |
| 2644 Utf8Value(const Utf8Value&) = delete; | 2695 Utf8Value(const Utf8Value&) = delete; |
| 2645 void operator=(const Utf8Value&) = delete; | 2696 void operator=(const Utf8Value&) = delete; |
| 2646 | 2697 |
| 2647 private: | 2698 private: |
| 2648 char* str_; | 2699 char* str_; |
| 2649 int length_; | 2700 int length_; |
| 2650 }; | 2701 }; |
| 2651 | 2702 |
| 2652 /** | 2703 /** |
| 2653 * Converts an object to a two-byte string. | 2704 * 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() | 2705 * 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 | 2706 * method of the object) then the length() method returns 0 and the * operator |
| 2656 * returns NULL. | 2707 * returns NULL. |
| 2657 */ | 2708 */ |
| 2658 class V8_EXPORT Value { | 2709 class V8_EXPORT Value { |
| 2659 public: | 2710 public: |
| 2660 explicit Value(Local<v8::Value> obj); | 2711 explicit Value(Local<v8::Value> obj); |
| 2661 ~Value(); | 2712 ~Value(); |
| 2662 uint16_t* operator*() { return str_; } | 2713 uint16_t* operator*() { return str_; } |
| 2663 const uint16_t* operator*() const { return str_; } | 2714 const uint16_t* operator*() const { return str_; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2678 void VerifyExternalStringResource(ExternalStringResource* val) const; | 2729 void VerifyExternalStringResource(ExternalStringResource* val) const; |
| 2679 static void CheckCast(v8::Value* obj); | 2730 static void CheckCast(v8::Value* obj); |
| 2680 }; | 2731 }; |
| 2681 | 2732 |
| 2682 | 2733 |
| 2683 /** | 2734 /** |
| 2684 * A JavaScript symbol (ECMA-262 edition 6) | 2735 * A JavaScript symbol (ECMA-262 edition 6) |
| 2685 */ | 2736 */ |
| 2686 class V8_EXPORT Symbol : public Name { | 2737 class V8_EXPORT Symbol : public Name { |
| 2687 public: | 2738 public: |
| 2688 // Returns the print name string of the symbol, or undefined if none. | 2739 /** |
| 2740 * Returns the print name string of the symbol, or undefined if none. |
| 2741 */ |
| 2689 Local<Value> Name() const; | 2742 Local<Value> Name() const; |
| 2690 | 2743 |
| 2691 // Create a symbol. If name is not empty, it will be used as the description. | 2744 /** |
| 2745 * Create a symbol. If name is not empty, it will be used as the description. |
| 2746 */ |
| 2692 static Local<Symbol> New(Isolate* isolate, | 2747 static Local<Symbol> New(Isolate* isolate, |
| 2693 Local<String> name = Local<String>()); | 2748 Local<String> name = Local<String>()); |
| 2694 | 2749 |
| 2695 // Access global symbol registry. | 2750 /** |
| 2696 // Note that symbols created this way are never collected, so | 2751 * Access global symbol registry. |
| 2697 // they should only be used for statically fixed properties. | 2752 * 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. | 2753 * they should only be used for statically fixed properties. |
| 2699 // To minimize the potential for clashes, use qualified names as keys. | 2754 * Also, there is only one global name space for the names used as keys. |
| 2755 * To minimize the potential for clashes, use qualified names as keys. |
| 2756 */ |
| 2700 static Local<Symbol> For(Isolate *isolate, Local<String> name); | 2757 static Local<Symbol> For(Isolate *isolate, Local<String> name); |
| 2701 | 2758 |
| 2702 // Retrieve a global symbol. Similar to |For|, but using a separate | 2759 /** |
| 2703 // registry that is not accessible by (and cannot clash with) JavaScript code. | 2760 * Retrieve a global symbol. Similar to |For|, but using a separate |
| 2761 * registry that is not accessible by (and cannot clash with) JavaScript code. |
| 2762 */ |
| 2704 static Local<Symbol> ForApi(Isolate *isolate, Local<String> name); | 2763 static Local<Symbol> ForApi(Isolate *isolate, Local<String> name); |
| 2705 | 2764 |
| 2706 // Well-known symbols | 2765 // Well-known symbols |
| 2707 static Local<Symbol> GetIterator(Isolate* isolate); | 2766 static Local<Symbol> GetIterator(Isolate* isolate); |
| 2708 static Local<Symbol> GetUnscopables(Isolate* isolate); | 2767 static Local<Symbol> GetUnscopables(Isolate* isolate); |
| 2709 static Local<Symbol> GetToPrimitive(Isolate* isolate); | 2768 static Local<Symbol> GetToPrimitive(Isolate* isolate); |
| 2710 static Local<Symbol> GetToStringTag(Isolate* isolate); | 2769 static Local<Symbol> GetToStringTag(Isolate* isolate); |
| 2711 static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate); | 2770 static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate); |
| 2712 | 2771 |
| 2713 V8_INLINE static Symbol* Cast(Value* obj); | 2772 V8_INLINE static Symbol* Cast(Value* obj); |
| 2714 | 2773 |
| 2715 private: | 2774 private: |
| 2716 Symbol(); | 2775 Symbol(); |
| 2717 static void CheckCast(Value* obj); | 2776 static void CheckCast(Value* obj); |
| 2718 }; | 2777 }; |
| 2719 | 2778 |
| 2720 | 2779 |
| 2721 /** | 2780 /** |
| 2722 * A private symbol | 2781 * A private symbol |
| 2723 * | 2782 * |
| 2724 * This is an experimental feature. Use at your own risk. | 2783 * This is an experimental feature. Use at your own risk. |
| 2725 */ | 2784 */ |
| 2726 class V8_EXPORT Private : public Data { | 2785 class V8_EXPORT Private : public Data { |
| 2727 public: | 2786 public: |
| 2728 // Returns the print name string of the private symbol, or undefined if none. | 2787 /** |
| 2788 * Returns the print name string of the private symbol, or undefined if none. |
| 2789 */ |
| 2729 Local<Value> Name() const; | 2790 Local<Value> Name() const; |
| 2730 | 2791 |
| 2731 // Create a private symbol. If name is not empty, it will be the description. | 2792 /** |
| 2793 * Create a private symbol. If name is not empty, it will be the description. |
| 2794 */ |
| 2732 static Local<Private> New(Isolate* isolate, | 2795 static Local<Private> New(Isolate* isolate, |
| 2733 Local<String> name = Local<String>()); | 2796 Local<String> name = Local<String>()); |
| 2734 | 2797 |
| 2735 // Retrieve a global private symbol. If a symbol with this name has not | 2798 /** |
| 2736 // been retrieved in the same isolate before, it is created. | 2799 * 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 | 2800 * been retrieved in the same isolate before, it is created. |
| 2738 // they should only be used for statically fixed properties. | 2801 * 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. | 2802 * they should only be used for statically fixed properties. |
| 2740 // To minimize the potential for clashes, use qualified names as keys, | 2803 * Also, there is only one global name space for the names used as keys. |
| 2741 // e.g., "Class#property". | 2804 * To minimize the potential for clashes, use qualified names as keys, |
| 2805 * e.g., "Class#property". |
| 2806 */ |
| 2742 static Local<Private> ForApi(Isolate* isolate, Local<String> name); | 2807 static Local<Private> ForApi(Isolate* isolate, Local<String> name); |
| 2743 | 2808 |
| 2744 private: | 2809 private: |
| 2745 Private(); | 2810 Private(); |
| 2746 }; | 2811 }; |
| 2747 | 2812 |
| 2748 | 2813 |
| 2749 /** | 2814 /** |
| 2750 * A JavaScript number value (ECMA-262, 4.3.20) | 2815 * A JavaScript number value (ECMA-262, 4.3.20) |
| 2751 */ | 2816 */ |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4056 | 4121 |
| 4057 /** | 4122 /** |
| 4058 * Free the memory block of size |length|, pointed to by |data|. | 4123 * Free the memory block of size |length|, pointed to by |data|. |
| 4059 * That memory is guaranteed to be previously allocated by |Allocate|. | 4124 * That memory is guaranteed to be previously allocated by |Allocate|. |
| 4060 */ | 4125 */ |
| 4061 virtual void Free(void* data, size_t length) = 0; | 4126 virtual void Free(void* data, size_t length) = 0; |
| 4062 | 4127 |
| 4063 /** | 4128 /** |
| 4064 * malloc/free based convenience allocator. | 4129 * malloc/free based convenience allocator. |
| 4065 * | 4130 * |
| 4066 * Caller takes ownership. | 4131 * Caller takes ownership, i.e. the returned object needs to be freed using |
| 4132 * |delete allocator| once it is no longer in use. |
| 4067 */ | 4133 */ |
| 4068 static Allocator* NewDefaultAllocator(); | 4134 static Allocator* NewDefaultAllocator(); |
| 4069 }; | 4135 }; |
| 4070 | 4136 |
| 4071 /** | 4137 /** |
| 4072 * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| | 4138 * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
| 4073 * returns an instance of this class, populated, with a pointer to data | 4139 * returns an instance of this class, populated, with a pointer to data |
| 4074 * and byte length. | 4140 * and byte length. |
| 4075 * | 4141 * |
| 4076 * The Data pointer of ArrayBuffer::Contents is always allocated with | 4142 * 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. | 4166 * Create a new ArrayBuffer. Allocate |byte_length| bytes. |
| 4101 * Allocated memory will be owned by a created ArrayBuffer and | 4167 * Allocated memory will be owned by a created ArrayBuffer and |
| 4102 * will be deallocated when it is garbage-collected, | 4168 * will be deallocated when it is garbage-collected, |
| 4103 * unless the object is externalized. | 4169 * unless the object is externalized. |
| 4104 */ | 4170 */ |
| 4105 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); | 4171 static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length); |
| 4106 | 4172 |
| 4107 /** | 4173 /** |
| 4108 * Create a new ArrayBuffer over an existing memory block. | 4174 * Create a new ArrayBuffer over an existing memory block. |
| 4109 * The created array buffer is by default immediately in externalized state. | 4175 * The created array buffer is by default immediately in externalized state. |
| 4110 * The memory block will not be reclaimed when a created ArrayBuffer | 4176 * In externalized state, the memory block will not be reclaimed when a |
| 4111 * is garbage-collected. | 4177 * created ArrayBuffer is garbage-collected. |
| 4178 * In internalized state, the memory block will be released using |
| 4179 * |Allocator::Free| once all ArrayBuffers referencing it are collected by |
| 4180 * the garbage collector. |
| 4112 */ | 4181 */ |
| 4113 static Local<ArrayBuffer> New( | 4182 static Local<ArrayBuffer> New( |
| 4114 Isolate* isolate, void* data, size_t byte_length, | 4183 Isolate* isolate, void* data, size_t byte_length, |
| 4115 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); | 4184 ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); |
| 4116 | 4185 |
| 4117 /** | 4186 /** |
| 4118 * Returns true if ArrayBuffer is externalized, that is, does not | 4187 * Returns true if ArrayBuffer is externalized, that is, does not |
| 4119 * own its memory block. | 4188 * own its memory block. |
| 4120 */ | 4189 */ |
| 4121 bool IsExternal() const; | 4190 bool IsExternal() const; |
| (...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6050 public: | 6119 public: |
| 6051 HeapStatistics(); | 6120 HeapStatistics(); |
| 6052 size_t total_heap_size() { return total_heap_size_; } | 6121 size_t total_heap_size() { return total_heap_size_; } |
| 6053 size_t total_heap_size_executable() { return total_heap_size_executable_; } | 6122 size_t total_heap_size_executable() { return total_heap_size_executable_; } |
| 6054 size_t total_physical_size() { return total_physical_size_; } | 6123 size_t total_physical_size() { return total_physical_size_; } |
| 6055 size_t total_available_size() { return total_available_size_; } | 6124 size_t total_available_size() { return total_available_size_; } |
| 6056 size_t used_heap_size() { return used_heap_size_; } | 6125 size_t used_heap_size() { return used_heap_size_; } |
| 6057 size_t heap_size_limit() { return heap_size_limit_; } | 6126 size_t heap_size_limit() { return heap_size_limit_; } |
| 6058 size_t malloced_memory() { return malloced_memory_; } | 6127 size_t malloced_memory() { return malloced_memory_; } |
| 6059 size_t peak_malloced_memory() { return peak_malloced_memory_; } | 6128 size_t peak_malloced_memory() { return peak_malloced_memory_; } |
| 6129 |
| 6130 /** |
| 6131 * Returns a 0/1 boolean, which signifies whether the |--zap_code_space| |
| 6132 * option is enabled or not, which makes V8 overwrite heap garbage with a bit |
| 6133 * pattern. |
| 6134 */ |
| 6060 size_t does_zap_garbage() { return does_zap_garbage_; } | 6135 size_t does_zap_garbage() { return does_zap_garbage_; } |
| 6061 | 6136 |
| 6062 private: | 6137 private: |
| 6063 size_t total_heap_size_; | 6138 size_t total_heap_size_; |
| 6064 size_t total_heap_size_executable_; | 6139 size_t total_heap_size_executable_; |
| 6065 size_t total_physical_size_; | 6140 size_t total_physical_size_; |
| 6066 size_t total_available_size_; | 6141 size_t total_available_size_; |
| 6067 size_t used_heap_size_; | 6142 size_t used_heap_size_; |
| 6068 size_t heap_size_limit_; | 6143 size_t heap_size_limit_; |
| 6069 size_t malloced_memory_; | 6144 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 | 7915 * 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 | 7916 * yet, or because a TerminateExecution exception was thrown. In that case, a |
| 7842 * "Nothing" value is returned. | 7917 * "Nothing" value is returned. |
| 7843 */ | 7918 */ |
| 7844 template <class T> | 7919 template <class T> |
| 7845 class Maybe { | 7920 class Maybe { |
| 7846 public: | 7921 public: |
| 7847 V8_INLINE bool IsNothing() const { return !has_value_; } | 7922 V8_INLINE bool IsNothing() const { return !has_value_; } |
| 7848 V8_INLINE bool IsJust() const { return has_value_; } | 7923 V8_INLINE bool IsJust() const { return has_value_; } |
| 7849 | 7924 |
| 7850 // Will crash if the Maybe<> is nothing. | 7925 /** |
| 7926 * An alias for |FromJust|. Will crash if the Maybe<> is nothing. |
| 7927 */ |
| 7851 V8_INLINE T ToChecked() const { return FromJust(); } | 7928 V8_INLINE T ToChecked() const { return FromJust(); } |
| 7852 | 7929 |
| 7930 /** |
| 7931 * Converts this Maybe<> to a value of type T. If this Maybe<> is |
| 7932 * nothing (empty), |false| is returned and |out| is left untouched. |
| 7933 */ |
| 7853 V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const { | 7934 V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const { |
| 7854 if (V8_LIKELY(IsJust())) *out = value_; | 7935 if (V8_LIKELY(IsJust())) *out = value_; |
| 7855 return IsJust(); | 7936 return IsJust(); |
| 7856 } | 7937 } |
| 7857 | 7938 |
| 7858 // Will crash if the Maybe<> is nothing. | 7939 /** |
| 7940 * Converts this Maybe<> to a value of type T. If this Maybe<> is |
| 7941 * nothing (empty), V8 will crash the process. |
| 7942 */ |
| 7859 V8_INLINE T FromJust() const { | 7943 V8_INLINE T FromJust() const { |
| 7860 if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); | 7944 if (V8_UNLIKELY(!IsJust())) V8::FromJustIsNothing(); |
| 7861 return value_; | 7945 return value_; |
| 7862 } | 7946 } |
| 7863 | 7947 |
| 7948 /** |
| 7949 * Converts this Maybe<> to a value of type T, using a default value if this |
| 7950 * Maybe<> is nothing (empty). |
| 7951 */ |
| 7864 V8_INLINE T FromMaybe(const T& default_value) const { | 7952 V8_INLINE T FromMaybe(const T& default_value) const { |
| 7865 return has_value_ ? value_ : default_value; | 7953 return has_value_ ? value_ : default_value; |
| 7866 } | 7954 } |
| 7867 | 7955 |
| 7868 V8_INLINE bool operator==(const Maybe& other) const { | 7956 V8_INLINE bool operator==(const Maybe& other) const { |
| 7869 return (IsJust() == other.IsJust()) && | 7957 return (IsJust() == other.IsJust()) && |
| 7870 (!IsJust() || FromJust() == other.FromJust()); | 7958 (!IsJust() || FromJust() == other.FromJust()); |
| 7871 } | 7959 } |
| 7872 | 7960 |
| 7873 V8_INLINE bool operator!=(const Maybe& other) const { | 7961 V8_INLINE bool operator!=(const Maybe& other) const { |
| (...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9903 */ | 9991 */ |
| 9904 | 9992 |
| 9905 | 9993 |
| 9906 } // namespace v8 | 9994 } // namespace v8 |
| 9907 | 9995 |
| 9908 | 9996 |
| 9909 #undef TYPE_CHECK | 9997 #undef TYPE_CHECK |
| 9910 | 9998 |
| 9911 | 9999 |
| 9912 #endif // INCLUDE_V8_H_ | 10000 #endif // INCLUDE_V8_H_ |
| OLD | NEW |