// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /** \mainpage V8 API Reference Guide * * V8 is Google's open source JavaScript engine. * * This set of documents provides reference material generated from the * V8 header file, include/v8.h. * * For other documentation see http://code.google.com/apis/v8/ */ #ifndef INCLUDE_V8_H_ #define INCLUDE_V8_H_ #include #include #include #include #include #include "v8-version.h" // NOLINT(build/include) #include "v8config.h" // NOLINT(build/include) // We reserve the V8_* prefix for macros defined in V8 public API and // assume there are no name conflicts with the embedder's code. #ifdef V8_OS_WIN // Setup for Windows DLL export/import. When building the V8 DLL the // BUILDING_V8_SHARED needs to be defined. When building a program which uses // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 // static library or building a program which uses the V8 static library neither // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ build configuration to ensure that at most one of these is set #endif #ifdef BUILDING_V8_SHARED # define V8_EXPORT __declspec(dllexport) #elif USING_V8_SHARED # define V8_EXPORT __declspec(dllimport) #else # define V8_EXPORT #endif // BUILDING_V8_SHARED #else // V8_OS_WIN // Setup for Linux shared library export. #if V8_HAS_ATTRIBUTE_VISIBILITY && defined(V8_SHARED) # ifdef BUILDING_V8_SHARED # define V8_EXPORT __attribute__ ((visibility("default"))) # else # define V8_EXPORT # endif #else # define V8_EXPORT #endif #endif // V8_OS_WIN /** * The v8 JavaScript engine. */ namespace v8 { class AccessorSignature; class Array; class Boolean; class BooleanObject; class Context; class CpuProfiler; class Data; class Date; class External; class Function; class FunctionTemplate; class HeapProfiler; class ImplementationUtilities; class Int32; class Integer; class Isolate; template class Maybe; class Name; class Number; class NumberObject; class Object; class ObjectOperationDescriptor; class ObjectTemplate; class Platform; class Primitive; class Promise; class Proxy; class RawOperationDescriptor; class Script; class SharedArrayBuffer; class Signature; class StartupData; class StackFrame; class StackTrace; class String; class StringObject; class Symbol; class SymbolObject; class Private; class Uint32; class Utils; class Value; template class Local; template class MaybeLocal; template class Eternal; template class NonCopyablePersistentTraits; template class PersistentBase; template > class Persistent; template class Global; template class PersistentValueMap; template class PersistentValueMapBase; template class GlobalValueMap; template class PersistentValueVector; template class WeakCallbackObject; class FunctionTemplate; class ObjectTemplate; class Data; template class FunctionCallbackInfo; template class PropertyCallbackInfo; class StackTrace; class StackFrame; class Isolate; class CallHandlerHelper; class EscapableHandleScope; template class ReturnValue; namespace experimental { class FastAccessorBuilder; } // namespace experimental namespace internal { class Arguments; class Heap; class HeapObject; class Isolate; class Object; struct StreamedSource; template class CustomArguments; class PropertyCallbackArguments; class FunctionCallbackArguments; class GlobalHandles; } // namespace internal /** * General purpose unique identifier. */ class UniqueId { public: explicit UniqueId(intptr_t data) : data_(data) {} bool operator==(const UniqueId& other) const { return data_ == other.data_; } bool operator!=(const UniqueId& other) const { return data_ != other.data_; } bool operator<(const UniqueId& other) const { return data_ < other.data_; } private: intptr_t data_; }; // --- Handles --- #define TYPE_CHECK(T, S) \ while (false) { \ *(static_cast(0)) = static_cast(0); \ } /** * An object reference managed by the v8 garbage collector. * * All objects returned from v8 have to be tracked by the garbage * collector so that it knows that the objects are still alive. Also, * because the garbage collector may move objects, it is unsafe to * point directly to an object. Instead, all objects are stored in * handles which are known by the garbage collector and updated * whenever an object moves. Handles should always be passed by value * (except in cases like out-parameters) and they should never be * allocated on the heap. * * There are two types of handles: local and persistent handles. * Local handles are light-weight and transient and typically used in * local operations. They are managed by HandleScopes. Persistent * handles can be used when storing objects across several independent * operations and have to be explicitly deallocated when they're no * longer used. * * It is safe to extract the object stored in the handle by * dereferencing the handle (for instance, to extract the Object* from * a Local); the value will still be governed by a handle * behind the scenes and the same rules apply to these values as to * their handles. */ template class Local { public: V8_INLINE Local() : val_(0) {} template V8_INLINE Local(Local that) : val_(reinterpret_cast(*that)) { /** * This check fails when trying to convert between incompatible * handles. For example, converting from a Local to a * Local. */ TYPE_CHECK(T, S); } /** * Returns true if the handle is empty. */ V8_INLINE bool IsEmpty() const { return val_ == 0; } /** * Sets the handle to be empty. IsEmpty() will then return true. */ V8_INLINE void Clear() { val_ = 0; } V8_INLINE T* operator->() const { return val_; } V8_INLINE T* operator*() const { return val_; } /** * Checks whether two handles are the same. * Returns true if both are empty, or if the objects * to which they refer are identical. * The handles' references are not checked. */ template V8_INLINE bool operator==(const Local& that) const { internal::Object** a = reinterpret_cast(this->val_); internal::Object** b = reinterpret_cast(that.val_); if (a == 0) return b == 0; if (b == 0) return false; return *a == *b; } template V8_INLINE bool operator==( const PersistentBase& that) const { internal::Object** a = reinterpret_cast(this->val_); internal::Object** b = reinterpret_cast(that.val_); if (a == 0) return b == 0; if (b == 0) return false; return *a == *b; } /** * Checks whether two handles are different. * Returns true if only one of the handles is empty, or if * the objects to which they refer are different. * The handles' references are not checked. */ template V8_INLINE bool operator!=(const Local& that) const { return !operator==(that); } template V8_INLINE bool operator!=( const Persistent& that) const { return !operator==(that); } template V8_INLINE static Local Cast(Local 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. if (that.IsEmpty()) return Local(); #endif return Local(T::Cast(*that)); } template V8_INLINE Local As() { return Local::Cast(*this); } /** * Create a local handle for the content of another handle. * The referee is kept alive by the local handle even when * the original handle is destroyed/disposed. */ V8_INLINE static Local New(Isolate* isolate, Local that); V8_INLINE static Local New(Isolate* isolate, const PersistentBase& that); private: friend class Utils; template friend class Eternal; template friend class PersistentBase; template friend class Persistent; template friend class Local; template friend class MaybeLocal; template friend class FunctionCallbackInfo; template friend class PropertyCallbackInfo; friend class String; friend class Object; friend class Context; friend class Private; template friend class internal::CustomArguments; friend Local Undefined(Isolate* isolate); friend Local Null(Isolate* isolate); friend Local True(Isolate* isolate); friend Local False(Isolate* isolate); friend class HandleScope; friend class EscapableHandleScope; template friend class PersistentValueMapBase; template friend class PersistentValueVector; template friend class ReturnValue; explicit V8_INLINE Local(T* that) : val_(that) {} V8_INLINE static Local New(Isolate* isolate, T* that); T* val_; }; #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS) // Local is an alias for Local for historical reasons. template using Handle = Local; #endif /** * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether * the Local<> is empty before it can be used. * * If an API method returns a MaybeLocal<>, the API method can potentially fail * either because an exception is thrown, or because an exception is pending, * e.g. because a previous API call threw an exception that hasn't been caught * yet, or because a TerminateExecution exception was thrown. In that case, an * empty MaybeLocal is returned. */ template class MaybeLocal { public: V8_INLINE MaybeLocal() : val_(nullptr) {} template V8_INLINE MaybeLocal(Local that) : val_(reinterpret_cast(*that)) { TYPE_CHECK(T, S); } V8_INLINE bool IsEmpty() const { return val_ == nullptr; } template V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local* out) const { out->val_ = IsEmpty() ? nullptr : this->val_; return !IsEmpty(); } // Will crash if the MaybeLocal<> is empty. V8_INLINE Local ToLocalChecked(); template V8_INLINE Local FromMaybe(Local default_value) const { return IsEmpty() ? default_value : Local(val_); } private: T* val_; }; // Eternal handles are set-once handles that live for the life of the isolate. template class Eternal { public: V8_INLINE Eternal() : index_(kInitialValue) { } template V8_INLINE Eternal(Isolate* isolate, Local handle) : index_(kInitialValue) { Set(isolate, handle); } // Can only be safely called if already set. V8_INLINE Local Get(Isolate* isolate); V8_INLINE bool IsEmpty() { return index_ == kInitialValue; } template V8_INLINE void Set(Isolate* isolate, Local handle); private: static const int kInitialValue = -1; int index_; }; static const int kInternalFieldsInWeakCallback = 2; template class WeakCallbackInfo { public: typedef void (*Callback)(const WeakCallbackInfo& data); WeakCallbackInfo(Isolate* isolate, T* parameter, void* internal_fields[kInternalFieldsInWeakCallback], Callback* callback) : isolate_(isolate), parameter_(parameter), callback_(callback) { for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) { internal_fields_[i] = internal_fields[i]; } } V8_INLINE Isolate* GetIsolate() const { return isolate_; } V8_INLINE T* GetParameter() const { return parameter_; } V8_INLINE void* GetInternalField(int index) const; V8_INLINE V8_DEPRECATED("use indexed version", void* GetInternalField1() const) { return internal_fields_[0]; } V8_INLINE V8_DEPRECATED("use indexed version", void* GetInternalField2() const) { return internal_fields_[1]; } V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.", bool IsFirstPass() const) { return callback_ != nullptr; } // When first called, the embedder MUST Reset() the Global which triggered the // callback. The Global itself is unusable for anything else. No v8 other api // calls may be called in the first callback. Should additional work be // required, the embedder must set a second pass callback, which will be // called after all the initial callbacks are processed. // Calling SetSecondPassCallback on the second pass will immediately crash. void SetSecondPassCallback(Callback callback) const { *callback_ = callback; } private: Isolate* isolate_; T* parameter_; Callback* callback_; void* internal_fields_[kInternalFieldsInWeakCallback]; }; template class WeakCallbackData { public: typedef void (*Callback)(const WeakCallbackData& data); WeakCallbackData(Isolate* isolate, P* parameter, Local handle) : isolate_(isolate), parameter_(parameter), handle_(handle) {} V8_INLINE Isolate* GetIsolate() const { return isolate_; } V8_INLINE P* GetParameter() const { return parameter_; } V8_INLINE Local GetValue() const { return handle_; } private: Isolate* isolate_; P* parameter_; Local handle_; }; // TODO(dcarney): delete this with WeakCallbackData template using PhantomCallbackData = WeakCallbackInfo; enum class WeakCallbackType { kParameter, kInternalFields }; /** * An object reference that is independent of any handle scope. Where * a Local handle only lives as long as the HandleScope in which it was * allocated, a PersistentBase handle remains valid until it is explicitly * disposed. * * A persistent handle contains a reference to a storage cell within * the v8 engine which holds an object value and which is updated by * the garbage collector whenever the object is moved. A new storage * cell can be created using the constructor or PersistentBase::Reset and * existing handles can be disposed using PersistentBase::Reset. * */ template class PersistentBase { public: /** * 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); /** * 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 PersistentBase& other); V8_INLINE bool IsEmpty() const { return val_ == NULL; } V8_INLINE void Empty() { val_ = 0; } V8_INLINE Local Get(Isolate* isolate) const { return Local::New(isolate, *this); } template V8_INLINE bool operator==(const PersistentBase& that) const { internal::Object** a = reinterpret_cast(this->val_); internal::Object** b = reinterpret_cast(that.val_); if (a == NULL) return b == NULL; if (b == NULL) return false; return *a == *b; } template V8_INLINE bool operator==(const Local& that) const { internal::Object** a = reinterpret_cast(this->val_); internal::Object** b = reinterpret_cast(that.val_); if (a == NULL) return b == NULL; if (b == NULL) return false; return *a == *b; } template V8_INLINE bool operator!=(const PersistentBase& that) const { return !operator==(that); } template V8_INLINE bool operator!=(const Local& that) const { return !operator==(that); } /** * Install a finalization callback on this object. * NOTE: There is no guarantee as to *when* or even *if* the callback is * invoked. The invocation is performed solely on a best effort basis. * As always, GC-based finalization should *not* be relied upon for any * critical form of resource management! */ template V8_INLINE V8_DEPRECATED( "use WeakCallbackInfo version", void SetWeak(P* parameter, typename WeakCallbackData::Callback callback)); template V8_INLINE V8_DEPRECATED( "use WeakCallbackInfo version", void SetWeak(P* parameter, typename WeakCallbackData::Callback callback)); // Phantom persistents work like weak persistents, except that the pointer to // the object being collected is not available in the finalization callback. // This enables the garbage collector to collect the object and any objects // it references transitively in one GC cycle. At the moment you can either // specify a parameter for the callback or the location of two internal // fields in the dying object. template V8_INLINE V8_DEPRECATED( "use SetWeak", void SetPhantom(P* parameter, typename WeakCallbackInfo

