v8.h   v8.h 
skipping to change at line 88 skipping to change at line 88
#define V8EXPORT_INLINE #define V8EXPORT_INLINE
#else #else
#define V8EXPORT #define V8EXPORT
#define V8EXPORT_INLINE #define V8EXPORT_INLINE
#endif // BUILDING_V8_SHARED #endif // BUILDING_V8_SHARED
#else // _WIN32 #else // _WIN32
#include <stdint.h> #include <stdint.h>
// Setup for Linux shared library export. There is no need to destinguish // Setup for Linux shared library export. There is no need to distinguish
// neither between building or using the V8 shared library nor between usin // between building or using the V8 shared library, but we should not
g // export symbols when we are building a static library.
// the shared or static V8 library as there is on Windows. Therefore there #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
is
// no checking of BUILDING_V8_SHARED and USING_V8_SHARED.
#if defined(__GNUC__) && (__GNUC__ >= 4)
#define V8EXPORT __attribute__ ((visibility("default"))) #define V8EXPORT __attribute__ ((visibility("default")))
#define V8EXPORT_INLINE __attribute__ ((visibility("default"))) #define V8EXPORT_INLINE __attribute__ ((visibility("default")))
#else // defined(__GNUC__) && (__GNUC__ >= 4) #else // defined(__GNUC__) && (__GNUC__ >= 4)
#define V8EXPORT #define V8EXPORT
#define V8EXPORT_INLINE #define V8EXPORT_INLINE
#endif // defined(__GNUC__) && (__GNUC__ >= 4) #endif // defined(__GNUC__) && (__GNUC__ >= 4)
#endif // _WIN32 #endif // _WIN32
/** /**
skipping to change at line 131 skipping to change at line 130
class Date; class Date;
class ImplementationUtilities; class ImplementationUtilities;
class Signature; class Signature;
template <class T> class Handle; template <class T> class Handle;
template <class T> class Local; template <class T> class Local;
template <class T> class Persistent; template <class T> class Persistent;
class FunctionTemplate; class FunctionTemplate;
class ObjectTemplate; class ObjectTemplate;
class Data; class Data;
namespace internal {
class Object;
}
// --- W e a k H a n d l e s // --- W e a k H a n d l e s
/** /**
* A weak reference callback function. * A weak reference callback function.
* *
* \param object the weak global object to be reclaimed by the garbage coll ector * \param object the weak global object to be reclaimed by the garbage coll ector
* \param parameter the value passed in when making the weak global object * \param parameter the value passed in when making the weak global object
*/ */
typedef void (*WeakReferenceCallback)(Persistent<Value> object, typedef void (*WeakReferenceCallback)(Persistent<Value> object,
void* parameter); void* parameter);
skipping to change at line 180 skipping to change at line 185
* an Handle<Object>); the value will still be governed by a handle * an Handle<Object>); the value will still be governed by a handle
* behind the scenes and the same rules apply to these values as to * behind the scenes and the same rules apply to these values as to
* their handles. * their handles.
*/ */
template <class T> class V8EXPORT_INLINE Handle { template <class T> class V8EXPORT_INLINE Handle {
public: public:
/** /**
* Creates an empty handle. * Creates an empty handle.
*/ */
Handle(); inline Handle();
/** /**
* Creates a new handle for the specified value. * Creates a new handle for the specified value.
*/ */
explicit Handle(T* val) : val_(val) { } explicit Handle(T* val) : val_(val) { }
/** /**
* Creates a handle for the contents of the specified handle. This * Creates a handle for the contents of the specified handle. This
* constructor allows you to pass handles as arguments by value and * constructor allows you to pass handles as arguments by value and
* to assign between handles. However, if you try to assign between * to assign between handles. However, if you try to assign between
skipping to change at line 228 skipping to change at line 233
*/ */
void Clear() { this->val_ = 0; } void Clear() { this->val_ = 0; }
/** /**
* Checks whether two handles are the same. * Checks whether two handles are the same.
* Returns true if both are empty, or if the objects * Returns true if both are empty, or if the objects
* to which they refer are identical. * to which they refer are identical.
* The handles' references are not checked. * The handles' references are not checked.
*/ */
template <class S> bool operator==(Handle<S> that) const { template <class S> bool operator==(Handle<S> that) const {
void** a = reinterpret_cast<void**>(**this); internal::Object** a = reinterpret_cast<internal::Object**>(**this);
void** b = reinterpret_cast<void**>(*that); internal::Object** b = reinterpret_cast<internal::Object**>(*that);
if (a == 0) return b == 0; if (a == 0) return b == 0;
if (b == 0) return false; if (b == 0) return false;
return *a == *b; return *a == *b;
} }
/** /**
* Checks whether two handles are different. * Checks whether two handles are different.
* Returns true if only one of the handles is empty, or if * Returns true if only one of the handles is empty, or if
* the objects to which they refer are different. * the objects to which they refer are different.
* The handles' references are not checked. * The handles' references are not checked.
*/ */
template <class S> bool operator!=(Handle<S> that) const { template <class S> bool operator!=(Handle<S> that) const {
return !operator==(that); return !operator==(that);
} }
template <class S> static inline Handle<T> Cast(Handle<S> that) { template <class S> static inline Handle<T> Cast(Handle<S> that) {
#ifdef V8_ENABLE_CHECKS
// If we're going to perform the type check then we have to check
// that the handle isn't empty before doing the checked cast.
if (that.IsEmpty()) return Handle<T>(); if (that.IsEmpty()) return Handle<T>();
#endif
return Handle<T>(T::Cast(*that)); return Handle<T>(T::Cast(*that));
} }
private: private:
T* val_; T* val_;
}; };
/** /**
* A light-weight stack-allocated object handle. All operations * A light-weight stack-allocated object handle. All operations
* that return objects from within v8 return them in local handles. They * that return objects from within v8 return them in local handles. They
* are created within HandleScopes, and all local handles allocated within a * are created within HandleScopes, and all local handles allocated within a
* handle scope are destroyed when the handle scope is destroyed. Hence it * handle scope are destroyed when the handle scope is destroyed. Hence it
* is not necessary to explicitly deallocate local handles. * is not necessary to explicitly deallocate local handles.
*/ */
template <class T> class V8EXPORT_INLINE Local : public Handle<T> { template <class T> class V8EXPORT_INLINE Local : public Handle<T> {
public: public:
Local(); inline Local();
template <class S> inline Local(Local<S> that) template <class S> inline Local(Local<S> that)
: Handle<T>(reinterpret_cast<T*>(*that)) { : Handle<T>(reinterpret_cast<T*>(*that)) {
/** /**
* This check fails when trying to convert between incompatible * This check fails when trying to convert between incompatible
* handles. For example, converting from a Handle<String> to a * handles. For example, converting from a Handle<String> to a
* Handle<Number>. * Handle<Number>.
*/ */
TYPE_CHECK(T, S); TYPE_CHECK(T, S);
} }
template <class S> inline Local(S* that) : Handle<T>(that) { } template <class S> inline Local(S* that) : Handle<T>(that) { }
template <class S> static inline Local<T> Cast(Local<S> that) { template <class S> static inline Local<T> Cast(Local<S> that) {
#ifdef V8_ENABLE_CHECKS
// If we're going to perform the type check then we have to check
// that the handle isn't empty before doing the checked cast.
if (that.IsEmpty()) return Local<T>(); if (that.IsEmpty()) return Local<T>();
#endif
return Local<T>(T::Cast(*that)); return Local<T>(T::Cast(*that));
} }
/** Create a local handle for the content of another handle. /** Create a local handle for the content of another handle.
* The referee is kept alive by the local handle even when * The referee is kept alive by the local handle even when
* the original handle is destroyed/disposed. * the original handle is destroyed/disposed.
*/ */
static Local<T> New(Handle<T> that); inline static Local<T> New(Handle<T> that);
}; };
/** /**
* An object reference that is independent of any handle scope. Where * An object reference that is independent of any handle scope. Where
* a Local handle only lives as long as the HandleScope in which it was * a Local handle only lives as long as the HandleScope in which it was
* allocated, a Persistent handle remains valid until it is explicitly * allocated, a Persistent handle remains valid until it is explicitly
* disposed. * disposed.
* *
* A persistent handle contains a reference to a storage cell within * A persistent handle contains a reference to a storage cell within
* the v8 engine which holds an object value and which is updated by * the v8 engine which holds an object value and which is updated by
skipping to change at line 310 skipping to change at line 323
* different storage cells but rather two references to the same * different storage cells but rather two references to the same
* storage cell. * storage cell.
*/ */
template <class T> class V8EXPORT_INLINE Persistent : public Handle<T> { template <class T> class V8EXPORT_INLINE Persistent : public Handle<T> {
public: public:
/** /**
* Creates an empty persistent handle that doesn't point to any * Creates an empty persistent handle that doesn't point to any
* storage cell. * storage cell.
*/ */
Persistent(); inline Persistent();
/** /**
* Creates a persistent handle for the same storage cell as the * Creates a persistent handle for the same storage cell as the
* specified handle. This constructor allows you to pass persistent * specified handle. This constructor allows you to pass persistent
* handles as arguments by value and to assign between persistent * handles as arguments by value and to assign between persistent
* handles. However, attempting to assign between incompatible * handles. However, attempting to assign between incompatible
* persistent handles, for instance from a Persistent<String> to a * persistent handles, for instance from a Persistent<String> to a
* Persistent<Number> will cause a compiletime error. Assigning * Persistent<Number> will cause a compiletime error. Assigning
* between compatible persistent handles, for instance assigning a * between compatible persistent handles, for instance assigning a
* Persistent<String> to a variable declared as Persistent<Value>, * Persistent<String> to a variable declared as Persistent<Value>,
skipping to change at line 343 skipping to change at line 356
template <class S> inline Persistent(S* that) : Handle<T>(that) { } template <class S> inline Persistent(S* that) : Handle<T>(that) { }
/** /**
* "Casts" a plain handle which is known to be a persistent handle * "Casts" a plain handle which is known to be a persistent handle
* to a persistent handle. * to a persistent handle.
*/ */
template <class S> explicit inline Persistent(Handle<S> that) template <class S> explicit inline Persistent(Handle<S> that)
: Handle<T>(*that) { } : Handle<T>(*that) { }
template <class S> static inline Persistent<T> Cast(Persistent<S> that) { template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
#ifdef V8_ENABLE_CHECKS
// If we're going to perform the type check then we have to check
// that the handle isn't empty before doing the checked cast.
if (that.IsEmpty()) return Persistent<T>(); if (that.IsEmpty()) return Persistent<T>();
#endif
return Persistent<T>(T::Cast(*that)); return Persistent<T>(T::Cast(*that));
} }
/** /**
* Creates a new persistent handle for an existing local or * Creates a new persistent handle for an existing local or
* persistent handle. * persistent handle.
*/ */
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 any other references to the storage * This handle's reference, and any any other references to the storage
* cell remain and IsEmpty will still return false. * cell remain and IsEmpty will still return false.
*/ */
void Dispose(); inline void Dispose();
/** /**
* 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.
*/ */
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.*/
void ClearWeak(); inline void ClearWeak();
/** /**
*Checks if the handle holds the only reference to an object. *Checks if the handle holds the only reference to an object.
*/ */
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.
*/ */
bool IsWeak() const; inline bool IsWeak() const;
private: private:
friend class ImplementationUtilities; friend class ImplementationUtilities;
friend class ObjectTemplate; friend class ObjectTemplate;
}; };
/** /**
* A stack-allocated class that governs a number of local handles. * A stack-allocated class that governs a number of local handles.
* After a handle scope has been created, all local handles will be * After a handle scope has been created, all local handles will be
* allocated within that handle scope until either the handle scope is * allocated within that handle scope until either the handle scope is
skipping to change at line 421 skipping to change at line 438
template <class T> Local<T> Close(Handle<T> value); template <class T> Local<T> Close(Handle<T> value);
/** /**
* Counts the number of allocated handles. * Counts the number of allocated handles.
*/ */
static int NumberOfHandles(); static int NumberOfHandles();
/** /**
* Creates a new handle with the given value. * Creates a new handle with the given value.
*/ */
static void** CreateHandle(void* value); static internal::Object** CreateHandle(internal::Object* value);
private: private:
// Make it impossible to create heap-allocated or illegal handle // Make it impossible to create heap-allocated or illegal handle
// scopes by disallowing certain operations. // scopes by disallowing certain operations.
HandleScope(const HandleScope&); HandleScope(const HandleScope&);
void operator=(const HandleScope&); void operator=(const HandleScope&);
void* operator new(size_t size); void* operator new(size_t size);
void operator delete(void*, size_t); void operator delete(void*, size_t);
// This Data class is accessible internally through a typedef in the // This Data class is accessible internally through a typedef in the
// ImplementationUtilities class. // ImplementationUtilities class.
class V8EXPORT Data { class V8EXPORT Data {
public: public:
int extensions; int extensions;
void** next; internal::Object** next;
void** limit; internal::Object** limit;
inline void Initialize() { inline void Initialize() {
extensions = -1; extensions = -1;
next = limit = NULL; next = limit = NULL;
} }
}; };
Data previous_; Data previous_;
// Allow for the active closing of HandleScopes which allows to pass a ha ndle // Allow for the active closing of HandleScopes which allows to pass a ha ndle
// from the HandleScope being closed to the next top most HandleScope. // from the HandleScope being closed to the next top most HandleScope.
bool is_closed_; bool is_closed_;
void** RawClose(void** value); internal::Object** RawClose(internal::Object** value);
friend class ImplementationUtilities; friend class ImplementationUtilities;
}; };
// --- S p e c i a l o b j e c t s --- // --- S p e c i a l o b j e c t s ---
/** /**
* The superclass of values and API object templates. * The superclass of values and API object templates.
*/ */
class V8EXPORT Data { class V8EXPORT Data {
skipping to change at line 506 skipping to change at line 523
Handle<Integer> resource_line_offset_; Handle<Integer> resource_line_offset_;
Handle<Integer> resource_column_offset_; Handle<Integer> resource_column_offset_;
}; };
/** /**
* A compiled JavaScript script. * A compiled JavaScript script.
*/ */
class V8EXPORT Script { class V8EXPORT Script {
public: public:
/**
* Compiles the specified script. The ScriptOrigin* and ScriptData*
* parameters are owned by the caller of Script::Compile. No
* references to these objects are kept after compilation finishes.
*
* The script object returned is context independent; when run it
* will use the currently entered context.
*/
static Local<Script> New(Handle<String> source,
ScriptOrigin* origin = NULL,
ScriptData* pre_data = NULL);
/**
* Compiles the specified script using the specified file name
* object (typically a string) as the script's origin.
*
* The script object returned is context independent; when run it
* will use the currently entered context.
*/
static Local<Script> New(Handle<String> source,
Handle<Value> file_name);
/** /**
* Compiles the specified script. The ScriptOrigin* and ScriptData* * Compiles the specified script. The ScriptOrigin* and ScriptData*
* parameters are owned by the caller of Script::Compile. No * parameters are owned by the caller of Script::Compile. No
* references to these objects are kept after compilation finishes. * references to these objects are kept after compilation finishes.
*
* The script object returned is bound to the context that was active
* when this function was called. When run it will always use this
* context.
*/ */
static Local<Script> Compile(Handle<String> source, static Local<Script> Compile(Handle<String> source,
ScriptOrigin* origin = NULL, ScriptOrigin* origin = NULL,
ScriptData* pre_data = NULL); ScriptData* pre_data = NULL);
/** /**
* Compiles the specified script using the specified file name * Compiles the specified script using the specified file name
* object (typically a string) as the script's origin. * object (typically a string) as the script's origin.
*
* The script object returned is bound to the context that was active
* when this function was called. When run it will always use this
* context.
*/ */
static Local<Script> Compile(Handle<String> source, static Local<Script> Compile(Handle<String> source,
Handle<Value> file_name); Handle<Value> file_name);
/** /**
* Runs the script returning the resulting value. * Runs the script returning the resulting value. If the script is
* context independent (created using ::New) it will be run in the
* currently entered context. If it is context specific (created
* using ::Compile) it will be run in the context in which it was
* compiled.
*/ */
Local<Value> Run(); Local<Value> Run();
/** /**
* Returns the script id value. * Returns the script id value.
*/ */
Local<Value> Id(); Local<Value> Id();
/** /**
* Associate an additional data object with the script. This is mainly us ed * Associate an additional data object with the script. This is mainly us ed
skipping to change at line 627 skipping to change at line 678
/** /**
* Returns true if this value is false. * Returns true if this value is false.
*/ */
bool IsFalse() const; bool IsFalse() const;
/** /**
* Returns true if this value is an instance of the String type. * Returns true if this value is an instance of the String type.
* See ECMA-262 8.4. * See ECMA-262 8.4.
*/ */
bool IsString() const; inline bool IsString() const;
/** /**
* Returns true if this value is a function. * Returns true if this value is a function.
*/ */
bool IsFunction() const; bool IsFunction() const;
/** /**
* Returns true if this value is an array. * Returns true if this value is an array.
*/ */
bool IsArray() const; bool IsArray() const;
skipping to change at line 693 skipping to change at line 744
bool BooleanValue() const; bool BooleanValue() const;
double NumberValue() const; double NumberValue() const;
int64_t IntegerValue() const; int64_t IntegerValue() const;
uint32_t Uint32Value() const; uint32_t Uint32Value() const;
int32_t Int32Value() const; int32_t Int32Value() const;
/** JS == */ /** JS == */
bool Equals(Handle<Value> that) const; bool Equals(Handle<Value> that) const;
bool StrictEquals(Handle<Value> that) const; bool StrictEquals(Handle<Value> that) const;
private:
inline bool QuickIsString() const;
bool FullIsString() const;
}; };
/** /**
* The superclass of primitive values. See ECMA-262 4.3.2. * The superclass of primitive values. See ECMA-262 4.3.2.
*/ */
class V8EXPORT Primitive : public Value { }; class V8EXPORT Primitive : public Value { };
/** /**
* A primitive boolean value (ECMA-262, 4.3.14). Either the true * A primitive boolean value (ECMA-262, 4.3.14). Either the true
* or false value. * or false value.
skipping to change at line 821 skipping to change at line 876
private: private:
// Disallow copying and assigning. // Disallow copying and assigning.
ExternalAsciiStringResource(const ExternalAsciiStringResource&); ExternalAsciiStringResource(const ExternalAsciiStringResource&);
void operator=(const ExternalAsciiStringResource&); void operator=(const ExternalAsciiStringResource&);
}; };
/** /**
* Get the ExternalStringResource for an external string. Returns * Get the ExternalStringResource for an external string. Returns
* NULL if IsExternal() doesn't return true. * NULL if IsExternal() doesn't return true.
*/ */
ExternalStringResource* GetExternalStringResource() const; inline ExternalStringResource* GetExternalStringResource() const;
/** /**
* Get the ExternalAsciiStringResource for an external ascii string. * Get the ExternalAsciiStringResource for an external ascii string.
* Returns NULL if IsExternalAscii() doesn't return true. * Returns NULL if IsExternalAscii() doesn't return true.
*/ */
ExternalAsciiStringResource* GetExternalAsciiStringResource() const; ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
static String* Cast(v8::Value* obj); static inline String* Cast(v8::Value* obj);
/** /**
* Allocates a new string from either utf-8 encoded or ascii data. * Allocates a new string from either utf-8 encoded or ascii data.
* The second parameter 'length' gives the buffer length. * The second parameter 'length' gives the buffer length.
* If the data is utf-8 encoded, the caller must * If the data is utf-8 encoded, the caller must
* be careful to supply the length parameter. * be careful to supply the length parameter.
* If it is not given, the function calls * If it is not given, the function calls
* 'strlen' to determine the buffer length, it might be * 'strlen' to determine the buffer length, it might be
* wrong if 'data' contains a null character. * wrong if 'data' contains a null character.
*/ */
skipping to change at line 888 skipping to change at line 943
/** /**
* Associate an external string resource with this string by transforming it * Associate an external string resource with this string by transforming it
* in place so that existing references to this string in the JavaScript heap * in place so that existing references to this string in the JavaScript heap
* will use the external string resource. The external string resource's * will use the external string resource. The external string resource's
* character contents needs to be equivalent to this string. * character contents needs to be equivalent to this string.
* Returns true if the string has been changed to be an external string. * Returns true if the string has been changed to be an external string.
* The string is not modified if the operation fails. * The string is not modified if the operation fails.
*/ */
bool MakeExternal(ExternalAsciiStringResource* resource); bool MakeExternal(ExternalAsciiStringResource* resource);
/**
* Returns true if this string can be made external.
*/
bool CanMakeExternal();
/** Creates an undetectable string from the supplied ascii or utf-8 data. */ /** Creates an undetectable string from the supplied ascii or utf-8 data. */
static Local<String> NewUndetectable(const char* data, int length = -1); static Local<String> NewUndetectable(const char* data, int length = -1);
/** Creates an undetectable string from the supplied utf-16 data.*/ /** Creates an undetectable string from the supplied utf-16 data.*/
static Local<String> NewUndetectable(const uint16_t* data, int length = - 1); static Local<String> NewUndetectable(const uint16_t* data, int length = - 1);
/** /**
* Converts an object to a utf8-encoded character array. Useful if * Converts an object to a utf8-encoded character array. Useful if
* you want to print the object. If conversion to a string fails * you want to print the object. If conversion to a string fails
* (eg. due to an exception in the toString() method of the object) * (eg. due to an exception in the toString() method of the object)
* then the length() method returns 0 and the * operator returns * then the length() method returns 0 and the * operator returns
* NULL. * NULL.
*/ */
class V8EXPORT Utf8Value { class V8EXPORT Utf8Value {
public: public:
explicit Utf8Value(Handle<v8::Value> obj); explicit Utf8Value(Handle<v8::Value> obj);
~Utf8Value(); ~Utf8Value();
char* operator*() const { return str_; } char* operator*() { return str_; }
int length() { return length_; } const char* operator*() const { return str_; }
int length() const { return length_; }
private: private:
char* str_; char* str_;
int length_; int length_;
// Disallow copying and assigning. // Disallow copying and assigning.
Utf8Value(const Utf8Value&); Utf8Value(const Utf8Value&);
void operator=(const Utf8Value&); void operator=(const Utf8Value&);
}; };
/** /**
* Converts an object to an ascii string. * Converts an object to an ascii string.
* Useful if you want to print the object. * Useful if you want to print the object.
* If conversion to a string fails (eg. due to an exception in the toStri ng() * If conversion to a string fails (eg. due to an exception in the toStri ng()
* method of the object) then the length() method returns 0 and the * ope rator * method of the object) then the length() method returns 0 and the * ope rator
* returns NULL. * returns NULL.
*/ */
class V8EXPORT AsciiValue { class V8EXPORT AsciiValue {
public: public:
explicit AsciiValue(Handle<v8::Value> obj); explicit AsciiValue(Handle<v8::Value> obj);
~AsciiValue(); ~AsciiValue();
char* operator*() const { return str_; } char* operator*() { return str_; }
int length() { return length_; } const char* operator*() const { return str_; }
int length() const { return length_; }
private: private:
char* str_; char* str_;
int length_; int length_;
// Disallow copying and assigning. // Disallow copying and assigning.
AsciiValue(const AsciiValue&); AsciiValue(const AsciiValue&);
void operator=(const AsciiValue&); void operator=(const AsciiValue&);
}; };
/** /**
* Converts an object to a two-byte string. * Converts an object to a two-byte string.
* If conversion to a string fails (eg. due to an exception in the toStri ng() * If conversion to a string fails (eg. due to an exception in the toStri ng()
* method of the object) then the length() method returns 0 and the * ope rator * method of the object) then the length() method returns 0 and the * ope rator
* returns NULL. * returns NULL.
*/ */
class V8EXPORT Value { class V8EXPORT Value {
public: public:
explicit Value(Handle<v8::Value> obj); explicit Value(Handle<v8::Value> obj);
~Value(); ~Value();
uint16_t* operator*() const { return str_; } uint16_t* operator*() { return str_; }
int length() { return length_; } const uint16_t* operator*() const { return str_; }
int length() const { return length_; }
private: private:
uint16_t* str_; uint16_t* str_;
int length_; int length_;
// Disallow copying and assigning. // Disallow copying and assigning.
Value(const Value&); Value(const Value&);
void operator=(const Value&); void operator=(const Value&);
}; };
private:
void VerifyExternalStringResource(ExternalStringResource* val) const;
static void CheckCast(v8::Value* obj);
}; };
/** /**
* A JavaScript number value (ECMA-262, 4.3.20) * A JavaScript number value (ECMA-262, 4.3.20)
*/ */
class V8EXPORT Number : public Primitive { class V8EXPORT Number : public Primitive {
public: public:
double Value() const; double Value() const;
static Local<Number> New(double value); static Local<Number> New(double value);
static Number* Cast(v8::Value* obj); static inline Number* Cast(v8::Value* obj);
private: private:
Number(); Number();
static void CheckCast(v8::Value* obj);
}; };
/** /**
* A JavaScript value representing a signed integer. * A JavaScript value representing a signed integer.
*/ */
class V8EXPORT Integer : public Number { class V8EXPORT Integer : public Number {
public: public:
static Local<Integer> New(int32_t value); static Local<Integer> New(int32_t value);
int64_t Value() const; int64_t Value() const;
static Integer* Cast(v8::Value* obj); static inline Integer* Cast(v8::Value* obj);
private: private:
Integer(); Integer();
static void CheckCast(v8::Value* obj);
}; };
/** /**
* A JavaScript value representing a 32-bit signed integer. * A JavaScript value representing a 32-bit signed integer.
*/ */
class V8EXPORT Int32 : public Integer { class V8EXPORT Int32 : public Integer {
public: public:
int32_t Value() const; int32_t Value() const;
private: private:
Int32(); Int32();
skipping to change at line 1017 skipping to change at line 1086
class V8EXPORT Date : public Value { class V8EXPORT Date : public Value {
public: public:
static Local<Value> New(double time); static Local<Value> New(double time);
/** /**
* A specialization of Value::NumberValue that is more efficient * A specialization of Value::NumberValue that is more efficient
* because we know the structure of this object. * because we know the structure of this object.
*/ */
double NumberValue() const; double NumberValue() const;
static Date* Cast(v8::Value* obj); static inline Date* Cast(v8::Value* obj);
private:
static void CheckCast(v8::Value* obj);
}; };
enum PropertyAttribute { enum PropertyAttribute {
None = 0, None = 0,
ReadOnly = 1 << 0, ReadOnly = 1 << 0,
DontEnum = 1 << 1, DontEnum = 1 << 1,
DontDelete = 1 << 2 DontDelete = 1 << 2
}; };
/** /**
skipping to change at line 1080 skipping to change at line 1151
Local<Array> GetPropertyNames(); Local<Array> GetPropertyNames();
/** /**
* Get the prototype object. This does not skip objects marked to * Get the prototype object. This does not skip objects marked to
* be skipped by __proto__ and it does not consult the security * be skipped by __proto__ and it does not consult the security
* handler. * handler.
*/ */
Local<Value> GetPrototype(); Local<Value> GetPrototype();
/** /**
* Finds an instance of the given function template in the prototype
* chain.
*/
Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl)
;
/**
* Call builtin Object.prototype.toString on this object. * Call builtin Object.prototype.toString on this object.
* This is different from Value::ToString() that may call * This is different from Value::ToString() that may call
* user-defined toString function. This one does not. * user-defined toString function. This one does not.
*/ */
Local<String> ObjectProtoToString(); Local<String> ObjectProtoToString();
/** Gets the number of internal fields for this Object. */ /** Gets the number of internal fields for this Object. */
int InternalFieldCount(); int InternalFieldCount();
/** Gets the value in an internal field. */ /** Gets the value in an internal field. */
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. */
void SetInternalField(int index, Handle<Value> value); void SetInternalField(int index, Handle<Value> value);
// The two functions below do not perform index bounds checks and
// they do not check that the VM is still running. Use with caution.
/** Gets a native pointer from an internal field. */ /** Gets a native pointer from an internal field. */
void* GetPointerFromInternalField(int index); inline void* GetPointerFromInternalField(int index);
/** Sets a native pointer in an internal field. */ /** Sets a native pointer in an internal field. */
void SetPointerInInternalField(int index, void* value); void SetPointerInInternalField(int index, void* value);
// Testers for local properties. // Testers for local properties.
bool HasRealNamedProperty(Handle<String> key); bool HasRealNamedProperty(Handle<String> key);
bool HasRealIndexedProperty(uint32_t index); bool HasRealIndexedProperty(uint32_t index);
bool HasRealNamedCallbackProperty(Handle<String> key); 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.
skipping to change at line 1159 skipping to change at line 1235
/** /**
* Set the backing store of the indexed properties to be managed by the * Set the backing store of the indexed properties to be managed by the
* embedding layer. Access to the indexed properties will follow the rule s * embedding layer. Access to the indexed properties will follow the rule s
* spelled out in CanvasPixelArray. * spelled out in CanvasPixelArray.
* Note: The embedding program still owns the data and needs to ensure th at * Note: The embedding program still owns the data and needs to ensure th at
* the backing store is preserved while V8 has a reference. * the backing store is preserved while V8 has a reference.
*/ */
void SetIndexedPropertiesToPixelData(uint8_t* data, int length); void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
static Local<Object> New(); static Local<Object> New();
static Object* Cast(Value* obj); static inline Object* Cast(Value* obj);
private: private:
Object(); Object();
static void CheckCast(Value* obj);
Local<Value> CheckedGetInternalField(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 V8EXPORT Array : public Object { class V8EXPORT Array : public Object {
public: public:
uint32_t Length() const; uint32_t Length() const;
/** /**
* Clones an element at index |index|. Returns an empty * Clones an element at index |index|. Returns an empty
* handle if cloning fails (for any reason). * handle if cloning fails (for any reason).
*/ */
Local<Object> CloneElementAt(uint32_t index); Local<Object> CloneElementAt(uint32_t index);
static Local<Array> New(int length = 0); static Local<Array> New(int length = 0);
static Array* Cast(Value* obj); static inline Array* Cast(Value* obj);
private: private:
Array(); Array();
static void CheckCast(Value* obj);
}; };
/** /**
* A JavaScript function object (ECMA-262, 15.3). * A JavaScript function object (ECMA-262, 15.3).
*/ */
class V8EXPORT Function : public Object { class V8EXPORT Function : public Object {
public: public:
Local<Object> NewInstance() const; Local<Object> NewInstance() const;
Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
void SetName(Handle<String> name); void SetName(Handle<String> name);
Handle<Value> GetName() const; Handle<Value> GetName() const;
static Function* Cast(Value* obj); static inline Function* Cast(Value* obj);
private: private:
Function(); Function();
static void CheckCast(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 used to associate C++ data structures with JavaScript * mainly used to associate C++ data structures with JavaScript
* objects. * objects.
* *
* The Wrap function V8 will return the most optimal Value object wrapping the * 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 * 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 * 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 * value Unwrap should be used, all other operations on that object will le ad
* to unpredictable results. * to unpredictable results.
*/ */
class V8EXPORT External : public Value { class V8EXPORT External : public Value {
public: public:
static Local<Value> Wrap(void* data); static Local<Value> Wrap(void* data);
static void* Unwrap(Handle<Value> obj); static inline void* Unwrap(Handle<Value> obj);
static Local<External> New(void* value); static Local<External> New(void* value);
static External* Cast(Value* obj); static inline External* Cast(Value* obj);
void* Value() const; void* Value() const;
private: private:
External(); External();
static void CheckCast(v8::Value* obj);
static inline void* QuickUnwrap(Handle<v8::Value> obj);
static void* FullUnwrap(Handle<v8::Value> obj);
}; };
// --- T e m p l a t e s --- // --- T e m p l a t e s ---
/** /**
* 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 1907 skipping to change at line 1996
// --- C o n t e x t G e n e r a t o r --- // --- C o n t e x t G e n e r a t o r ---
/** /**
* Applications must provide a callback function which is called to generat e * Applications must provide a callback function which is called to generat e
* a context if a context was not deserialized from the snapshot. * a context if a context was not deserialized from the snapshot.
*/ */
typedef Persistent<Context> (*ContextGenerator)(); typedef Persistent<Context> (*ContextGenerator)();
/** /**
* Profiler modules.
*
* In V8, profiler consists of several modules: CPU profiler, and different
* kinds of heap profiling. Each can be turned on / off independently.
* When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx,
* modules are enabled only temporarily for making a snapshot of the heap.
*/
enum ProfilerModules {
PROFILER_MODULE_NONE = 0,
PROFILER_MODULE_CPU = 1,
PROFILER_MODULE_HEAP_STATS = 1 << 1,
PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2,
PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16
};
/**
* Container class for static utility functions. * Container class for static utility functions.
*/ */
class V8EXPORT V8 { class V8EXPORT V8 {
public: public:
/** Set the callback to invoke in case of fatal errors. */ /** Set the callback to invoke in case of fatal errors. */
static void SetFatalErrorHandler(FatalErrorCallback that); static void SetFatalErrorHandler(FatalErrorCallback that);
/** /**
* Ignore out-of-memory exceptions. * Ignore out-of-memory exceptions.
* *
skipping to change at line 2060 skipping to change at line 2165
* See also PauseProfiler(). * See also PauseProfiler().
*/ */
static void ResumeProfiler(); static void ResumeProfiler();
/** /**
* Return whether profiler is currently paused. * Return whether profiler is currently paused.
*/ */
static bool IsProfilerPaused(); static bool IsProfilerPaused();
/** /**
* Resumes specified profiler modules.
* "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CP
U)".
* See ProfilerModules enum.
*
* \param flags Flags specifying profiler modules.
*/
static void ResumeProfilerEx(int flags);
/**
* Pauses specified profiler modules.
* "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)
".
* See ProfilerModules enum.
*
* \param flags Flags specifying profiler modules.
*/
static void PauseProfilerEx(int flags);
/**
* Returns active (resumed) profiler modules.
* See ProfilerModules enum.
*
* \returns active profiler modules.
*/
static int GetActiveProfilerModules();
/**
* If logging is performed into a memory buffer (via --logfile=*), allows to * If logging is performed into a memory buffer (via --logfile=*), allows to
* retrieve previously written messages. This can be used for retrieving * retrieve previously written messages. This can be used for retrieving
* profiler log data in the application. This function is thread-safe. * profiler log data in the application. This function is thread-safe.
* *
* Caller provides a destination buffer that must exist during GetLogLine s * Caller provides a destination buffer that must exist during GetLogLine s
* call. Only whole log lines are copied into the buffer. * call. Only whole log lines are copied into the buffer.
* *
* \param from_pos specified a point in a buffer to read from, 0 is the * \param from_pos specified a point in a buffer to read from, 0 is the
* beginning of a buffer. It is assumed that caller updates its current * beginning of a buffer. It is assumed that caller updates its current
* position using returned size value from the previous call. * position using returned size value from the previous call.
* \param dest_buf destination buffer for log data. * \param dest_buf destination buffer for log data.
* \param max_size size of the destination buffer. * \param max_size size of the destination buffer.
* \returns actual size of log data copied into buffer. * \returns actual size of log data copied into buffer.
*/ */
static int GetLogLines(int from_pos, char* dest_buf, int max_size); static int GetLogLines(int from_pos, char* dest_buf, int max_size);
/** /**
* Retrieve the V8 thread id of the calling thread.
*
* The thread id for a thread should only be retrieved after the V8
* lock has been acquired with a Locker object with that thread.
*/
static int GetCurrentThreadId();
/**
* Forcefully terminate execution of a JavaScript thread. This can
* be used to terminate long-running scripts.
*
* TerminateExecution should only be called when then V8 lock has
* been acquired with a Locker object. Therefore, in order to be
* able to terminate long-running threads, preemption must be
* enabled to allow the user of TerminateExecution to acquire the
* lock.
*
* The termination is achieved by throwing an exception that is
* uncatchable by JavaScript exception handlers. Termination
* exceptions act as if they were caught by a C++ TryCatch exception
* handlers. If forceful termination is used, any C++ TryCatch
* exception handler that catches an exception should check if that
* exception is a termination exception and immediately return if
* that is the case. Returning immediately in that case will
* continue the propagation of the termination exception if needed.
*
* The thread id passed to TerminateExecution must have been
* obtained by calling GetCurrentThreadId on the thread in question.
*
* \param thread_id The thread id of the thread to terminate.
*/
static void TerminateExecution(int thread_id);
/**
* Forcefully terminate the current thread of JavaScript execution.
*
* This method can be used by any thread even if that thread has not
* acquired the V8 lock with a Locker object.
*/
static void TerminateExecution();
/**
* Releases any resources used by v8 and stops any utility threads * Releases any resources used by v8 and stops any utility threads
* that may be running. Note that disposing v8 is permanent, it * that may be running. Note that disposing v8 is permanent, it
* cannot be reinitialized. * cannot be reinitialized.
* *
* It should generally not be necessary to dispose v8 before exiting * It should generally not be necessary to dispose v8 before exiting
* a process, this should happen automatically. It is only necessary * a process, this should happen automatically. It is only necessary
* to use if the process needs the resources taken up by v8. * to use if the process needs the resources taken up by v8.
*/ */
static bool Dispose(); static bool Dispose();
/**
* Optional notification that the embedder is idle.
* V8 uses the notification to reduce memory footprint.
* This call can be used repeatedly if the embedder remains idle.
* \param is_high_priority tells whether the embedder is high priority.
* Returns true if the embedder should stop calling IdleNotification
* until real work has been done. This indicates that V8 has done
* as much cleanup as it will be able to do.
*/
static bool IdleNotification(bool is_high_priority);
/**
* Optional notification that the system is running low on memory.
* V8 uses these notifications to attempt to free memory.
*/
static void LowMemoryNotification();
private: private:
V8(); V8();
static void** GlobalizeReference(void** handle); static internal::Object** GlobalizeReference(internal::Object** handle);
static void DisposeGlobal(void** global_handle); static void DisposeGlobal(internal::Object** global_handle);
static void MakeWeak(void** global_handle, void* data, WeakReferenceCallb static void MakeWeak(internal::Object** global_handle,
ack); void* data,
static void ClearWeak(void** global_handle); WeakReferenceCallback);
static bool IsGlobalNearDeath(void** global_handle); static void ClearWeak(internal::Object** global_handle);
static bool IsGlobalWeak(void** global_handle); static bool IsGlobalNearDeath(internal::Object** global_handle);
static bool IsGlobalWeak(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;
}; };
/** /**
* An external exception handler. * An external exception handler.
*/ */
skipping to change at line 2125 skipping to change at line 2317
* Unregisters and deletes this try/catch block. * Unregisters and deletes this try/catch block.
*/ */
~TryCatch(); ~TryCatch();
/** /**
* Returns true if an exception has been caught by this try/catch block. * Returns true if an exception has been caught by this try/catch block.
*/ */
bool HasCaught() const; bool HasCaught() const;
/** /**
* For certain types of exceptions, it makes no sense to continue
* execution.
*
* Currently, the only type of exception that can be caught by a
* TryCatch handler and for which it does not make sense to continue
* is termination exception. Such exceptions are thrown when the
* TerminateExecution methods are called to terminate a long-running
* script.
*
* If CanContinue returns false, the correct action is to perform
* any C++ cleanup needed and then return.
*/
bool CanContinue() const;
/**
* Returns the exception caught by this try/catch block. If no exception has * Returns the exception caught by this try/catch block. If no exception has
* been caught an empty handle is returned. * been caught an empty handle is returned.
* *
* The returned handle is valid until this TryCatch block has been destro yed. * The returned handle is valid until this TryCatch block has been destro yed.
*/ */
Local<Value> Exception() const; Local<Value> Exception() const;
/** /**
* Returns the .stack property of the thrown object. If no .stack
* property is present an empty handle is returned.
*/
Local<Value> StackTrace() const;
/**
* Returns the message associated with this exception. If there is * Returns the message associated with this exception. If there is
* no message associated an empty handle is returned. * no message associated an empty handle is returned.
* *
* The returned handle is valid until this TryCatch block has been * The returned handle is valid until this TryCatch block has been
* destroyed. * destroyed.
*/ */
Local<v8::Message> Message() const; Local<v8::Message> Message() const;
/** /**
* Clears any exceptions that may have been caught by this try/catch bloc k. * Clears any exceptions that may have been caught by this try/catch bloc k.
skipping to change at line 2174 skipping to change at line 2387
* which holds source information about where the exception * which holds source information about where the exception
* occurred. True by default. * occurred. True by default.
*/ */
void SetCaptureMessage(bool value); void SetCaptureMessage(bool value);
public: public:
TryCatch* next_; TryCatch* next_;
void* exception_; void* exception_;
void* message_; void* message_;
bool is_verbose_; bool is_verbose_;
bool can_continue_;
bool capture_message_; bool capture_message_;
void* js_handler_; void* js_handler_;
}; };
// --- C o n t e x t --- // --- C o n t e x t ---
/** /**
* Ignore * Ignore
*/ */
class V8EXPORT ExtensionConfiguration { class V8EXPORT ExtensionConfiguration {
skipping to change at line 2404 skipping to change at line 2618
static bool active_; static bool active_;
// Disallow copying and assigning. // Disallow copying and assigning.
Locker(const Locker&); Locker(const Locker&);
void operator=(const Locker&); void operator=(const Locker&);
}; };
// --- I m p l e m e n t a t i o n --- // --- I m p l e m e n t a t i o n ---
namespace internal {
// Tag information for HeapObject.
const int kHeapObjectTag = 1;
const int kHeapObjectTagSize = 2;
const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
// Tag information for Smi.
const int kSmiTag = 0;
const int kSmiTagSize = 1;
const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
/**
* This class exports constants and functionality from within v8 that
* is necessary to implement inline functions in the v8 api. Don't
* depend on functions and constants defined here.
*/
class Internals {
public:
// These values match non-compiler-dependent values defined within
// the implementation of v8.
static const int kHeapObjectMapOffset = 0;
static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int);
static const int kStringResourceOffset = 2 * sizeof(void*);
static const int kProxyProxyOffset = sizeof(void*);
static const int kJSObjectHeaderSize = 3 * sizeof(void*);
static const int kFullStringRepresentationMask = 0x07;
static const int kExternalTwoByteRepresentationTag = 0x03;
static const int kAlignedPointerShift = 2;
// These constants are compiler dependent so their values must be
// defined within the implementation.
static int kJSObjectType;
static int kFirstNonstringType;
static int kProxyType;
static inline bool HasHeapObjectTag(internal::Object* value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
kHeapObjectTag);
}
static inline bool HasSmiTag(internal::Object* value) {
return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
}
static inline int SmiValue(internal::Object* value) {
return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> kSmiTagSi
ze;
}
static inline bool IsExternalTwoByteString(int instance_type) {
int representation = (instance_type & kFullStringRepresentationMask);
return representation == kExternalTwoByteRepresentationTag;
}
template <typename T>
static inline T ReadField(Object* ptr, int offset) {
uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectT
ag;
return *reinterpret_cast<T*>(addr);
}
};
}
template <class T> template <class T>
Handle<T>::Handle() : val_(0) { } Handle<T>::Handle() : val_(0) { }
template <class T> template <class T>
Local<T>::Local() : Handle<T>() { } Local<T>::Local() : Handle<T>() { }
template <class T> template <class T>
Local<T> Local<T>::New(Handle<T> that) { Local<T> Local<T>::New(Handle<T> that) {
if (that.IsEmpty()) return Local<T>(); if (that.IsEmpty()) return Local<T>();
void** p = reinterpret_cast<void**>(*that); internal::Object** p = reinterpret_cast<internal::Object**>(*that);
return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
} }
template <class T> template <class T>
Persistent<T> Persistent<T>::New(Handle<T> that) { Persistent<T> Persistent<T>::New(Handle<T> that) {
if (that.IsEmpty()) return Persistent<T>(); if (that.IsEmpty()) return Persistent<T>();
void** p = reinterpret_cast<void**>(*that); internal::Object** p = reinterpret_cast<internal::Object**>(*that);
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>::IsNearDeath() const { bool Persistent<T>::IsNearDeath() const {
if (this->IsEmpty()) return false; if (this->IsEmpty()) return false;
return V8::IsGlobalNearDeath(reinterpret_cast<void**>(**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<void**>(**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<void**>(**this)); V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
} }
template <class T> 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<void**>(**this), parameters, callback); V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
parameters,
callback);
} }
template <class T> template <class T>
void Persistent<T>::ClearWeak() { void Persistent<T>::ClearWeak() {
V8::ClearWeak(reinterpret_cast<void**>(**this)); V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
} }
Local<Value> Arguments::operator[](int i) const { Local<Value> Arguments::operator[](int i) const {
if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
return Local<Value>(reinterpret_cast<Value*>(values_ - i)); return Local<Value>(reinterpret_cast<Value*>(values_ - i));
} }
Local<Function> Arguments::Callee() const { Local<Function> Arguments::Callee() const {
return callee_; return callee_;
} }
skipping to change at line 2498 skipping to change at line 2779
Local<Object> AccessorInfo::This() const { Local<Object> AccessorInfo::This() const {
return self_; return self_;
} }
Local<Object> AccessorInfo::Holder() const { Local<Object> AccessorInfo::Holder() const {
return holder_; return holder_;
} }
template <class T> template <class T>
Local<T> HandleScope::Close(Handle<T> value) { Local<T> HandleScope::Close(Handle<T> value) {
void** after = RawClose(reinterpret_cast<void**>(*value)); internal::Object** before = reinterpret_cast<internal::Object**>(*value);
internal::Object** after = RawClose(before);
return Local<T>(reinterpret_cast<T*>(after)); return Local<T>(reinterpret_cast<T*>(after));
} }
Handle<Value> ScriptOrigin::ResourceName() const { Handle<Value> ScriptOrigin::ResourceName() const {
return resource_name_; return resource_name_;
} }
Handle<Integer> ScriptOrigin::ResourceLineOffset() const { Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
return resource_line_offset_; return resource_line_offset_;
} }
skipping to change at line 2522 skipping to change at line 2804
} }
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) {
#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::Internals I;
O* obj = *reinterpret_cast<O**>(this);
O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset);
int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset)
;
if (instance_type == 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 + (sizeof(void*) * index);
O* value = I::ReadField<O*>(obj, offset);
O** result = HandleScope::CreateHandle(value);
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
}
void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
typedef internal::Object O;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
if (I::HasSmiTag(obj)) {
int value = I::SmiValue(obj) << I::kAlignedPointerShift;
return reinterpret_cast<void*>(value);
} else {
O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset);
int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffse
t);
if (instance_type == I::kProxyType) {
return I::ReadField<void*>(obj, I::kProxyProxyOffset);
} else {
return NULL;
}
}
}
void* Object::GetPointerFromInternalField(int index) {
return External::Unwrap(GetInternalField(index));
}
String* String::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<String*>(value);
}
String::ExternalStringResource* String::GetExternalStringResource() const {
typedef internal::Object O;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset);
int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset)
;
String::ExternalStringResource* result;
if (I::IsExternalTwoByteString(instance_type)) {
void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
result = reinterpret_cast<String::ExternalStringResource*>(value);
} else {
result = NULL;
}
#ifdef V8_ENABLE_CHECKS
VerifyExternalStringResource(result);
#endif
return result;
}
bool Value::IsString() const {
#ifdef V8_ENABLE_CHECKS
return FullIsString();
#else
return QuickIsString();
#endif
}
bool Value::QuickIsString() const {
typedef internal::Object O;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
if (!I::HasHeapObjectTag(obj)) return false;
O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset);
int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset)
;
return (instance_type < I::kFirstNonstringType);
}
Number* Number::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Number*>(value);
}
Integer* Integer::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Integer*>(value);
}
Date* Date::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Date*>(value);
}
Object* Object::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Object*>(value);
}
Array* Array::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Array*>(value);
}
Function* Function::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<Function*>(value);
}
External* External::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
#endif
return static_cast<External*>(value);
}
/** /**
* \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. 71 change blocks. 
60 lines changed or deleted 498 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/