From f579e1194046c50f2e6bb54348d48c8e7d1a53cf Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Fri, 15 Mar 2019 18:35:06 +0530 Subject: deps: update V8 to 7.4.288.13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/26685 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: Refael Ackermann --- deps/v8/include/libplatform/libplatform.h | 9 - deps/v8/include/libplatform/v8-tracing.h | 14 +- deps/v8/include/v8-internal.h | 41 +- deps/v8/include/v8-platform.h | 18 +- deps/v8/include/v8-profiler.h | 111 ----- deps/v8/include/v8-util.h | 18 +- deps/v8/include/v8-version.h | 6 +- deps/v8/include/v8.h | 713 +++++++++++++++++++++++------- 8 files changed, 605 insertions(+), 325 deletions(-) (limited to 'deps/v8/include') diff --git a/deps/v8/include/libplatform/libplatform.h b/deps/v8/include/libplatform/libplatform.h index 13c0db9a85..6908aeaa88 100644 --- a/deps/v8/include/libplatform/libplatform.h +++ b/deps/v8/include/libplatform/libplatform.h @@ -41,15 +41,6 @@ V8_PLATFORM_EXPORT std::unique_ptr NewDefaultPlatform( InProcessStackDumping::kDisabled, std::unique_ptr tracing_controller = {}); -V8_PLATFORM_EXPORT V8_DEPRECATED( - "Use NewDefaultPlatform instead", - v8::Platform* CreateDefaultPlatform( - int thread_pool_size = 0, - IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled, - InProcessStackDumping in_process_stack_dumping = - InProcessStackDumping::kDisabled, - v8::TracingController* tracing_controller = nullptr)); - /** * Pumps the message loop for the given isolate. * diff --git a/deps/v8/include/libplatform/v8-tracing.h b/deps/v8/include/libplatform/v8-tracing.h index 250d5fbdb9..bc249cb9ec 100644 --- a/deps/v8/include/libplatform/v8-tracing.h +++ b/deps/v8/include/libplatform/v8-tracing.h @@ -5,6 +5,7 @@ #ifndef V8_LIBPLATFORM_V8_TRACING_H_ #define V8_LIBPLATFORM_V8_TRACING_H_ +#include #include #include #include @@ -221,12 +222,10 @@ class V8_PLATFORM_EXPORT TraceConfig { class V8_PLATFORM_EXPORT TracingController : public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) { public: - enum Mode { DISABLED = 0, RECORDING_MODE }; - - // The pointer returned from GetCategoryGroupEnabledInternal() points to a - // value with zero or more of the following bits. Used in this class only. - // The TRACE_EVENT macros should only use the value as a bool. - // These values must be in sync with macro values in TraceEvent.h in Blink. + // The pointer returned from GetCategoryGroupEnabled() points to a value with + // zero or more of the following bits. Used in this class only. The + // TRACE_EVENT macros should only use the value as a bool. These values must + // be in sync with macro values in TraceEvent.h in Blink. enum CategoryGroupEnabledFlags { // Category group enabled for the recording mode. ENABLED_FOR_RECORDING = 1 << 0, @@ -273,7 +272,6 @@ class V8_PLATFORM_EXPORT TracingController virtual int64_t CurrentCpuTimestampMicroseconds(); private: - const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group); void UpdateCategoryGroupEnabledFlag(size_t category_index); void UpdateCategoryGroupEnabledFlags(); @@ -281,7 +279,7 @@ class V8_PLATFORM_EXPORT TracingController std::unique_ptr trace_config_; std::unique_ptr mutex_; std::unordered_set observers_; - Mode mode_ = DISABLED; + std::atomic_bool recording_{false}; // Disallow copy and assign TracingController(const TracingController&) = delete; diff --git a/deps/v8/include/v8-internal.h b/deps/v8/include/v8-internal.h index 7f9c27ebb9..bb69bb915d 100644 --- a/deps/v8/include/v8-internal.h +++ b/deps/v8/include/v8-internal.h @@ -31,7 +31,7 @@ static const Address kNullAddress = 0; const int kApiSystemPointerSize = sizeof(void*); const int kApiTaggedSize = kApiSystemPointerSize; const int kApiDoubleSize = sizeof(double); -const int kApiIntSize = sizeof(int); +const int kApiInt32Size = sizeof(int32_t); const int kApiInt64Size = sizeof(int64_t); // Tag information for HeapObject. @@ -88,16 +88,16 @@ struct SmiTagging<8> { } }; -#if defined(V8_COMPRESS_POINTERS) +#ifdef V8_COMPRESS_POINTERS static_assert( kApiSystemPointerSize == kApiInt64Size, "Pointer compression can be enabled only for 64-bit architectures"); #endif -#if defined(V8_COMPRESS_POINTERS) || defined(V8_31BIT_SMIS_ON_64BIT_ARCH) -typedef SmiTagging PlatformSmiTagging; +#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH +typedef SmiTagging PlatformSmiTagging; #else -typedef SmiTagging PlatformSmiTagging; +typedef SmiTagging PlatformSmiTagging; #endif const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; @@ -122,15 +122,13 @@ class Internals { // These values match non-compiler-dependent values defined within // the implementation of v8. static const int kHeapObjectMapOffset = 0; - static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiIntSize; - static const int kStringResourceOffset = 1 * kApiTaggedSize + 2 * kApiIntSize; + static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size; + static const int kStringResourceOffset = + 1 * kApiTaggedSize + 2 * kApiInt32Size; static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize; static const int kForeignAddressOffset = kApiTaggedSize; static const int kJSObjectHeaderSize = 3 * kApiTaggedSize; - static const int kJSObjectHeaderSizeForEmbedderFields = - (kJSObjectHeaderSize + kApiSystemPointerSize - 1) & - -kApiSystemPointerSize; static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize; static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize; static const int kEmbedderDataSlotSize = @@ -148,7 +146,7 @@ class Internals { static const int kIsolateEmbedderDataOffset = 0; static const int kExternalMemoryOffset = - kNumIsolateDataSlots * kApiTaggedSize; + kNumIsolateDataSlots * kApiSystemPointerSize; static const int kExternalMemoryLimitOffset = kExternalMemoryOffset + kApiInt64Size; static const int kExternalMemoryAtLastMarkCompactOffset = @@ -163,8 +161,8 @@ class Internals { static const int kFalseValueRootIndex = 8; static const int kEmptyStringRootIndex = 9; - static const int kNodeClassIdOffset = 1 * kApiTaggedSize; - static const int kNodeFlagsOffset = 1 * kApiTaggedSize + 3; + static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize; + static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3; static const int kNodeStateMask = 0x7; static const int kNodeStateIsWeakValue = 2; static const int kNodeStateIsPendingValue = 3; @@ -172,9 +170,9 @@ class Internals { static const int kNodeIsIndependentShift = 3; static const int kNodeIsActiveShift = 4; - static const int kFirstNonstringType = 0x80; - static const int kOddballType = 0x83; - static const int kForeignType = 0x87; + static const int kFirstNonstringType = 0x40; + static const int kOddballType = 0x43; + static const int kForeignType = 0x47; static const int kJSSpecialApiObjectType = 0x410; static const int kJSApiObjectType = 0x420; static const int kJSObjectType = 0x421; @@ -182,6 +180,12 @@ class Internals { static const int kUndefinedOddballKind = 5; static const int kNullOddballKind = 3; + // Constants used by PropertyCallbackInfo to check if we should throw when an + // error occurs. + static const int kThrowOnError = 0; + static const int kDontThrow = 1; + static const int kInferShouldThrowMode = 2; + // Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an // incremental GC once the external memory reaches this limit. static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024; @@ -367,6 +371,11 @@ V8_INLINE void PerformCastCheck(T* data) { // that's guaranteed to never be in ReadOnlySpace. V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj); +// Returns if we need to throw when an error occurs. This infers the language +// mode based on the current context and the closure. This returns true if the +// language mode is strict. +V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate); + } // namespace internal } // namespace v8 diff --git a/deps/v8/include/v8-platform.h b/deps/v8/include/v8-platform.h index fc008979f6..556407d876 100644 --- a/deps/v8/include/v8-platform.h +++ b/deps/v8/include/v8-platform.h @@ -70,6 +70,17 @@ class TaskRunner { virtual void PostDelayedTask(std::unique_ptr task, double delay_in_seconds) = 0; + /** + * Schedules a task to be invoked by this TaskRunner. The task is scheduled + * after the given number of seconds |delay_in_seconds|. The TaskRunner + * implementation takes ownership of |task|. The |task| cannot be nested + * within other task executions. + * + * Requires that |TaskRunner::NonNestableDelayedTasksEnabled()| is true. + */ + virtual void PostNonNestableDelayedTask(std::unique_ptr task, + double delay_in_seconds) {} + /** * Schedules an idle task to be invoked by this TaskRunner. The task is * scheduled when the embedder is idle. Requires that @@ -90,6 +101,11 @@ class TaskRunner { */ virtual bool NonNestableTasksEnabled() const { return false; } + /** + * Returns true if non-nestable delayed tasks are enabled for this TaskRunner. + */ + virtual bool NonNestableDelayedTasksEnabled() const { return false; } + TaskRunner() = default; virtual ~TaskRunner() = default; @@ -430,7 +446,7 @@ class Platform { * since epoch. Useful for implementing |CurrentClockTimeMillis| if * nothing special needed. */ - static double SystemClockTimeMillis(); + V8_EXPORT static double SystemClockTimeMillis(); }; } // namespace v8 diff --git a/deps/v8/include/v8-profiler.h b/deps/v8/include/v8-profiler.h index 94d3fcfcf6..3adce79be5 100644 --- a/deps/v8/include/v8-profiler.h +++ b/deps/v8/include/v8-profiler.h @@ -746,33 +746,6 @@ class V8_EXPORT HeapProfiler { kSamplingForceGC = 1 << 0, }; - typedef std::unordered_set*> - RetainerChildren; - typedef std::vector> - RetainerGroups; - typedef std::vector*, - const v8::PersistentBase*>> - RetainerEdges; - - struct RetainerInfos { - RetainerGroups groups; - RetainerEdges edges; - }; - - /** - * Callback function invoked to retrieve all RetainerInfos from the embedder. - */ - typedef RetainerInfos (*GetRetainerInfosCallback)(v8::Isolate* isolate); - - /** - * Callback function invoked for obtaining RetainedObjectInfo for - * the given JavaScript wrapper object. It is prohibited to enter V8 - * while the callback is running: only getters on the handle and - * GetPointerFromInternalField on the objects are allowed. - */ - typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id, - Local wrapper); - /** * Callback function invoked during heap snapshot generation to retrieve * the embedder object graph. The callback should use graph->AddEdge(..) to @@ -925,16 +898,6 @@ class V8_EXPORT HeapProfiler { */ void DeleteAllHeapSnapshots(); - /** Binds a callback to embedder's class ID. */ - V8_DEPRECATED( - "Use AddBuildEmbedderGraphCallback to provide info about embedder nodes", - void SetWrapperClassInfoProvider(uint16_t class_id, - WrapperInfoCallback callback)); - - V8_DEPRECATED( - "Use AddBuildEmbedderGraphCallback to provide info about embedder nodes", - void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback)); - V8_DEPRECATED( "Use AddBuildEmbedderGraphCallback to provide info about embedder nodes", void SetBuildEmbedderGraphCallback( @@ -958,80 +921,6 @@ class V8_EXPORT HeapProfiler { HeapProfiler& operator=(const HeapProfiler&); }; -/** - * Interface for providing information about embedder's objects - * held by global handles. This information is reported in two ways: - * - * 1. When calling AddObjectGroup, an embedder may pass - * RetainedObjectInfo instance describing the group. To collect - * this information while taking a heap snapshot, V8 calls GC - * prologue and epilogue callbacks. - * - * 2. When a heap snapshot is collected, V8 additionally - * requests RetainedObjectInfos for persistent handles that - * were not previously reported via AddObjectGroup. - * - * Thus, if an embedder wants to provide information about native - * objects for heap snapshots, it can do it in a GC prologue - * handler, and / or by assigning wrapper class ids in the following way: - * - * 1. Bind a callback to class id by calling SetWrapperClassInfoProvider. - * 2. Call SetWrapperClassId on certain persistent handles. - * - * V8 takes ownership of RetainedObjectInfo instances passed to it and - * keeps them alive only during snapshot collection. Afterwards, they - * are freed by calling the Dispose class function. - */ -class V8_EXPORT RetainedObjectInfo { // NOLINT - public: - /** Called by V8 when it no longer needs an instance. */ - virtual void Dispose() = 0; - - /** Returns whether two instances are equivalent. */ - virtual bool IsEquivalent(RetainedObjectInfo* other) = 0; - - /** - * Returns hash value for the instance. Equivalent instances - * must have the same hash value. - */ - virtual intptr_t GetHash() = 0; - - /** - * Returns human-readable label. It must be a null-terminated UTF-8 - * encoded string. V8 copies its contents during a call to GetLabel. - */ - virtual const char* GetLabel() = 0; - - /** - * Returns human-readable group label. It must be a null-terminated UTF-8 - * encoded string. V8 copies its contents during a call to GetGroupLabel. - * Heap snapshot generator will collect all the group names, create - * top level entries with these names and attach the objects to the - * corresponding top level group objects. There is a default - * implementation which is required because embedders don't have their - * own implementation yet. - */ - virtual const char* GetGroupLabel() { return GetLabel(); } - - /** - * Returns element count in case if a global handle retains - * a subgraph by holding one of its nodes. - */ - virtual intptr_t GetElementCount() { return -1; } - - /** Returns embedder's object size in bytes. */ - virtual intptr_t GetSizeInBytes() { return -1; } - - protected: - RetainedObjectInfo() = default; - virtual ~RetainedObjectInfo() = default; - - private: - RetainedObjectInfo(const RetainedObjectInfo&); - RetainedObjectInfo& operator=(const RetainedObjectInfo&); -}; - - /** * A struct for exporting HeapStats data from V8, using "push" model. * See HeapProfiler::GetHeapStats. diff --git a/deps/v8/include/v8-util.h b/deps/v8/include/v8-util.h index 7f12ead16b..466b99fd6b 100644 --- a/deps/v8/include/v8-util.h +++ b/deps/v8/include/v8-util.h @@ -198,12 +198,9 @@ class PersistentValueMapBase { * Call V8::RegisterExternallyReferencedObject with the map value for given * key. */ - void RegisterExternallyReferencedObject(K& key) { - assert(Contains(key)); - V8::RegisterExternallyReferencedObject( - reinterpret_cast(FromVal(Traits::Get(&impl_, key))), - reinterpret_cast(GetIsolate())); - } + V8_DEPRECATE_SOON( + "Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference", + inline void RegisterExternallyReferencedObject(K& key)); /** * Return value for key and remove it from the map. @@ -355,6 +352,15 @@ class PersistentValueMapBase { const char* label_; }; +template +inline void +PersistentValueMapBase::RegisterExternallyReferencedObject( + K& key) { + assert(Contains(key)); + V8::RegisterExternallyReferencedObject( + reinterpret_cast(FromVal(Traits::Get(&impl_, key))), + reinterpret_cast(GetIsolate())); +} template class PersistentValueMap : public PersistentValueMapBase { diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index abf640228f..402da028c3 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -9,9 +9,9 @@ // NOTE these macros are used by some of the tool scripts and the build // system so their names cannot be changed without changing the scripts. #define V8_MAJOR_VERSION 7 -#define V8_MINOR_VERSION 3 -#define V8_BUILD_NUMBER 492 -#define V8_PATCH_LEVEL 25 +#define V8_MINOR_VERSION 4 +#define V8_BUILD_NUMBER 288 +#define V8_PATCH_LEVEL 13 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index c5d9fc3a97..6ecc48af33 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -54,6 +54,7 @@ class Integer; class Isolate; template class Maybe; +class MicrotaskQueue; class Name; class Number; class NumberObject; @@ -92,6 +93,8 @@ template > class Persistent; template class Global; +template +class TracedGlobal; template class PersistentValueMap; template class PersistentValueMapBase; @@ -117,6 +120,7 @@ class Heap; class HeapObject; class Isolate; class LocalEmbedderHeapTracer; +class MicrotaskQueue; class NeverReadOnlySpaceObject; struct ScriptStreamingData; template class CustomArguments; @@ -275,6 +279,7 @@ class Local { V8_INLINE static Local New(Isolate* isolate, Local that); V8_INLINE static Local New(Isolate* isolate, const PersistentBase& that); + V8_INLINE static Local New(Isolate* isolate, const TracedGlobal& that); private: friend class Utils; @@ -303,6 +308,8 @@ class Local { template friend class PersistentValueVector; template friend class ReturnValue; + template + friend class TracedGlobal; explicit V8_INLINE Local(T* that) : val_(that) {} V8_INLINE static Local New(Isolate* isolate, T* that); @@ -542,7 +549,9 @@ template class PersistentBase { * is alive. Only allowed when the embedder is asked to trace its heap by * EmbedderHeapTracer. */ - V8_INLINE void RegisterExternalReference(Isolate* isolate) const; + V8_DEPRECATE_SOON( + "Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference", + V8_INLINE void RegisterExternalReference(Isolate* isolate) const); /** * Marks the reference to this object independent. Garbage collector is free @@ -550,9 +559,10 @@ template class PersistentBase { * independent handle should not assume that it will be preceded by a global * GC prologue callback or followed by a global GC epilogue callback. */ - V8_DEPRECATE_SOON( - "Objects are always considered independent. " - "Use MarkActive to avoid collecting otherwise dead weak handles.", + V8_DEPRECATED( + "Weak objects are always considered independent. " + "Use TracedGlobal when trying to use EmbedderHeapTracer. " + "Use a strong handle when trying to keep an object alive.", V8_INLINE void MarkIndependent()); /** @@ -562,22 +572,19 @@ template class PersistentBase { * * This bit is cleared after the each garbage collection pass. */ - V8_INLINE void MarkActive(); + V8_DEPRECATE_SOON("Use TracedGlobal.", V8_INLINE void MarkActive()); - V8_DEPRECATE_SOON("See MarkIndependent.", - V8_INLINE bool IsIndependent() const); + V8_DEPRECATED("See MarkIndependent.", V8_INLINE bool IsIndependent() const); /** Checks if the handle holds the only reference to an object. */ - V8_DEPRECATE_SOON( - "Garbage collection internal state should not be relied on.", - V8_INLINE bool IsNearDeath() const); + V8_DEPRECATED("Garbage collection internal state should not be relied on.", + V8_INLINE bool IsNearDeath() const); /** Returns true if the handle's reference is weak. */ V8_INLINE bool IsWeak() const; /** - * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface - * description in v8-profiler.h for details. + * Assigns a wrapper class ID to the handle. */ V8_INLINE void SetWrapperClassId(uint16_t class_id); @@ -758,6 +765,7 @@ class Global : public PersistentBase { * A Global with no storage cell. */ V8_INLINE Global() : PersistentBase(nullptr) {} + /** * Construct a Global from a Local. * When the Local is non-empty, a new storage cell is created @@ -768,6 +776,7 @@ class Global : public PersistentBase { : PersistentBase(PersistentBase::New(isolate, *that)) { TYPE_CHECK(T, S); } + /** * Construct a Global from a PersistentBase. * When the Persistent is non-empty, a new storage cell is created @@ -778,26 +787,20 @@ class Global : public PersistentBase { : PersistentBase(PersistentBase::New(isolate, that.val_)) { TYPE_CHECK(T, S); } + /** * Move constructor. */ - V8_INLINE Global(Global&& other) : PersistentBase(other.val_) { - other.val_ = nullptr; - } + V8_INLINE Global(Global&& other); + V8_INLINE ~Global() { this->Reset(); } + /** * Move via assignment. */ template - V8_INLINE Global& operator=(Global&& rhs) { // NOLINT - TYPE_CHECK(T, S); - if (this != &rhs) { - this->Reset(); - this->val_ = rhs.val_; - rhs.val_ = nullptr; - } - return *this; - } + V8_INLINE Global& operator=(Global&& rhs); + /** * Pass allows returning uniques from functions, etc. */ @@ -822,6 +825,151 @@ class Global : public PersistentBase { template using UniquePersistent = Global; +/** + * A traced handle with move semantics, similar to std::unique_ptr. The handle + * is to be used together with |v8::EmbedderHeapTracer| and specifies edges from + * the embedder into V8's heap. + * + * The exact semantics are: + * - Tracing garbage collections use |v8::EmbedderHeapTracer|. + * - Non-tracing garbage collections refer to + * |v8::EmbedderHeapTracer::IsRootForNonTracingGC()| whether the handle should + * be treated as root or not. + */ +template +class V8_EXPORT TracedGlobal { + public: + /** + * An empty TracedGlobal without storage cell. + */ + TracedGlobal() = default; + ~TracedGlobal() { Reset(); } + + /** + * Construct a TracedGlobal from a Local. + * + * When the Local is non-empty, a new storage cell is created + * pointing to the same object. + */ + template + TracedGlobal(Isolate* isolate, Local that) + : val_(New(isolate, *that, &val_)) { + TYPE_CHECK(T, S); + } + + /** + * Move constructor initializing TracedGlobal from an existing one. + */ + V8_INLINE TracedGlobal(TracedGlobal&& other); + + /** + * Move assignment operator initializing TracedGlobal from an existing one. + */ + template + V8_INLINE TracedGlobal& operator=(TracedGlobal&& rhs); + + /** + * TracedGlobal only supports move semantics and forbids copying. + */ + TracedGlobal(const TracedGlobal&) = delete; + void operator=(const TracedGlobal&) = delete; + + /** + * Returns true if this TracedGlobal is empty, i.e., has not been assigned an + * object. + */ + bool IsEmpty() const { return val_ == nullptr; } + + /** + * If non-empty, destroy the underlying storage cell. |IsEmpty| will return + * true after this call. + */ + V8_INLINE void Reset(); + + /** + * If non-empty, destroy the underlying storage cell and create a new one with + * the contents of other if other is non empty + */ + template + V8_INLINE void Reset(Isolate* isolate, const Local& other); + + /** + * Construct a Local from this handle. + */ + Local Get(Isolate* isolate) const { return Local::New(isolate, *this); } + + template + V8_INLINE TracedGlobal& As() const { + return reinterpret_cast&>( + const_cast&>(*this)); + } + + template + V8_INLINE bool operator==(const TracedGlobal& that) const { + internal::Address* a = reinterpret_cast(this->val_); + internal::Address* b = reinterpret_cast(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template + V8_INLINE bool operator==(const Local& that) const { + internal::Address* a = reinterpret_cast(this->val_); + internal::Address* b = reinterpret_cast(that.val_); + if (a == nullptr) return b == nullptr; + if (b == nullptr) return false; + return *a == *b; + } + + template + V8_INLINE bool operator!=(const TracedGlobal& that) const { + return !operator==(that); + } + + template + V8_INLINE bool operator!=(const Local& that) const { + return !operator==(that); + } + + /** + * Assigns a wrapper class ID to the handle. + */ + V8_INLINE void SetWrapperClassId(uint16_t class_id); + + /** + * Returns the class ID previously assigned to this handle or 0 if no class ID + * was previously assigned. + */ + V8_INLINE uint16_t WrapperClassId() const; + + /** + * Adds a finalization callback to the handle. The type of this callback is + * similar to WeakCallbackType::kInternalFields, i.e., it will pass the + * parameter and the first two internal fields of the object. + * + * The callback is then supposed to reset the handle in the callback. No + * further V8 API may be called in this callback. In case additional work + * involving V8 needs to be done, a second callback can be scheduled using + * WeakCallbackInfo::SetSecondPassCallback. + */ + V8_INLINE void SetFinalizationCallback( + void* parameter, WeakCallbackInfo::Callback callback); + + private: + V8_INLINE static T* New(Isolate* isolate, T* that, T** slot); + + T* operator*() const { return this->val_; } + + T* val_ = nullptr; + + friend class EmbedderHeapTracer; + template + friend class Local; + friend class Object; + template + friend class ReturnValue; +}; /** * A stack-allocated class that governs a number of local handles. @@ -1861,10 +2009,6 @@ class V8_EXPORT JSON { /** * Value serialization compatible with the HTML structured clone algorithm. * The format is backward-compatible (i.e. safe to store to disk). - * - * WARNING: This API is under development, and changes (including incompatible - * changes to the API or wire format) may occur without notice until this - * warning is removed. */ class V8_EXPORT ValueSerializer { public: @@ -1985,10 +2129,6 @@ class V8_EXPORT ValueSerializer { /** * Deserializes values from data written with ValueSerializer, or a compatible * implementation. - * - * WARNING: This API is under development, and changes (including incompatible - * changes to the API or wire format) may occur without notice until this - * warning is removed. */ class V8_EXPORT ValueDeserializer { public: @@ -2416,9 +2556,9 @@ class V8_EXPORT Value : public Data { bool BooleanValue(Isolate* isolate) const; - V8_DEPRECATE_SOON("BooleanValue can never throw. Use Isolate version.", - V8_WARN_UNUSED_RESULT Maybe BooleanValue( - Local context) const); + V8_DEPRECATED("BooleanValue can never throw. Use Isolate version.", + V8_WARN_UNUSED_RESULT Maybe BooleanValue( + Local context) const); V8_WARN_UNUSED_RESULT Maybe NumberValue(Local context) const; V8_WARN_UNUSED_RESULT Maybe IntegerValue( Local context) const; @@ -2615,10 +2755,6 @@ class V8_EXPORT String : public Name { public: virtual ~ExternalStringResourceBase() = default; - V8_DEPRECATED("Use IsCacheable().", virtual bool IsCompressible() const) { - return false; - } - /** * If a string is cacheable, the value returned by * ExternalStringResource::data() may be cached, otherwise it is not @@ -3381,7 +3517,6 @@ class V8_EXPORT Object : public Value { * array returned by this method contains the same values as would * be enumerated by a for-in statement over this object. */ - V8_DEPRECATED("Use maybe version", Local GetPropertyNames()); V8_WARN_UNUSED_RESULT MaybeLocal GetPropertyNames( Local context); V8_WARN_UNUSED_RESULT MaybeLocal GetPropertyNames( @@ -3394,7 +3529,6 @@ class V8_EXPORT Object : public Value { * the returned array doesn't contain the names of properties from * prototype objects. */ - V8_DEPRECATED("Use maybe version", Local GetOwnPropertyNames()); V8_WARN_UNUSED_RESULT MaybeLocal GetOwnPropertyNames( Local context); @@ -3450,12 +3584,17 @@ class V8_EXPORT Object : public Value { /** Gets the number of internal fields for this Object. */ int InternalFieldCount(); - /** Same as above, but works for Persistents */ + /** Same as above, but works for PersistentBase. */ V8_INLINE static int InternalFieldCount( const PersistentBase& object) { return object.val_->InternalFieldCount(); } + /** Same as above, but works for TracedGlobal. */ + V8_INLINE static int InternalFieldCount(const TracedGlobal& object) { + return object.val_->InternalFieldCount(); + } + /** Gets the value from an internal field. */ V8_INLINE Local GetInternalField(int index); @@ -3469,12 +3608,18 @@ class V8_EXPORT Object : public Value { */ V8_INLINE void* GetAlignedPointerFromInternalField(int index); - /** Same as above, but works for Persistents */ + /** Same as above, but works for PersistentBase. */ V8_INLINE static void* GetAlignedPointerFromInternalField( const PersistentBase& object, int index) { return object.val_->GetAlignedPointerFromInternalField(index); } + /** Same as above, but works for TracedGlobal. */ + V8_INLINE static void* GetAlignedPointerFromInternalField( + const TracedGlobal& object, int index) { + return object.val_->GetAlignedPointerFromInternalField(index); + } + /** * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such * a field, GetAlignedPointerFromInternalField must be used, everything else @@ -3493,8 +3638,6 @@ class V8_EXPORT Object : public Value { Local key); V8_WARN_UNUSED_RESULT Maybe HasOwnProperty(Local context, uint32_t index); - V8_DEPRECATED("Use maybe version", - bool HasRealNamedProperty(Local key)); /** * Use HasRealNamedProperty() if you want to check if an object has an own * property without causing side effects, i.e., without calling interceptors. @@ -3510,12 +3653,8 @@ class V8_EXPORT Object : public Value { */ V8_WARN_UNUSED_RESULT Maybe HasRealNamedProperty(Local context, Local key); - V8_DEPRECATED("Use maybe version", - bool HasRealIndexedProperty(uint32_t index)); V8_WARN_UNUSED_RESULT Maybe HasRealIndexedProperty( Local context, uint32_t index); - V8_DEPRECATED("Use maybe version", - bool HasRealNamedCallbackProperty(Local key)); V8_WARN_UNUSED_RESULT Maybe HasRealNamedCallbackProperty( Local context, Local key); @@ -3761,6 +3900,8 @@ class ReturnValue { template V8_INLINE void Set(const Global& handle); template + V8_INLINE void Set(const TracedGlobal& handle); + template V8_INLINE void Set(const Local handle); // Fast primitive setters V8_INLINE void Set(bool value); @@ -3984,11 +4125,6 @@ class V8_EXPORT Function : public Object { Local data = Local(), int length = 0, ConstructorBehavior behavior = ConstructorBehavior::kAllow, SideEffectType side_effect_type = SideEffectType::kHasSideEffect); - static V8_DEPRECATED("Use maybe version", - Local New(Isolate* isolate, - FunctionCallback callback, - Local data = Local(), - int length = 0)); V8_WARN_UNUSED_RESULT MaybeLocal NewInstance( Local context, int argc, Local argv[]) const; @@ -4007,9 +4143,6 @@ class V8_EXPORT Function : public Object { Local context, int argc, Local argv[], SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const; - V8_DEPRECATED("Use maybe version", - Local Call(Local recv, int argc, - Local argv[])); V8_WARN_UNUSED_RESULT MaybeLocal Call(Local context, Local recv, int argc, Local argv[]); @@ -4194,14 +4327,6 @@ class V8_EXPORT PropertyDescriptor { // GenericDescriptor PropertyDescriptor(); - // DataDescriptor (implicit / DEPRECATED) - // Templatized such that the explicit constructor is chosen first. - // TODO(clemensh): Remove after 7.3 branch. - template - V8_DEPRECATED( - "Use explicit constructor", - PropertyDescriptor(Local value)); // NOLINT(runtime/explicit) - // DataDescriptor explicit PropertyDescriptor(Local value); @@ -4242,11 +4367,6 @@ class V8_EXPORT PropertyDescriptor { PrivateData* private_; }; -// TODO(clemensh): Remove after 7.3 branch. -template -PropertyDescriptor::PropertyDescriptor(Local value) - : PropertyDescriptor(value) {} - /** * An instance of the built-in Proxy constructor (ECMA-262, 6th Edition, * 26.2.1). @@ -4336,27 +4456,6 @@ class V8_EXPORT CompiledWasmModule { // An instance of WebAssembly.Module. class V8_EXPORT WasmModuleObject : public Object { public: - // TODO(clemensh): Remove after 7.3 branch. - typedef std::pair, size_t> SerializedModule; - - /** - * A unowned reference to a byte buffer. - * TODO(clemensh): Remove after 7.3 branch. - */ - struct BufferReference { - const uint8_t* start; - size_t size; - BufferReference(const uint8_t* start, size_t size) - : start(start), size(size) {} - - // Implicit conversion to and from MemorySpan. - BufferReference(MemorySpan span) // NOLINT(runtime/explicit) - : start(span.data()), size(span.size()) {} - operator MemorySpan() const { - return MemorySpan{start, size}; - } - }; - /** * An opaque, native heap object for transferring wasm modules. It * supports move semantics, and does not support copy semantics. @@ -4398,25 +4497,12 @@ class V8_EXPORT WasmModuleObject : public Object { static MaybeLocal FromTransferrableModule( Isolate* isolate, const TransferrableModule&); - /** - * Get the wasm-encoded bytes that were used to compile this module. - */ - V8_DEPRECATED("Use CompiledWasmModule::GetWireBytesRef()", - BufferReference GetWasmWireBytesRef()); - /** * Get the compiled module for this module object. The compiled module can be * shared by several module objects. */ CompiledWasmModule GetCompiledModule(); - /** - * Serialize the compiled module. The serialized data does not include the - * uncompiled bytes. - */ - V8_DEPRECATED("Use CompiledWasmModule::Serialize()", - SerializedModule Serialize()); - /** * If possible, deserialize the module, otherwise compile it from the provided * uncompiled bytes. @@ -5079,7 +5165,8 @@ class V8_EXPORT SharedArrayBuffer : public Object { allocation_length_(0), allocation_mode_(Allocator::AllocationMode::kNormal), deleter_(nullptr), - deleter_data_(nullptr) {} + deleter_data_(nullptr), + is_growable_(false) {} void* AllocationBase() const { return allocation_base_; } size_t AllocationLength() const { return allocation_length_; } @@ -5091,12 +5178,13 @@ class V8_EXPORT SharedArrayBuffer : public Object { size_t ByteLength() const { return byte_length_; } DeleterCallback Deleter() const { return deleter_; } void* DeleterData() const { return deleter_data_; } + bool IsGrowable() const { return is_growable_; } private: Contents(void* data, size_t byte_length, void* allocation_base, size_t allocation_length, Allocator::AllocationMode allocation_mode, DeleterCallback deleter, - void* deleter_data); + void* deleter_data, bool is_growable); void* data_; size_t byte_length_; @@ -5105,6 +5193,7 @@ class V8_EXPORT SharedArrayBuffer : public Object { Allocator::AllocationMode allocation_mode_; DeleterCallback deleter_; void* deleter_data_; + bool is_growable_; friend class SharedArrayBuffer; }; @@ -5132,6 +5221,14 @@ class V8_EXPORT SharedArrayBuffer : public Object { Isolate* isolate, void* data, size_t byte_length, ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); + /** + * Create a new SharedArrayBuffer over an existing memory block. Propagate + * flags to indicate whether the underlying buffer can be grown. + */ + static Local New( + Isolate* isolate, const SharedArrayBuffer::Contents&, + ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); + /** * Returns true if SharedArrayBuffer is externalized, that is, does not * own its memory block. @@ -5192,6 +5289,21 @@ class V8_EXPORT Date : public Object { V8_INLINE static Date* Cast(Value* obj); + /** + * Time zone redetection indicator for + * DateTimeConfigurationChangeNotification. + * + * kSkip indicates V8 that the notification should not trigger redetecting + * host time zone. kRedetect indicates V8 that host time zone should be + * redetected, and used to set the default time zone. + * + * The host time zone detection may require file system access or similar + * operations unlikely to be available inside a sandbox. If v8 is run inside a + * sandbox, the host time zone has to be detected outside the sandbox before + * calling DateTimeConfigurationChangeNotification function. + */ + enum class TimeZoneDetection { kSkip, kRedetect }; + /** * Notification that the embedder has changed the time zone, * daylight savings time, or other date / time configuration @@ -5204,7 +5316,11 @@ class V8_EXPORT Date : public Object { * This API should not be called more than needed as it will * negatively impact the performance of date operations. */ - static void DateTimeConfigurationChangeNotification(Isolate* isolate); + V8_DEPRECATE_SOON( + "Use Isolate::DateTimeConfigurationChangeNotification", + static void DateTimeConfigurationChangeNotification( + Isolate* isolate, + TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip)); private: static void CheckCast(Value* obj); @@ -5829,7 +5945,6 @@ class V8_EXPORT FunctionTemplate : public Template { SideEffectType side_effect_type = SideEffectType::kHasSideEffect); /** Returns the unique function instance in the current execution context.*/ - V8_DEPRECATED("Use maybe version", Local GetFunction()); V8_WARN_UNUSED_RESULT MaybeLocal GetFunction( Local context); @@ -5904,7 +6019,8 @@ class V8_EXPORT FunctionTemplate : public Template { * function template. By default, instances of a function template * are not ignored. */ - void SetHiddenPrototype(bool value); + V8_DEPRECATED("This feature is incompatible with ES6+.", + void SetHiddenPrototype(bool value)); /** * Sets the ReadOnly flag in the attributes of the 'prototype' property @@ -6126,7 +6242,6 @@ class V8_EXPORT ObjectTemplate : public Template { size_t index); /** Creates a new instance of this template.*/ - V8_DEPRECATED("Use maybe version", Local NewInstance()); V8_WARN_UNUSED_RESULT MaybeLocal NewInstance(Local context); /** @@ -6346,20 +6461,6 @@ class V8_EXPORT AccessorSignature : public Data { // --- Extensions --- -V8_DEPRECATED("Implementation detail", class) -V8_EXPORT ExternalOneByteStringResourceImpl - : public String::ExternalOneByteStringResource { - public: - ExternalOneByteStringResourceImpl() : data_(nullptr), length_(0) {} - ExternalOneByteStringResourceImpl(const char* data, size_t length) - : data_(data), length_(length) {} - const char* data() const override { return data_; } - size_t length() const override { return length_; } - - private: - const char* data_; - size_t length_; -}; /** * Ignore @@ -6381,8 +6482,8 @@ class V8_EXPORT Extension { // NOLINT const String::ExternalOneByteStringResource* source() const { return source_; } - int dependency_count() { return dep_count_; } - const char** dependencies() { return deps_; } + int dependency_count() const { return dep_count_; } + const char** dependencies() const { return deps_; } void set_auto_enable(bool value) { auto_enable_ = value; } bool auto_enable() { return auto_enable_; } @@ -6399,9 +6500,11 @@ class V8_EXPORT Extension { // NOLINT bool auto_enable_; }; +V8_DEPRECATED( + "Use unique_ptr version or stop using extension (http://crbug.com/334679).", + void V8_EXPORT RegisterExtension(Extension* extension)); -void V8_EXPORT RegisterExtension(Extension* extension); - +void V8_EXPORT RegisterExtension(std::unique_ptr); // --- Statics --- @@ -6461,8 +6564,14 @@ class V8_EXPORT ResourceConstraints { void set_code_range_size(size_t limit_in_mb) { code_range_size_ = limit_in_mb; } - size_t max_zone_pool_size() const { return max_zone_pool_size_; } - void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; } + V8_DEPRECATE_SOON("Zone does not pool memory any more.", + size_t max_zone_pool_size() const) { + return max_zone_pool_size_; + } + V8_DEPRECATE_SOON("Zone does not pool memory any more.", + void set_max_zone_pool_size(size_t bytes)) { + max_zone_pool_size_ = bytes; + } private: // max_semi_space_size_ is in KB @@ -6636,6 +6745,7 @@ typedef void (*PromiseRejectCallback)(PromiseRejectMessage message); // --- Microtasks Callbacks --- typedef void (*MicrotasksCompletedCallback)(Isolate*); +typedef void (*MicrotasksCompletedCallbackWithData)(Isolate*, void*); typedef void (*MicrotaskCallback)(void* data); @@ -6648,6 +6758,80 @@ typedef void (*MicrotaskCallback)(void* data); */ enum class MicrotasksPolicy { kExplicit, kScoped, kAuto }; +/** + * Represents the microtask queue, where microtasks are stored and processed. + * https://html.spec.whatwg.org/multipage/webappapis.html#microtask-queue + * https://html.spec.whatwg.org/multipage/webappapis.html#enqueuejob(queuename,-job,-arguments) + * https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint + * + * A MicrotaskQueue instance may be associated to multiple Contexts by passing + * it to Context::New(), and they can be detached by Context::DetachGlobal(). + * The embedder must keep the MicrotaskQueue instance alive until all associated + * Contexts are gone or detached. + * + * Use the same instance of MicrotaskQueue for all Contexts that may access each + * other synchronously. E.g. for Web embedding, use the same instance for all + * origins that share the same URL scheme and eTLD+1. + */ +class V8_EXPORT MicrotaskQueue { + public: + /** + * Creates an empty MicrotaskQueue instance. + */ + static std::unique_ptr New(); + + virtual ~MicrotaskQueue() = default; + + /** + * Enqueues the callback to the queue. + */ + virtual void EnqueueMicrotask(Isolate* isolate, + Local microtask) = 0; + + /** + * Enqueues the callback to the queue. + */ + virtual void EnqueueMicrotask(v8::Isolate* isolate, + MicrotaskCallback callback, + void* data = nullptr) = 0; + + /** + * Adds a callback to notify the embedder after microtasks were run. The + * callback is triggered by explicit RunMicrotasks call or automatic + * microtasks execution (see Isolate::SetMicrotasksPolicy). + * + * Callback will trigger even if microtasks were attempted to run, + * but the microtasks queue was empty and no single microtask was actually + * executed. + * + * Executing scripts inside the callback will not re-trigger microtasks and + * the callback. + */ + virtual void AddMicrotasksCompletedCallback( + MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0; + + /** + * Removes callback that was installed by AddMicrotasksCompletedCallback. + */ + virtual void RemoveMicrotasksCompletedCallback( + MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0; + + /** + * Runs microtasks if no microtask is running on this MicrotaskQueue instance. + */ + virtual void PerformCheckpoint(Isolate* isolate) = 0; + + /** + * Returns true if a microtask is running on this MicrotaskQueue instance. + */ + virtual bool IsRunningMicrotasks() const = 0; + + private: + friend class internal::MicrotaskQueue; + MicrotaskQueue() = default; + MicrotaskQueue(const MicrotaskQueue&) = delete; + MicrotaskQueue& operator=(const MicrotaskQueue&) = delete; +}; /** * This scope is used to control microtasks when kScopeMicrotasksInvocation @@ -6663,6 +6847,7 @@ class V8_EXPORT MicrotasksScope { enum Type { kRunMicrotasks, kDoNotRunMicrotasks }; MicrotasksScope(Isolate* isolate, Type type); + MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type); ~MicrotasksScope(); /** @@ -6686,6 +6871,7 @@ class V8_EXPORT MicrotasksScope { private: internal::Isolate* const isolate_; + internal::MicrotaskQueue* const microtask_queue_; bool run_; }; @@ -6874,8 +7060,6 @@ class V8_EXPORT HeapCodeStatistics { friend class Isolate; }; -class RetainedObjectInfo; - /** * A JIT code event is issued each time code is added, moved or removed. * @@ -6956,7 +7140,7 @@ struct JitCodeEvent { * See documentation https://developers.google.com/web/tools/chrome-devtools/ * profile/evaluate-performance/rail */ -enum RAILMode { +enum RAILMode : unsigned { // Response performance mode: In this mode very low virtual machine latency // is provided. V8 will try to avoid JavaScript execution interruptions. // Throughput may be throttled. @@ -7037,8 +7221,23 @@ class V8_EXPORT EmbedderHeapTracer { kEmpty, }; + /** + * Interface for iterating through TracedGlobal handles. + */ + class V8_EXPORT TracedGlobalHandleVisitor { + public: + virtual ~TracedGlobalHandleVisitor() = default; + virtual void VisitTracedGlobalHandle(const TracedGlobal& value) = 0; + }; + virtual ~EmbedderHeapTracer() = default; + /** + * Iterates all TracedGlobal handles created for the v8::Isolate the tracer is + * attached to. + */ + void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor); + /** * Called by v8 to register internal fields of found wrappers. * @@ -7048,6 +7247,8 @@ class V8_EXPORT EmbedderHeapTracer { virtual void RegisterV8References( const std::vector >& embedder_fields) = 0; + void RegisterEmbedderReference(const TracedGlobal& ref); + /** * Called at the beginning of a GC cycle. */ @@ -7084,15 +7285,6 @@ class V8_EXPORT EmbedderHeapTracer { */ virtual void EnterFinalPause(EmbedderStackState stack_state) = 0; - /** - * Called when tracing is aborted. - * - * The embedder is expected to throw away all intermediate data and reset to - * the initial state. - */ - V8_DEPRECATED("Obsolete as V8 will not abort tracing anymore.", - virtual void AbortTracing()) {} - /* * Called by the embedder to request immediate finalization of the currently * running tracing phase that has been started with TracePrologue and not @@ -7104,6 +7296,17 @@ 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. + * + * Default implementation will keep all TracedGlobal references as roots. + */ + virtual bool IsRootForNonTracingGC( + const v8::TracedGlobal& handle) { + return true; + } + /* * Called by the embedder to immediately perform a full garbage collection. * @@ -7314,6 +7517,7 @@ class V8_EXPORT Isolate { class V8_EXPORT SuppressMicrotaskExecutionScope { public: explicit SuppressMicrotaskExecutionScope(Isolate* isolate); + explicit SuppressMicrotaskExecutionScope(MicrotaskQueue* microtask_queue); ~SuppressMicrotaskExecutionScope(); // Prevent copying of Scope objects. @@ -7324,6 +7528,7 @@ class V8_EXPORT Isolate { private: internal::Isolate* const isolate_; + internal::MicrotaskQueue* const microtask_queue_; }; /** @@ -7434,6 +7639,7 @@ class V8_EXPORT Isolate { kRegExpMatchIsTrueishOnNonJSRegExp = 72, kRegExpMatchIsFalseishOnJSRegExp = 73, kDateGetTimezoneOffset = 74, + kStringNormalize = 75, // If you add new values here, you'll also need to update Chromium's: // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to @@ -7987,18 +8193,18 @@ class V8_EXPORT Isolate { void SetPromiseRejectCallback(PromiseRejectCallback callback); /** - * Runs the Microtask Work Queue until empty + * Runs the default MicrotaskQueue until it gets empty. * Any exceptions thrown by microtask callbacks are swallowed. */ void RunMicrotasks(); /** - * Enqueues the callback to the Microtask Work Queue + * Enqueues the callback to the default MicrotaskQueue */ void EnqueueMicrotask(Local microtask); /** - * Enqueues the callback to the Microtask Work Queue + * Enqueues the callback to the default MicrotaskQueue */ void EnqueueMicrotask(MicrotaskCallback callback, void* data = nullptr); @@ -8014,14 +8220,15 @@ class V8_EXPORT Isolate { /** * Adds a callback to notify the host application after - * microtasks were run. The callback is triggered by explicit RunMicrotasks - * call or automatic microtasks execution (see SetAutorunMicrotasks). + * microtasks were run on the default MicrotaskQueue. The callback is + * triggered by explicit RunMicrotasks call or automatic microtasks execution + * (see SetMicrotaskPolicy). * * Callback will trigger even if microtasks were attempted to run, * but the microtasks queue was empty and no single microtask was actually * executed. * - * Executing scriptsinside the callback will not re-trigger microtasks and + * Executing scripts inside the callback will not re-trigger microtasks and * the callback. */ void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback); @@ -8244,10 +8451,6 @@ class V8_EXPORT Isolate { void SetWasmModuleCallback(ExtensionCallback callback); void SetWasmInstanceCallback(ExtensionCallback callback); - V8_DEPRECATED( - "The callback set in SetWasmStreamingCallback is used now", - void SetWasmCompileStreamingCallback(ApiImplementationCallback callback)); - void SetWasmStreamingCallback(WasmStreamingCallback callback); void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback); @@ -8321,7 +8524,7 @@ class V8_EXPORT Isolate { * garbage collection but is free to visit an arbitrary superset of these * objects. */ - V8_DEPRECATE_SOON( + V8_DEPRECATED( "Use VisitHandlesWithClassIds", void VisitHandlesForPartialDependence(PersistentHandleVisitor* visitor)); @@ -8345,6 +8548,45 @@ class V8_EXPORT Isolate { */ void SetAllowAtomicsWait(bool allow); + /** + * Time zone redetection indicator for + * DateTimeConfigurationChangeNotification. + * + * kSkip indicates V8 that the notification should not trigger redetecting + * host time zone. kRedetect indicates V8 that host time zone should be + * redetected, and used to set the default time zone. + * + * The host time zone detection may require file system access or similar + * operations unlikely to be available inside a sandbox. If v8 is run inside a + * sandbox, the host time zone has to be detected outside the sandbox before + * calling DateTimeConfigurationChangeNotification function. + */ + enum class TimeZoneDetection { kSkip, kRedetect }; + + /** + * Notification that the embedder has changed the time zone, daylight savings + * time or other date / time configuration parameters. V8 keeps a cache of + * various values used for date / time computation. This notification will + * reset those cached values for the current context so that date / time + * configuration changes would be reflected. + * + * This API should not be called more than needed as it will negatively impact + * the performance of date operations. + */ + void DateTimeConfigurationChangeNotification( + TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip); + + /** + * Notification that the embedder has changed the locale. V8 keeps a cache of + * various values used for locale computation. This notification will reset + * those cached values for the current context so that locale configuration + * changes would be reflected. + * + * This API should not be called more than needed as it will negatively impact + * the performance of locale operations. + */ + void LocaleConfigurationChangeNotification(); + Isolate() = delete; ~Isolate() = delete; Isolate(const Isolate&) = delete; @@ -8547,13 +8789,6 @@ class V8_EXPORT V8 { void* context)); #endif // V8_OS_POSIX - /** - * Enable the default signal handler rather than using one provided by the - * embedder. - */ - V8_DEPRECATED("Use EnableWebAssemblyTrapHandler", - static bool RegisterDefaultSignalHandler()); - /** * Activate trap-based bounds checking for WebAssembly. * @@ -8567,13 +8802,24 @@ class V8_EXPORT V8 { static internal::Address* GlobalizeReference(internal::Isolate* isolate, internal::Address* handle); - static internal::Address* CopyPersistent(internal::Address* handle); + static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate, + internal::Address* handle, + internal::Address* slot); + static void MoveGlobalReference(internal::Address** from, + internal::Address** to); + static void MoveTracedGlobalReference(internal::Address** from, + internal::Address** to); + static internal::Address* CopyGlobalReference(internal::Address* from); static void DisposeGlobal(internal::Address* global_handle); + static void DisposeTracedGlobal(internal::Address* global_handle); static void MakeWeak(internal::Address* location, void* data, WeakCallbackInfo::Callback weak_callback, WeakCallbackType type); static void MakeWeak(internal::Address** location_addr); static void* ClearWeak(internal::Address* location); + static void SetFinalizationCallbackTraced( + internal::Address* location, void* parameter, + WeakCallbackInfo::Callback callback); static void AnnotateStrongRetainer(internal::Address* location, const char* label); static Value* Eternalize(Isolate* isolate, Value* handle); @@ -8587,12 +8833,16 @@ class V8_EXPORT V8 { static void FromJustIsNothing(); static void ToLocalEmpty(); static void InternalFieldOutOfBounds(int index); + template + friend class Global; template friend class Local; template friend class MaybeLocal; template friend class Maybe; template + friend class TracedGlobal; + template friend class WeakCallbackInfo; template friend class Eternal; template friend class PersistentBase; @@ -9048,7 +9298,8 @@ class V8_EXPORT Context { MaybeLocal global_template = MaybeLocal(), MaybeLocal global_object = MaybeLocal(), DeserializeInternalFieldsCallback internal_fields_deserializer = - DeserializeInternalFieldsCallback()); + DeserializeInternalFieldsCallback(), + MicrotaskQueue* microtask_queue = nullptr); /** * Create a new context from a (non-default) context snapshot. There @@ -9068,13 +9319,13 @@ class V8_EXPORT Context { * * \param global_object See v8::Context::New. */ - static MaybeLocal FromSnapshot( Isolate* isolate, size_t context_snapshot_index, DeserializeInternalFieldsCallback embedder_fields_deserializer = DeserializeInternalFieldsCallback(), ExtensionConfiguration* extensions = nullptr, - MaybeLocal global_object = MaybeLocal()); + MaybeLocal global_object = MaybeLocal(), + MicrotaskQueue* microtask_queue = nullptr); /** * Returns an global object that isn't backed by an actual context. @@ -9452,6 +9703,10 @@ Local Local::New(Isolate* isolate, const PersistentBase& that) { return New(isolate, that.val_); } +template +Local Local::New(Isolate* isolate, const TracedGlobal& that) { + return New(isolate, that.val_); +} template Local Local::New(Isolate* isolate, T* that) { @@ -9514,7 +9769,7 @@ void Persistent::Copy(const Persistent& that) { this->Reset(); if (that.IsEmpty()) return; internal::Address* p = reinterpret_cast(that.val_); - this->val_ = reinterpret_cast(V8::CopyPersistent(p)); + this->val_ = reinterpret_cast(V8::CopyGlobalReference(p)); M::Copy(that, this); } @@ -9647,6 +9902,109 @@ uint16_t PersistentBase::WrapperClassId() const { return *reinterpret_cast(addr); } +template +Global::Global(Global&& other) : PersistentBase(other.val_) { + if (other.val_ != nullptr) { + V8::MoveGlobalReference(reinterpret_cast(&other.val_), + reinterpret_cast(&this->val_)); + other.val_ = nullptr; + } +} + +template +template +Global& Global::operator=(Global&& rhs) { + TYPE_CHECK(T, S); + if (this != &rhs) { + this->Reset(); + if (rhs.val_ != nullptr) { + this->val_ = rhs.val_; + V8::MoveGlobalReference( + reinterpret_cast(&rhs.val_), + reinterpret_cast(&this->val_)); + rhs.val_ = nullptr; + } + } + return *this; +} + +template +T* TracedGlobal::New(Isolate* isolate, T* that, T** slot) { + if (that == nullptr) return nullptr; + internal::Address* p = reinterpret_cast(that); + return reinterpret_cast(V8::GlobalizeTracedReference( + reinterpret_cast(isolate), p, + reinterpret_cast(slot))); +} + +template +void TracedGlobal::Reset() { + if (IsEmpty()) return; + V8::DisposeTracedGlobal(reinterpret_cast(val_)); + val_ = nullptr; +} + +template +template +void TracedGlobal::Reset(Isolate* isolate, const Local& other) { + TYPE_CHECK(T, S); + Reset(); + if (other.IsEmpty()) return; + this->val_ = New(isolate, other.val_, &val_); +} + +template +TracedGlobal::TracedGlobal(TracedGlobal&& other) : val_(other.val_) { + if (other.val_ != nullptr) { + V8::MoveTracedGlobalReference( + reinterpret_cast(&other.val_), + reinterpret_cast(&this->val_)); + other.val_ = nullptr; + } +} + +template +template +TracedGlobal& TracedGlobal::operator=(TracedGlobal&& rhs) { + TYPE_CHECK(T, S); + if (this != &rhs) { + this->Reset(); + if (rhs.val_ != nullptr) { + this->val_ = rhs.val_; + V8::MoveTracedGlobalReference( + reinterpret_cast(&rhs.val_), + reinterpret_cast(&this->val_)); + rhs.val_ = nullptr; + } + } + return *this; +} + +template +void TracedGlobal::SetWrapperClassId(uint16_t class_id) { + typedef internal::Internals I; + if (IsEmpty()) return; + internal::Address* obj = reinterpret_cast(this->val_); + uint8_t* addr = reinterpret_cast(obj) + I::kNodeClassIdOffset; + *reinterpret_cast(addr) = class_id; +} + +template +uint16_t TracedGlobal::WrapperClassId() const { + typedef internal::Internals I; + if (IsEmpty()) return 0; + internal::Address* obj = reinterpret_cast(this->val_); + uint8_t* addr = reinterpret_cast(obj) + I::kNodeClassIdOffset; + return *reinterpret_cast(addr); +} + +template +void TracedGlobal::SetFinalizationCallback( + void* parameter, typename WeakCallbackInfo::Callback callback) { + V8::SetFinalizationCallbackTraced( + reinterpret_cast(this->val_), parameter, callback); +} + template ReturnValue::ReturnValue(internal::Address* slot) : value_(slot) {} @@ -9672,6 +10030,17 @@ void ReturnValue::Set(const Global& handle) { } } +template +template +void ReturnValue::Set(const TracedGlobal& handle) { + TYPE_CHECK(T, S); + if (V8_UNLIKELY(handle.IsEmpty())) { + *value_ = GetDefaultValue(); + } else { + *value_ = *reinterpret_cast(*handle); + } +} + template template void ReturnValue::Set(const Local handle) { @@ -9954,8 +10323,7 @@ Local Object::GetInternalField(int index) { if (instance_type == I::kJSObjectType || instance_type == I::kJSApiObjectType || instance_type == I::kJSSpecialApiObjectType) { - int offset = I::kJSObjectHeaderSizeForEmbedderFields + - (I::kEmbedderDataSlotSize * index); + int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index); A value = I::ReadTaggedAnyField(obj, offset); internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(obj); @@ -9978,8 +10346,7 @@ void* Object::GetAlignedPointerFromInternalField(int index) { if (V8_LIKELY(instance_type == I::kJSObjectType || instance_type == I::kJSApiObjectType || instance_type == I::kJSSpecialApiObjectType)) { - int offset = I::kJSObjectHeaderSizeForEmbedderFields + - (I::kEmbedderDataSlotSize * index); + int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index); return I::ReadRawField(obj, offset); } #endif @@ -10478,10 +10845,14 @@ ReturnValue PropertyCallbackInfo::GetReturnValue() const { template bool PropertyCallbackInfo::ShouldThrowOnError() const { typedef internal::Internals I; - return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(0); + if (args_[kShouldThrowOnErrorIndex] != + I::IntToSmi(I::kInferShouldThrowMode)) { + return args_[kShouldThrowOnErrorIndex] != I::IntToSmi(I::kDontThrow); + } + return v8::internal::ShouldThrowOnError( + reinterpret_cast(GetIsolate())); } - Local Undefined(Isolate* isolate) { typedef internal::Address S; typedef internal::Internals I; -- cgit v1.2.3