diff options
Diffstat (limited to 'deps/v8/include/v8.h')
-rw-r--r-- | deps/v8/include/v8.h | 194 |
1 files changed, 85 insertions, 109 deletions
diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index da4eb341295..18d72f1630c 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -18,15 +18,17 @@ #include <stddef.h> #include <stdint.h> #include <stdio.h> + #include <memory> #include <string> #include <type_traits> #include <utility> #include <vector> -#include "v8-internal.h" // NOLINT(build/include) -#include "v8-version.h" // NOLINT(build/include) -#include "v8config.h" // NOLINT(build/include) +#include "cppgc/common.h" +#include "v8-internal.h" // NOLINT(build/include_directory) +#include "v8-version.h" // NOLINT(build/include_directory) +#include "v8config.h" // NOLINT(build/include_directory) // We reserve the V8_* prefix for macros defined in V8 public API and // assume there are no name conflicts with the embedder's code. @@ -123,19 +125,21 @@ namespace internal { enum class ArgumentsType; template <ArgumentsType> class Arguments; +template <typename T> +class CustomArguments; class DeferredHandles; +class FunctionCallbackArguments; +class GlobalHandles; class Heap; class HeapObject; class ExternalString; class Isolate; class LocalEmbedderHeapTracer; class MicrotaskQueue; -struct ScriptStreamingData; -template<typename T> class CustomArguments; class PropertyCallbackArguments; -class FunctionCallbackArguments; -class GlobalHandles; +class ReadOnlyHeap; class ScopedExternalStringLock; +struct ScriptStreamingData; class ThreadLocalTop; namespace wasm { @@ -1752,11 +1756,9 @@ class V8_EXPORT ScriptCompiler { public: enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 }; -#if defined(_MSC_VER) && _MSC_VER >= 1910 /* Disable on VS2015 */ V8_DEPRECATE_SOON( "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); @@ -4764,11 +4766,17 @@ class V8_EXPORT CompiledWasmModule { */ MemorySpan<const uint8_t> GetWireBytesRef(); + const std::string& source_url() const { return source_url_; } + private: - explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>); - friend class Utils; + friend class WasmModuleObject; + friend class WasmStreaming; + + explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>, + const char* source_url, size_t url_length); const std::shared_ptr<internal::wasm::NativeModule> native_module_; + const std::string source_url_; }; // An instance of WebAssembly.Module. @@ -5936,37 +5944,6 @@ class V8_EXPORT RegExp : public Object { }; /** - * An instance of the built-in FinalizationRegistry constructor. - * - * The C++ name is FinalizationGroup for backwards compatibility. This API is - * experimental and deprecated. - */ -class V8_EXPORT FinalizationGroup : public Object { - public: - /** - * Runs the cleanup callback of the given FinalizationRegistry. - * - * V8 will inform the embedder that there are finalizer callbacks be - * called through HostCleanupFinalizationGroupCallback. - * - * HostCleanupFinalizationGroupCallback should schedule a task to - * call FinalizationGroup::Cleanup() at some point in the - * future. It's the embedders responsiblity to make this call at a - * time which does not interrupt synchronous ECMAScript code - * execution. - * - * If the result is Nothing<bool> then an exception has - * occurred. Otherwise the result is |true| if the cleanup callback - * was called successfully. The result is never |false|. - */ - V8_DEPRECATED( - "FinalizationGroup cleanup is automatic if " - "HostCleanupFinalizationGroupCallback is not set") - static V8_WARN_UNUSED_RESULT Maybe<bool> Cleanup( - Local<FinalizationGroup> finalization_group); -}; - -/** * A JavaScript value that wraps a C++ void*. This type of value is mainly used * to associate C++ data structures with JavaScript objects. */ @@ -6451,11 +6428,6 @@ class V8_EXPORT FunctionTemplate : public Template { SideEffectType side_effect_type = SideEffectType::kHasSideEffect, const CFunction* c_function = nullptr); - /** Get a template included in the snapshot by index. */ - V8_DEPRECATED("Use v8::Isolate::GetDataFromSnapshotOnce instead") - static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate, - size_t index); - /** * Creates a function template backed/cached by a private property. */ @@ -6745,11 +6717,6 @@ class V8_EXPORT ObjectTemplate : public Template { Isolate* isolate, Local<FunctionTemplate> constructor = Local<FunctionTemplate>()); - /** Get a template included in the snapshot by index. */ - V8_DEPRECATED("Use v8::Isolate::GetDataFromSnapshotOnce instead") - static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate, - size_t index); - /** Creates a new instance of this template.*/ V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context); @@ -7182,6 +7149,9 @@ class V8_EXPORT Exception { static Local<Value> ReferenceError(Local<String> message); static Local<Value> SyntaxError(Local<String> message); static Local<Value> TypeError(Local<String> message); + static Local<Value> WasmCompileError(Local<String> message); + static Local<Value> WasmLinkError(Local<String> message); + static Local<Value> WasmRuntimeError(Local<String> message); static Local<Value> Error(Local<String> message); /** @@ -7226,20 +7196,6 @@ typedef void (*BeforeCallEnteredCallback)(Isolate*); typedef void (*CallCompletedCallback)(Isolate*); /** - * HostCleanupFinalizationGroupCallback is called when we require the - * embedder to enqueue a task that would call - * FinalizationGroup::Cleanup(). - * - * The FinalizationGroup is the one for which the embedder needs to - * call FinalizationGroup::Cleanup() on. - * - * The context provided is the one in which the FinalizationGroup was - * created in. - */ -typedef void (*HostCleanupFinalizationGroupCallback)( - Local<Context> context, Local<FinalizationGroup> fg); - -/** * HostImportModuleDynamicallyCallback is called when we require the * embedder to load a module. This is used as part of the dynamic * import syntax. @@ -7265,7 +7221,8 @@ typedef MaybeLocal<Promise> (*HostImportModuleDynamicallyCallback)( /** * HostInitializeImportMetaObjectCallback is called the first time import.meta - * is accessed for a module. Subsequent access will reuse the same value. + * is accessed for a module. Subsequent access will reuse the same value. The + * callback must not throw. * * The method combines two implementation-defined abstract operations into one: * HostGetImportMetaProperties and HostFinalizeImportMeta. @@ -7336,6 +7293,7 @@ class PromiseRejectMessage { typedef void (*PromiseRejectCallback)(PromiseRejectMessage message); // --- Microtasks Callbacks --- +V8_DEPRECATE_SOON("Use *WithData version.") typedef void (*MicrotasksCompletedCallback)(Isolate*); typedef void (*MicrotasksCompletedCallbackWithData)(Isolate*, void*); typedef void (*MicrotaskCallback)(void* data); @@ -7527,6 +7485,9 @@ typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context); typedef Local<String> (*WasmLoadSourceMapCallback)(Isolate* isolate, const char* name); +// --- Callback for checking if WebAssembly Simd is enabled --- +typedef bool (*WasmSimdEnabledCallback)(Local<Context> context); + // --- Garbage Collection Callbacks --- /** @@ -7604,6 +7565,7 @@ class V8_EXPORT SharedMemoryStatistics { size_t read_only_space_physical_size_; friend class V8; + friend class internal::ReadOnlyHeap; }; /** @@ -7883,16 +7845,12 @@ enum class MemoryPressureLevel { kNone, kModerate, kCritical }; */ class V8_EXPORT EmbedderHeapTracer { public: + using EmbedderStackState = cppgc::EmbedderStackState; + enum TraceFlags : uint64_t { kNoFlags = 0, kReduceMemory = 1 << 0, - }; - - // Indicator for the stack state of the embedder. - enum EmbedderStackState { - kUnknown, - kNonEmpty, - kEmpty, + kForced = 1 << 2, }; /** @@ -8455,7 +8413,7 @@ class V8_EXPORT Isolate { kOptimizedFunctionWithOneShotBytecode = 71, kRegExpMatchIsTrueishOnNonJSRegExp = 72, kRegExpMatchIsFalseishOnJSRegExp = 73, - kDateGetTimezoneOffset = 74, + kDateGetTimezoneOffset = 74, // Unused. kStringNormalize = 75, kCallSiteAPIGetFunctionSloppyCall = 76, kCallSiteAPIGetThisSloppyCall = 77, @@ -8471,6 +8429,24 @@ class V8_EXPORT Isolate { kDateTimeFormatDateTimeStyle = 87, kBreakIteratorTypeWord = 88, kBreakIteratorTypeLine = 89, + kInvalidatedArrayBufferDetachingProtector = 90, + kInvalidatedArrayConstructorProtector = 91, + kInvalidatedArrayIteratorLookupChainProtector = 92, + kInvalidatedArraySpeciesLookupChainProtector = 93, + kInvalidatedIsConcatSpreadableLookupChainProtector = 94, + kInvalidatedMapIteratorLookupChainProtector = 95, + kInvalidatedNoElementsProtector = 96, + kInvalidatedPromiseHookProtector = 97, + kInvalidatedPromiseResolveLookupChainProtector = 98, + kInvalidatedPromiseSpeciesLookupChainProtector = 99, + kInvalidatedPromiseThenLookupChainProtector = 100, + kInvalidatedRegExpSpeciesLookupChainProtector = 101, + kInvalidatedSetIteratorLookupChainProtector = 102, + kInvalidatedStringIteratorLookupChainProtector = 103, + kInvalidatedStringLengthOverflowLookupChainProtector = 104, + kInvalidatedTypedArraySpeciesLookupChainProtector = 105, + kWasmSimdOpcodes = 106, + kVarRedeclaredCatchBinding = 107, // 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 @@ -8560,17 +8536,6 @@ class V8_EXPORT Isolate { AbortOnUncaughtExceptionCallback callback); /** - * This specifies the callback to be called when FinalizationRegistries - * are ready to be cleaned up and require FinalizationGroup::Cleanup() - * to be called in a future task. - */ - V8_DEPRECATED( - "FinalizationRegistry cleanup is automatic if " - "HostCleanupFinalizationGroupCallback is not set") - void SetHostCleanupFinalizationGroupCallback( - HostCleanupFinalizationGroupCallback callback); - - /** * This specifies the callback called by the upcoming dynamic * import() language feature to load modules. */ @@ -9384,6 +9349,8 @@ class V8_EXPORT Isolate { void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback); + void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback); + /** * Check if V8 is dead and therefore unusable. This is the case after * fatal errors such as out-of-memory situations. @@ -9522,7 +9489,6 @@ class V8_EXPORT Isolate { internal::Address* GetDataFromSnapshotOnce(size_t index); void ReportExternalAllocationLimitReached(); - void CheckMemoryPressure(); }; class V8_EXPORT StartupData { @@ -9608,7 +9574,13 @@ class V8_EXPORT V8 { * Initializes V8. This function needs to be called before the first Isolate * is created. It always returns true. */ - static bool Initialize(); + V8_INLINE static bool Initialize() { + const int kBuildConfiguration = + (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) | + (internal::SmiValuesAre31Bits() ? k31BitSmis : 0) | + (internal::HeapSandboxIsEnabled() ? kHeapSandbox : 0); + return Initialize(kBuildConfiguration); + } /** * Allows the host application to provide a callback which can be used @@ -9742,6 +9714,18 @@ class V8_EXPORT V8 { private: V8(); + enum BuildConfigurationFeatures { + kPointerCompression = 1 << 0, + k31BitSmis = 1 << 1, + kHeapSandbox = 1 << 2, + }; + + /** + * Checks that the embedder build configuration is compatible with + * the V8 binary and if so initializes V8. + */ + static bool Initialize(int build_config); + static internal::Address* GlobalizeReference(internal::Isolate* isolate, internal::Address* handle); static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate, @@ -9866,13 +9850,6 @@ class V8_EXPORT SnapshotCreator { SerializeInternalFieldsCallback()); /** - * Add a template to be included in the snapshot blob. - * \returns the index of the template in the snapshot blob. - */ - V8_DEPRECATED("use AddData instead") - size_t AddTemplate(Local<Template> template_obj); - - /** * Attach arbitrary V8::Data to the context snapshot, which can be retrieved * via Context::GetDataFromSnapshot after deserialization. This data does not * survive when a new snapshot is created from an existing snapshot. @@ -11382,7 +11359,9 @@ void* Object::GetAlignedPointerFromInternalField(int index) { instance_type == I::kJSApiObjectType || instance_type == I::kJSSpecialApiObjectType)) { int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index); - return I::ReadRawField<void*>(obj, offset); + internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj); + A value = I::ReadExternalPointerField(isolate, obj, offset); + return reinterpret_cast<void*>(value); } #endif return SlowGetAlignedPointerFromInternalField(index); @@ -11412,7 +11391,9 @@ String::ExternalStringResource* String::GetExternalStringResource() const { ExternalStringResource* result; if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { - void* value = I::ReadRawField<void*>(obj, I::kStringResourceOffset); + internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj); + A value = + I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset); result = reinterpret_cast<String::ExternalStringResource*>(value); } else { result = GetExternalStringResourceSlow(); @@ -11434,8 +11415,10 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBase( ExternalStringResourceBase* resource; if (type == I::kExternalOneByteRepresentationTag || type == I::kExternalTwoByteRepresentationTag) { - void* value = I::ReadRawField<void*>(obj, I::kStringResourceOffset); - resource = static_cast<ExternalStringResourceBase*>(value); + internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj); + A value = + I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset); + resource = reinterpret_cast<ExternalStringResourceBase*>(value); } else { resource = GetExternalStringResourceBaseSlow(encoding_out); } @@ -11951,7 +11934,6 @@ MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) { int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( int64_t change_in_bytes) { typedef internal::Internals I; - constexpr int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024; int64_t* external_memory = reinterpret_cast<int64_t*>( reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset); int64_t* external_memory_limit = reinterpret_cast<int64_t*>( @@ -11974,14 +11956,6 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( if (change_in_bytes <= 0) return *external_memory; - int64_t allocation_diff_since_last_mc = static_cast<int64_t>( - static_cast<uint64_t>(*external_memory) - - static_cast<uint64_t>(*external_memory_low_since_mc)); - // Only check memory pressure and potentially trigger GC if the amount of - // external memory increased. - if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) { - CheckMemoryPressure(); - } if (amount > *external_memory_limit) { ReportExternalAllocationLimitReached(); } @@ -12023,7 +11997,9 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) { I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset); int value_offset = I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index); - return I::ReadRawField<void*>(embedder_data, value_offset); + internal::Isolate* isolate = I::GetIsolateForHeapSandbox(ctx); + return reinterpret_cast<void*>( + I::ReadExternalPointerField(isolate, embedder_data, value_offset)); #else return SlowGetAlignedPointerFromEmbedderData(index); #endif |