v8.h | v8.h | |||
---|---|---|---|---|
skipping to change at line 79 | skipping to change at line 79 | |||
#define V8EXPORT __attribute__ ((visibility("default"))) | #define V8EXPORT __attribute__ ((visibility("default"))) | |||
#else | #else | |||
#define V8EXPORT | #define V8EXPORT | |||
#endif | #endif | |||
#else | #else | |||
#define V8EXPORT | #define V8EXPORT | |||
#endif | #endif | |||
#endif // _WIN32 | #endif // _WIN32 | |||
// TODO(svenpanne) Remove this when the Chrome's v8 bindings have been adap | ||||
ted. | ||||
#define V8_DISABLE_DEPRECATIONS 1 | ||||
#if defined(__GNUC__) && !defined(V8_DISABLE_DEPRECATIONS) | ||||
#define V8_DEPRECATED(func) func __attribute__ ((deprecated)) | ||||
#elif defined(_MSC_VER) && !defined(V8_DISABLE_DEPRECATIONS) | ||||
#define V8_DEPRECATED(func) __declspec(deprecated) func | ||||
#else | ||||
#define V8_DEPRECATED(func) func | ||||
#endif | ||||
/** | /** | |||
* The v8 JavaScript engine. | * The v8 JavaScript engine. | |||
*/ | */ | |||
namespace v8 { | namespace v8 { | |||
class Context; | class Context; | |||
class String; | class String; | |||
class StringObject; | class StringObject; | |||
class Value; | class Value; | |||
class Utils; | class Utils; | |||
skipping to change at line 379 | skipping to change at line 390 | |||
*/ | */ | |||
inline static Persistent<T> New(Handle<T> that); | inline static Persistent<T> New(Handle<T> that); | |||
/** | /** | |||
* Releases the storage cell referenced by this persistent handle. | * Releases the storage cell referenced by this persistent handle. | |||
* Does not remove the reference to the cell from any handles. | * Does not remove the reference to the cell from any handles. | |||
* This handle's reference, and any other references to the storage | * This handle's reference, and any other references to the storage | |||
* cell remain and IsEmpty will still return false. | * cell remain and IsEmpty will still return false. | |||
*/ | */ | |||
inline void Dispose(); | inline void Dispose(); | |||
inline void Dispose(Isolate* isolate); | ||||
/** | /** | |||
* Make the reference to this object weak. When only weak handles | * Make the reference to this object weak. When only weak handles | |||
* refer to the object, the garbage collector will perform a | * refer to the object, the garbage collector will perform a | |||
* callback to the given V8::WeakReferenceCallback function, passing | * callback to the given V8::WeakReferenceCallback function, passing | |||
* it the object reference and the given parameters. | * it the object reference and the given parameters. | |||
*/ | */ | |||
inline void MakeWeak(void* parameters, WeakReferenceCallback callback); | inline void MakeWeak(void* parameters, WeakReferenceCallback callback); | |||
/** Clears the weak reference to this object. */ | /** Clears the weak reference to this object. */ | |||
skipping to change at line 402 | skipping to change at line 414 | |||
* Marks the reference to this object independent. Garbage collector | * Marks the reference to this object independent. Garbage collector | |||
* is free to ignore any object groups containing this object. | * is free to ignore any object groups containing this object. | |||
* Weak callback for an independent handle should not | * Weak callback for an independent handle should not | |||
* assume that it will be preceded by a global GC prologue callback | * assume that it will be preceded by a global GC prologue callback | |||
* or followed by a global GC epilogue callback. | * or followed by a global GC epilogue callback. | |||
*/ | */ | |||
inline void MarkIndependent(); | inline void MarkIndependent(); | |||
/** Returns true if this handle was previously marked as independent. */ | /** Returns true if this handle was previously marked as independent. */ | |||
inline bool IsIndependent() const; | inline bool IsIndependent() const; | |||
inline bool IsIndependent(Isolate* isolate) const; | ||||
/** Checks if the handle holds the only reference to an object. */ | /** Checks if the handle holds the only reference to an object. */ | |||
inline bool IsNearDeath() const; | inline bool IsNearDeath() const; | |||
/** Returns true if the handle's reference is weak. */ | /** Returns true if the handle's reference is weak. */ | |||
inline bool IsWeak() const; | inline bool IsWeak() const; | |||
/** | /** | |||
* Assigns a wrapper class ID to the handle. See RetainedObjectInfo | * Assigns a wrapper class ID to the handle. See RetainedObjectInfo | |||
* interface description in v8-profiler.h for details. | * interface description in v8-profiler.h for details. | |||
skipping to change at line 1563 | skipping to change at line 1576 | |||
*/ | */ | |||
V8EXPORT Local<Value> GetConstructor(); | V8EXPORT Local<Value> GetConstructor(); | |||
/** | /** | |||
* Returns the name of the function invoked as a constructor for this obj ect. | * Returns the name of the function invoked as a constructor for this obj ect. | |||
*/ | */ | |||
V8EXPORT Local<String> GetConstructorName(); | V8EXPORT Local<String> GetConstructorName(); | |||
/** Gets the number of internal fields for this Object. */ | /** Gets the number of internal fields for this Object. */ | |||
V8EXPORT int InternalFieldCount(); | V8EXPORT int InternalFieldCount(); | |||
/** Gets the value in an internal field. */ | ||||
/** Gets the value from an internal field. */ | ||||
inline Local<Value> GetInternalField(int index); | inline Local<Value> GetInternalField(int index); | |||
/** Sets the value in an internal field. */ | /** Sets the value in an internal field. */ | |||
V8EXPORT void SetInternalField(int index, Handle<Value> value); | V8EXPORT void SetInternalField(int index, Handle<Value> value); | |||
/** Gets a native pointer from an internal field. */ | /** | |||
inline void* GetPointerFromInternalField(int index); | * Gets a native pointer from an internal field. Deprecated. If the point | |||
er is | ||||
* always 2-byte-aligned, use GetAlignedPointerFromInternalField instead, | ||||
* otherwise use a combination of GetInternalField, External::Cast and | ||||
* External::Value. | ||||
*/ | ||||
V8_DEPRECATED(void* GetPointerFromInternalField(int index)); | ||||
/** | ||||
* Sets a native pointer in an internal field. Deprecated. If the pointer | ||||
is | ||||
* always 2-byte aligned, use SetAlignedPointerInInternalField instead, | ||||
* otherwise use a combination of External::New and SetInternalField. | ||||
*/ | ||||
inline V8_DEPRECATED(void SetPointerInInternalField(int index, void* valu | ||||
e)); | ||||
/** Sets a native pointer in an internal field. */ | /** | |||
V8EXPORT void SetPointerInInternalField(int index, void* value); | * Gets a 2-byte-aligned native pointer from an internal field. This fiel | |||
d | ||||
* must have been set by SetAlignedPointerInInternalField, everything els | ||||
e | ||||
* leads to undefined behavior. | ||||
*/ | ||||
inline void* GetAlignedPointerFromInternalField(int index); | ||||
/** | ||||
* Sets a 2-byte-aligned native pointer in an internal field. To retrieve | ||||
such | ||||
* a field, GetAlignedPointerFromInternalField must be used, everything e | ||||
lse | ||||
* leads to undefined behavior. | ||||
*/ | ||||
V8EXPORT void SetAlignedPointerInInternalField(int index, void* value); | ||||
// Testers for local properties. | // Testers for local properties. | |||
V8EXPORT bool HasOwnProperty(Handle<String> key); | V8EXPORT bool HasOwnProperty(Handle<String> key); | |||
V8EXPORT bool HasRealNamedProperty(Handle<String> key); | V8EXPORT bool HasRealNamedProperty(Handle<String> key); | |||
V8EXPORT bool HasRealIndexedProperty(uint32_t index); | V8EXPORT bool HasRealIndexedProperty(uint32_t index); | |||
V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); | V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); | |||
/** | /** | |||
* If result.IsEmpty() no real property was located in the prototype chai n. | * If result.IsEmpty() no real property was located in the prototype chai n. | |||
* This means interceptors in the prototype chain are not called. | * This means interceptors in the prototype chain are not called. | |||
skipping to change at line 1703 | skipping to change at line 1741 | |||
*/ | */ | |||
V8EXPORT Local<Value> CallAsConstructor(int argc, | V8EXPORT Local<Value> CallAsConstructor(int argc, | |||
Handle<Value> argv[]); | Handle<Value> argv[]); | |||
V8EXPORT static Local<Object> New(); | V8EXPORT static Local<Object> New(); | |||
static inline Object* Cast(Value* obj); | static inline Object* Cast(Value* obj); | |||
private: | private: | |||
V8EXPORT Object(); | V8EXPORT Object(); | |||
V8EXPORT static void CheckCast(Value* obj); | V8EXPORT static void CheckCast(Value* obj); | |||
V8EXPORT Local<Value> CheckedGetInternalField(int index); | V8EXPORT Local<Value> SlowGetInternalField(int index); | |||
V8EXPORT void* SlowGetPointerFromInternalField(int index); | V8EXPORT void* SlowGetAlignedPointerFromInternalField(int index); | |||
/** | ||||
* If quick access to the internal field is possible this method | ||||
* returns the value. Otherwise an empty handle is returned. | ||||
*/ | ||||
inline Local<Value> UncheckedGetInternalField(int index); | ||||
}; | }; | |||
/** | /** | |||
* An instance of the built-in array constructor (ECMA-262, 15.4.2). | * An instance of the built-in array constructor (ECMA-262, 15.4.2). | |||
*/ | */ | |||
class Array : public Object { | class Array : public Object { | |||
public: | public: | |||
V8EXPORT uint32_t Length() const; | V8EXPORT uint32_t Length() const; | |||
/** | /** | |||
skipping to change at line 1913 | skipping to change at line 1945 | |||
*/ | */ | |||
V8EXPORT Flags GetFlags() const; | V8EXPORT Flags GetFlags() const; | |||
static inline RegExp* Cast(v8::Value* obj); | static inline RegExp* Cast(v8::Value* obj); | |||
private: | private: | |||
V8EXPORT static void CheckCast(v8::Value* obj); | V8EXPORT static void CheckCast(v8::Value* obj); | |||
}; | }; | |||
/** | /** | |||
* A JavaScript value that wraps a C++ void*. This type of value is | * A JavaScript value that wraps a C++ void*. This type of value is mainly | |||
* mainly used to associate C++ data structures with JavaScript | used | |||
* objects. | * to associate C++ data structures with JavaScript objects. | |||
* | ||||
* The Wrap function V8 will return the most optimal Value object wrapping | ||||
the | ||||
* C++ void*. The type of the value is not guaranteed to be an External obj | ||||
ect | ||||
* and no assumptions about its type should be made. To access the wrapped | ||||
* value Unwrap should be used, all other operations on that object will le | ||||
ad | ||||
* to unpredictable results. | ||||
*/ | */ | |||
class External : public Value { | class External : public Value { | |||
public: | public: | |||
V8EXPORT static Local<Value> Wrap(void* data); | /** Deprecated, use New instead. */ | |||
static inline void* Unwrap(Handle<Value> obj); | V8_DEPRECATED(static inline Local<Value> Wrap(void* value)); | |||
/** Deprecated, use a combination of Cast and Value instead. */ | ||||
V8_DEPRECATED(static inline void* Unwrap(Handle<Value> obj)); | ||||
V8EXPORT static Local<External> New(void* value); | V8EXPORT static Local<External> New(void* value); | |||
static inline External* Cast(Value* obj); | static inline External* Cast(Value* obj); | |||
V8EXPORT void* Value() const; | V8EXPORT void* Value() const; | |||
private: | private: | |||
V8EXPORT External(); | ||||
V8EXPORT static void CheckCast(v8::Value* obj); | V8EXPORT static void CheckCast(v8::Value* obj); | |||
static inline void* QuickUnwrap(Handle<v8::Value> obj); | ||||
V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj); | ||||
}; | }; | |||
// --- Templates --- | // --- Templates --- | |||
/** | /** | |||
* The superclass of object and function templates. | * The superclass of object and function templates. | |||
*/ | */ | |||
class V8EXPORT Template : public Data { | class V8EXPORT Template : public Data { | |||
public: | public: | |||
/** Adds a property to each instance created by this template.*/ | /** Adds a property to each instance created by this template.*/ | |||
skipping to change at line 3369 | skipping to change at line 3394 | |||
*/ | */ | |||
static bool Dispose(); | static bool Dispose(); | |||
/** | /** | |||
* Get statistics about the heap memory usage. | * Get statistics about the heap memory usage. | |||
*/ | */ | |||
static void GetHeapStatistics(HeapStatistics* heap_statistics); | static void GetHeapStatistics(HeapStatistics* heap_statistics); | |||
/** | /** | |||
* Iterates through all external resources referenced from current isolat e | * Iterates through all external resources referenced from current isolat e | |||
* heap. This method is not expected to be used except for debugging purp | * heap. GC is not invoked prior to iterating, therefore there is no | |||
oses | * guarantee that visited objects are still alive. | |||
* and may be quite slow. | ||||
*/ | */ | |||
static void VisitExternalResources(ExternalResourceVisitor* visitor); | static void VisitExternalResources(ExternalResourceVisitor* visitor); | |||
/** | /** | |||
* Iterates through all the persistent handles in the current isolate's h eap | * Iterates through all the persistent handles in the current isolate's h eap | |||
* that have class_ids. | * that have class_ids. | |||
*/ | */ | |||
static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); | static void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); | |||
/** | /** | |||
skipping to change at line 3413 | skipping to change at line 3438 | |||
* of context disposals - including this one - since the last time | * of context disposals - including this one - since the last time | |||
* V8 had a chance to clean up. | * V8 had a chance to clean up. | |||
*/ | */ | |||
static int ContextDisposedNotification(); | static int ContextDisposedNotification(); | |||
private: | private: | |||
V8(); | V8(); | |||
static internal::Object** GlobalizeReference(internal::Object** handle); | static internal::Object** GlobalizeReference(internal::Object** handle); | |||
static void DisposeGlobal(internal::Object** global_handle); | static void DisposeGlobal(internal::Object** global_handle); | |||
static void DisposeGlobal(internal::Isolate* isolate, | ||||
internal::Object** global_handle); | ||||
static void MakeWeak(internal::Object** global_handle, | static void MakeWeak(internal::Object** global_handle, | |||
void* data, | void* data, | |||
WeakReferenceCallback); | WeakReferenceCallback); | |||
static void ClearWeak(internal::Object** global_handle); | static void ClearWeak(internal::Object** global_handle); | |||
static void MarkIndependent(internal::Object** global_handle); | static void MarkIndependent(internal::Object** global_handle); | |||
static bool IsGlobalIndependent(internal::Object** global_handle); | static bool IsGlobalIndependent(internal::Object** global_handle); | |||
static bool IsGlobalIndependent(internal::Isolate* isolate, | ||||
internal::Object** global_handle); | ||||
static bool IsGlobalNearDeath(internal::Object** global_handle); | static bool IsGlobalNearDeath(internal::Object** global_handle); | |||
static bool IsGlobalWeak(internal::Object** global_handle); | static bool IsGlobalWeak(internal::Object** global_handle); | |||
static void SetWrapperClassId(internal::Object** global_handle, | static void SetWrapperClassId(internal::Object** global_handle, | |||
uint16_t class_id); | uint16_t class_id); | |||
static uint16_t GetWrapperClassId(internal::Object** global_handle); | static uint16_t GetWrapperClassId(internal::Object** global_handle); | |||
template <class T> friend class Handle; | template <class T> friend class Handle; | |||
template <class T> friend class Local; | template <class T> friend class Local; | |||
template <class T> friend class Persistent; | template <class T> friend class Persistent; | |||
friend class Context; | friend class Context; | |||
skipping to change at line 3665 | skipping to change at line 3694 | |||
*/ | */ | |||
void Exit(); | void Exit(); | |||
/** Returns true if the context has experienced an out of memory situatio n. */ | /** Returns true if the context has experienced an out of memory situatio n. */ | |||
bool HasOutOfMemoryException(); | bool HasOutOfMemoryException(); | |||
/** Returns true if V8 has a current context. */ | /** Returns true if V8 has a current context. */ | |||
static bool InContext(); | static bool InContext(); | |||
/** | /** | |||
* Associate an additional data object with the context. This is mainly u | * Gets embedder data with index 0. Deprecated, use GetEmbedderData with | |||
sed | index | |||
* with the debugger to provide additional information on the context thr | * 0 instead. | |||
ough | */ | |||
* the debugger API. | V8_DEPRECATED(inline Local<Value> GetData()); | |||
/** | ||||
* Sets embedder data with index 0. Deprecated, use SetEmbedderData with | ||||
index | ||||
* 0 instead. | ||||
*/ | */ | |||
void SetData(Handle<Value> data); | V8_DEPRECATED(inline void SetData(Handle<Value> value)); | |||
Local<Value> GetData(); | ||||
/** | ||||
* Gets the embedder data with the given index, which must have been set | ||||
by a | ||||
* previous call to SetEmbedderData with the same index. Note that index | ||||
0 | ||||
* currently has a special meaning for Chrome's debugger. | ||||
*/ | ||||
inline Local<Value> GetEmbedderData(int index); | ||||
/** | ||||
* 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); | ||||
/** | ||||
* Gets a 2-byte-aligned native pointer from the embedder data with the g | ||||
iven | ||||
* index, which must have bees set by a previous call to | ||||
* SetAlignedPointerInEmbedderData with the same index. Note that index 0 | ||||
* currently has a special meaning for Chrome's debugger. | ||||
*/ | ||||
inline void* GetAlignedPointerFromEmbedderData(int index); | ||||
/** | ||||
* Sets a 2-byte-aligned native pointer in the embedder data with the giv | ||||
en | ||||
* index, growing the data as needed. Note that index 0 currently has a | ||||
* special meaning for Chrome's debugger. | ||||
*/ | ||||
void SetAlignedPointerInEmbedderData(int index, void* value); | ||||
/** | /** | |||
* Control whether code generation from strings is allowed. Calling | * Control whether code generation from strings is allowed. Calling | |||
* this method with false will disable 'eval' and the 'Function' | * this method with false will disable 'eval' and the 'Function' | |||
* constructor for code running in this context. If 'eval' or the | * constructor for code running in this context. If 'eval' or the | |||
* 'Function' constructor are used an exception will be thrown. | * 'Function' constructor are used an exception will be thrown. | |||
* | * | |||
* If code generation from strings is not allowed the | * If code generation from strings is not allowed the | |||
* V8::AllowCodeGenerationFromStrings callback will be invoked if | * V8::AllowCodeGenerationFromStrings callback will be invoked if | |||
* set before blocking the call to 'eval' or the 'Function' | * set before blocking the call to 'eval' or the 'Function' | |||
skipping to change at line 3719 | skipping to change at line 3781 | |||
inline ~Scope() { context_->Exit(); } | inline ~Scope() { context_->Exit(); } | |||
private: | private: | |||
Handle<Context> context_; | Handle<Context> context_; | |||
}; | }; | |||
private: | private: | |||
friend class Value; | friend class Value; | |||
friend class Script; | friend class Script; | |||
friend class Object; | friend class Object; | |||
friend class Function; | friend class Function; | |||
Local<Value> SlowGetEmbedderData(int index); | ||||
void* SlowGetAlignedPointerFromEmbedderData(int index); | ||||
}; | }; | |||
/** | /** | |||
* Multiple threads in V8 are allowed, but only one thread at a time | * Multiple threads in V8 are allowed, but only one thread at a time | |||
* is allowed to use any given V8 isolate. See Isolate class | * is allowed to use any given V8 isolate. See Isolate class | |||
* comments. The definition of 'using V8 isolate' includes | * comments. The definition of 'using V8 isolate' includes | |||
* accessing handles or holding onto object pointers obtained | * accessing handles or holding onto object pointers obtained | |||
* from V8 handles while in the particular V8 isolate. It is up | * from V8 handles while in the particular V8 isolate. It is up | |||
* to the user of V8 to ensure (perhaps with locking) that this | * to the user of V8 to ensure (perhaps with locking) that this | |||
* constraint is not violated. In addition to any other synchronization | * constraint is not violated. In addition to any other synchronization | |||
skipping to change at line 3945 | skipping to change at line 4010 | |||
// Smi constants for 32-bit systems. | // Smi constants for 32-bit systems. | |||
template <> struct SmiTagging<4> { | template <> struct SmiTagging<4> { | |||
static const int kSmiShiftSize = 0; | static const int kSmiShiftSize = 0; | |||
static const int kSmiValueSize = 31; | static const int kSmiValueSize = 31; | |||
static inline int SmiToInt(internal::Object* value) { | static inline int SmiToInt(internal::Object* value) { | |||
int shift_bits = kSmiTagSize + kSmiShiftSize; | int shift_bits = kSmiTagSize + kSmiShiftSize; | |||
// Throw away top 32 bits and shift down (requires >> to be sign extend ing). | // Throw away top 32 bits and shift down (requires >> to be sign extend ing). | |||
return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bit s; | return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bit s; | |||
} | } | |||
// For 32-bit systems any 2 bytes aligned pointer can be encoded as smi | ||||
// with a plain reinterpret_cast. | ||||
static const uintptr_t kEncodablePointerMask = 0x1; | ||||
static const int kPointerToSmiShift = 0; | ||||
}; | }; | |||
// Smi constants for 64-bit systems. | // Smi constants for 64-bit systems. | |||
template <> struct SmiTagging<8> { | template <> struct SmiTagging<8> { | |||
static const int kSmiShiftSize = 31; | static const int kSmiShiftSize = 31; | |||
static const int kSmiValueSize = 32; | static const int kSmiValueSize = 32; | |||
static inline int SmiToInt(internal::Object* value) { | static inline int SmiToInt(internal::Object* value) { | |||
int shift_bits = kSmiTagSize + kSmiShiftSize; | int shift_bits = kSmiTagSize + kSmiShiftSize; | |||
// Shift down and throw away top 32 bits. | // Shift down and throw away top 32 bits. | |||
return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits ); | return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits ); | |||
} | } | |||
// To maximize the range of pointers that can be encoded | ||||
// in the available 32 bits, we require them to be 8 bytes aligned. | ||||
// This gives 2 ^ (32 + 3) = 32G address space covered. | ||||
// It might be not enough to cover stack allocated objects on some platfo | ||||
rms. | ||||
static const int kPointerAlignment = 3; | ||||
static const uintptr_t kEncodablePointerMask = | ||||
~(uintptr_t(0xffffffff) << kPointerAlignment); | ||||
static const int kPointerToSmiShift = | ||||
kSmiTagSize + kSmiShiftSize - kPointerAlignment; | ||||
}; | }; | |||
typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; | typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; | |||
const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | |||
const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | |||
const uintptr_t kEncodablePointerMask = | ||||
PlatformSmiTagging::kEncodablePointerMask; | ||||
const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; | ||||
/** | /** | |||
* This class exports constants and functionality from within v8 that | * This class exports constants and functionality from within v8 that | |||
* is necessary to implement inline functions in the v8 api. Don't | * is necessary to implement inline functions in the v8 api. Don't | |||
* depend on functions and constants defined here. | * depend on functions and constants defined here. | |||
*/ | */ | |||
class Internals { | class Internals { | |||
public: | public: | |||
// These values match non-compiler-dependent values defined within | // These values match non-compiler-dependent values defined within | |||
// the implementation of v8. | // the implementation of v8. | |||
static const int kHeapObjectMapOffset = 0; | static const int kHeapObjectMapOffset = 0; | |||
static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSi ze; | static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSi ze; | |||
static const int kStringResourceOffset = 3 * kApiPointerSize; | static const int kStringResourceOffset = 3 * kApiPointerSize; | |||
static const int kOddballKindOffset = 3 * kApiPointerSize; | static const int kOddballKindOffset = 3 * kApiPointerSize; | |||
static const int kForeignAddressOffset = kApiPointerSize; | static const int kForeignAddressOffset = kApiPointerSize; | |||
static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | |||
static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; | ||||
static const int kContextHeaderSize = 2 * kApiPointerSize; | ||||
static const int kContextEmbedderDataIndex = 54; | ||||
static const int kFullStringRepresentationMask = 0x07; | static const int kFullStringRepresentationMask = 0x07; | |||
static const int kStringEncodingMask = 0x4; | static const int kStringEncodingMask = 0x4; | |||
static const int kExternalTwoByteRepresentationTag = 0x02; | static const int kExternalTwoByteRepresentationTag = 0x02; | |||
static const int kExternalAsciiRepresentationTag = 0x06; | static const int kExternalAsciiRepresentationTag = 0x06; | |||
static const int kIsolateStateOffset = 0; | static const int kIsolateStateOffset = 0; | |||
static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | |||
static const int kIsolateRootsOffset = 3 * kApiPointerSize; | static const int kIsolateRootsOffset = 3 * kApiPointerSize; | |||
static const int kUndefinedValueRootIndex = 5; | static const int kUndefinedValueRootIndex = 5; | |||
static const int kNullValueRootIndex = 7; | static const int kNullValueRootIndex = 7; | |||
static const int kTrueValueRootIndex = 8; | static const int kTrueValueRootIndex = 8; | |||
static const int kFalseValueRootIndex = 9; | static const int kFalseValueRootIndex = 9; | |||
static const int kEmptySymbolRootIndex = 117; | static const int kEmptySymbolRootIndex = 118; | |||
static const int kJSObjectType = 0xaa; | static const int kJSObjectType = 0xaa; | |||
static const int kFirstNonstringType = 0x80; | static const int kFirstNonstringType = 0x80; | |||
static const int kOddballType = 0x82; | static const int kOddballType = 0x82; | |||
static const int kForeignType = 0x85; | static const int kForeignType = 0x85; | |||
static const int kUndefinedOddballKind = 5; | static const int kUndefinedOddballKind = 5; | |||
static const int kNullOddballKind = 3; | static const int kNullOddballKind = 3; | |||
static inline bool HasHeapObjectTag(internal::Object* value) { | static inline bool HasHeapObjectTag(internal::Object* value) { | |||
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | |||
kHeapObjectTag); | kHeapObjectTag); | |||
} | } | |||
static inline bool HasSmiTag(internal::Object* value) { | ||||
return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | ||||
} | ||||
static inline int SmiValue(internal::Object* value) { | static inline int SmiValue(internal::Object* value) { | |||
return PlatformSmiTagging::SmiToInt(value); | return PlatformSmiTagging::SmiToInt(value); | |||
} | } | |||
static inline int GetInstanceType(internal::Object* obj) { | static inline int GetInstanceType(internal::Object* obj) { | |||
typedef internal::Object O; | typedef internal::Object O; | |||
O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | |||
return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | |||
} | } | |||
static inline int GetOddballKind(internal::Object* obj) { | static inline int GetOddballKind(internal::Object* obj) { | |||
typedef internal::Object O; | typedef internal::Object O; | |||
return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | |||
} | } | |||
static inline void* GetExternalPointerFromSmi(internal::Object* value) { | ||||
const uintptr_t address = reinterpret_cast<uintptr_t>(value); | ||||
return reinterpret_cast<void*>(address >> kPointerToSmiShift); | ||||
} | ||||
static inline void* GetExternalPointer(internal::Object* obj) { | ||||
if (HasSmiTag(obj)) { | ||||
return GetExternalPointerFromSmi(obj); | ||||
} else if (GetInstanceType(obj) == kForeignType) { | ||||
return ReadField<void*>(obj, kForeignAddressOffset); | ||||
} else { | ||||
return NULL; | ||||
} | ||||
} | ||||
static inline bool IsExternalTwoByteString(int instance_type) { | static inline bool IsExternalTwoByteString(int instance_type) { | |||
int representation = (instance_type & kFullStringRepresentationMask); | int representation = (instance_type & kFullStringRepresentationMask); | |||
return representation == kExternalTwoByteRepresentationTag; | return representation == kExternalTwoByteRepresentationTag; | |||
} | } | |||
static inline bool IsInitialized(v8::Isolate* isolate) { | static inline bool IsInitialized(v8::Isolate* isolate) { | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffs et; | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffs et; | |||
return *reinterpret_cast<int*>(addr) == 1; | return *reinterpret_cast<int*>(addr) == 1; | |||
} | } | |||
skipping to change at line 4092 | skipping to change at line 4121 | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffs et; | uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffs et; | |||
return reinterpret_cast<internal::Object**>(addr + index * kApiPointerS ize); | return reinterpret_cast<internal::Object**>(addr + index * kApiPointerS ize); | |||
} | } | |||
template <typename T> | template <typename T> | |||
static inline T ReadField(Object* ptr, int offset) { | static inline T ReadField(Object* ptr, int offset) { | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectT ag; | uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectT ag; | |||
return *reinterpret_cast<T*>(addr); | return *reinterpret_cast<T*>(addr); | |||
} | } | |||
template <typename T> | ||||
static inline T ReadEmbedderData(Context* context, int index) { | ||||
typedef internal::Object O; | ||||
typedef internal::Internals I; | ||||
O* ctx = *reinterpret_cast<O**>(context); | ||||
int embedder_data_offset = I::kContextHeaderSize + | ||||
(internal::kApiPointerSize * I::kContextEmbedderDataIndex); | ||||
O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); | ||||
int value_offset = | ||||
I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); | ||||
return I::ReadField<T>(embedder_data, value_offset); | ||||
} | ||||
static inline bool CanCastToHeapObject(void* o) { return false; } | static inline bool CanCastToHeapObject(void* o) { return false; } | |||
static inline bool CanCastToHeapObject(Context* o) { return true; } | static inline bool CanCastToHeapObject(Context* o) { return true; } | |||
static inline bool CanCastToHeapObject(String* o) { return true; } | static inline bool CanCastToHeapObject(String* o) { return true; } | |||
static inline bool CanCastToHeapObject(Object* o) { return true; } | static inline bool CanCastToHeapObject(Object* o) { return true; } | |||
static inline bool CanCastToHeapObject(Message* o) { return true; } | static inline bool CanCastToHeapObject(Message* o) { return true; } | |||
static inline bool CanCastToHeapObject(StackTrace* o) { return true; } | static inline bool CanCastToHeapObject(StackTrace* o) { return true; } | |||
static inline bool CanCastToHeapObject(StackFrame* o) { return true; } | static inline bool CanCastToHeapObject(StackFrame* o) { return true; } | |||
}; | }; | |||
} // namespace internal | } // namespace internal | |||
skipping to change at line 4132 | skipping to change at line 4174 | |||
return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); | return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); | |||
} | } | |||
template <class T> | template <class T> | |||
bool Persistent<T>::IsIndependent() const { | bool Persistent<T>::IsIndependent() const { | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
return V8::IsGlobalIndependent(reinterpret_cast<internal::Object**>(**thi s)); | return V8::IsGlobalIndependent(reinterpret_cast<internal::Object**>(**thi s)); | |||
} | } | |||
template <class T> | template <class T> | |||
bool Persistent<T>::IsIndependent(Isolate* isolate) const { | ||||
if (this->IsEmpty()) return false; | ||||
return V8::IsGlobalIndependent(reinterpret_cast<internal::Isolate*>(isola | ||||
te), | ||||
reinterpret_cast<internal::Object**>(**thi | ||||
s)); | ||||
} | ||||
template <class T> | ||||
bool Persistent<T>::IsNearDeath() const { | bool Persistent<T>::IsNearDeath() const { | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this) ); | return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this) ); | |||
} | } | |||
template <class T> | template <class T> | |||
bool Persistent<T>::IsWeak() const { | bool Persistent<T>::IsWeak() const { | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); | return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::Dispose() { | void Persistent<T>::Dispose() { | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); | |||
} | } | |||
template <class T> | template <class T> | |||
void Persistent<T>::Dispose(Isolate* isolate) { | ||||
if (this->IsEmpty()) return; | ||||
V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate), | ||||
reinterpret_cast<internal::Object**>(**this)); | ||||
} | ||||
template <class T> | ||||
Persistent<T>::Persistent() : Handle<T>() { } | Persistent<T>::Persistent() : Handle<T>() { } | |||
template <class T> | template <class T> | |||
void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callba ck) { | void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callba ck) { | |||
V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), | V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), | |||
parameters, | parameters, | |||
callback); | callback); | |||
} | } | |||
template <class T> | template <class T> | |||
skipping to change at line 4251 | skipping to change at line 4307 | |||
Handle<Boolean> Boolean::New(bool value) { | Handle<Boolean> Boolean::New(bool value) { | |||
return value ? True() : False(); | return value ? True() : False(); | |||
} | } | |||
void Template::Set(const char* name, v8::Handle<Data> value) { | void Template::Set(const char* name, v8::Handle<Data> value) { | |||
Set(v8::String::New(name), value); | Set(v8::String::New(name), value); | |||
} | } | |||
Local<Value> Object::GetInternalField(int index) { | Local<Value> Object::GetInternalField(int index) { | |||
#ifndef V8_ENABLE_CHECKS | #ifndef V8_ENABLE_CHECKS | |||
Local<Value> quick_result = UncheckedGetInternalField(index); | ||||
if (!quick_result.IsEmpty()) return quick_result; | ||||
#endif | ||||
return CheckedGetInternalField(index); | ||||
} | ||||
Local<Value> Object::UncheckedGetInternalField(int index) { | ||||
typedef internal::Object O; | typedef internal::Object O; | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
O* obj = *reinterpret_cast<O**>(this); | O* obj = *reinterpret_cast<O**>(this); | |||
// Fast path: If the object is a plain JSObject, which is the common case | ||||
, we | ||||
// know where to find the internal fields and can return the value direct | ||||
ly. | ||||
if (I::GetInstanceType(obj) == I::kJSObjectType) { | if (I::GetInstanceType(obj) == I::kJSObjectType) { | |||
// If the object is a plain JSObject, which is the common case, | ||||
// we know where to find the internal fields and can return the | ||||
// value directly. | ||||
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * inde x); | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * inde x); | |||
O* value = I::ReadField<O*>(obj, offset); | O* value = I::ReadField<O*>(obj, offset); | |||
O** result = HandleScope::CreateHandle(value); | O** result = HandleScope::CreateHandle(value); | |||
return Local<Value>(reinterpret_cast<Value*>(result)); | return Local<Value>(reinterpret_cast<Value*>(result)); | |||
} else { | ||||
return Local<Value>(); | ||||
} | } | |||
} | ||||
void* External::Unwrap(Handle<v8::Value> obj) { | ||||
#ifdef V8_ENABLE_CHECKS | ||||
return FullUnwrap(obj); | ||||
#else | ||||
return QuickUnwrap(obj); | ||||
#endif | #endif | |||
return SlowGetInternalField(index); | ||||
} | } | |||
void* External::QuickUnwrap(Handle<v8::Value> wrapper) { | void Object::SetPointerInInternalField(int index, void* value) { | |||
typedef internal::Object O; | SetInternalField(index, External::New(value)); | |||
O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); | ||||
return internal::Internals::GetExternalPointer(obj); | ||||
} | } | |||
void* Object::GetPointerFromInternalField(int index) { | void* Object::GetAlignedPointerFromInternalField(int index) { | |||
#ifndef V8_ENABLE_CHECKS | ||||
typedef internal::Object O; | typedef internal::Object O; | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
O* obj = *reinterpret_cast<O**>(this); | O* obj = *reinterpret_cast<O**>(this); | |||
// Fast path: If the object is a plain JSObject, which is the common case | ||||
, we | ||||
// know where to find the internal fields and can return the value direct | ||||
ly. | ||||
if (I::GetInstanceType(obj) == I::kJSObjectType) { | if (I::GetInstanceType(obj) == I::kJSObjectType) { | |||
// If the object is a plain JSObject, which is the common case, | ||||
// we know where to find the internal fields and can return the | ||||
// value directly. | ||||
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * inde x); | int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * inde x); | |||
O* value = I::ReadField<O*>(obj, offset); | return I::ReadField<void*>(obj, offset); | |||
return I::GetExternalPointer(value); | ||||
} | } | |||
#endif | ||||
return SlowGetPointerFromInternalField(index); | return SlowGetAlignedPointerFromInternalField(index); | |||
} | } | |||
String* String::Cast(v8::Value* value) { | String* String::Cast(v8::Value* value) { | |||
#ifdef V8_ENABLE_CHECKS | #ifdef V8_ENABLE_CHECKS | |||
CheckCast(value); | CheckCast(value); | |||
#endif | #endif | |||
return static_cast<String*>(value); | return static_cast<String*>(value); | |||
} | } | |||
Local<String> String::Empty(Isolate* isolate) { | Local<String> String::Empty(Isolate* isolate) { | |||
skipping to change at line 4477 | skipping to change at line 4512 | |||
return static_cast<Array*>(value); | return static_cast<Array*>(value); | |||
} | } | |||
Function* Function::Cast(v8::Value* value) { | Function* Function::Cast(v8::Value* value) { | |||
#ifdef V8_ENABLE_CHECKS | #ifdef V8_ENABLE_CHECKS | |||
CheckCast(value); | CheckCast(value); | |||
#endif | #endif | |||
return static_cast<Function*>(value); | return static_cast<Function*>(value); | |||
} | } | |||
Local<Value> External::Wrap(void* value) { | ||||
return External::New(value); | ||||
} | ||||
void* External::Unwrap(Handle<v8::Value> obj) { | ||||
return External::Cast(*obj)->Value(); | ||||
} | ||||
External* External::Cast(v8::Value* value) { | External* External::Cast(v8::Value* value) { | |||
#ifdef V8_ENABLE_CHECKS | #ifdef V8_ENABLE_CHECKS | |||
CheckCast(value); | CheckCast(value); | |||
#endif | #endif | |||
return static_cast<External*>(value); | return static_cast<External*>(value); | |||
} | } | |||
Isolate* AccessorInfo::GetIsolate() const { | Isolate* AccessorInfo::GetIsolate() const { | |||
return *reinterpret_cast<Isolate**>(&args_[-3]); | return *reinterpret_cast<Isolate**>(&args_[-3]); | |||
} | } | |||
skipping to change at line 4542 | skipping to change at line 4585 | |||
void Isolate::SetData(void* data) { | void Isolate::SetData(void* data) { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
I::SetEmbedderData(this, data); | I::SetEmbedderData(this, data); | |||
} | } | |||
void* Isolate::GetData() { | void* Isolate::GetData() { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
return I::GetEmbedderData(this); | return I::GetEmbedderData(this); | |||
} | } | |||
Local<Value> Context::GetData() { | ||||
return GetEmbedderData(0); | ||||
} | ||||
void Context::SetData(Handle<Value> data) { | ||||
SetEmbedderData(0, data); | ||||
} | ||||
Local<Value> Context::GetEmbedderData(int index) { | ||||
#ifndef V8_ENABLE_CHECKS | ||||
typedef internal::Object O; | ||||
typedef internal::Internals I; | ||||
O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, inde | ||||
x)); | ||||
return Local<Value>(reinterpret_cast<Value*>(result)); | ||||
#else | ||||
return SlowGetEmbedderData(index); | ||||
#endif | ||||
} | ||||
void* Context::GetAlignedPointerFromEmbedderData(int index) { | ||||
#ifndef V8_ENABLE_CHECKS | ||||
typedef internal::Internals I; | ||||
return I::ReadEmbedderData<void*>(this, index); | ||||
#else | ||||
return SlowGetAlignedPointerFromEmbedderData(index); | ||||
#endif | ||||
} | ||||
/** | /** | |||
* \example shell.cc | * \example shell.cc | |||
* A simple shell that takes a list of expressions on the | * A simple shell that takes a list of expressions on the | |||
* command-line and executes them. | * command-line and executes them. | |||
*/ | */ | |||
/** | /** | |||
* \example process.cc | * \example process.cc | |||
*/ | */ | |||
End of changes. 43 change blocks. | ||||
114 lines changed or deleted | 200 lines changed or added | |||