diff options
Diffstat (limited to 'deps/v8/include/v8.h')
-rw-r--r-- | deps/v8/include/v8.h | 1133 |
1 files changed, 725 insertions, 408 deletions
diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 910279b52e..6e1db3a581 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -94,6 +94,7 @@ class Primitive; class Promise; class RawOperationDescriptor; class Script; +class SharedArrayBuffer; class Signature; class StartupData; class StackFrame; @@ -102,7 +103,6 @@ class String; class StringObject; class Symbol; class SymbolObject; -class Private; class Uint32; class Utils; class Value; @@ -215,8 +215,8 @@ class Local { : val_(reinterpret_cast<T*>(*that)) { /** * This check fails when trying to convert between incompatible - * handles. For example, converting from a Handle<String> to a - * Handle<Number>. + * handles. For example, converting from a Local<String> to a + * Local<Number>. */ TYPE_CHECK(T, S); } @@ -311,7 +311,6 @@ class Local { friend class String; friend class Object; friend class Context; - friend class Private; template<class F> friend class internal::CustomArguments; friend Local<Primitive> Undefined(Isolate* isolate); friend Local<Primitive> Null(Isolate* isolate); @@ -331,9 +330,11 @@ class Local { }; -// Handle is an alias for Local for historical reasons. +#if !defined(V8_IMMINENT_DEPRECATION_WARNINGS) +// Local is an alias for Local for historical reasons. template <class T> using Handle = Local<T>; +#endif /** @@ -418,11 +419,11 @@ class WeakCallbackInfo { V8_INLINE void* GetInternalField(int index) const; V8_INLINE V8_DEPRECATE_SOON("use indexed version", - void* GetInternalField1()) const { + void* GetInternalField1() const) { return internal_fields_[0]; } V8_INLINE V8_DEPRECATE_SOON("use indexed version", - void* GetInternalField2()) const { + void* GetInternalField2() const) { return internal_fields_[1]; } @@ -496,7 +497,7 @@ template <class T> class PersistentBase { * and create a new one with the contents of other if other is non empty */ template <class S> - V8_INLINE void Reset(Isolate* isolate, const Handle<S>& other); + V8_INLINE void Reset(Isolate* isolate, const Local<S>& other); /** * If non-empty, destroy the underlying storage cell @@ -517,7 +518,8 @@ template <class T> class PersistentBase { return *a == *b; } - template <class S> V8_INLINE bool operator==(const Handle<S>& that) const { + template <class S> + V8_INLINE bool operator==(const Local<S>& that) const { internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); if (a == NULL) return b == NULL; @@ -530,7 +532,8 @@ template <class T> class PersistentBase { return !operator==(that); } - template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const { + template <class S> + V8_INLINE bool operator!=(const Local<S>& that) const { return !operator==(that); } @@ -693,11 +696,12 @@ template <class T, class M> class Persistent : public PersistentBase<T> { */ V8_INLINE Persistent() : PersistentBase<T>(0) { } /** - * Construct a Persistent from a Handle. - * When the Handle is non-empty, a new storage cell is created + * 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 <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that) + template <class S> + V8_INLINE Persistent(Isolate* isolate, Local<S> that) : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { TYPE_CHECK(T, S); } @@ -785,12 +789,12 @@ class Global : public PersistentBase<T> { */ V8_INLINE Global() : PersistentBase<T>(nullptr) {} /** - * Construct a Global from a Handle. - * When the Handle is non-empty, a new storage cell is created + * 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 <class S> - V8_INLINE Global(Isolate* isolate, Handle<S> that) + V8_INLINE Global(Isolate* isolate, Local<S> that) : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { TYPE_CHECK(T, S); } @@ -835,8 +839,11 @@ class Global : public PersistentBase<T> { typedef void MoveOnlyTypeForCPP03; private: + template <class F> + friend class ReturnValue; Global(Global&) = delete; void operator=(Global&) = delete; + V8_INLINE T* operator*() const { return this->val_; } }; @@ -973,44 +980,68 @@ class V8_EXPORT 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( - Handle<Value> resource_name, - Handle<Integer> resource_line_offset = Handle<Integer>(), - Handle<Integer> resource_column_offset = Handle<Integer>(), - Handle<Boolean> resource_is_shared_cross_origin = Handle<Boolean>(), - Handle<Integer> script_id = Handle<Integer>(), - Handle<Boolean> resource_is_embedder_debug_script = Handle<Boolean>(), - Handle<Value> source_map_url = Handle<Value>()) - : resource_name_(resource_name), - resource_line_offset_(resource_line_offset), - resource_column_offset_(resource_column_offset), - resource_is_embedder_debug_script_(resource_is_embedder_debug_script), - resource_is_shared_cross_origin_(resource_is_shared_cross_origin), - script_id_(script_id), - source_map_url_(source_map_url) {} - V8_INLINE Handle<Value> ResourceName() const; - V8_INLINE Handle<Integer> ResourceLineOffset() const; - V8_INLINE Handle<Integer> ResourceColumnOffset() const; + Local<Value> resource_name, + Local<Integer> resource_line_offset = Local<Integer>(), + Local<Integer> resource_column_offset = Local<Integer>(), + Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(), + Local<Integer> script_id = Local<Integer>(), + Local<Boolean> resource_is_embedder_debug_script = Local<Boolean>(), + Local<Value> source_map_url = Local<Value>(), + Local<Boolean> resource_is_opaque = Local<Boolean>()); + V8_INLINE Local<Value> ResourceName() const; + V8_INLINE Local<Integer> ResourceLineOffset() const; + V8_INLINE Local<Integer> ResourceColumnOffset() const; /** * Returns true for embedder's debugger scripts */ - V8_INLINE Handle<Boolean> ResourceIsEmbedderDebugScript() const; - V8_INLINE Handle<Boolean> ResourceIsSharedCrossOrigin() const; - V8_INLINE Handle<Integer> ScriptID() const; - V8_INLINE Handle<Value> SourceMapUrl() const; + V8_INLINE Local<Integer> ScriptID() const; + V8_INLINE Local<Value> SourceMapUrl() const; + V8_INLINE ScriptOriginOptions Options() const { return options_; } private: - Handle<Value> resource_name_; - Handle<Integer> resource_line_offset_; - Handle<Integer> resource_column_offset_; - Handle<Boolean> resource_is_embedder_debug_script_; - Handle<Boolean> resource_is_shared_cross_origin_; - Handle<Integer> script_id_; - Handle<Value> source_map_url_; + Local<Value> resource_name_; + Local<Integer> resource_line_offset_; + Local<Integer> resource_column_offset_; + ScriptOriginOptions options_; + Local<Integer> script_id_; + Local<Value> source_map_url_; }; @@ -1025,16 +1056,16 @@ class V8_EXPORT UnboundScript { Local<Script> BindToCurrentContext(); int GetId(); - Handle<Value> GetScriptName(); + Local<Value> GetScriptName(); /** * Data read from magic sourceURL comments. */ - Handle<Value> GetSourceURL(); + Local<Value> GetSourceURL(); /** * Data read from magic sourceMappingURL comments. */ - Handle<Value> GetSourceMappingURL(); + Local<Value> GetSourceMappingURL(); /** * Returns zero based line number of the code_pos location in the script. @@ -1057,15 +1088,15 @@ class V8_EXPORT Script { */ static V8_DEPRECATE_SOON( "Use maybe version", - Local<Script> Compile(Handle<String> source, + Local<Script> Compile(Local<String> source, ScriptOrigin* origin = nullptr)); static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile( - Local<Context> context, Handle<String> source, + Local<Context> context, Local<String> source, ScriptOrigin* origin = nullptr); static Local<Script> V8_DEPRECATE_SOON("Use maybe version", - Compile(Handle<String> source, - Handle<String> file_name)); + Compile(Local<String> source, + Local<String> file_name)); /** * Runs the script returning the resulting value. It will be run in the @@ -1157,12 +1188,11 @@ class V8_EXPORT ScriptCompiler { Local<String> source_string; // Origin information - Handle<Value> resource_name; - Handle<Integer> resource_line_offset; - Handle<Integer> resource_column_offset; - Handle<Boolean> resource_is_embedder_debug_script; - Handle<Boolean> resource_is_shared_cross_origin; - Handle<Value> source_map_url; + Local<Value> resource_name; + Local<Integer> resource_line_offset; + Local<Integer> resource_column_offset; + ScriptOriginOptions resource_options; + Local<Value> source_map_url; // Cached data from previous compilation (if a kConsume*Cache flag is // set), or hold newly generated cache data (kProduce*Cache flags) are @@ -1174,7 +1204,7 @@ class V8_EXPORT ScriptCompiler { * For streaming incomplete script data to V8. The embedder should implement a * subclass of this class. */ - class ExternalSourceStream { + class V8_EXPORT ExternalSourceStream { public: virtual ~ExternalSourceStream() {} @@ -1196,6 +1226,23 @@ class V8_EXPORT ScriptCompiler { * V8 has parsed the data it received so far. */ virtual size_t GetMoreData(const uint8_t** src) = 0; + + /** + * V8 calls this method to set a 'bookmark' at the current position in + * the source stream, for the purpose of (maybe) later calling + * ResetToBookmark. If ResetToBookmark is called later, then subsequent + * calls to GetMoreData should return the same data as they did when + * SetBookmark was called earlier. + * + * The embedder may return 'false' to indicate it cannot provide this + * functionality. + */ + virtual bool SetBookmark(); + + /** + * V8 calls this to return to a previously set bookmark. + */ + virtual void ResetToBookmark(); }; @@ -1242,10 +1289,7 @@ class V8_EXPORT ScriptCompiler { kProduceParserCache, kConsumeParserCache, kProduceCodeCache, - kConsumeCodeCache, - - // Support the previous API for a transition period. - kProduceDataToCache + kConsumeCodeCache }; /** @@ -1313,11 +1357,11 @@ class V8_EXPORT ScriptCompiler { static V8_DEPRECATE_SOON( "Use maybe version", Local<Script> Compile(Isolate* isolate, StreamedSource* source, - Handle<String> full_source_string, + Local<String> full_source_string, const ScriptOrigin& origin)); static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile( Local<Context> context, StreamedSource* source, - Handle<String> full_source_string, const ScriptOrigin& origin); + Local<String> full_source_string, const ScriptOrigin& origin); /** * Return a version tag for CachedData for the current V8 version & flags. @@ -1390,7 +1434,7 @@ class V8_EXPORT Message { public: Local<String> Get() const; - V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine()) const; + V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const); V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine( Local<Context> context) const; @@ -1404,19 +1448,19 @@ class V8_EXPORT Message { * Returns the resource name for the script from where the function causing * the error originates. */ - Handle<Value> GetScriptResourceName() const; + Local<Value> GetScriptResourceName() const; /** * Exception stack trace. By default stack traces are not captured for * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows * to change this option. */ - Handle<StackTrace> GetStackTrace() const; + Local<StackTrace> GetStackTrace() const; /** * Returns the number, 1-based, of the line where the error occurred. */ - V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber()) const; + V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const); V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const; /** @@ -1435,14 +1479,14 @@ class V8_EXPORT Message { * Returns the index within the line of the first character where * the error occurred. */ - V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn()) const; + V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const); V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const; /** * Returns the index within the line of the last character where * the error occurred. */ - V8_DEPRECATE_SOON("Use maybe version", int GetEndColumn()) const; + V8_DEPRECATE_SOON("Use maybe version", int GetEndColumn() const); V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const; /** @@ -1450,6 +1494,7 @@ class V8_EXPORT Message { * this Message was generated to V8. */ bool IsSharedCrossOrigin() const; + bool IsOpaque() const; // TODO(1245381): Print to a string instead of on a FILE. static void PrintCurrentStackTrace(Isolate* isolate, FILE* out); @@ -1625,10 +1670,10 @@ class V8_EXPORT JSON { class V8_EXPORT NativeWeakMap : public Data { public: static Local<NativeWeakMap> New(Isolate* isolate); - void Set(Handle<Value> key, Handle<Value> value); - Local<Value> Get(Handle<Value> key); - bool Has(Handle<Value> key); - bool Delete(Handle<Value> key); + void Set(Local<Value> key, Local<Value> value); + Local<Value> Get(Local<Value> key); + bool Has(Local<Value> key); + bool Delete(Local<Value> key); }; @@ -1781,37 +1826,31 @@ class V8_EXPORT Value : public Data { /** * Returns true if this value is a Map. - * This is an experimental feature. */ bool IsMap() const; /** * Returns true if this value is a Set. - * This is an experimental feature. */ bool IsSet() const; /** * Returns true if this value is a Map Iterator. - * This is an experimental feature. */ bool IsMapIterator() const; /** * Returns true if this value is a Set Iterator. - * This is an experimental feature. */ bool IsSetIterator() const; /** * Returns true if this value is a WeakMap. - * This is an experimental feature. */ bool IsWeakMap() const; /** * Returns true if this value is a WeakSet. - * This is an experimental feature. */ bool IsWeakSet() const; @@ -1888,11 +1927,24 @@ class V8_EXPORT Value : public Data { bool IsFloat64Array() const; /** + * Returns true if this value is a SIMD Float32x4. + * This is an experimental feature. + */ + bool IsFloat32x4() const; + + /** * Returns true if this value is a DataView. * This is an experimental feature. */ bool IsDataView() const; + /** + * Returns true if this value is a SharedArrayBuffer. + * This is an experimental feature. + */ + bool IsSharedArrayBuffer() const; + + V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean( Local<Context> context) const; V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber( @@ -1910,39 +1962,39 @@ class V8_EXPORT Value : public Data { V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const; V8_DEPRECATE_SOON("Use maybe version", - Local<Boolean> ToBoolean(Isolate* isolate)) const; + Local<Boolean> ToBoolean(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<Number> ToNumber(Isolate* isolate)) const; + Local<Number> ToNumber(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<String> ToString(Isolate* isolate)) const; + Local<String> ToString(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<String> ToDetailString(Isolate* isolate)) const; + Local<String> ToDetailString(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<Object> ToObject(Isolate* isolate)) const; + Local<Object> ToObject(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<Integer> ToInteger(Isolate* isolate)) const; + Local<Integer> ToInteger(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<Uint32> ToUint32(Isolate* isolate)) const; + Local<Uint32> ToUint32(Isolate* isolate) const); V8_DEPRECATE_SOON("Use maybe version", - Local<Int32> ToInt32(Isolate* isolate)) const; + Local<Int32> ToInt32(Isolate* isolate) const); inline V8_DEPRECATE_SOON("Use maybe version", - Local<Boolean> ToBoolean()) const; - inline V8_DEPRECATE_SOON("Use maybe version", Local<Number> ToNumber()) const; - inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString()) const; + Local<Boolean> ToBoolean() const); + inline V8_DEPRECATE_SOON("Use maybe version", Local<Number> ToNumber() const); + inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const); inline V8_DEPRECATE_SOON("Use maybe version", - Local<String> ToDetailString()) const; - inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject()) const; + Local<String> ToDetailString() const); + inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const); inline V8_DEPRECATE_SOON("Use maybe version", - Local<Integer> ToInteger()) const; - inline V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToUint32()) const; - inline V8_DEPRECATE_SOON("Use maybe version", Local<Int32> ToInt32()) const; + Local<Integer> ToInteger() const); + inline V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToUint32() const); + inline V8_DEPRECATE_SOON("Use maybe version", Local<Int32> ToInt32() const); /** * Attempts to convert a string to an array index. * Returns an empty handle if the conversion fails. */ - V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToArrayIndex()) const; + V8_DEPRECATE_SOON("Use maybe version", Local<Uint32> ToArrayIndex() const); V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex( Local<Context> context) const; @@ -1954,18 +2006,18 @@ class V8_EXPORT Value : public Data { Local<Context> context) const; V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const; - V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue()) const; - V8_DEPRECATE_SOON("Use maybe version", double NumberValue()) const; - V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue()) const; - V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value()) const; - V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value()) const; + V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const); + V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const); + V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const); + V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const); + V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const); /** JS == */ - V8_DEPRECATE_SOON("Use maybe version", bool Equals(Handle<Value> that)) const; + V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const); V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context, - Handle<Value> that) const; - bool StrictEquals(Handle<Value> that) const; - bool SameValue(Handle<Value> that) const; + Local<Value> that) const; + bool StrictEquals(Local<Value> that) const; + bool SameValue(Local<Value> that) const; template <class T> V8_INLINE static Value* Cast(T* value); @@ -1993,7 +2045,8 @@ class V8_EXPORT Boolean : public Primitive { public: bool Value() const; V8_INLINE static Boolean* Cast(v8::Value* obj); - V8_INLINE static Handle<Boolean> New(Isolate* isolate, bool value); + V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value); + private: static void CheckCast(v8::Value* obj); }; @@ -2274,7 +2327,7 @@ class V8_EXPORT String : public Name { * Creates a new string by concatenating the left and the right strings * passed in as parameters. */ - static Local<String> Concat(Handle<String> left, Handle<String> right); + static Local<String> Concat(Local<String> left, Local<String> right); /** * Creates a new external string using the data defined in the given @@ -2342,7 +2395,7 @@ class V8_EXPORT String : public Name { */ class V8_EXPORT Utf8Value { public: - explicit Utf8Value(Handle<v8::Value> obj); + explicit Utf8Value(Local<v8::Value> obj); ~Utf8Value(); char* operator*() { return str_; } const char* operator*() const { return str_; } @@ -2364,7 +2417,7 @@ class V8_EXPORT String : public Name { */ class V8_EXPORT Value { public: - explicit Value(Handle<v8::Value> obj); + explicit Value(Local<v8::Value> obj); ~Value(); uint16_t* operator*() { return str_; } const uint16_t* operator*() const { return str_; } @@ -2425,34 +2478,6 @@ class V8_EXPORT Symbol : public Name { /** - * A private symbol - * - * This is an experimental feature. Use at your own risk. - */ -class V8_EXPORT Private : public Data { - public: - // Returns the print name string of the private symbol, or undefined if none. - Local<Value> Name() const; - - // Create a private symbol. If name is not empty, it will be the description. - static Local<Private> New( - Isolate *isolate, Local<String> name = Local<String>()); - - // Retrieve a global private symbol. If a symbol with this name has not - // been retrieved in the same isolate before, it is created. - // Note that private symbols created this way are never collected, so - // they should only be used for statically fixed properties. - // Also, there is only one global name space for the names used as keys. - // To minimize the potential for clashes, use qualified names as keys, - // e.g., "Class#property". - static Local<Private> ForApi(Isolate *isolate, Local<String> name); - - private: - Private(); -}; - - -/** * A JavaScript number value (ECMA-262, 4.3.20) */ class V8_EXPORT Number : public Primitive { @@ -2562,15 +2587,39 @@ enum AccessControl { class V8_EXPORT Object : public Value { public: V8_DEPRECATE_SOON("Use maybe version", - bool Set(Handle<Value> key, Handle<Value> value)); + bool Set(Local<Value> key, Local<Value> value)); V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, Local<Value> key, Local<Value> value); V8_DEPRECATE_SOON("Use maybe version", - bool Set(uint32_t index, Handle<Value> value)); + bool Set(uint32_t index, Local<Value> value)); V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index, Local<Value> value); + // Implements CreateDataProperty (ECMA-262, 7.3.4). + // + // Defines a configurable, writable, enumerable property with the given value + // on the object unless the property already exists and is not configurable + // or the object is not extensible. + // + // Returns true on success. + V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context, + Local<Name> key, + Local<Value> value); + V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context, + uint32_t index, + Local<Value> value); + + // Implements DefineOwnProperty. + // + // In general, CreateDataProperty will be faster, however, does not allow + // for specifying attributes. + // + // Returns true on success. + V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty( + Local<Context> context, Local<Name> key, Local<Value> value, + PropertyAttribute attributes = None); + // Sets an own property on this object bypassing interceptors and // overriding accessors or read-only properties. // @@ -2579,14 +2628,15 @@ class V8_EXPORT Object : public Value { // will only be returned if the interceptor doesn't return a value. // // Note also that this only works for named properties. - V8_DEPRECATE_SOON("Use maybe version", - bool ForceSet(Handle<Value> key, Handle<Value> value, + V8_DEPRECATE_SOON("Use CreateDataProperty", + bool ForceSet(Local<Value> key, Local<Value> value, PropertyAttribute attribs = None)); - // TODO(dcarney): mark V8_WARN_UNUSED_RESULT - Maybe<bool> ForceSet(Local<Context> context, Local<Value> key, - Local<Value> value, PropertyAttribute attribs = None); + V8_DEPRECATE_SOON("Use CreateDataProperty", + Maybe<bool> ForceSet(Local<Context> context, + Local<Value> key, Local<Value> value, + PropertyAttribute attribs = None)); - V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Handle<Value> key)); + V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key)); V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, Local<Value> key); @@ -2600,7 +2650,7 @@ class V8_EXPORT Object : public Value { * None when the property doesn't exist. */ V8_DEPRECATE_SOON("Use maybe version", - PropertyAttribute GetPropertyAttributes(Handle<Value> key)); + PropertyAttribute GetPropertyAttributes(Local<Value> key)); V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes( Local<Context> context, Local<Value> key); @@ -2612,11 +2662,11 @@ class V8_EXPORT Object : public Value { V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor( Local<Context> context, Local<String> key); - V8_DEPRECATE_SOON("Use maybe version", bool Has(Handle<Value> key)); + V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key)); V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, Local<Value> key); - V8_DEPRECATE_SOON("Use maybe version", bool Delete(Handle<Value> key)); + V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key)); // TODO(dcarney): mark V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, Local<Value> key); @@ -2628,17 +2678,17 @@ class V8_EXPORT Object : public Value { Maybe<bool> Delete(Local<Context> context, uint32_t index); V8_DEPRECATE_SOON("Use maybe version", - bool SetAccessor(Handle<String> name, + bool SetAccessor(Local<String> name, AccessorGetterCallback getter, AccessorSetterCallback setter = 0, - Handle<Value> data = Handle<Value>(), + Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT, PropertyAttribute attribute = None)); V8_DEPRECATE_SOON("Use maybe version", - bool SetAccessor(Handle<Name> name, + bool SetAccessor(Local<Name> name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter = 0, - Handle<Value> data = Handle<Value>(), + Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT, PropertyAttribute attribute = None)); // TODO(dcarney): mark V8_WARN_UNUSED_RESULT @@ -2649,25 +2699,12 @@ class V8_EXPORT Object : public Value { AccessControl settings = DEFAULT, PropertyAttribute attribute = None); - void SetAccessorProperty(Local<Name> name, - Local<Function> getter, - Handle<Function> setter = Handle<Function>(), + void SetAccessorProperty(Local<Name> name, Local<Function> getter, + Local<Function> setter = Local<Function>(), PropertyAttribute attribute = None, AccessControl settings = DEFAULT); /** - * Functionality for private properties. - * This is an experimental feature, use at your own risk. - * Note: Private properties are inherited. Do not rely on this, since it may - * change. - */ - // TODO(dcarney): convert these or remove? - bool HasPrivate(Handle<Private> key); - bool SetPrivate(Handle<Private> key, Handle<Value> value); - bool DeletePrivate(Handle<Private> key); - Local<Value> GetPrivate(Handle<Private> key); - - /** * Returns an array containing the names of the enumerable properties * of this object, including properties from prototype objects. The * array returned by this method contains the same values as would @@ -2699,7 +2736,7 @@ class V8_EXPORT Object : public Value { * handler. */ V8_DEPRECATE_SOON("Use maybe version", - bool SetPrototype(Handle<Value> prototype)); + bool SetPrototype(Local<Value> prototype)); V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context, Local<Value> prototype); @@ -2707,7 +2744,7 @@ class V8_EXPORT Object : public Value { * Finds an instance of the given function template in the prototype * chain. */ - Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl); + Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl); /** * Call builtin Object.prototype.toString on this object. @@ -2736,7 +2773,7 @@ class V8_EXPORT Object : public Value { V8_INLINE Local<Value> GetInternalField(int index); /** Sets the value in an internal field. */ - void SetInternalField(int index, Handle<Value> value); + void SetInternalField(int index, Local<Value> value); /** * Gets a 2-byte-aligned native pointer from an internal field. This field @@ -2760,11 +2797,11 @@ class V8_EXPORT Object : public Value { // Testers for local properties. V8_DEPRECATE_SOON("Use maybe version", - bool HasOwnProperty(Handle<String> key)); + bool HasOwnProperty(Local<String> key)); V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context, Local<Name> key); V8_DEPRECATE_SOON("Use maybe version", - bool HasRealNamedProperty(Handle<String> key)); + bool HasRealNamedProperty(Local<String> key)); V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context, Local<Name> key); V8_DEPRECATE_SOON("Use maybe version", @@ -2772,7 +2809,7 @@ class V8_EXPORT Object : public Value { V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty( Local<Context> context, uint32_t index); V8_DEPRECATE_SOON("Use maybe version", - bool HasRealNamedCallbackProperty(Handle<String> key)); + bool HasRealNamedCallbackProperty(Local<String> key)); V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty( Local<Context> context, Local<Name> key); @@ -2782,7 +2819,7 @@ class V8_EXPORT Object : public Value { */ V8_DEPRECATE_SOON( "Use maybe version", - Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key)); + Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key)); V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain( Local<Context> context, Local<Name> key); @@ -2794,7 +2831,7 @@ class V8_EXPORT Object : public Value { V8_DEPRECATE_SOON( "Use maybe version", Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain( - Handle<String> key)); + Local<String> key)); V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context, Local<Name> key); @@ -2805,7 +2842,7 @@ class V8_EXPORT Object : public Value { * This means interceptors in the prototype chain are not called. */ V8_DEPRECATE_SOON("Use maybe version", - Local<Value> GetRealNamedProperty(Handle<String> key)); + Local<Value> GetRealNamedProperty(Local<String> key)); V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty( Local<Context> context, Local<Name> key); @@ -2816,7 +2853,7 @@ class V8_EXPORT Object : public Value { */ V8_DEPRECATE_SOON("Use maybe version", Maybe<PropertyAttribute> GetRealNamedPropertyAttributes( - Handle<String> key)); + Local<String> key)); V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes( Local<Context> context, Local<Name> key); @@ -2827,13 +2864,6 @@ class V8_EXPORT Object : public Value { bool HasIndexedLookupInterceptor(); /** - * Turns on access check on the object if the object is an instance of - * a template that has access check callbacks. If an object has no - * access check info, the object cannot be accessed by anyone. - */ - V8_DEPRECATE_SOON("No alternative", void TurnOnAccessCheck()); - - /** * Returns the identity hash for this object. The current implementation * uses a hidden property on the object to store the identity hash. * @@ -2849,9 +2879,9 @@ class V8_EXPORT Object : public Value { * identity hash) are prefixed with "v8::". */ // TODO(dcarney): convert these to take a isolate and optionally bailout? - bool SetHiddenValue(Handle<String> key, Handle<Value> value); - Local<Value> GetHiddenValue(Handle<String> key); - bool DeleteHiddenValue(Handle<String> key); + bool SetHiddenValue(Local<String> key, Local<Value> value); + Local<Value> GetHiddenValue(Local<String> key); + bool DeleteHiddenValue(Local<String> key); /** * Clone this object with a fast but shallow copy. Values will point @@ -2877,12 +2907,12 @@ class V8_EXPORT Object : public Value { * ObjectTemplate::SetCallAsFunctionHandler method. */ V8_DEPRECATE_SOON("Use maybe version", - Local<Value> CallAsFunction(Handle<Value> recv, int argc, - Handle<Value> argv[])); + Local<Value> CallAsFunction(Local<Value> recv, int argc, + Local<Value> argv[])); V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context, - Handle<Value> recv, + Local<Value> recv, int argc, - Handle<Value> argv[]); + Local<Value> argv[]); /** * Call an Object as a constructor if a callback is set by the @@ -2891,7 +2921,7 @@ class V8_EXPORT Object : public Value { */ V8_DEPRECATE_SOON("Use maybe version", Local<Value> CallAsConstructor(int argc, - Handle<Value> argv[])); + Local<Value> argv[])); V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor( Local<Context> context, int argc, Local<Value> argv[]); @@ -2941,6 +2971,89 @@ class V8_EXPORT Array : public Object { }; +/** + * An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1). + */ +class V8_EXPORT Map : public Object { + public: + size_t Size() const; + void Clear(); + V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context, + Local<Value> key, + Local<Value> value); + V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, + Local<Value> key); + + /** + * Returns an array of length Size() * 2, where index N is the Nth key and + * index N + 1 is the Nth value. + */ + Local<Array> AsArray() const; + + /** + * Creates a new empty Map. + */ + static Local<Map> New(Isolate* isolate); + + /** + * Creates a new Map containing the elements of array, which must be formatted + * in the same manner as the array returned from AsArray(). + * Guaranteed to be side-effect free if the array contains no holes. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Map> FromArray(Local<Context> context, + Local<Array> array); + + V8_INLINE static Map* Cast(Value* obj); + + private: + Map(); + static void CheckCast(Value* obj); +}; + + +/** + * An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1). + */ +class V8_EXPORT Set : public Object { + public: + size_t Size() const; + void Clear(); + V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, + Local<Value> key); + V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context, + Local<Value> key); + + /** + * Returns an array of the keys in this Set. + */ + Local<Array> AsArray() const; + + /** + * Creates a new empty Set. + */ + static Local<Set> New(Isolate* isolate); + + /** + * Creates a new Set containing the items in array. + * Guaranteed to be side-effect free if the array contains no holes. + */ + static V8_WARN_UNUSED_RESULT MaybeLocal<Set> FromArray(Local<Context> context, + Local<Array> array); + + V8_INLINE static Set* Cast(Value* obj); + + private: + Set(); + static void CheckCast(Value* obj); +}; + + template<typename T> class ReturnValue { public: @@ -2948,9 +3061,14 @@ class ReturnValue { : value_(that.value_) { TYPE_CHECK(T, S); } - // Handle setters - template <typename S> V8_INLINE void Set(const Persistent<S>& handle); - template <typename S> V8_INLINE void Set(const Handle<S> handle); + // Local setters + template <typename S> + V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead", + void Set(const Persistent<S>& handle)); + template <typename S> + V8_INLINE void Set(const Global<S>& handle); + template <typename S> + V8_INLINE void Set(const Local<S> handle); // Fast primitive setters V8_INLINE void Set(bool value); V8_INLINE void Set(double i); @@ -3066,32 +3184,36 @@ class V8_EXPORT Function : public Object { * Create a function in the current execution context * for a given FunctionCallback. */ - static Local<Function> New(Isolate* isolate, - FunctionCallback callback, - Local<Value> data = Local<Value>(), - int length = 0); + static MaybeLocal<Function> New(Local<Context> context, + FunctionCallback callback, + Local<Value> data = Local<Value>(), + int length = 0); + static V8_DEPRECATE_SOON( + "Use maybe version", + Local<Function> New(Isolate* isolate, FunctionCallback callback, + Local<Value> data = Local<Value>(), int length = 0)); V8_DEPRECATE_SOON("Use maybe version", - Local<Object> NewInstance(int argc, - Handle<Value> argv[])) const; + Local<Object> NewInstance(int argc, Local<Value> argv[]) + const); V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance( - Local<Context> context, int argc, Handle<Value> argv[]) const; + Local<Context> context, int argc, Local<Value> argv[]) const; - V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance()) const; + V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance() const); V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance( Local<Context> context) const { return NewInstance(context, 0, nullptr); } V8_DEPRECATE_SOON("Use maybe version", - Local<Value> Call(Handle<Value> recv, int argc, - Handle<Value> argv[])); + Local<Value> Call(Local<Value> recv, int argc, + Local<Value> argv[])); V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context, - Handle<Value> recv, int argc, - Handle<Value> argv[]); + Local<Value> recv, int argc, + Local<Value> argv[]); - void SetName(Handle<String> name); - Handle<Value> GetName() const; + void SetName(Local<String> name); + Local<Value> GetName() const; /** * Name inferred from variable or property assignment of this function. @@ -3099,13 +3221,13 @@ class V8_EXPORT Function : public Object { * in an OO style, where many functions are anonymous but are assigned * to object properties. */ - Handle<Value> GetInferredName() const; + Local<Value> GetInferredName() const; /** * User-defined name assigned to the "displayName" property of this function. * Used to facilitate debugging and profiling of JavaScript code. */ - Handle<Value> GetDisplayName() const; + Local<Value> GetDisplayName() const; /** * Returns zero based line number of function body and @@ -3169,13 +3291,13 @@ class V8_EXPORT Promise : public Object { * Resolve/reject the associated promise with a given value. * Ignored if the promise is no longer pending. */ - V8_DEPRECATE_SOON("Use maybe version", void Resolve(Handle<Value> value)); + V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value)); // TODO(dcarney): mark V8_WARN_UNUSED_RESULT - Maybe<bool> Resolve(Local<Context> context, Handle<Value> value); + Maybe<bool> Resolve(Local<Context> context, Local<Value> value); - V8_DEPRECATE_SOON("Use maybe version", void Reject(Handle<Value> value)); + V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value)); // TODO(dcarney): mark V8_WARN_UNUSED_RESULT - Maybe<bool> Reject(Local<Context> context, Handle<Value> value); + Maybe<bool> Reject(Local<Context> context, Local<Value> value); V8_INLINE static Resolver* Cast(Value* obj); @@ -3191,19 +3313,19 @@ class V8_EXPORT Promise : public Object { * invoked at the end of turn. */ V8_DEPRECATE_SOON("Use maybe version", - Local<Promise> Chain(Handle<Function> handler)); + Local<Promise> Chain(Local<Function> handler)); V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Chain(Local<Context> context, - Handle<Function> handler); + Local<Function> handler); V8_DEPRECATE_SOON("Use maybe version", - Local<Promise> Catch(Handle<Function> handler)); + Local<Promise> Catch(Local<Function> handler)); V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context, - Handle<Function> handler); + Local<Function> handler); V8_DEPRECATE_SOON("Use maybe version", - Local<Promise> Then(Handle<Function> handler)); + Local<Promise> Then(Local<Function> handler)); V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context, - Handle<Function> handler); + Local<Function> handler); /** * Returns true if the promise has at least one derived promise, and @@ -3312,7 +3434,7 @@ class V8_EXPORT ArrayBuffer : public Object { ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); /** - * Returns true if ArrayBuffer is extrenalized, that is, does not + * Returns true if ArrayBuffer is externalized, that is, does not * own its memory block. */ bool IsExternal() const; @@ -3445,7 +3567,9 @@ class V8_EXPORT TypedArray : public ArrayBufferView { */ class V8_EXPORT Uint8Array : public TypedArray { public: - static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer, + static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, size_t length); V8_INLINE static Uint8Array* Cast(Value* obj); @@ -3461,8 +3585,11 @@ class V8_EXPORT Uint8Array : public TypedArray { */ class V8_EXPORT Uint8ClampedArray : public TypedArray { public: - static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer, - size_t byte_offset, size_t length); + static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint8ClampedArray> New( + Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, + size_t length); V8_INLINE static Uint8ClampedArray* Cast(Value* obj); private: @@ -3476,8 +3603,10 @@ class V8_EXPORT Uint8ClampedArray : public TypedArray { */ class V8_EXPORT Int8Array : public TypedArray { public: - static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer, - size_t byte_offset, size_t length); + static Local<Int8Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); V8_INLINE static Int8Array* Cast(Value* obj); private: @@ -3492,8 +3621,10 @@ class V8_EXPORT Int8Array : public TypedArray { */ class V8_EXPORT Uint16Array : public TypedArray { public: - static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer, - size_t byte_offset, size_t length); + static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); V8_INLINE static Uint16Array* Cast(Value* obj); private: @@ -3508,7 +3639,9 @@ class V8_EXPORT Uint16Array : public TypedArray { */ class V8_EXPORT Int16Array : public TypedArray { public: - static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer, + static Local<Int16Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, size_t length); V8_INLINE static Int16Array* Cast(Value* obj); @@ -3524,8 +3657,10 @@ class V8_EXPORT Int16Array : public TypedArray { */ class V8_EXPORT Uint32Array : public TypedArray { public: - static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer, - size_t byte_offset, size_t length); + static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); V8_INLINE static Uint32Array* Cast(Value* obj); private: @@ -3540,7 +3675,9 @@ class V8_EXPORT Uint32Array : public TypedArray { */ class V8_EXPORT Int32Array : public TypedArray { public: - static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer, + static Local<Int32Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, size_t length); V8_INLINE static Int32Array* Cast(Value* obj); @@ -3556,8 +3693,10 @@ class V8_EXPORT Int32Array : public TypedArray { */ class V8_EXPORT Float32Array : public TypedArray { public: - static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer, - size_t byte_offset, size_t length); + static Local<Float32Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); V8_INLINE static Float32Array* Cast(Value* obj); private: @@ -3572,8 +3711,10 @@ class V8_EXPORT Float32Array : public TypedArray { */ class V8_EXPORT Float64Array : public TypedArray { public: - static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer, - size_t byte_offset, size_t length); + static Local<Float64Array> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer, + size_t byte_offset, size_t length); V8_INLINE static Float64Array* Cast(Value* obj); private: @@ -3588,7 +3729,9 @@ class V8_EXPORT Float64Array : public TypedArray { */ class V8_EXPORT DataView : public ArrayBufferView { public: - static Local<DataView> New(Handle<ArrayBuffer> array_buffer, + static Local<DataView> New(Local<ArrayBuffer> array_buffer, + size_t byte_offset, size_t length); + static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, size_t length); V8_INLINE static DataView* Cast(Value* obj); @@ -3599,6 +3742,105 @@ class V8_EXPORT DataView : public ArrayBufferView { /** + * An instance of the built-in SharedArrayBuffer constructor. + * This API is experimental and may change significantly. + */ +class V8_EXPORT SharedArrayBuffer : public Object { + public: + /** + * The contents of an |SharedArrayBuffer|. Externalization of + * |SharedArrayBuffer| returns an instance of this class, populated, with a + * pointer to data and byte length. + * + * The Data pointer of SharedArrayBuffer::Contents is always allocated with + * |ArrayBuffer::Allocator::Allocate| by the allocator specified in + * v8::Isolate::CreateParams::array_buffer_allocator. + * + * This API is experimental and may change significantly. + */ + class V8_EXPORT Contents { // NOLINT + public: + Contents() : data_(NULL), byte_length_(0) {} + + void* Data() const { return data_; } + size_t ByteLength() const { return byte_length_; } + + private: + void* data_; + size_t byte_length_; + + friend class SharedArrayBuffer; + }; + + + /** + * Data length in bytes. + */ + size_t ByteLength() const; + + /** + * Create a new SharedArrayBuffer. Allocate |byte_length| bytes. + * Allocated memory will be owned by a created SharedArrayBuffer and + * will be deallocated when it is garbage-collected, + * unless the object is externalized. + */ + static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length); + + /** + * Create a new SharedArrayBuffer over an existing memory block. The created + * array buffer is immediately in externalized state unless otherwise + * specified. The memory block will not be reclaimed when a created + * SharedArrayBuffer is garbage-collected. + */ + static Local<SharedArrayBuffer> New( + Isolate* isolate, void* data, size_t byte_length, + ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); + + /** + * Returns true if SharedArrayBuffer is externalized, that is, does not + * own its memory block. + */ + bool IsExternal() const; + + /** + * Make this SharedArrayBuffer external. The pointer to underlying memory + * block and byte length are returned as |Contents| structure. After + * SharedArrayBuffer had been etxrenalized, it does no longer owns the memory + * block. The caller should take steps to free memory when it is no longer + * needed. + * + * The memory block is guaranteed to be allocated with |Allocator::Allocate| + * by the allocator specified in + * v8::Isolate::CreateParams::array_buffer_allocator. + * + */ + Contents Externalize(); + + /** + * Get a pointer to the ArrayBuffer's underlying memory block without + * externalizing it. If the ArrayBuffer is not externalized, this pointer + * will become invalid as soon as the ArrayBuffer became garbage collected. + * + * The embedder should make sure to hold a strong reference to the + * ArrayBuffer while accessing this pointer. + * + * The memory block is guaranteed to be allocated with |Allocator::Allocate| + * by the allocator specified in + * v8::Isolate::CreateParams::array_buffer_allocator. + */ + Contents GetContents(); + + V8_INLINE static SharedArrayBuffer* Cast(Value* obj); + + static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; + + private: + SharedArrayBuffer(); + static void CheckCast(Value* obj); +}; + + +/** * An instance of the built-in Date constructor (ECMA-262, 15.9). */ class V8_EXPORT Date : public Object { @@ -3672,7 +3914,7 @@ class V8_EXPORT BooleanObject : public Object { */ class V8_EXPORT StringObject : public Object { public: - static Local<Value> New(Handle<String> value); + static Local<Value> New(Local<String> value); Local<String> ValueOf() const; @@ -3690,7 +3932,7 @@ class V8_EXPORT StringObject : public Object { */ class V8_EXPORT SymbolObject : public Object { public: - static Local<Value> New(Isolate* isolate, Handle<Symbol> value); + static Local<Value> New(Isolate* isolate, Local<Symbol> value); Local<Symbol> ValueOf() const; @@ -3728,10 +3970,10 @@ class V8_EXPORT RegExp : public Object { * is equivalent to evaluating "/foo/gm". */ static V8_DEPRECATE_SOON("Use maybe version", - Local<RegExp> New(Handle<String> pattern, + Local<RegExp> New(Local<String> pattern, Flags flags)); static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context, - Handle<String> pattern, + Local<String> pattern, Flags flags); /** @@ -3775,9 +4017,9 @@ class V8_EXPORT External : public Value { class V8_EXPORT Template : public Data { public: /** Adds a property to each instance created by this template.*/ - void Set(Handle<Name> name, Handle<Data> value, + void Set(Local<Name> name, Local<Data> value, PropertyAttribute attributes = None); - V8_INLINE void Set(Isolate* isolate, const char* name, Handle<Data> value); + V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value); void SetAccessorProperty( Local<Name> name, @@ -3813,24 +4055,20 @@ class V8_EXPORT Template : public Data { * defined by FunctionTemplate::HasInstance()), an implicit TypeError is * thrown and no callback is invoked. */ - void SetNativeDataProperty(Local<String> name, - AccessorGetterCallback getter, - AccessorSetterCallback setter = 0, - // TODO(dcarney): gcc can't handle Local below - Handle<Value> data = Handle<Value>(), - PropertyAttribute attribute = None, - Local<AccessorSignature> signature = - Local<AccessorSignature>(), - AccessControl settings = DEFAULT); - void SetNativeDataProperty(Local<Name> name, - AccessorNameGetterCallback getter, - AccessorNameSetterCallback setter = 0, - // TODO(dcarney): gcc can't handle Local below - Handle<Value> data = Handle<Value>(), - PropertyAttribute attribute = None, - Local<AccessorSignature> signature = - Local<AccessorSignature>(), - AccessControl settings = DEFAULT); + void SetNativeDataProperty( + Local<String> name, AccessorGetterCallback getter, + AccessorSetterCallback setter = 0, + // TODO(dcarney): gcc can't handle Local below + Local<Value> data = Local<Value>(), PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>(), + AccessControl settings = DEFAULT); + void SetNativeDataProperty( + Local<Name> name, AccessorNameGetterCallback getter, + AccessorNameSetterCallback setter = 0, + // TODO(dcarney): gcc can't handle Local below + Local<Value> data = Local<Value>(), PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>(), + AccessControl settings = DEFAULT); private: Template(); @@ -4109,11 +4347,9 @@ class V8_EXPORT FunctionTemplate : public Template { public: /** Creates a function template.*/ static Local<FunctionTemplate> New( - Isolate* isolate, - FunctionCallback callback = 0, - Handle<Value> data = Handle<Value>(), - Handle<Signature> signature = Handle<Signature>(), - int length = 0); + Isolate* isolate, FunctionCallback callback = 0, + Local<Value> data = Local<Value>(), + Local<Signature> signature = Local<Signature>(), int length = 0); /** Returns the unique function instance in the current execution context.*/ V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction()); @@ -4126,7 +4362,7 @@ class V8_EXPORT FunctionTemplate : public Template { * FunctionTemplate is called. */ void SetCallHandler(FunctionCallback callback, - Handle<Value> data = Handle<Value>()); + Local<Value> data = Local<Value>()); /** Set the predefined length property for the FunctionTemplate. */ void SetLength(int length); @@ -4135,7 +4371,7 @@ class V8_EXPORT FunctionTemplate : public Template { Local<ObjectTemplate> InstanceTemplate(); /** Causes the function template to inherit from a parent function template.*/ - void Inherit(Handle<FunctionTemplate> parent); + void Inherit(Local<FunctionTemplate> parent); /** * A PrototypeTemplate is the template used to create the prototype object @@ -4148,7 +4384,7 @@ class V8_EXPORT FunctionTemplate : public Template { * printing objects created with the function created from the * FunctionTemplate as its constructor. */ - void SetClassName(Handle<String> name); + void SetClassName(Local<String> name); /** @@ -4187,7 +4423,7 @@ class V8_EXPORT FunctionTemplate : public Template { * Returns true if the given object is an instance of this function * template. */ - bool HasInstance(Handle<Value> object); + bool HasInstance(Local<Value> object); private: FunctionTemplate(); @@ -4217,7 +4453,7 @@ struct NamedPropertyHandlerConfiguration { GenericNamedPropertyQueryCallback query = 0, GenericNamedPropertyDeleterCallback deleter = 0, GenericNamedPropertyEnumeratorCallback enumerator = 0, - Handle<Value> data = Handle<Value>(), + Local<Value> data = Local<Value>(), PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) : getter(getter), setter(setter), @@ -4232,7 +4468,7 @@ struct NamedPropertyHandlerConfiguration { GenericNamedPropertyQueryCallback query; GenericNamedPropertyDeleterCallback deleter; GenericNamedPropertyEnumeratorCallback enumerator; - Handle<Value> data; + Local<Value> data; PropertyHandlerFlags flags; }; @@ -4245,7 +4481,7 @@ struct IndexedPropertyHandlerConfiguration { IndexedPropertyQueryCallback query = 0, IndexedPropertyDeleterCallback deleter = 0, IndexedPropertyEnumeratorCallback enumerator = 0, - Handle<Value> data = Handle<Value>(), + Local<Value> data = Local<Value>(), PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) : getter(getter), setter(setter), @@ -4260,7 +4496,7 @@ struct IndexedPropertyHandlerConfiguration { IndexedPropertyQueryCallback query; IndexedPropertyDeleterCallback deleter; IndexedPropertyEnumeratorCallback enumerator; - Handle<Value> data; + Local<Value> data; PropertyHandlerFlags flags; }; @@ -4276,7 +4512,7 @@ class V8_EXPORT ObjectTemplate : public Template { /** Creates an ObjectTemplate. */ static Local<ObjectTemplate> New( Isolate* isolate, - Handle<FunctionTemplate> constructor = Handle<FunctionTemplate>()); + Local<FunctionTemplate> constructor = Local<FunctionTemplate>()); static V8_DEPRECATE_SOON("Use isolate version", Local<ObjectTemplate> New()); /** Creates a new instance of this template.*/ @@ -4312,22 +4548,16 @@ class V8_EXPORT ObjectTemplate : public Template { * defined by FunctionTemplate::HasInstance()), an implicit TypeError is * thrown and no callback is invoked. */ - void SetAccessor(Handle<String> name, - AccessorGetterCallback getter, - AccessorSetterCallback setter = 0, - Handle<Value> data = Handle<Value>(), - AccessControl settings = DEFAULT, - PropertyAttribute attribute = None, - Handle<AccessorSignature> signature = - Handle<AccessorSignature>()); - void SetAccessor(Handle<Name> name, - AccessorNameGetterCallback getter, - AccessorNameSetterCallback setter = 0, - Handle<Value> data = Handle<Value>(), - AccessControl settings = DEFAULT, - PropertyAttribute attribute = None, - Handle<AccessorSignature> signature = - Handle<AccessorSignature>()); + void SetAccessor( + Local<String> name, AccessorGetterCallback getter, + AccessorSetterCallback setter = 0, Local<Value> data = Local<Value>(), + AccessControl settings = DEFAULT, PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>()); + void SetAccessor( + Local<Name> name, AccessorNameGetterCallback getter, + AccessorNameSetterCallback setter = 0, Local<Value> data = Local<Value>(), + AccessControl settings = DEFAULT, PropertyAttribute attribute = None, + Local<AccessorSignature> signature = Local<AccessorSignature>()); /** * Sets a named property handler on the object template. @@ -4350,13 +4580,12 @@ class V8_EXPORT ObjectTemplate : public Template { * whenever they are invoked. */ // TODO(dcarney): deprecate - void SetNamedPropertyHandler( - NamedPropertyGetterCallback getter, - NamedPropertySetterCallback setter = 0, - NamedPropertyQueryCallback query = 0, - NamedPropertyDeleterCallback deleter = 0, - NamedPropertyEnumeratorCallback enumerator = 0, - Handle<Value> data = Handle<Value>()); + void SetNamedPropertyHandler(NamedPropertyGetterCallback getter, + NamedPropertySetterCallback setter = 0, + NamedPropertyQueryCallback query = 0, + NamedPropertyDeleterCallback deleter = 0, + NamedPropertyEnumeratorCallback enumerator = 0, + Local<Value> data = Local<Value>()); void SetHandler(const NamedPropertyHandlerConfiguration& configuration); /** @@ -4383,7 +4612,7 @@ class V8_EXPORT ObjectTemplate : public Template { IndexedPropertyQueryCallback query = 0, IndexedPropertyDeleterCallback deleter = 0, IndexedPropertyEnumeratorCallback enumerator = 0, - Handle<Value> data = Handle<Value>()) { + Local<Value> data = Local<Value>()) { SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query, deleter, enumerator, data)); } @@ -4394,7 +4623,7 @@ class V8_EXPORT ObjectTemplate : public Template { * function. */ void SetCallAsFunctionHandler(FunctionCallback callback, - Handle<Value> data = Handle<Value>()); + Local<Value> data = Local<Value>()); /** * Mark object instances of the template as undetectable. @@ -4407,20 +4636,16 @@ class V8_EXPORT ObjectTemplate : public Template { void MarkAsUndetectable(); /** - * Sets access check callbacks on the object template. + * Sets access check callbacks on the object template and enables + * access checks. * * When accessing properties on instances of this object template, * the access check callback will be called to determine whether or * not to allow cross-context access to the properties. - * The last parameter specifies whether access checks are turned - * on by default on instances. If access checks are off by default, - * they can be turned on on individual instances by calling - * Object::TurnOnAccessCheck(). */ void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, - Handle<Value> data = Handle<Value>(), - bool turned_on_by_default = true); + Local<Value> data = Local<Value>()); /** * Gets the number of internal fields for objects generated from @@ -4437,7 +4662,7 @@ class V8_EXPORT ObjectTemplate : public Template { private: ObjectTemplate(); static Local<ObjectTemplate> New(internal::Isolate* isolate, - Handle<FunctionTemplate> constructor); + Local<FunctionTemplate> constructor); friend class FunctionTemplate; }; @@ -4449,7 +4674,7 @@ class V8_EXPORT Signature : public Data { public: static Local<Signature> New( Isolate* isolate, - Handle<FunctionTemplate> receiver = Handle<FunctionTemplate>()); + Local<FunctionTemplate> receiver = Local<FunctionTemplate>()); private: Signature(); @@ -4462,9 +4687,9 @@ class V8_EXPORT Signature : public Data { */ class V8_EXPORT AccessorSignature : public Data { public: - static Local<AccessorSignature> New(Isolate* isolate, - Handle<FunctionTemplate> receiver = - Handle<FunctionTemplate>()); + static Local<AccessorSignature> New( + Isolate* isolate, + Local<FunctionTemplate> receiver = Local<FunctionTemplate>()); private: AccessorSignature(); @@ -4477,9 +4702,10 @@ class V8_EXPORT AccessorSignature : public Data { */ class V8_EXPORT TypeSwitch : public Data { public: - static Local<TypeSwitch> New(Handle<FunctionTemplate> type); - static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); - int match(Handle<Value> value); + static Local<TypeSwitch> New(Local<FunctionTemplate> type); + static Local<TypeSwitch> New(int argc, Local<FunctionTemplate> types[]); + int match(Local<Value> value); + private: TypeSwitch(); }; @@ -4514,9 +4740,9 @@ class V8_EXPORT Extension { // NOLINT const char** deps = 0, int source_length = -1); virtual ~Extension() { } - virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( - v8::Isolate* isolate, v8::Handle<v8::String> name) { - return v8::Handle<v8::FunctionTemplate>(); + virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( + v8::Isolate* isolate, v8::Local<v8::String> name) { + return v8::Local<v8::FunctionTemplate>(); } const char* name() const { return name_; } @@ -4547,10 +4773,10 @@ void V8_EXPORT RegisterExtension(Extension* extension); // --- Statics --- -V8_INLINE Handle<Primitive> Undefined(Isolate* isolate); -V8_INLINE Handle<Primitive> Null(Isolate* isolate); -V8_INLINE Handle<Boolean> True(Isolate* isolate); -V8_INLINE Handle<Boolean> False(Isolate* isolate); +V8_INLINE Local<Primitive> Undefined(Isolate* isolate); +V8_INLINE Local<Primitive> Null(Isolate* isolate); +V8_INLINE Local<Boolean> True(Isolate* isolate); +V8_INLINE Local<Boolean> False(Isolate* isolate); /** @@ -4622,7 +4848,7 @@ class V8_EXPORT ResourceConstraints { typedef void (*FatalErrorCallback)(const char* location, const char* message); -typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> error); +typedef void (*MessageCallback)(Local<Message> message, Local<Value> error); // --- Tracing --- @@ -4634,24 +4860,24 @@ typedef void (*LogEventCallback)(const char* name, int event); */ class V8_EXPORT Exception { public: - static Local<Value> RangeError(Handle<String> message); - static Local<Value> ReferenceError(Handle<String> message); - static Local<Value> SyntaxError(Handle<String> message); - static Local<Value> TypeError(Handle<String> message); - static Local<Value> Error(Handle<String> message); + static Local<Value> RangeError(Local<String> message); + static Local<Value> ReferenceError(Local<String> message); + static Local<Value> SyntaxError(Local<String> message); + static Local<Value> TypeError(Local<String> message); + static Local<Value> Error(Local<String> message); /** * Creates an error message for the given exception. * Will try to reconstruct the original stack trace from the exception value, * or capture the current stack trace if not available. */ - static Local<Message> CreateMessage(Handle<Value> exception); + static Local<Message> CreateMessage(Local<Value> exception); /** * Returns the original stack trace that was captured at the creation time * of a given exception, or an empty handle if not available. */ - static Local<StackTrace> GetStackTrace(Handle<Value> exception); + static Local<StackTrace> GetStackTrace(Local<Value> exception); }; @@ -4699,25 +4925,25 @@ enum PromiseRejectEvent { class PromiseRejectMessage { public: - PromiseRejectMessage(Handle<Promise> promise, PromiseRejectEvent event, - Handle<Value> value, Handle<StackTrace> stack_trace) + PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event, + Local<Value> value, Local<StackTrace> stack_trace) : promise_(promise), event_(event), value_(value), stack_trace_(stack_trace) {} - V8_INLINE Handle<Promise> GetPromise() const { return promise_; } + V8_INLINE Local<Promise> GetPromise() const { return promise_; } V8_INLINE PromiseRejectEvent GetEvent() const { return event_; } - V8_INLINE Handle<Value> GetValue() const { return value_; } + V8_INLINE Local<Value> GetValue() const { return value_; } // DEPRECATED. Use v8::Exception::CreateMessage(GetValue())->GetStackTrace() - V8_INLINE Handle<StackTrace> GetStackTrace() const { return stack_trace_; } + V8_INLINE Local<StackTrace> GetStackTrace() const { return stack_trace_; } private: - Handle<Promise> promise_; + Local<Promise> promise_; PromiseRejectEvent event_; - Handle<Value> value_; - Handle<StackTrace> stack_trace_; + Local<Value> value_; + Local<StackTrace> stack_trace_; }; typedef void (*PromiseRejectCallback)(PromiseRejectMessage message); @@ -4815,6 +5041,24 @@ class V8_EXPORT HeapSpaceStatistics { }; +class V8_EXPORT HeapObjectStatistics { + public: + HeapObjectStatistics(); + const char* object_type() { return object_type_; } + const char* object_sub_type() { return object_sub_type_; } + size_t object_count() { return object_count_; } + size_t object_size() { return object_size_; } + + private: + const char* object_type_; + const char* object_sub_type_; + size_t object_count_; + size_t object_size_; + + friend class Isolate; +}; + + class RetainedObjectInfo; @@ -4860,7 +5104,7 @@ struct JitCodeEvent { // Size of the instructions. size_t code_len; // Script info for CODE_ADDED event. - Handle<UnboundScript> script; + Local<UnboundScript> script; // User-defined data for *_LINE_INFO_* event. It's used to hold the source // code line information which is returned from the // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent @@ -4920,7 +5164,7 @@ typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); class V8_EXPORT ExternalResourceVisitor { // NOLINT public: virtual ~ExternalResourceVisitor() {} - virtual void VisitExternalString(Handle<String> string) {} + virtual void VisitExternalString(Local<String> string) {} }; @@ -5107,6 +5351,7 @@ class V8_EXPORT Isolate { kStoreBufferOverflow = 4, kSlotsBufferOverflow = 5, kObjectObserve = 6, + kForcedGC = 7, kUseCounterFeatureCount // This enum value must be last. }; @@ -5125,7 +5370,7 @@ class V8_EXPORT Isolate { */ static Isolate* New(const CreateParams& params); - static V8_DEPRECATE_SOON("Always pass CreateParams", Isolate* New()); + static V8_DEPRECATED("Always pass CreateParams", Isolate* New()); /** * Returns the entered isolate for the current thread or NULL in @@ -5203,6 +5448,23 @@ class V8_EXPORT Isolate { size_t index); /** + * Returns the number of types of objects tracked in the heap at GC. + */ + size_t NumberOfTrackedHeapObjectTypes(); + + /** + * Get statistics about objects in the heap. + * + * \param object_statistics The HeapObjectStatistics object to fill in + * statistics of objects of given type, which were live in the previous GC. + * \param type_index The index of the type of object to fill details about, + * which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1. + * \returns true on success. + */ + bool GetHeapObjectStatisticsAtLastGC(HeapObjectStatistics* object_statistics, + size_t type_index); + + /** * Get a call stack sample from the isolate. * \param state Execution state. * \param frames Caller allocated buffer to store stack frames. @@ -5439,7 +5701,7 @@ class V8_EXPORT Isolate { /** * Experimental: Enqueues the callback to the Microtask Work Queue */ - void EnqueueMicrotask(Handle<Function> microtask); + void EnqueueMicrotask(Local<Function> microtask); /** * Experimental: Enqueues the callback to the Microtask Work Queue @@ -5591,7 +5853,7 @@ class V8_EXPORT Isolate { * Otherwise, the exception object will be passed to the callback instead. */ bool AddMessageListener(MessageCallback that, - Handle<Value> data = Handle<Value>()); + Local<Value> data = Local<Value>()); /** * Remove all message listeners from the specified callback function. @@ -5762,7 +6024,7 @@ class V8_EXPORT V8 { V8_INLINE static V8_DEPRECATE_SOON( "Use isolate version", bool AddMessageListener(MessageCallback that, - Handle<Value> data = Handle<Value>())); + Local<Value> data = Local<Value>())); /** * Remove all message listeners from the specified callback function. @@ -6160,7 +6422,7 @@ class V8_EXPORT TryCatch { * ReThrow; the caller must return immediately to where the exception * is caught. */ - Handle<Value> ReThrow(); + Local<Value> ReThrow(); /** * Returns the exception caught by this try/catch block. If no exception has @@ -6174,7 +6436,7 @@ class V8_EXPORT TryCatch { * Returns the .stack property of the thrown object. If no .stack * property is present an empty handle is returned. */ - V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace()) const; + V8_DEPRECATE_SOON("Use maybe version.", Local<Value> StackTrace() const); V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace( Local<Context> context) const; @@ -6322,22 +6584,21 @@ class V8_EXPORT Context { * and only object identify will remain. */ static Local<Context> New( - Isolate* isolate, - ExtensionConfiguration* extensions = NULL, - Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), - Handle<Value> global_object = Handle<Value>()); + Isolate* isolate, ExtensionConfiguration* extensions = NULL, + Local<ObjectTemplate> global_template = Local<ObjectTemplate>(), + Local<Value> global_object = Local<Value>()); /** * Sets the security token for the context. To access an object in * another context, the security tokens must match. */ - void SetSecurityToken(Handle<Value> token); + void SetSecurityToken(Local<Value> token); /** Restores the security token to the default value. */ void UseDefaultSecurityToken(); /** Returns the security token of this context.*/ - Handle<Value> GetSecurityToken(); + Local<Value> GetSecurityToken(); /** * Enter this context. After entering a context, all code compiled @@ -6371,11 +6632,17 @@ class V8_EXPORT Context { V8_INLINE Local<Value> GetEmbedderData(int index); /** + * Gets the exports object used by V8 extras. Extra natives get a reference + * to this object and can use it to export functionality. + */ + Local<Object> GetExtrasExportsObject(); + + /** * Sets the embedder data with the given index, growing the data as * needed. Note that index 0 currently has a special meaning for Chrome's * debugger. */ - void SetEmbedderData(int index, Handle<Value> value); + void SetEmbedderData(int index, Local<Value> value); /** * Gets a 2-byte-aligned native pointer from the embedder data with the given @@ -6418,7 +6685,7 @@ class V8_EXPORT Context { * code generation from strings is not allowed and 'eval' or the 'Function' * constructor are called. */ - void SetErrorMessageForCodeGenerationFromStrings(Handle<String> message); + void SetErrorMessageForCodeGenerationFromStrings(Local<String> message); /** * Stack-allocated class which sets the execution context for all @@ -6426,13 +6693,13 @@ class V8_EXPORT Context { */ class Scope { public: - explicit V8_INLINE Scope(Handle<Context> context) : context_(context) { + explicit V8_INLINE Scope(Local<Context> context) : context_(context) { context_->Enter(); } V8_INLINE ~Scope() { context_->Exit(); } private: - Handle<Context> context_; + Local<Context> context_; }; private: @@ -6672,7 +6939,7 @@ class Internals { static const int kJSObjectHeaderSize = 3 * kApiPointerSize; static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; static const int kContextHeaderSize = 2 * kApiPointerSize; - static const int kContextEmbedderDataIndex = 77; + static const int kContextEmbedderDataIndex = 81; static const int kFullStringRepresentationMask = 0x07; static const int kStringEncodingMask = 0x4; static const int kExternalTwoByteRepresentationTag = 0x02; @@ -6708,7 +6975,7 @@ class Internals { static const int kJSObjectType = 0xbe; static const int kFirstNonstringType = 0x80; static const int kOddballType = 0x83; - static const int kForeignType = 0x86; + static const int kForeignType = 0x87; static const int kUndefinedOddballKind = 5; static const int kNullOddballKind = 3; @@ -6939,7 +7206,7 @@ void PersistentBase<T>::Reset() { template <class T> template <class S> -void PersistentBase<T>::Reset(Isolate* isolate, const Handle<S>& other) { +void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) { TYPE_CHECK(T, S); Reset(); if (other.IsEmpty()) return; @@ -7064,9 +7331,20 @@ void ReturnValue<T>::Set(const Persistent<S>& handle) { } } -template<typename T> -template<typename S> -void ReturnValue<T>::Set(const Handle<S> handle) { +template <typename T> +template <typename S> +void ReturnValue<T>::Set(const Global<S>& handle) { + TYPE_CHECK(T, S); + if (V8_UNLIKELY(handle.IsEmpty())) { + *value_ = GetDefaultValue(); + } else { + *value_ = *reinterpret_cast<internal::Object**>(*handle); + } +} + +template <typename T> +template <typename S> +void ReturnValue<T>::Set(const Local<S> handle) { TYPE_CHECK(T, S); if (V8_UNLIKELY(handle.IsEmpty())) { *value_ = GetDefaultValue(); @@ -7225,38 +7503,42 @@ int FunctionCallbackInfo<T>::Length() const { return length_; } - -Handle<Value> ScriptOrigin::ResourceName() const { - return resource_name_; -} - - -Handle<Integer> ScriptOrigin::ResourceLineOffset() const { +ScriptOrigin::ScriptOrigin(Local<Value> resource_name, + Local<Integer> resource_line_offset, + Local<Integer> resource_column_offset, + Local<Boolean> resource_is_shared_cross_origin, + Local<Integer> script_id, + Local<Boolean> resource_is_embedder_debug_script, + Local<Value> source_map_url, + Local<Boolean> resource_is_opaque) + : resource_name_(resource_name), + resource_line_offset_(resource_line_offset), + resource_column_offset_(resource_column_offset), + options_(!resource_is_embedder_debug_script.IsEmpty() && + resource_is_embedder_debug_script->IsTrue(), + !resource_is_shared_cross_origin.IsEmpty() && + resource_is_shared_cross_origin->IsTrue(), + !resource_is_opaque.IsEmpty() && resource_is_opaque->IsTrue()), + script_id_(script_id), + source_map_url_(source_map_url) {} + +Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; } + + +Local<Integer> ScriptOrigin::ResourceLineOffset() const { return resource_line_offset_; } -Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { +Local<Integer> ScriptOrigin::ResourceColumnOffset() const { return resource_column_offset_; } -Handle<Boolean> ScriptOrigin::ResourceIsEmbedderDebugScript() const { - return resource_is_embedder_debug_script_; -} +Local<Integer> ScriptOrigin::ScriptID() const { return script_id_; } -Handle<Boolean> ScriptOrigin::ResourceIsSharedCrossOrigin() const { - return resource_is_shared_cross_origin_; -} - - -Handle<Integer> ScriptOrigin::ScriptID() const { - return script_id_; -} - - -Handle<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; } +Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; } ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin, @@ -7265,8 +7547,7 @@ ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin, resource_name(origin.ResourceName()), resource_line_offset(origin.ResourceLineOffset()), resource_column_offset(origin.ResourceColumnOffset()), - resource_is_embedder_debug_script(origin.ResourceIsEmbedderDebugScript()), - resource_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin()), + resource_options(origin.Options()), source_map_url(origin.SourceMapUrl()), cached_data(data) {} @@ -7287,13 +7568,15 @@ const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData() } -Handle<Boolean> Boolean::New(Isolate* isolate, bool value) { +Local<Boolean> Boolean::New(Isolate* isolate, bool value) { return value ? True(isolate) : False(isolate); } -void Template::Set(Isolate* isolate, const char* name, v8::Handle<Data> value) { - Set(v8::String::NewFromUtf8(isolate, name), value); +void Template::Set(Isolate* isolate, const char* name, v8::Local<Data> value) { + Set(v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal) + .ToLocalChecked(), + value); } @@ -7446,41 +7729,51 @@ template <class T> Value* Value::Cast(T* value) { Local<Boolean> Value::ToBoolean() const { - return ToBoolean(Isolate::GetCurrent()); + return ToBoolean(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<Boolean>()); } Local<Number> Value::ToNumber() const { - return ToNumber(Isolate::GetCurrent()); + return ToNumber(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<Number>()); } Local<String> Value::ToString() const { - return ToString(Isolate::GetCurrent()); + return ToString(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<String>()); } Local<String> Value::ToDetailString() const { - return ToDetailString(Isolate::GetCurrent()); + return ToDetailString(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<String>()); } Local<Object> Value::ToObject() const { - return ToObject(Isolate::GetCurrent()); + return ToObject(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<Object>()); } Local<Integer> Value::ToInteger() const { - return ToInteger(Isolate::GetCurrent()); + return ToInteger(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<Integer>()); } Local<Uint32> Value::ToUint32() const { - return ToUint32(Isolate::GetCurrent()); + return ToUint32(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<Uint32>()); } -Local<Int32> Value::ToInt32() const { return ToInt32(Isolate::GetCurrent()); } +Local<Int32> Value::ToInt32() const { + return ToInt32(Isolate::GetCurrent()->GetCurrentContext()) + .FromMaybe(Local<Int32>()); +} Boolean* Boolean::Cast(v8::Value* value) { @@ -7603,6 +7896,22 @@ Array* Array::Cast(v8::Value* value) { } +Map* Map::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Map*>(value); +} + + +Set* Set::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<Set*>(value); +} + + Promise* Promise::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS CheckCast(value); @@ -7723,6 +8032,14 @@ DataView* DataView::Cast(v8::Value* value) { } +SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) { +#ifdef V8_ENABLE_CHECKS + CheckCast(value); +#endif + return static_cast<SharedArrayBuffer*>(value); +} + + Function* Function::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS CheckCast(value); @@ -7769,39 +8086,39 @@ ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const { } -Handle<Primitive> Undefined(Isolate* isolate) { +Local<Primitive> Undefined(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); - return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); + return Local<Primitive>(reinterpret_cast<Primitive*>(slot)); } -Handle<Primitive> Null(Isolate* isolate) { +Local<Primitive> Null(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); - return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); + return Local<Primitive>(reinterpret_cast<Primitive*>(slot)); } -Handle<Boolean> True(Isolate* isolate) { +Local<Boolean> True(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); - return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); + return Local<Boolean>(reinterpret_cast<Boolean*>(slot)); } -Handle<Boolean> False(Isolate* isolate) { +Local<Boolean> False(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); - return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); + return Local<Boolean>(reinterpret_cast<Boolean*>(slot)); } @@ -7909,7 +8226,7 @@ bool V8::IsDead() { } -bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { +bool V8::AddMessageListener(MessageCallback that, Local<Value> data) { Isolate* isolate = Isolate::GetCurrent(); return isolate->AddMessageListener(that, data); } |