diff options
Diffstat (limited to 'deps/v8/include/v8.h')
-rw-r--r-- | deps/v8/include/v8.h | 192 |
1 files changed, 127 insertions, 65 deletions
diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index ba87e57a1e..c4720ca695 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -596,7 +596,7 @@ template <class T> class PersistentBase { */ V8_INLINE uint16_t WrapperClassId() const; - PersistentBase(const PersistentBase& other) = delete; // NOLINT + PersistentBase(const PersistentBase& other) = delete; void operator=(const PersistentBase&) = delete; private: @@ -708,7 +708,7 @@ template <class T, class M> class Persistent : public PersistentBase<T> { return *this; } template <class S, class M2> - V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT + V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { Copy(that); return *this; } @@ -723,7 +723,7 @@ template <class T, class M> class Persistent : public PersistentBase<T> { // TODO(dcarney): this is pretty useless, fix or remove template <class S> - V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT + V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { #ifdef V8_ENABLE_CHECKS // If we're going to perform the type check then we have to check // that the handle isn't empty before doing the checked cast. @@ -734,7 +734,7 @@ template <class T, class M> class Persistent : public PersistentBase<T> { // TODO(dcarney): this is pretty useless, fix or remove template <class S> - V8_INLINE Persistent<S>& As() const { // NOLINT + V8_INLINE Persistent<S>& As() const { return Persistent<S>::Cast(*this); } @@ -803,7 +803,7 @@ class Global : public PersistentBase<T> { /** * Pass allows returning uniques from functions, etc. */ - Global Pass() { return static_cast<Global&&>(*this); } // NOLINT + Global Pass() { return static_cast<Global&&>(*this); } /* * For compatibility with Chromium's base::Bind (base::Passed). @@ -905,8 +905,8 @@ class TracedReferenceBase { * The exact semantics are: * - Tracing garbage collections use |v8::EmbedderHeapTracer| or cppgc. * - Non-tracing garbage collections refer to - * |v8::EmbedderHeapTracer::IsRootForNonTracingGC()| whether the handle should - * be treated as root or not. + * |v8::EmbedderRootsHandler::IsRoot()| whether the handle should + * be treated as root or not. * * Note that the base class cannot be instantiated itself. Choose from * - TracedGlobal @@ -1427,9 +1427,7 @@ class ScriptOriginOptions { */ class ScriptOrigin { public: -#if defined(_MSC_VER) && _MSC_VER >= 1910 /* Disable on VS2015 */ V8_DEPRECATE_SOON("Use constructor with primitive C++ types") -#endif V8_INLINE explicit ScriptOrigin( Local<Value> resource_name, Local<Integer> resource_line_offset, Local<Integer> resource_column_offset, @@ -1440,9 +1438,7 @@ class ScriptOrigin { Local<Boolean> is_wasm = Local<Boolean>(), Local<Boolean> is_module = Local<Boolean>(), Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>()); -#if defined(_MSC_VER) && _MSC_VER >= 1910 /* Disable on VS2015 */ V8_DEPRECATE_SOON("Use constructor that takes an isolate") -#endif V8_INLINE explicit ScriptOrigin( Local<Value> resource_name, int resource_line_offset = 0, int resource_column_offset = 0, @@ -1653,7 +1649,7 @@ class V8_EXPORT Module : public Data { */ int GetIdentityHash() const; - using ResolveCallback = + using ResolveCallback V8_DEPRECATE_SOON("Use ResolveModuleCallback") = MaybeLocal<Module> (*)(Local<Context> context, Local<String> specifier, Local<Module> referrer); using ResolveModuleCallback = MaybeLocal<Module> (*)( @@ -1678,10 +1674,12 @@ class V8_EXPORT Module : public Data { /** * Evaluates the module and its dependencies. * - * If status is kInstantiated, run the module's code. On success, set status - * to kEvaluated and return the completion value; on failure, set status to - * kErrored and propagate the thrown exception (which is then also available - * via |GetException|). + * If status is kInstantiated, run the module's code and return a Promise + * object. On success, set status to kEvaluated and resolve the Promise with + * the completion value; on failure, set status to kErrored and reject the + * Promise with the error. + * + * If IsGraphAsync() is false, the returned Promise is settled. */ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context); @@ -1942,11 +1940,9 @@ class V8_EXPORT ScriptCompiler { public: enum Encoding { ONE_BYTE, TWO_BYTE, UTF8, WINDOWS_1252 }; -#if defined(_MSC_VER) && _MSC_VER >= 1910 /* Disable on VS2015 */ V8_DEPRECATED( "This class takes ownership of source_stream, so use the constructor " "taking a unique_ptr to make these semantics clearer") -#endif StreamedSource(ExternalSourceStream* source_stream, Encoding encoding); StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream, Encoding encoding); @@ -2430,7 +2426,7 @@ struct SampleInfo { StateTag vm_state; // Current VM state. void* external_callback_entry; // External callback address if VM is // executing an external callback. - void* top_context; // Incumbent native context address. + void* context; // Incumbent native context address. }; struct MemoryRange { @@ -3282,7 +3278,7 @@ class V8_EXPORT String : public Name { */ bool IsExternalOneByte() const; - class V8_EXPORT ExternalStringResourceBase { // NOLINT + class V8_EXPORT ExternalStringResourceBase { public: virtual ~ExternalStringResourceBase() = default; @@ -3632,10 +3628,9 @@ class V8_EXPORT Symbol : public Name { /** * Returns the description string of the symbol, or undefined if none. */ + V8_DEPRECATE_SOON("Use Symbol::Description(isolate)") Local<Value> Description() const; - - V8_DEPRECATED("Use Symbol::Description()") - Local<Value> Name() const { return Description(); } + Local<Value> Description(Isolate* isolate) const; /** * Create a symbol. If description is not empty, it will be used as the @@ -3986,8 +3981,7 @@ class V8_EXPORT Object : public Value { // // Returns true on success. V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty( - Local<Context> context, Local<Name> key, - PropertyDescriptor& descriptor); // NOLINT(runtime/references) + Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor); V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, Local<Value> key); @@ -4777,17 +4771,6 @@ class V8_EXPORT Function : public Object { Local<Value> GetDebugName() const; /** - * User-defined name assigned to the "displayName" property of this function. - * Used to facilitate debugging and profiling of JavaScript code. - */ - V8_DEPRECATED( - "Use v8::Object::Get() instead to look up \"displayName\". " - "V8 and DevTools no longer use \"displayName\" in stack " - "traces, but the standard \"name\" property. " - "See http://crbug.com/1177685.") - Local<Value> GetDisplayName() const; - - /** * Returns zero based line number of function body and * kLineOffsetNotFound if no information available. */ @@ -5364,7 +5347,7 @@ class V8_EXPORT ArrayBuffer : public Object { * Note that it is unsafe to call back into V8 from any of the allocator * functions. */ - class V8_EXPORT Allocator { // NOLINT + class V8_EXPORT Allocator { public: virtual ~Allocator() = default; @@ -6516,6 +6499,15 @@ class V8_EXPORT FunctionTemplate : public Template { SideEffectType side_effect_type = SideEffectType::kHasSideEffect, const CFunction* c_function = nullptr); + /** Creates a function template for multiple overloaded fast API calls.*/ + static Local<FunctionTemplate> NewWithCFunctionOverloads( + Isolate* isolate, FunctionCallback callback = nullptr, + Local<Value> data = Local<Value>(), + Local<Signature> signature = Local<Signature>(), int length = 0, + ConstructorBehavior behavior = ConstructorBehavior::kAllow, + SideEffectType side_effect_type = SideEffectType::kHasSideEffect, + const MemorySpan<const CFunction>& c_function_overloads = {}); + /** * Creates a function template backed/cached by a private property. */ @@ -6547,7 +6539,7 @@ class V8_EXPORT FunctionTemplate : public Template { void SetCallHandler( FunctionCallback callback, Local<Value> data = Local<Value>(), SideEffectType side_effect_type = SideEffectType::kHasSideEffect, - const CFunction* c_function = nullptr); + const MemorySpan<const CFunction>& c_function_overloads = {}); /** Set the predefined length property for the FunctionTemplate. */ void SetLength(int length); @@ -6608,6 +6600,15 @@ class V8_EXPORT FunctionTemplate : public Template { */ bool HasInstance(Local<Value> object); + /** + * Returns true if the given value is an API object that was constructed by an + * instance of this function template (without checking for inheriting + * function templates). + * + * This is an experimental feature and may still change significantly. + */ + bool IsLeafTemplateForApiObject(v8::Local<v8::Value> value) const; + V8_INLINE static FunctionTemplate* Cast(Data* data); private: @@ -7041,7 +7042,7 @@ class V8_EXPORT AccessorSignature : public Data { /** * Ignore */ -class V8_EXPORT Extension { // NOLINT +class V8_EXPORT Extension { public: // Note that the strings passed into this constructor must live as long // as the Extension itself. @@ -7143,6 +7144,11 @@ class V8_EXPORT ResourceConstraints { /** * The amount of virtual memory reserved for generated code. This is relevant * for 64-bit architectures that rely on code range for calls in code. + * + * When V8_COMPRESS_POINTERS_IN_SHARED_CAGE is defined, there is a shared + * process-wide code range that is lazily initialized. This value is used to + * configure that shared code range when the first Isolate is + * created. Subsequent Isolates ignore this value. */ size_t code_range_size_in_bytes() const { return code_range_size_; } void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; } @@ -7287,7 +7293,8 @@ using CallCompletedCallback = void (*)(Isolate*); * fails (e.g. due to stack overflow), the embedder must propagate * that exception by returning an empty MaybeLocal. */ -using HostImportModuleDynamicallyCallback = +using HostImportModuleDynamicallyCallback V8_DEPRECATE_SOON( + "Use HostImportModuleDynamicallyWithImportAssertionsCallback instead") = MaybeLocal<Promise> (*)(Local<Context> context, Local<ScriptOrModule> referrer, Local<String> specifier); @@ -7592,6 +7599,10 @@ using WasmSimdEnabledCallback = bool (*)(Local<Context> context); // --- Callback for checking if WebAssembly exceptions are enabled --- using WasmExceptionsEnabledCallback = bool (*)(Local<Context> context); +// --- Callback for checking if the SharedArrayBuffer constructor is enabled --- +using SharedArrayBufferConstructorEnabledCallback = + bool (*)(Local<Context> context); + // --- Garbage Collection Callbacks --- /** @@ -7913,17 +7924,16 @@ using UnhandledExceptionCallback = /** * Interface for iterating through all external resources in the heap. */ -class V8_EXPORT ExternalResourceVisitor { // NOLINT +class V8_EXPORT ExternalResourceVisitor { public: virtual ~ExternalResourceVisitor() = default; virtual void VisitExternalString(Local<String> string) {} }; - /** * Interface for iterating through all the persistent handles in the heap. */ -class V8_EXPORT PersistentHandleVisitor { // NOLINT +class V8_EXPORT PersistentHandleVisitor { public: virtual ~PersistentHandleVisitor() = default; virtual void VisitPersistentHandle(Persistent<Value>* value, @@ -7941,6 +7951,45 @@ class V8_EXPORT PersistentHandleVisitor { // NOLINT enum class MemoryPressureLevel { kNone, kModerate, kCritical }; /** + * Handler for embedder roots on non-unified heap garbage collections. + */ +class V8_EXPORT EmbedderRootsHandler { + public: + virtual ~EmbedderRootsHandler() = default; + + /** + * Returns true if the TracedGlobal handle should be considered as root for + * the currently running non-tracing garbage collection and false otherwise. + * The default implementation will keep all TracedGlobal references as roots. + * + * If this returns false, then V8 may decide that the object referred to by + * such a handle is reclaimed. In that case: + * - No action is required if handles are used with destructors, i.e., by just + * using |TracedGlobal|. + * - When run without destructors, i.e., by using |TracedReference|, V8 calls + * |ResetRoot|. + * + * Note that the |handle| is different from the handle that the embedder holds + * for retaining the object. The embedder may use |WrapperClassId()| to + * distinguish cases where it wants handles to be treated as roots from not + * being treated as roots. + */ + virtual bool IsRoot(const v8::TracedReference<v8::Value>& handle) = 0; + virtual bool IsRoot(const v8::TracedGlobal<v8::Value>& handle) = 0; + + /** + * Used in combination with |IsRoot|. Called by V8 when an + * object that is backed by a handle is reclaimed by a non-tracing garbage + * collection. It is up to the embedder to reset the original handle. + * + * Note that the |handle| is different from the handle that the embedder holds + * for retaining the object. It is up to the embedder to find the original + * handle via the object or class id. + */ + virtual void ResetRoot(const v8::TracedReference<v8::Value>& handle) = 0; +}; + +/** * Interface for tracing through the embedder heap. During a V8 garbage * collection, V8 collects hidden fields of all potential wrappers, and at the * end of its marking phase iterates the collection and asks the embedder to @@ -8002,6 +8051,9 @@ class V8_EXPORT EmbedderHeapTracer { /** * Called by the embedder to notify V8 of an empty execution stack. */ + V8_DEPRECATE_SOON( + "This call only optimized internal caches which V8 is able to figure out " + "on its own now.") void NotifyEmptyEmbedderStack(); /** @@ -8065,34 +8117,14 @@ class V8_EXPORT EmbedderHeapTracer { void FinalizeTracing(); /** - * Returns true if the TracedGlobal handle should be considered as root for - * the currently running non-tracing garbage collection and false otherwise. - * The default implementation will keep all TracedGlobal references as roots. - * - * If this returns false, then V8 may decide that the object referred to by - * such a handle is reclaimed. In that case: - * - No action is required if handles are used with destructors, i.e., by just - * using |TracedGlobal|. - * - When run without destructors, i.e., by using - * |TracedReference|, V8 calls |ResetHandleInNonTracingGC|. - * - * Note that the |handle| is different from the handle that the embedder holds - * for retaining the object. The embedder may use |WrapperClassId()| to - * distinguish cases where it wants handles to be treated as roots from not - * being treated as roots. + * See documentation on EmbedderRootsHandler. */ virtual bool IsRootForNonTracingGC( const v8::TracedReference<v8::Value>& handle); virtual bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>& handle); /** - * Used in combination with |IsRootForNonTracingGC|. Called by V8 when an - * object that is backed by a handle is reclaimed by a non-tracing garbage - * collection. It is up to the embedder to reset the original handle. - * - * Note that the |handle| is different from the handle that the embedder holds - * for retaining the object. It is up to the embedder to find the original - * handle via the object or class id. + * See documentation on EmbedderRootsHandler. */ virtual void ResetHandleInNonTracingGC( const v8::TracedReference<v8::Value>& handle); @@ -8551,6 +8583,7 @@ class V8_EXPORT Isolate { kWasmBulkMemory = 109, // Unused. kWasmMultiValue = 110, kWasmExceptionHandling = 111, + kInvalidatedMegaDOMProtector = 112, // If you add new values here, you'll also need to update Chromium's: // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to @@ -8887,6 +8920,17 @@ class V8_EXPORT Isolate { Local<Context> GetIncumbentContext(); /** + * Schedules a v8::Exception::Error with the given message. + * See ThrowException for more details. Templatized to provide compile-time + * errors in case of too long strings (see v8::String::NewFromUtf8Literal). + */ + template <int N> + Local<Value> ThrowError(const char (&message)[N]) { + return ThrowError(String::NewFromUtf8Literal(this, message)); + } + Local<Value> ThrowError(Local<String> message); + + /** * Schedules an exception to be thrown when returning to JavaScript. When an * exception has been scheduled it is illegal to invoke any JavaScript * operation; the caller must return immediately and only after the exception @@ -8931,6 +8975,18 @@ class V8_EXPORT Isolate { EmbedderHeapTracer* GetEmbedderHeapTracer(); /** + * Sets an embedder roots handle that V8 should consider when performing + * non-unified heap garbage collections. + * + * Using only EmbedderHeapTracer automatically sets up a default handler. + * The intended use case is for setting a custom handler after invoking + * `AttachCppHeap()`. + * + * V8 does not take ownership of the handler. + */ + void SetEmbedderRootsHandler(EmbedderRootsHandler* handler); + + /** * Attaches a managed C++ heap as an extension to the JavaScript heap. The * embedder maintains ownership of the CppHeap. At most one C++ heap can be * attached to V8. @@ -9499,6 +9555,9 @@ class V8_EXPORT Isolate { void SetWasmExceptionsEnabledCallback(WasmExceptionsEnabledCallback callback); + void SetSharedArrayBufferConstructorEnabledCallback( + SharedArrayBufferConstructorEnabledCallback callback); + /** * This function can be called by the embedder to signal V8 that the dynamic * enabling of features has finished. V8 can now set up dynamically added @@ -9873,6 +9932,9 @@ class V8_EXPORT V8 { * Notifies V8 that the process is cross-origin-isolated, which enables * defining the SharedArrayBuffer function on the global object of Contexts. */ + V8_DEPRECATED( + "Use the command line argument --enable-sharedarraybuffer-per-context " + "together with SetSharedArrayBufferConstructorEnabledCallback") static void SetIsCrossOriginIsolated(); private: |