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

Side by Side Diff: include/v8.h

Issue 2748473004: [wasm] Transferrable modules (Closed)
Patch Set: feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 class StackFrame; 101 class StackFrame;
102 class StackTrace; 102 class StackTrace;
103 class String; 103 class String;
104 class StringObject; 104 class StringObject;
105 class Symbol; 105 class Symbol;
106 class SymbolObject; 106 class SymbolObject;
107 class Private; 107 class Private;
108 class Uint32; 108 class Uint32;
109 class Utils; 109 class Utils;
110 class Value; 110 class Value;
111 class WasmCompiledModule;
111 template <class T> class Local; 112 template <class T> class Local;
112 template <class T> 113 template <class T>
113 class MaybeLocal; 114 class MaybeLocal;
114 template <class T> class Eternal; 115 template <class T> class Eternal;
115 template<class T> class NonCopyablePersistentTraits; 116 template<class T> class NonCopyablePersistentTraits;
116 template<class T> class PersistentBase; 117 template<class T> class PersistentBase;
117 template <class T, class M = NonCopyablePersistentTraits<T> > 118 template <class T, class M = NonCopyablePersistentTraits<T> >
118 class Persistent; 119 class Persistent;
119 template <class T> 120 template <class T>
120 class Global; 121 class Global;
(...skipping 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 * object, using the same ID if this SharedArrayBuffer has already been 1704 * object, using the same ID if this SharedArrayBuffer has already been
1704 * serialized in this buffer. When deserializing, this ID will be passed to 1705 * serialized in this buffer. When deserializing, this ID will be passed to
1705 * ValueDeserializer::TransferSharedArrayBuffer as |transfer_id|. 1706 * ValueDeserializer::TransferSharedArrayBuffer as |transfer_id|.
1706 * 1707 *
1707 * If the object cannot be serialized, an 1708 * If the object cannot be serialized, an
1708 * exception should be thrown and Nothing<uint32_t>() returned. 1709 * exception should be thrown and Nothing<uint32_t>() returned.
1709 */ 1710 */
1710 virtual Maybe<uint32_t> GetSharedArrayBufferId( 1711 virtual Maybe<uint32_t> GetSharedArrayBufferId(
1711 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer); 1712 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
1712 1713
1714 virtual Maybe<uint32_t> GetWasmModuleTransferId(
1715 Isolate* isolate, Local<WasmCompiledModule> module);
1713 /* 1716 /*
1714 * Allocates memory for the buffer of at least the size provided. The actual 1717 * Allocates memory for the buffer of at least the size provided. The actual
1715 * size (which may be greater or equal) is written to |actual_size|. If no 1718 * size (which may be greater or equal) is written to |actual_size|. If no
1716 * buffer has been allocated yet, nullptr will be provided. 1719 * buffer has been allocated yet, nullptr will be provided.
1717 * 1720 *
1718 * If the memory cannot be allocated, nullptr should be returned. 1721 * If the memory cannot be allocated, nullptr should be returned.
1719 * |actual_size| will be ignored. It is assumed that |old_buffer| is still 1722 * |actual_size| will be ignored. It is assumed that |old_buffer| is still
1720 * valid in this case and has not been modified. 1723 * valid in this case and has not been modified.
1721 */ 1724 */
1722 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size, 1725 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 class V8_EXPORT Delegate { 1816 class V8_EXPORT Delegate {
1814 public: 1817 public:
1815 virtual ~Delegate() {} 1818 virtual ~Delegate() {}
1816 1819
1817 /* 1820 /*
1818 * The embedder overrides this method to read some kind of host object, if 1821 * The embedder overrides this method to read some kind of host object, if
1819 * possible. If not, a suitable exception should be thrown and 1822 * possible. If not, a suitable exception should be thrown and
1820 * MaybeLocal<Object>() returned. 1823 * MaybeLocal<Object>() returned.
1821 */ 1824 */
1822 virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate); 1825 virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
1826
1827 /*
1828 * Get a WasmCompiledModule given a transfer_id previously provided
1829 * by ValueSerializer::GetWasmModuleTransferId
1830 */
1831 virtual MaybeLocal<WasmCompiledModule> GetWasmModuleFromId(
1832 Isolate* isolate, uint32_t transfer_id);
1823 }; 1833 };
1824 1834
1825 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size); 1835 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
1826 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size, 1836 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
1827 Delegate* delegate); 1837 Delegate* delegate);
1828 ~ValueDeserializer(); 1838 ~ValueDeserializer();
1829 1839
1830 /* 1840 /*
1831 * Reads and validates a header (including the format version). 1841 * Reads and validates a header (including the format version).
1832 * May, for example, reject an invalid or unsupported wire format. 1842 * May, for example, reject an invalid or unsupported wire format.
(...skipping 23 matching lines...) Expand all
1856 /* 1866 /*
1857 * Must be called before ReadHeader to enable support for reading the legacy 1867 * Must be called before ReadHeader to enable support for reading the legacy
1858 * wire format (i.e., which predates this being shipped). 1868 * wire format (i.e., which predates this being shipped).
1859 * 1869 *
1860 * Don't use this unless you need to read data written by previous versions of 1870 * Don't use this unless you need to read data written by previous versions of
1861 * blink::ScriptValueSerializer. 1871 * blink::ScriptValueSerializer.
1862 */ 1872 */
1863 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format); 1873 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
1864 1874
1865 /* 1875 /*
1876 * Expect inline wasm in the data stream (rather than in-memory transfer)
1877 */
1878 void SetExpectInlineWasm(bool allow_inline_wasm);
1879
1880 /*
1866 * Reads the underlying wire format version. Likely mostly to be useful to 1881 * Reads the underlying wire format version. Likely mostly to be useful to
1867 * legacy code reading old wire format versions. Must be called after 1882 * legacy code reading old wire format versions. Must be called after
1868 * ReadHeader. 1883 * ReadHeader.
1869 */ 1884 */
1870 uint32_t GetWireFormatVersion() const; 1885 uint32_t GetWireFormatVersion() const;
1871 1886
1872 /* 1887 /*
1873 * Reads raw data in various common formats to the buffer. 1888 * Reads raw data in various common formats to the buffer.
1874 * Note that integer types are read in base-128 varint format, not with a 1889 * Note that integer types are read in base-128 varint format, not with a
1875 * binary copy. For use during an override of Delegate::ReadHostObject. 1890 * binary copy. For use during an override of Delegate::ReadHostObject.
(...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after
3897 private: 3912 private:
3898 Proxy(); 3913 Proxy();
3899 static void CheckCast(Value* obj); 3914 static void CheckCast(Value* obj);
3900 }; 3915 };
3901 3916
3902 class V8_EXPORT WasmCompiledModule : public Object { 3917 class V8_EXPORT WasmCompiledModule : public Object {
3903 public: 3918 public:
3904 typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule; 3919 typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> SerializedModule;
3905 // A buffer that is owned by the caller. 3920 // A buffer that is owned by the caller.
3906 typedef std::pair<const uint8_t*, size_t> CallerOwnedBuffer; 3921 typedef std::pair<const uint8_t*, size_t> CallerOwnedBuffer;
3922
3923 // An opaque, native heap object for transferring wasm modules. It
3924 // supports move semantics, and does not support copy semantics.
3925 class TransferrableModule final {
3926 public:
3927 TransferrableModule(TransferrableModule&& src) = default;
3928 TransferrableModule(const TransferrableModule& src) = delete;
3929
3930 TransferrableModule& operator=(TransferrableModule&& src) = default;
3931 TransferrableModule& operator=(const TransferrableModule& src) = delete;
3932
3933 private:
3934 typedef std::pair<std::unique_ptr<const uint8_t[]>, size_t> OwnedBuffer;
3935 friend class WasmCompiledModule;
3936 TransferrableModule(OwnedBuffer&& code, OwnedBuffer&& bytes)
3937 : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {}
3938
3939 OwnedBuffer compiled_code = {nullptr, 0};
3940 OwnedBuffer wire_bytes = {nullptr, 0};
3941 };
3942
3943 // Get an in-memory, non-persistable, and context-independent (meaning,
3944 // suitable for transfer to another Isolate and Context) representation
3945 // of this wasm compiled module.
3946 TransferrableModule GetTransferrableModule();
3947
3948 // Efficiently re-create a WasmCompiledModule, without recompiling, from
3949 // a TransferrableModule.
3950 static MaybeLocal<WasmCompiledModule> FromTransferrableModule(
3951 Isolate* isolate, const TransferrableModule&);
3952
3907 // Get the wasm-encoded bytes that were used to compile this module. 3953 // Get the wasm-encoded bytes that were used to compile this module.
3908 Local<String> GetWasmWireBytes(); 3954 Local<String> GetWasmWireBytes();
3909 3955
3910 // Serialize the compiled module. The serialized data does not include the 3956 // Serialize the compiled module. The serialized data does not include the
3911 // uncompiled bytes. 3957 // uncompiled bytes.
3912 SerializedModule Serialize(); 3958 SerializedModule Serialize();
3913 3959
3914 // If possible, deserialize the module, otherwise compile it from the provided 3960 // If possible, deserialize the module, otherwise compile it from the provided
3915 // uncompiled bytes. 3961 // uncompiled bytes.
3916 static MaybeLocal<WasmCompiledModule> DeserializeOrCompile( 3962 static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
3917 Isolate* isolate, const CallerOwnedBuffer& serialized_module, 3963 Isolate* isolate, const CallerOwnedBuffer& serialized_module,
3918 const CallerOwnedBuffer& wire_bytes); 3964 const CallerOwnedBuffer& wire_bytes);
3919 V8_INLINE static WasmCompiledModule* Cast(Value* obj); 3965 V8_INLINE static WasmCompiledModule* Cast(Value* obj);
3920 3966
3921 private: 3967 private:
3922 static MaybeLocal<WasmCompiledModule> Deserialize( 3968 static MaybeLocal<WasmCompiledModule> Deserialize(
3923 Isolate* isolate, const CallerOwnedBuffer& serialized_module, 3969 Isolate* isolate, const CallerOwnedBuffer& serialized_module,
3924 const CallerOwnedBuffer& wire_bytes); 3970 const CallerOwnedBuffer& wire_bytes);
3925 static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate, 3971 static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
3926 const uint8_t* start, 3972 const uint8_t* start,
3927 size_t length); 3973 size_t length);
3974 static CallerOwnedBuffer AsCallerOwned(
3975 const TransferrableModule::OwnedBuffer& buff) {
3976 return {buff.first.get(), buff.second};
3977 }
3978
3928 WasmCompiledModule(); 3979 WasmCompiledModule();
3929 static void CheckCast(Value* obj); 3980 static void CheckCast(Value* obj);
3930 }; 3981 };
3931 3982
3932 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 3983 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
3933 // The number of required internal fields can be defined by embedder. 3984 // The number of required internal fields can be defined by embedder.
3934 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 3985 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
3935 #endif 3986 #endif
3936 3987
3937 3988
(...skipping 5899 matching lines...) Expand 10 before | Expand all | Expand 10 after
9837 */ 9888 */
9838 9889
9839 9890
9840 } // namespace v8 9891 } // namespace v8
9841 9892
9842 9893
9843 #undef TYPE_CHECK 9894 #undef TYPE_CHECK
9844 9895
9845 9896
9846 #endif // INCLUDE_V8_H_ 9897 #endif // INCLUDE_V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698