| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 * dereferencing the handle (for instance, to extract the Object* from | 164 * dereferencing the handle (for instance, to extract the Object* from |
| 165 * a Handle<Object>); the value will still be governed by a handle | 165 * a Handle<Object>); the value will still be governed by a handle |
| 166 * behind the scenes and the same rules apply to these values as to | 166 * behind the scenes and the same rules apply to these values as to |
| 167 * their handles. | 167 * their handles. |
| 168 */ | 168 */ |
| 169 template <class T> class Handle { | 169 template <class T> class Handle { |
| 170 public: | 170 public: |
| 171 /** | 171 /** |
| 172 * Creates an empty handle. | 172 * Creates an empty handle. |
| 173 */ | 173 */ |
| 174 inline Handle(); | 174 inline Handle() : val_(0) {} |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * Creates a new handle for the specified value. | 177 * Creates a new handle for the specified value. |
| 178 */ | 178 */ |
| 179 inline explicit Handle(T* val) : val_(val) { } | 179 inline explicit Handle(T* val) : val_(val) {} |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * Creates a handle for the contents of the specified handle. This | 182 * Creates a handle for the contents of the specified handle. This |
| 183 * constructor allows you to pass handles as arguments by value and | 183 * constructor allows you to pass handles as arguments by value and |
| 184 * to assign between handles. However, if you try to assign between | 184 * to assign between handles. However, if you try to assign between |
| 185 * incompatible handles, for instance from a Handle<String> to a | 185 * incompatible handles, for instance from a Handle<String> to a |
| 186 * Handle<Number> it will cause a compile-time error. Assigning | 186 * Handle<Number> it will cause a compile-time error. Assigning |
| 187 * between compatible handles, for instance assigning a | 187 * between compatible handles, for instance assigning a |
| 188 * Handle<String> to a variable declared as Handle<Value>, is legal | 188 * Handle<String> to a variable declared as Handle<Value>, is legal |
| 189 * because String is a subclass of Value. | 189 * because String is a subclass of Value. |
| 190 */ | 190 */ |
| 191 template <class S> inline Handle(Handle<S> that) | 191 template <class S> inline Handle(Handle<S> that) |
| 192 : val_(reinterpret_cast<T*>(*that)) { | 192 : val_(reinterpret_cast<T*>(*that)) { |
| 193 /** | 193 /** |
| 194 * This check fails when trying to convert between incompatible | 194 * This check fails when trying to convert between incompatible |
| 195 * handles. For example, converting from a Handle<String> to a | 195 * handles. For example, converting from a Handle<String> to a |
| 196 * Handle<Number>. | 196 * Handle<Number>. |
| 197 */ | 197 */ |
| 198 TYPE_CHECK(T, S); | 198 TYPE_CHECK(T, S); |
| 199 } | 199 } |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * Returns true if the handle is empty. | 202 * Returns true if the handle is empty. |
| 203 */ | 203 */ |
| 204 inline bool IsEmpty() const { return val_ == 0; } | 204 inline bool IsEmpty() const { return val_ == 0; } |
| 205 | 205 |
| 206 /** |
| 207 * Sets the handle to be empty. IsEmpty() will then return true. |
| 208 */ |
| 209 inline void Clear() { val_ = 0; } |
| 210 |
| 206 inline T* operator->() const { return val_; } | 211 inline T* operator->() const { return val_; } |
| 207 | 212 |
| 208 inline T* operator*() const { return val_; } | 213 inline T* operator*() const { return val_; } |
| 209 | 214 |
| 210 /** | 215 /** |
| 211 * Sets the handle to be empty. IsEmpty() will then return true. | |
| 212 */ | |
| 213 inline void Clear() { this->val_ = 0; } | |
| 214 | |
| 215 /** | |
| 216 * Checks whether two handles are the same. | 216 * Checks whether two handles are the same. |
| 217 * Returns true if both are empty, or if the objects | 217 * Returns true if both are empty, or if the objects |
| 218 * to which they refer are identical. | 218 * to which they refer are identical. |
| 219 * The handles' references are not checked. | 219 * The handles' references are not checked. |
| 220 */ | 220 */ |
| 221 template <class S> inline bool operator==(Handle<S> that) const { | 221 template <class S> inline bool operator==(Handle<S> that) const { |
| 222 internal::Object** a = reinterpret_cast<internal::Object**>(**this); | 222 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 223 internal::Object** b = reinterpret_cast<internal::Object**>(*that); | 223 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 224 if (a == 0) return b == 0; | 224 if (a == 0) return b == 0; |
| 225 if (b == 0) return false; | 225 if (b == 0) return false; |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 * | 1032 * |
| 1033 * Copies up to length characters into the output buffer. | 1033 * Copies up to length characters into the output buffer. |
| 1034 * Only null-terminates if there is enough space in the buffer. | 1034 * Only null-terminates if there is enough space in the buffer. |
| 1035 * | 1035 * |
| 1036 * \param buffer The buffer into which the string will be copied. | 1036 * \param buffer The buffer into which the string will be copied. |
| 1037 * \param start The starting position within the string at which | 1037 * \param start The starting position within the string at which |
| 1038 * copying begins. | 1038 * copying begins. |
| 1039 * \param length The number of characters to copy from the string. For | 1039 * \param length The number of characters to copy from the string. For |
| 1040 * WriteUtf8 the number of bytes in the buffer. | 1040 * WriteUtf8 the number of bytes in the buffer. |
| 1041 * \param nchars_ref The number of characters written, can be NULL. | 1041 * \param nchars_ref The number of characters written, can be NULL. |
| 1042 * \param hints Various hints that might affect performance of this or | 1042 * \param options Various options that might affect performance of this or |
| 1043 * subsequent operations. | 1043 * subsequent operations. |
| 1044 * \return The number of characters copied to the buffer excluding the null | 1044 * \return The number of characters copied to the buffer excluding the null |
| 1045 * terminator. For WriteUtf8: The number of bytes copied to the buffer | 1045 * terminator. For WriteUtf8: The number of bytes copied to the buffer |
| 1046 * including the null terminator. | 1046 * including the null terminator (if written). |
| 1047 */ | 1047 */ |
| 1048 enum WriteHints { | 1048 enum WriteOptions { |
| 1049 NO_HINTS = 0, | 1049 NO_OPTIONS = 0, |
| 1050 HINT_MANY_WRITES_EXPECTED = 1 | 1050 HINT_MANY_WRITES_EXPECTED = 1, |
| 1051 NO_NULL_TERMINATION = 2 |
| 1051 }; | 1052 }; |
| 1052 | 1053 |
| 1053 V8EXPORT int Write(uint16_t* buffer, | 1054 V8EXPORT int Write(uint16_t* buffer, |
| 1054 int start = 0, | 1055 int start = 0, |
| 1055 int length = -1, | 1056 int length = -1, |
| 1056 WriteHints hints = NO_HINTS) const; // UTF-16 | 1057 int options = NO_OPTIONS) const; // UTF-16 |
| 1057 V8EXPORT int WriteAscii(char* buffer, | 1058 V8EXPORT int WriteAscii(char* buffer, |
| 1058 int start = 0, | 1059 int start = 0, |
| 1059 int length = -1, | 1060 int length = -1, |
| 1060 WriteHints hints = NO_HINTS) const; // ASCII | 1061 int options = NO_OPTIONS) const; // ASCII |
| 1061 V8EXPORT int WriteUtf8(char* buffer, | 1062 V8EXPORT int WriteUtf8(char* buffer, |
| 1062 int length = -1, | 1063 int length = -1, |
| 1063 int* nchars_ref = NULL, | 1064 int* nchars_ref = NULL, |
| 1064 WriteHints hints = NO_HINTS) const; // UTF-8 | 1065 int options = NO_OPTIONS) const; // UTF-8 |
| 1065 | 1066 |
| 1066 /** | 1067 /** |
| 1067 * A zero length string. | 1068 * A zero length string. |
| 1068 */ | 1069 */ |
| 1069 V8EXPORT static v8::Local<v8::String> Empty(); | 1070 V8EXPORT static v8::Local<v8::String> Empty(); |
| 1070 | 1071 |
| 1071 /** | 1072 /** |
| 1072 * Returns true if the string is external | 1073 * Returns true if the string is external |
| 1073 */ | 1074 */ |
| 1074 V8EXPORT bool IsExternal() const; | 1075 V8EXPORT bool IsExternal() const; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 /** | 1329 /** |
| 1329 * A JavaScript number value (ECMA-262, 4.3.20) | 1330 * A JavaScript number value (ECMA-262, 4.3.20) |
| 1330 */ | 1331 */ |
| 1331 class Number : public Primitive { | 1332 class Number : public Primitive { |
| 1332 public: | 1333 public: |
| 1333 V8EXPORT double Value() const; | 1334 V8EXPORT double Value() const; |
| 1334 V8EXPORT static Local<Number> New(double value); | 1335 V8EXPORT static Local<Number> New(double value); |
| 1335 static inline Number* Cast(v8::Value* obj); | 1336 static inline Number* Cast(v8::Value* obj); |
| 1336 private: | 1337 private: |
| 1337 V8EXPORT Number(); | 1338 V8EXPORT Number(); |
| 1338 static void CheckCast(v8::Value* obj); | 1339 V8EXPORT static void CheckCast(v8::Value* obj); |
| 1339 }; | 1340 }; |
| 1340 | 1341 |
| 1341 | 1342 |
| 1342 /** | 1343 /** |
| 1343 * A JavaScript value representing a signed integer. | 1344 * A JavaScript value representing a signed integer. |
| 1344 */ | 1345 */ |
| 1345 class Integer : public Number { | 1346 class Integer : public Number { |
| 1346 public: | 1347 public: |
| 1347 V8EXPORT static Local<Integer> New(int32_t value); | 1348 V8EXPORT static Local<Integer> New(int32_t value); |
| 1348 V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value); | 1349 V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 | 1703 |
| 1703 /** | 1704 /** |
| 1704 * Creates a JavaScript array with the given length. If the length | 1705 * Creates a JavaScript array with the given length. If the length |
| 1705 * is negative the returned array will have length 0. | 1706 * is negative the returned array will have length 0. |
| 1706 */ | 1707 */ |
| 1707 V8EXPORT static Local<Array> New(int length = 0); | 1708 V8EXPORT static Local<Array> New(int length = 0); |
| 1708 | 1709 |
| 1709 static inline Array* Cast(Value* obj); | 1710 static inline Array* Cast(Value* obj); |
| 1710 private: | 1711 private: |
| 1711 V8EXPORT Array(); | 1712 V8EXPORT Array(); |
| 1712 static void CheckCast(Value* obj); | 1713 V8EXPORT static void CheckCast(Value* obj); |
| 1713 }; | 1714 }; |
| 1714 | 1715 |
| 1715 | 1716 |
| 1716 /** | 1717 /** |
| 1717 * A JavaScript function object (ECMA-262, 15.3). | 1718 * A JavaScript function object (ECMA-262, 15.3). |
| 1718 */ | 1719 */ |
| 1719 class Function : public Object { | 1720 class Function : public Object { |
| 1720 public: | 1721 public: |
| 1721 V8EXPORT Local<Object> NewInstance() const; | 1722 V8EXPORT Local<Object> NewInstance() const; |
| 1722 V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; | 1723 V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| (...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3820 static inline bool CanCastToHeapObject(Object* o) { return true; } | 3821 static inline bool CanCastToHeapObject(Object* o) { return true; } |
| 3821 static inline bool CanCastToHeapObject(Message* o) { return true; } | 3822 static inline bool CanCastToHeapObject(Message* o) { return true; } |
| 3822 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } | 3823 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } |
| 3823 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } | 3824 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } |
| 3824 }; | 3825 }; |
| 3825 | 3826 |
| 3826 } // namespace internal | 3827 } // namespace internal |
| 3827 | 3828 |
| 3828 | 3829 |
| 3829 template <class T> | 3830 template <class T> |
| 3830 Handle<T>::Handle() : val_(0) { } | |
| 3831 | |
| 3832 | |
| 3833 template <class T> | |
| 3834 Local<T>::Local() : Handle<T>() { } | 3831 Local<T>::Local() : Handle<T>() { } |
| 3835 | 3832 |
| 3836 | 3833 |
| 3837 template <class T> | 3834 template <class T> |
| 3838 Local<T> Local<T>::New(Handle<T> that) { | 3835 Local<T> Local<T>::New(Handle<T> that) { |
| 3839 if (that.IsEmpty()) return Local<T>(); | 3836 if (that.IsEmpty()) return Local<T>(); |
| 3840 T* that_ptr = *that; | 3837 T* that_ptr = *that; |
| 3841 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | 3838 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); |
| 3842 if (internal::Internals::CanCastToHeapObject(that_ptr)) { | 3839 if (internal::Internals::CanCastToHeapObject(that_ptr)) { |
| 3843 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | 3840 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4201 | 4198 |
| 4202 | 4199 |
| 4203 } // namespace v8 | 4200 } // namespace v8 |
| 4204 | 4201 |
| 4205 | 4202 |
| 4206 #undef V8EXPORT | 4203 #undef V8EXPORT |
| 4207 #undef TYPE_CHECK | 4204 #undef TYPE_CHECK |
| 4208 | 4205 |
| 4209 | 4206 |
| 4210 #endif // V8_H_ | 4207 #endif // V8_H_ |
| OLD | NEW |