::Callback callback, int internal_field_index1 = -1, int internal_field_index2 = -1)); template V8_INLINE void SetWeak(P* parameter, typename WeakCallbackInfo

::Callback callback, WeakCallbackType type); template V8_INLINE P* ClearWeak(); // TODO(dcarney): remove this. V8_INLINE void ClearWeak() { ClearWeak(); } /** * Allows the embedder to tell the v8 garbage collector that a certain object * is alive. Only allowed when the embedder is asked to trace its heap by * EmbedderHeapTracer. */ V8_INLINE void RegisterExternalReference(Isolate* isolate); /** * Marks the reference to this object independent. Garbage collector is free * to ignore any object groups containing this object. Weak callback for an * 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_INLINE void MarkIndependent(); /** * Marks the reference to this object partially dependent. Partially dependent * handles only depend on other partially dependent handles and these * dependencies are provided through object groups. It provides a way to build * smaller object groups for young objects that represent only a subset of all * external dependencies. This mark is automatically cleared after each * garbage collection. */ V8_INLINE void MarkPartiallyDependent(); /** * Marks the reference to this object as active. The scavenge garbage * collection should not reclaim the objects marked as active. * This bit is cleared after the each garbage collection pass. */ V8_INLINE void MarkActive(); V8_INLINE bool IsIndependent() const; /** Checks if the handle holds the only reference to an object. */ 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. */ 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; private: friend class Isolate; friend class Utils; template friend class Local; template friend class Persistent; template friend class Global; template friend class PersistentBase; template friend class ReturnValue; template friend class PersistentValueMapBase; template friend class PersistentValueVector; friend class Object; explicit V8_INLINE PersistentBase(T* val) : val_(val) {} PersistentBase(const PersistentBase& other) = delete; // NOLINT void operator=(const PersistentBase&) = delete; V8_INLINE static T* New(Isolate* isolate, T* that); T* val_; }; /** * Default traits for Persistent. This class does not allow * use of the copy constructor or assignment operator. * At present kResetInDestructor is not set, but that will change in a future * version. */ template class NonCopyablePersistentTraits { public: typedef Persistent > NonCopyablePersistent; static const bool kResetInDestructor = false; template V8_INLINE static void Copy(const Persistent& source, NonCopyablePersistent* dest) { Uncompilable(); } // TODO(dcarney): come up with a good compile error here. template V8_INLINE static void Uncompilable() { TYPE_CHECK(O, Primitive); } }; /** * Helper class traits to allow copying and assignment of Persistent. * This will clone the contents of storage cell, but not any of the flags, etc. */ template struct CopyablePersistentTraits { typedef Persistent > CopyablePersistent; static const bool kResetInDestructor = true; template static V8_INLINE void Copy(const Persistent& source, CopyablePersistent* dest) { // do nothing, just allow copy } }; /** * A PersistentBase which allows copy and assignment. * * Copy, assignment and destructor bevavior is controlled by the traits * class M. * * Note: Persistent class hierarchy is subject to future changes. */ template class Persistent : public PersistentBase { public: /** * A Persistent with no storage cell. */ V8_INLINE Persistent() : PersistentBase(0) { } /** * Construct a Persistent from a Local. * When the Local is non-empty, a new storage cell is created * pointing to the same object, and no flags are set. */ template V8_INLINE Persistent(Isolate* isolate, Local that) : PersistentBase(PersistentBase::New(isolate, *that)) { TYPE_CHECK(T, S); } /** * Construct a Persistent from a Persistent. * When the Persistent is non-empty, a new storage cell is created * pointing to the same object, and no flags are set. */ template V8_INLINE Persistent(Isolate* isolate, const Persistent& that) : PersistentBase(PersistentBase::New(isolate, *that)) { TYPE_CHECK(T, S); } /** * The copy constructors and assignment operator create a Persistent * exactly as the Persistent constructor, but the Copy function from the * traits class is called, allowing the setting of flags based on the * copied Persistent. */ V8_INLINE Persistent(const Persistent& that) : PersistentBase(0) { Copy(that); } template V8_INLINE Persistent(const Persistent& that) : PersistentBase(0) { Copy(that); } V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT Copy(that); return *this; } template V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT Copy(that); return *this; } /** * The destructor will dispose the Persistent based on the * kResetInDestructor flags in the traits class. Since not calling dispose * can result in a memory leak, it is recommended to always set this flag. */ V8_INLINE ~Persistent() { if (M::kResetInDestructor) this->Reset(); } // TODO(dcarney): this is pretty useless, fix or remove template V8_INLINE static Persistent& Cast(Persistent& that) { // NOLINT #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. if (!that.IsEmpty()) T::Cast(*that); #endif return reinterpret_cast&>(that); } // TODO(dcarney): this is pretty useless, fix or remove template V8_INLINE Persistent& As() { // NOLINT return Persistent::Cast(*this); } private: friend class Isolate; friend class Utils; template friend class Local; template friend class Persistent; template friend class ReturnValue; explicit V8_INLINE Persistent(T* that) : PersistentBase(that) {} V8_INLINE T* operator*() const { return this->val_; } template V8_INLINE void Copy(const Persistent& that); }; /** * A PersistentBase which has move semantics. * * Note: Persistent class hierarchy is subject to future changes. */ template class Global : public PersistentBase { public: /** * 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 * pointing to the same object, and no flags are set. */ template V8_INLINE Global(Isolate* isolate, Local that) : 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 * pointing to the same object, and no flags are set. */ template V8_INLINE Global(Isolate* isolate, const PersistentBase& that) : PersistentBase(PersistentBase::New(isolate, that.val_)) { TYPE_CHECK(T, S); } /** * Move constructor. */ V8_INLINE Global(Global&& other) : PersistentBase(other.val_) { // NOLINT other.val_ = nullptr; } 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; } /** * Pass allows returning uniques from functions, etc. */ Global Pass() { return static_cast(*this); } // NOLINT /* * For compatibility with Chromium's base::Bind (base::Passed). */ typedef void MoveOnlyTypeForCPP03; private: template friend class ReturnValue; Global(const Global&) = delete; void operator=(const Global&) = delete; V8_INLINE T* operator*() const { return this->val_; } }; // UniquePersistent is an alias for Global for historical reason. template using UniquePersistent = Global; /** * A stack-allocated class that governs a number of local handles. * After a handle scope has been created, all local handles will be * allocated within that handle scope until either the handle scope is * deleted or another handle scope is created. If there is already a * handle scope and a new one is created, all allocations will take * place in the new handle scope until it is deleted. After that, * new handles will again be allocated in the original handle scope. * * After the handle scope of a local handle has been deleted the * garbage collector will no longer track the object stored in the * handle and may deallocate it. The behavior of accessing a handle * for which the handle scope has been deleted is undefined. */ class V8_EXPORT HandleScope { public: explicit HandleScope(Isolate* isolate); ~HandleScope(); /** * Counts the number of allocated handles. */ static int NumberOfHandles(Isolate* isolate); V8_INLINE Isolate* GetIsolate() const { return reinterpret_cast(isolate_); } protected: V8_INLINE HandleScope() {} void Initialize(Isolate* isolate); static internal::Object** CreateHandle(internal::Isolate* isolate, internal::Object* value); private: // Uses heap_object to obtain the current Isolate. static internal::Object** CreateHandle(internal::HeapObject* heap_object, internal::Object* value); // Make it hard to create heap-allocated or illegal handle scopes by // disallowing certain operations. HandleScope(const HandleScope&); void operator=(const HandleScope&); void* operator new(size_t size); void operator delete(void*, size_t); internal::Isolate* isolate_; internal::Object** prev_next_; internal::Object** prev_limit_; // Local::New uses CreateHandle with an Isolate* parameter. template friend class Local; // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with // a HeapObject* in their shortcuts. friend class Object; friend class Context; }; /** * A HandleScope which first allocates a handle in the current scope * which will be later filled with the escape value. */ class V8_EXPORT EscapableHandleScope : public HandleScope { public: explicit EscapableHandleScope(Isolate* isolate); V8_INLINE ~EscapableHandleScope() {} /** * Pushes the value into the previous scope and returns a handle to it. * Cannot be called twice. */ template V8_INLINE Local Escape(Local value) { internal::Object** slot = Escape(reinterpret_cast(*value)); return Local(reinterpret_cast(slot)); } private: internal::Object** Escape(internal::Object** escape_value); // Make it hard to create heap-allocated or illegal handle scopes by // disallowing certain operations. EscapableHandleScope(const EscapableHandleScope&); void operator=(const EscapableHandleScope&); void* operator new(size_t size); void operator delete(void*, size_t); internal::Object** escape_slot_; }; class V8_EXPORT SealHandleScope { public: SealHandleScope(Isolate* isolate); ~SealHandleScope(); private: // Make it hard to create heap-allocated or illegal handle scopes by // disallowing certain operations. SealHandleScope(const SealHandleScope&); void operator=(const SealHandleScope&); void* operator new(size_t size); void operator delete(void*, size_t); internal::Isolate* isolate_; internal::Object** prev_limit_; int prev_sealed_level_; }; // --- Special objects --- /** * The superclass of values and API object templates. */ class V8_EXPORT Data { private: Data(); }; /** * The optional attributes of ScriptOrigin. */ class ScriptOriginOptions { public: V8_INLINE ScriptOriginOptions(bool is_embedder_debug_script = false, bool is_shared_cross_origin = false, bool is_opaque = false) : flags_((is_embedder_debug_script ? kIsEmbedderDebugScript : 0) | (is_shared_cross_origin ? kIsSharedCrossOrigin : 0) | (is_opaque ? kIsOpaque : 0)) {} V8_INLINE ScriptOriginOptions(int flags) : flags_(flags & (kIsEmbedderDebugScript | kIsSharedCrossOrigin | kIsOpaque)) {} bool IsEmbedderDebugScript() const { return (flags_ & kIsEmbedderDebugScript) != 0; } bool IsSharedCrossOrigin() const { return (flags_ & kIsSharedCrossOrigin) != 0; } bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; } int Flags() const { return flags_; } private: enum { kIsEmbedderDebugScript = 1, kIsSharedCrossOrigin = 1 << 1, kIsOpaque = 1 << 2 }; const int flags_; }; /** * The origin, within a file, of a script. */ class ScriptOrigin { public: V8_INLINE ScriptOrigin( Local resource_name, Local resource_line_offset = Local(), Local resource_column_offset = Local(), Local resource_is_shared_cross_origin = Local(), Local script_id = Local(), Local resource_is_embedder_debug_script = Local(), Local source_map_url = Local(), Local resource_is_opaque = Local()); V8_INLINE Local ResourceName() const; V8_INLINE Local ResourceLineOffset() const; V8_INLINE Local ResourceColumnOffset() const; /** * Returns true for embedder's debugger scripts */ V8_INLINE Local ScriptID() const; V8_INLINE Local SourceMapUrl() const; V8_INLINE ScriptOriginOptions Options() const { return options_; } private: Local resource_name_; Local resource_line_offset_; Local resource_column_offset_; ScriptOriginOptions options_; Local script_id_; Local source_map_url_; }; /** * A compiled JavaScript script, not yet tied to a Context. */ class V8_EXPORT UnboundScript { public: /** * Binds the script to the currently entered context. */ Local