Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 class Date; | 120 class Date; |
| 121 class ImplementationUtilities; | 121 class ImplementationUtilities; |
| 122 class Signature; | 122 class Signature; |
| 123 template <class T> class Handle; | 123 template <class T> class Handle; |
| 124 template <class T> class Local; | 124 template <class T> class Local; |
| 125 template <class T> class Persistent; | 125 template <class T> class Persistent; |
| 126 class FunctionTemplate; | 126 class FunctionTemplate; |
| 127 class ObjectTemplate; | 127 class ObjectTemplate; |
| 128 class Data; | 128 class Data; |
| 129 | 129 |
| 130 namespace internal { | |
| 131 | |
| 132 class Object; | |
| 133 | |
| 134 } | |
| 135 | |
| 130 | 136 |
| 131 // --- W e a k H a n d l e s | 137 // --- W e a k H a n d l e s |
| 132 | 138 |
| 133 | 139 |
| 134 /** | 140 /** |
| 135 * A weak reference callback function. | 141 * A weak reference callback function. |
| 136 * | 142 * |
| 137 * \param object the weak global object to be reclaimed by the garbage collector | 143 * \param object the weak global object to be reclaimed by the garbage collector |
| 138 * \param parameter the value passed in when making the weak global object | 144 * \param parameter the value passed in when making the weak global object |
| 139 */ | 145 */ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 */ | 226 */ |
| 221 void Clear() { this->val_ = 0; } | 227 void Clear() { this->val_ = 0; } |
| 222 | 228 |
| 223 /** | 229 /** |
| 224 * Checks whether two handles are the same. | 230 * Checks whether two handles are the same. |
| 225 * Returns true if both are empty, or if the objects | 231 * Returns true if both are empty, or if the objects |
| 226 * to which they refer are identical. | 232 * to which they refer are identical. |
| 227 * The handles' references are not checked. | 233 * The handles' references are not checked. |
| 228 */ | 234 */ |
| 229 template <class S> bool operator==(Handle<S> that) const { | 235 template <class S> bool operator==(Handle<S> that) const { |
| 230 void** a = reinterpret_cast<void**>(**this); | 236 internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| 231 void** b = reinterpret_cast<void**>(*that); | 237 internal::Object** b = reinterpret_cast<internal::Object**>(*that); |
| 232 if (a == 0) return b == 0; | 238 if (a == 0) return b == 0; |
| 233 if (b == 0) return false; | 239 if (b == 0) return false; |
| 234 return *a == *b; | 240 return *a == *b; |
| 235 } | 241 } |
| 236 | 242 |
| 237 /** | 243 /** |
| 238 * Checks whether two handles are different. | 244 * Checks whether two handles are different. |
| 239 * Returns true if only one of the handles is empty, or if | 245 * Returns true if only one of the handles is empty, or if |
| 240 * the objects to which they refer are different. | 246 * the objects to which they refer are different. |
| 241 * The handles' references are not checked. | 247 * The handles' references are not checked. |
| 242 */ | 248 */ |
| 243 template <class S> bool operator!=(Handle<S> that) const { | 249 template <class S> bool operator!=(Handle<S> that) const { |
| 244 return !operator==(that); | 250 return !operator==(that); |
| 245 } | 251 } |
| 246 | 252 |
| 247 template <class S> static inline Handle<T> Cast(Handle<S> that) { | 253 template <class S> static inline Handle<T> Cast(Handle<S> that) { |
| 254 #ifdef V8_ENABLE_CHECKS | |
| 255 // If we're going to perform the type check then we have to check | |
| 256 // that the handle isn't empty before doing the checked cast. | |
| 248 if (that.IsEmpty()) return Handle<T>(); | 257 if (that.IsEmpty()) return Handle<T>(); |
| 258 #endif | |
| 249 return Handle<T>(T::Cast(*that)); | 259 return Handle<T>(T::Cast(*that)); |
| 250 } | 260 } |
| 251 | 261 |
| 252 private: | 262 private: |
| 253 T* val_; | 263 T* val_; |
| 254 }; | 264 }; |
| 255 | 265 |
| 256 | 266 |
| 257 /** | 267 /** |
| 258 * A light-weight stack-allocated object handle. All operations | 268 * A light-weight stack-allocated object handle. All operations |
| 259 * that return objects from within v8 return them in local handles. They | 269 * that return objects from within v8 return them in local handles. They |
| 260 * are created within HandleScopes, and all local handles allocated within a | 270 * are created within HandleScopes, and all local handles allocated within a |
| 261 * handle scope are destroyed when the handle scope is destroyed. Hence it | 271 * handle scope are destroyed when the handle scope is destroyed. Hence it |
| 262 * is not necessary to explicitly deallocate local handles. | 272 * is not necessary to explicitly deallocate local handles. |
| 263 */ | 273 */ |
| 264 template <class T> class V8EXPORT_INLINE Local : public Handle<T> { | 274 template <class T> class V8EXPORT_INLINE Local : public Handle<T> { |
| 265 public: | 275 public: |
| 266 inline Local(); | 276 inline Local(); |
| 267 template <class S> inline Local(Local<S> that) | 277 template <class S> inline Local(Local<S> that) |
| 268 : Handle<T>(reinterpret_cast<T*>(*that)) { | 278 : Handle<T>(reinterpret_cast<T*>(*that)) { |
| 269 /** | 279 /** |
| 270 * This check fails when trying to convert between incompatible | 280 * This check fails when trying to convert between incompatible |
| 271 * handles. For example, converting from a Handle<String> to a | 281 * handles. For example, converting from a Handle<String> to a |
| 272 * Handle<Number>. | 282 * Handle<Number>. |
| 273 */ | 283 */ |
| 274 TYPE_CHECK(T, S); | 284 TYPE_CHECK(T, S); |
| 275 } | 285 } |
| 276 template <class S> inline Local(S* that) : Handle<T>(that) { } | 286 template <class S> inline Local(S* that) : Handle<T>(that) { } |
| 277 template <class S> static inline Local<T> Cast(Local<S> that) { | 287 template <class S> static inline Local<T> Cast(Local<S> that) { |
| 288 #ifdef V8_ENABLE_CHECKS | |
| 289 // If we're going to perform the type check then we have to check | |
| 290 // that the handle isn't empty before doing the checked cast. | |
| 278 if (that.IsEmpty()) return Local<T>(); | 291 if (that.IsEmpty()) return Local<T>(); |
| 292 #endif | |
| 279 return Local<T>(T::Cast(*that)); | 293 return Local<T>(T::Cast(*that)); |
| 280 } | 294 } |
| 281 | 295 |
| 282 /** Create a local handle for the content of another handle. | 296 /** Create a local handle for the content of another handle. |
| 283 * The referee is kept alive by the local handle even when | 297 * The referee is kept alive by the local handle even when |
| 284 * the original handle is destroyed/disposed. | 298 * the original handle is destroyed/disposed. |
| 285 */ | 299 */ |
| 286 inline static Local<T> New(Handle<T> that); | 300 inline static Local<T> New(Handle<T> that); |
| 287 }; | 301 }; |
| 288 | 302 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 template <class S> inline Persistent(S* that) : Handle<T>(that) { } | 351 template <class S> inline Persistent(S* that) : Handle<T>(that) { } |
| 338 | 352 |
| 339 /** | 353 /** |
| 340 * "Casts" a plain handle which is known to be a persistent handle | 354 * "Casts" a plain handle which is known to be a persistent handle |
| 341 * to a persistent handle. | 355 * to a persistent handle. |
| 342 */ | 356 */ |
| 343 template <class S> explicit inline Persistent(Handle<S> that) | 357 template <class S> explicit inline Persistent(Handle<S> that) |
| 344 : Handle<T>(*that) { } | 358 : Handle<T>(*that) { } |
| 345 | 359 |
| 346 template <class S> static inline Persistent<T> Cast(Persistent<S> that) { | 360 template <class S> static inline Persistent<T> Cast(Persistent<S> that) { |
| 361 #ifdef V8_ENABLE_CHECKS | |
| 362 // If we're going to perform the type check then we have to check | |
| 363 // that the handle isn't empty before doing the checked cast. | |
| 347 if (that.IsEmpty()) return Persistent<T>(); | 364 if (that.IsEmpty()) return Persistent<T>(); |
| 365 #endif | |
| 348 return Persistent<T>(T::Cast(*that)); | 366 return Persistent<T>(T::Cast(*that)); |
| 349 } | 367 } |
| 350 | 368 |
| 351 /** | 369 /** |
| 352 * Creates a new persistent handle for an existing local or | 370 * Creates a new persistent handle for an existing local or |
| 353 * persistent handle. | 371 * persistent handle. |
| 354 */ | 372 */ |
| 355 inline static Persistent<T> New(Handle<T> that); | 373 inline static Persistent<T> New(Handle<T> that); |
| 356 | 374 |
| 357 /** | 375 /** |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 template <class T> Local<T> Close(Handle<T> value); | 434 template <class T> Local<T> Close(Handle<T> value); |
| 417 | 435 |
| 418 /** | 436 /** |
| 419 * Counts the number of allocated handles. | 437 * Counts the number of allocated handles. |
| 420 */ | 438 */ |
| 421 static int NumberOfHandles(); | 439 static int NumberOfHandles(); |
| 422 | 440 |
| 423 /** | 441 /** |
| 424 * Creates a new handle with the given value. | 442 * Creates a new handle with the given value. |
| 425 */ | 443 */ |
| 426 static void** CreateHandle(void* value); | 444 static internal::Object** CreateHandle(internal::Object* value); |
| 427 | 445 |
| 428 private: | 446 private: |
| 429 // Make it impossible to create heap-allocated or illegal handle | 447 // Make it impossible to create heap-allocated or illegal handle |
| 430 // scopes by disallowing certain operations. | 448 // scopes by disallowing certain operations. |
| 431 HandleScope(const HandleScope&); | 449 HandleScope(const HandleScope&); |
| 432 void operator=(const HandleScope&); | 450 void operator=(const HandleScope&); |
| 433 void* operator new(size_t size); | 451 void* operator new(size_t size); |
| 434 void operator delete(void*, size_t); | 452 void operator delete(void*, size_t); |
| 435 | 453 |
| 436 // This Data class is accessible internally through a typedef in the | 454 // This Data class is accessible internally through a typedef in the |
| 437 // ImplementationUtilities class. | 455 // ImplementationUtilities class. |
| 438 class V8EXPORT Data { | 456 class V8EXPORT Data { |
| 439 public: | 457 public: |
| 440 int extensions; | 458 int extensions; |
| 441 void** next; | 459 internal::Object** next; |
| 442 void** limit; | 460 internal::Object** limit; |
| 443 inline void Initialize() { | 461 inline void Initialize() { |
| 444 extensions = -1; | 462 extensions = -1; |
| 445 next = limit = NULL; | 463 next = limit = NULL; |
| 446 } | 464 } |
| 447 }; | 465 }; |
| 448 | 466 |
| 449 Data previous_; | 467 Data previous_; |
| 450 | 468 |
| 451 // Allow for the active closing of HandleScopes which allows to pass a handle | 469 // Allow for the active closing of HandleScopes which allows to pass a handle |
| 452 // from the HandleScope being closed to the next top most HandleScope. | 470 // from the HandleScope being closed to the next top most HandleScope. |
| 453 bool is_closed_; | 471 bool is_closed_; |
| 454 void** RawClose(void** value); | 472 internal::Object** RawClose(internal::Object** value); |
| 455 | 473 |
| 456 friend class ImplementationUtilities; | 474 friend class ImplementationUtilities; |
| 457 }; | 475 }; |
| 458 | 476 |
| 459 | 477 |
| 460 // --- S p e c i a l o b j e c t s --- | 478 // --- S p e c i a l o b j e c t s --- |
| 461 | 479 |
| 462 | 480 |
| 463 /** | 481 /** |
| 464 * The superclass of values and API object templates. | 482 * The superclass of values and API object templates. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 | 682 |
| 665 /** | 683 /** |
| 666 * Returns true if this value is false. | 684 * Returns true if this value is false. |
| 667 */ | 685 */ |
| 668 bool IsFalse() const; | 686 bool IsFalse() const; |
| 669 | 687 |
| 670 /** | 688 /** |
| 671 * Returns true if this value is an instance of the String type. | 689 * Returns true if this value is an instance of the String type. |
| 672 * See ECMA-262 8.4. | 690 * See ECMA-262 8.4. |
| 673 */ | 691 */ |
| 674 bool IsString() const; | 692 inline bool IsString() const; |
| 675 | 693 |
| 676 /** | 694 /** |
| 677 * Returns true if this value is a function. | 695 * Returns true if this value is a function. |
| 678 */ | 696 */ |
| 679 bool IsFunction() const; | 697 bool IsFunction() const; |
| 680 | 698 |
| 681 /** | 699 /** |
| 682 * Returns true if this value is an array. | 700 * Returns true if this value is an array. |
| 683 */ | 701 */ |
| 684 bool IsArray() const; | 702 bool IsArray() const; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 | 748 |
| 731 bool BooleanValue() const; | 749 bool BooleanValue() const; |
| 732 double NumberValue() const; | 750 double NumberValue() const; |
| 733 int64_t IntegerValue() const; | 751 int64_t IntegerValue() const; |
| 734 uint32_t Uint32Value() const; | 752 uint32_t Uint32Value() const; |
| 735 int32_t Int32Value() const; | 753 int32_t Int32Value() const; |
| 736 | 754 |
| 737 /** JS == */ | 755 /** JS == */ |
| 738 bool Equals(Handle<Value> that) const; | 756 bool Equals(Handle<Value> that) const; |
| 739 bool StrictEquals(Handle<Value> that) const; | 757 bool StrictEquals(Handle<Value> that) const; |
| 758 | |
| 759 private: | |
| 760 inline bool QuickIsString() const; | |
| 761 bool FullIsString() const; | |
| 740 }; | 762 }; |
| 741 | 763 |
| 742 | 764 |
| 743 /** | 765 /** |
| 744 * The superclass of primitive values. See ECMA-262 4.3.2. | 766 * The superclass of primitive values. See ECMA-262 4.3.2. |
| 745 */ | 767 */ |
| 746 class V8EXPORT Primitive : public Value { }; | 768 class V8EXPORT Primitive : public Value { }; |
| 747 | 769 |
| 748 | 770 |
| 749 /** | 771 /** |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 private: | 883 private: |
| 862 // Disallow copying and assigning. | 884 // Disallow copying and assigning. |
| 863 ExternalAsciiStringResource(const ExternalAsciiStringResource&); | 885 ExternalAsciiStringResource(const ExternalAsciiStringResource&); |
| 864 void operator=(const ExternalAsciiStringResource&); | 886 void operator=(const ExternalAsciiStringResource&); |
| 865 }; | 887 }; |
| 866 | 888 |
| 867 /** | 889 /** |
| 868 * Get the ExternalStringResource for an external string. Returns | 890 * Get the ExternalStringResource for an external string. Returns |
| 869 * NULL if IsExternal() doesn't return true. | 891 * NULL if IsExternal() doesn't return true. |
| 870 */ | 892 */ |
| 871 ExternalStringResource* GetExternalStringResource() const; | 893 inline ExternalStringResource* GetExternalStringResource() const; |
| 872 | 894 |
| 873 /** | 895 /** |
| 874 * Get the ExternalAsciiStringResource for an external ascii string. | 896 * Get the ExternalAsciiStringResource for an external ascii string. |
| 875 * Returns NULL if IsExternalAscii() doesn't return true. | 897 * Returns NULL if IsExternalAscii() doesn't return true. |
| 876 */ | 898 */ |
| 877 ExternalAsciiStringResource* GetExternalAsciiStringResource() const; | 899 ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
| 878 | 900 |
| 879 static String* Cast(v8::Value* obj); | 901 static inline String* Cast(v8::Value* obj); |
| 880 | 902 |
| 881 /** | 903 /** |
| 882 * Allocates a new string from either utf-8 encoded or ascii data. | 904 * Allocates a new string from either utf-8 encoded or ascii data. |
| 883 * The second parameter 'length' gives the buffer length. | 905 * The second parameter 'length' gives the buffer length. |
| 884 * If the data is utf-8 encoded, the caller must | 906 * If the data is utf-8 encoded, the caller must |
| 885 * be careful to supply the length parameter. | 907 * be careful to supply the length parameter. |
| 886 * If it is not given, the function calls | 908 * If it is not given, the function calls |
| 887 * 'strlen' to determine the buffer length, it might be | 909 * 'strlen' to determine the buffer length, it might be |
| 888 * wrong if 'data' contains a null character. | 910 * wrong if 'data' contains a null character. |
| 889 */ | 911 */ |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 uint16_t* operator*() const { return str_; } | 1025 uint16_t* operator*() const { return str_; } |
| 1004 int length() { return length_; } | 1026 int length() { return length_; } |
| 1005 private: | 1027 private: |
| 1006 uint16_t* str_; | 1028 uint16_t* str_; |
| 1007 int length_; | 1029 int length_; |
| 1008 | 1030 |
| 1009 // Disallow copying and assigning. | 1031 // Disallow copying and assigning. |
| 1010 Value(const Value&); | 1032 Value(const Value&); |
| 1011 void operator=(const Value&); | 1033 void operator=(const Value&); |
| 1012 }; | 1034 }; |
| 1035 | |
| 1036 private: | |
| 1037 void VerifyExternalStringResource(ExternalStringResource* val) const; | |
| 1038 static void CheckCast(v8::Value* obj); | |
| 1013 }; | 1039 }; |
| 1014 | 1040 |
| 1015 | 1041 |
| 1016 /** | 1042 /** |
| 1017 * A JavaScript number value (ECMA-262, 4.3.20) | 1043 * A JavaScript number value (ECMA-262, 4.3.20) |
| 1018 */ | 1044 */ |
| 1019 class V8EXPORT Number : public Primitive { | 1045 class V8EXPORT Number : public Primitive { |
| 1020 public: | 1046 public: |
| 1021 double Value() const; | 1047 double Value() const; |
| 1022 static Local<Number> New(double value); | 1048 static Local<Number> New(double value); |
| 1023 static Number* Cast(v8::Value* obj); | 1049 static inline Number* Cast(v8::Value* obj); |
| 1024 private: | 1050 private: |
| 1025 Number(); | 1051 Number(); |
| 1052 static void CheckCast(v8::Value* obj); | |
| 1026 }; | 1053 }; |
| 1027 | 1054 |
| 1028 | 1055 |
| 1029 /** | 1056 /** |
| 1030 * A JavaScript value representing a signed integer. | 1057 * A JavaScript value representing a signed integer. |
| 1031 */ | 1058 */ |
| 1032 class V8EXPORT Integer : public Number { | 1059 class V8EXPORT Integer : public Number { |
| 1033 public: | 1060 public: |
| 1034 static Local<Integer> New(int32_t value); | 1061 static Local<Integer> New(int32_t value); |
| 1035 int64_t Value() const; | 1062 int64_t Value() const; |
| 1036 static Integer* Cast(v8::Value* obj); | 1063 static inline Integer* Cast(v8::Value* obj); |
| 1037 private: | 1064 private: |
| 1038 Integer(); | 1065 Integer(); |
| 1066 static void CheckCast(v8::Value* obj); | |
| 1039 }; | 1067 }; |
| 1040 | 1068 |
| 1041 | 1069 |
| 1042 /** | 1070 /** |
| 1043 * A JavaScript value representing a 32-bit signed integer. | 1071 * A JavaScript value representing a 32-bit signed integer. |
| 1044 */ | 1072 */ |
| 1045 class V8EXPORT Int32 : public Integer { | 1073 class V8EXPORT Int32 : public Integer { |
| 1046 public: | 1074 public: |
| 1047 int32_t Value() const; | 1075 int32_t Value() const; |
| 1048 private: | 1076 private: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1067 class V8EXPORT Date : public Value { | 1095 class V8EXPORT Date : public Value { |
| 1068 public: | 1096 public: |
| 1069 static Local<Value> New(double time); | 1097 static Local<Value> New(double time); |
| 1070 | 1098 |
| 1071 /** | 1099 /** |
| 1072 * A specialization of Value::NumberValue that is more efficient | 1100 * A specialization of Value::NumberValue that is more efficient |
| 1073 * because we know the structure of this object. | 1101 * because we know the structure of this object. |
| 1074 */ | 1102 */ |
| 1075 double NumberValue() const; | 1103 double NumberValue() const; |
| 1076 | 1104 |
| 1077 static Date* Cast(v8::Value* obj); | 1105 static inline Date* Cast(v8::Value* obj); |
| 1106 private: | |
| 1107 static void CheckCast(v8::Value* obj); | |
| 1078 }; | 1108 }; |
| 1079 | 1109 |
| 1080 | 1110 |
| 1081 enum PropertyAttribute { | 1111 enum PropertyAttribute { |
| 1082 None = 0, | 1112 None = 0, |
| 1083 ReadOnly = 1 << 0, | 1113 ReadOnly = 1 << 0, |
| 1084 DontEnum = 1 << 1, | 1114 DontEnum = 1 << 1, |
| 1085 DontDelete = 1 << 2 | 1115 DontDelete = 1 << 2 |
| 1086 }; | 1116 }; |
| 1087 | 1117 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1146 /** | 1176 /** |
| 1147 * Call builtin Object.prototype.toString on this object. | 1177 * Call builtin Object.prototype.toString on this object. |
| 1148 * This is different from Value::ToString() that may call | 1178 * This is different from Value::ToString() that may call |
| 1149 * user-defined toString function. This one does not. | 1179 * user-defined toString function. This one does not. |
| 1150 */ | 1180 */ |
| 1151 Local<String> ObjectProtoToString(); | 1181 Local<String> ObjectProtoToString(); |
| 1152 | 1182 |
| 1153 /** Gets the number of internal fields for this Object. */ | 1183 /** Gets the number of internal fields for this Object. */ |
| 1154 int InternalFieldCount(); | 1184 int InternalFieldCount(); |
| 1155 /** Gets the value in an internal field. */ | 1185 /** Gets the value in an internal field. */ |
| 1156 Local<Value> GetInternalField(int index); | 1186 inline Local<Value> GetInternalField(int index); |
| 1157 /** Sets the value in an internal field. */ | 1187 /** Sets the value in an internal field. */ |
| 1158 void SetInternalField(int index, Handle<Value> value); | 1188 void SetInternalField(int index, Handle<Value> value); |
| 1159 | 1189 |
| 1160 // The two functions below do not perform index bounds checks and | |
| 1161 // they do not check that the VM is still running. Use with caution. | |
| 1162 /** Gets a native pointer from an internal field. */ | 1190 /** Gets a native pointer from an internal field. */ |
| 1163 void* GetPointerFromInternalField(int index); | 1191 inline void* GetPointerFromInternalField(int index); |
| 1192 | |
| 1164 /** Sets a native pointer in an internal field. */ | 1193 /** Sets a native pointer in an internal field. */ |
| 1165 void SetPointerInInternalField(int index, void* value); | 1194 void SetPointerInInternalField(int index, void* value); |
| 1166 | 1195 |
| 1167 // Testers for local properties. | 1196 // Testers for local properties. |
| 1168 bool HasRealNamedProperty(Handle<String> key); | 1197 bool HasRealNamedProperty(Handle<String> key); |
| 1169 bool HasRealIndexedProperty(uint32_t index); | 1198 bool HasRealIndexedProperty(uint32_t index); |
| 1170 bool HasRealNamedCallbackProperty(Handle<String> key); | 1199 bool HasRealNamedCallbackProperty(Handle<String> key); |
| 1171 | 1200 |
| 1172 /** | 1201 /** |
| 1173 * If result.IsEmpty() no real property was located in the prototype chain. | 1202 * If result.IsEmpty() no real property was located in the prototype chain. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1216 /** | 1245 /** |
| 1217 * Set the backing store of the indexed properties to be managed by the | 1246 * Set the backing store of the indexed properties to be managed by the |
| 1218 * embedding layer. Access to the indexed properties will follow the rules | 1247 * embedding layer. Access to the indexed properties will follow the rules |
| 1219 * spelled out in CanvasPixelArray. | 1248 * spelled out in CanvasPixelArray. |
| 1220 * Note: The embedding program still owns the data and needs to ensure that | 1249 * Note: The embedding program still owns the data and needs to ensure that |
| 1221 * the backing store is preserved while V8 has a reference. | 1250 * the backing store is preserved while V8 has a reference. |
| 1222 */ | 1251 */ |
| 1223 void SetIndexedPropertiesToPixelData(uint8_t* data, int length); | 1252 void SetIndexedPropertiesToPixelData(uint8_t* data, int length); |
| 1224 | 1253 |
| 1225 static Local<Object> New(); | 1254 static Local<Object> New(); |
| 1226 static Object* Cast(Value* obj); | 1255 static inline Object* Cast(Value* obj); |
| 1227 private: | 1256 private: |
| 1228 Object(); | 1257 Object(); |
| 1258 static void CheckCast(Value* obj); | |
| 1259 Local<Value> CheckedGetInternalField(int index); | |
| 1260 | |
| 1261 /** | |
| 1262 * If quick access to the internal field is possible this method | |
| 1263 * returns the value. Otherwise an empty handle is returned. | |
| 1264 */ | |
| 1265 inline Local<Value> UncheckedGetInternalField(int index); | |
| 1229 }; | 1266 }; |
| 1230 | 1267 |
| 1231 | 1268 |
| 1232 /** | 1269 /** |
| 1233 * An instance of the built-in array constructor (ECMA-262, 15.4.2). | 1270 * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 1234 */ | 1271 */ |
| 1235 class V8EXPORT Array : public Object { | 1272 class V8EXPORT Array : public Object { |
| 1236 public: | 1273 public: |
| 1237 uint32_t Length() const; | 1274 uint32_t Length() const; |
| 1238 | 1275 |
| 1239 /** | 1276 /** |
| 1240 * Clones an element at index |index|. Returns an empty | 1277 * Clones an element at index |index|. Returns an empty |
| 1241 * handle if cloning fails (for any reason). | 1278 * handle if cloning fails (for any reason). |
| 1242 */ | 1279 */ |
| 1243 Local<Object> CloneElementAt(uint32_t index); | 1280 Local<Object> CloneElementAt(uint32_t index); |
| 1244 | 1281 |
| 1245 static Local<Array> New(int length = 0); | 1282 static Local<Array> New(int length = 0); |
| 1246 static Array* Cast(Value* obj); | 1283 static inline Array* Cast(Value* obj); |
| 1247 private: | 1284 private: |
| 1248 Array(); | 1285 Array(); |
| 1286 static void CheckCast(Value* obj); | |
| 1249 }; | 1287 }; |
| 1250 | 1288 |
| 1251 | 1289 |
| 1252 /** | 1290 /** |
| 1253 * A JavaScript function object (ECMA-262, 15.3). | 1291 * A JavaScript function object (ECMA-262, 15.3). |
| 1254 */ | 1292 */ |
| 1255 class V8EXPORT Function : public Object { | 1293 class V8EXPORT Function : public Object { |
| 1256 public: | 1294 public: |
| 1257 Local<Object> NewInstance() const; | 1295 Local<Object> NewInstance() const; |
| 1258 Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; | 1296 Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; |
| 1259 Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); | 1297 Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]); |
| 1260 void SetName(Handle<String> name); | 1298 void SetName(Handle<String> name); |
| 1261 Handle<Value> GetName() const; | 1299 Handle<Value> GetName() const; |
| 1262 static Function* Cast(Value* obj); | 1300 static inline Function* Cast(Value* obj); |
| 1263 private: | 1301 private: |
| 1264 Function(); | 1302 Function(); |
| 1303 static void CheckCast(Value* obj); | |
| 1265 }; | 1304 }; |
| 1266 | 1305 |
| 1267 | 1306 |
| 1268 /** | 1307 /** |
| 1269 * A JavaScript value that wraps a C++ void*. This type of value is | 1308 * A JavaScript value that wraps a C++ void*. This type of value is |
| 1270 * mainly used to associate C++ data structures with JavaScript | 1309 * mainly used to associate C++ data structures with JavaScript |
| 1271 * objects. | 1310 * objects. |
| 1272 * | 1311 * |
| 1273 * The Wrap function V8 will return the most optimal Value object wrapping the | 1312 * The Wrap function V8 will return the most optimal Value object wrapping the |
| 1274 * C++ void*. The type of the value is not guaranteed to be an External object | 1313 * C++ void*. The type of the value is not guaranteed to be an External object |
| 1275 * and no assumptions about its type should be made. To access the wrapped | 1314 * and no assumptions about its type should be made. To access the wrapped |
| 1276 * value Unwrap should be used, all other operations on that object will lead | 1315 * value Unwrap should be used, all other operations on that object will lead |
| 1277 * to unpredictable results. | 1316 * to unpredictable results. |
| 1278 */ | 1317 */ |
| 1279 class V8EXPORT External : public Value { | 1318 class V8EXPORT External : public Value { |
| 1280 public: | 1319 public: |
| 1281 static Local<Value> Wrap(void* data); | 1320 static Local<Value> Wrap(void* data); |
| 1282 static void* Unwrap(Handle<Value> obj); | 1321 static inline void* Unwrap(Handle<Value> obj); |
| 1283 | 1322 |
| 1284 static Local<External> New(void* value); | 1323 static Local<External> New(void* value); |
| 1285 static External* Cast(Value* obj); | 1324 static inline External* Cast(Value* obj); |
| 1286 void* Value() const; | 1325 void* Value() const; |
| 1287 private: | 1326 private: |
| 1288 External(); | 1327 External(); |
| 1328 static void CheckCast(v8::Value* obj); | |
| 1329 static inline void* QuickUnwrap(Handle<v8::Value> obj); | |
| 1330 static void* FullUnwrap(Handle<v8::Value> obj); | |
| 1289 }; | 1331 }; |
| 1290 | 1332 |
| 1291 | 1333 |
| 1292 // --- T e m p l a t e s --- | 1334 // --- T e m p l a t e s --- |
| 1293 | 1335 |
| 1294 | 1336 |
| 1295 /** | 1337 /** |
| 1296 * The superclass of object and function templates. | 1338 * The superclass of object and function templates. |
| 1297 */ | 1339 */ |
| 1298 class V8EXPORT Template : public Data { | 1340 class V8EXPORT Template : public Data { |
| (...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2290 | 2332 |
| 2291 /** | 2333 /** |
| 2292 * Optional notification that the system is running low on memory. | 2334 * Optional notification that the system is running low on memory. |
| 2293 * V8 uses these notifications to attempt to free memory. | 2335 * V8 uses these notifications to attempt to free memory. |
| 2294 */ | 2336 */ |
| 2295 static void LowMemoryNotification(); | 2337 static void LowMemoryNotification(); |
| 2296 | 2338 |
| 2297 private: | 2339 private: |
| 2298 V8(); | 2340 V8(); |
| 2299 | 2341 |
| 2300 static void** GlobalizeReference(void** handle); | 2342 static internal::Object** GlobalizeReference(internal::Object** handle); |
| 2301 static void DisposeGlobal(void** global_handle); | 2343 static void DisposeGlobal(internal::Object** global_handle); |
| 2302 static void MakeWeak(void** global_handle, void* data, WeakReferenceCallback); | 2344 static void MakeWeak(internal::Object** global_handle, |
| 2303 static void ClearWeak(void** global_handle); | 2345 void* data, |
| 2304 static bool IsGlobalNearDeath(void** global_handle); | 2346 WeakReferenceCallback); |
| 2305 static bool IsGlobalWeak(void** global_handle); | 2347 static void ClearWeak(internal::Object** global_handle); |
| 2348 static bool IsGlobalNearDeath(internal::Object** global_handle); | |
| 2349 static bool IsGlobalWeak(internal::Object** global_handle); | |
| 2306 | 2350 |
| 2307 template <class T> friend class Handle; | 2351 template <class T> friend class Handle; |
| 2308 template <class T> friend class Local; | 2352 template <class T> friend class Local; |
| 2309 template <class T> friend class Persistent; | 2353 template <class T> friend class Persistent; |
| 2310 friend class Context; | 2354 friend class Context; |
| 2311 }; | 2355 }; |
| 2312 | 2356 |
| 2313 | 2357 |
| 2314 /** | 2358 /** |
| 2315 * An external exception handler. | 2359 * An external exception handler. |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2634 | 2678 |
| 2635 // Disallow copying and assigning. | 2679 // Disallow copying and assigning. |
| 2636 Locker(const Locker&); | 2680 Locker(const Locker&); |
| 2637 void operator=(const Locker&); | 2681 void operator=(const Locker&); |
| 2638 }; | 2682 }; |
| 2639 | 2683 |
| 2640 | 2684 |
| 2641 | 2685 |
| 2642 // --- I m p l e m e n t a t i o n --- | 2686 // --- I m p l e m e n t a t i o n --- |
| 2643 | 2687 |
| 2688 | |
| 2689 namespace internal { | |
| 2690 | |
| 2691 | |
| 2692 // Tag information for HeapObject. | |
| 2693 const int kHeapObjectTag = 1; | |
| 2694 const int kHeapObjectTagSize = 2; | |
| 2695 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | |
| 2696 | |
| 2697 | |
| 2698 // Tag information for Smi. | |
| 2699 const int kSmiTag = 0; | |
| 2700 const int kSmiTagSize = 1; | |
| 2701 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | |
| 2702 | |
| 2703 | |
| 2704 /** | |
| 2705 * This class exports constants and functionality from within v8 that | |
| 2706 * is necessary to implement inline functions in the v8 api. Don't | |
| 2707 * depend on functions and constants defined here. | |
| 2708 */ | |
| 2709 class Internals { | |
| 2710 public: | |
| 2711 | |
| 2712 // These values match non-compiler-dependent values defined within | |
| 2713 // the implementation of v8. | |
| 2714 static const int kHeapObjectMapOffset = 0; | |
| 2715 static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int); | |
| 2716 static const int kStringResourceOffset = 2 * sizeof(void*); | |
| 2717 static const int kProxyProxyOffset = sizeof(void*); | |
| 2718 static const int kJSObjectHeaderSize = 3 * sizeof(void*); | |
| 2719 static const int kFullStringRepresentationMask = 0x07; | |
| 2720 static const int kExternalTwoByteRepresentationTag = 0x03; | |
| 2721 static const int kAlignedPointerShift = 2; | |
| 2722 | |
| 2723 // These constants are compiler dependent so their values must be | |
| 2724 // defined within the implementation. | |
| 2725 static int kJSObjectType; | |
| 2726 static int kFirstNonstringType; | |
| 2727 static int kProxyType; | |
| 2728 | |
| 2729 static inline bool HasHeapObjectTag(internal::Object* value) { | |
| 2730 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | |
| 2731 kHeapObjectTag); | |
|
Mads Ager (chromium)
2009/08/26 06:22:20
I would align this with '(reinterpret_cast...' on
| |
| 2732 } | |
| 2733 | |
| 2734 static inline bool HasSmiTag(internal::Object* value) { | |
| 2735 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == | |
|
Mads Ager (chromium)
2009/08/26 06:22:20
This should fit on one line?
| |
| 2736 kSmiTag); | |
| 2737 } | |
| 2738 | |
| 2739 static inline int SmiValue(internal::Object* value) { | |
| 2740 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> kSmiTagSize; | |
| 2741 } | |
| 2742 | |
| 2743 static inline bool IsExternalTwoByteString(int instance_type) { | |
| 2744 int representation = (instance_type & kFullStringRepresentationMask); | |
| 2745 return representation == kExternalTwoByteRepresentationTag; | |
| 2746 } | |
| 2747 | |
| 2748 template <typename T> | |
| 2749 static inline T ReadField(Object* ptr, int offset) { | |
| 2750 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | |
| 2751 return *reinterpret_cast<T*>(addr); | |
| 2752 } | |
| 2753 | |
| 2754 }; | |
| 2755 | |
| 2756 } | |
| 2757 | |
| 2758 | |
| 2644 template <class T> | 2759 template <class T> |
| 2645 Handle<T>::Handle() : val_(0) { } | 2760 Handle<T>::Handle() : val_(0) { } |
| 2646 | 2761 |
| 2647 | 2762 |
| 2648 template <class T> | 2763 template <class T> |
| 2649 Local<T>::Local() : Handle<T>() { } | 2764 Local<T>::Local() : Handle<T>() { } |
| 2650 | 2765 |
| 2651 | 2766 |
| 2652 template <class T> | 2767 template <class T> |
| 2653 Local<T> Local<T>::New(Handle<T> that) { | 2768 Local<T> Local<T>::New(Handle<T> that) { |
| 2654 if (that.IsEmpty()) return Local<T>(); | 2769 if (that.IsEmpty()) return Local<T>(); |
| 2655 void** p = reinterpret_cast<void**>(*that); | 2770 internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
| 2656 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); | 2771 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); |
| 2657 } | 2772 } |
| 2658 | 2773 |
| 2659 | 2774 |
| 2660 template <class T> | 2775 template <class T> |
| 2661 Persistent<T> Persistent<T>::New(Handle<T> that) { | 2776 Persistent<T> Persistent<T>::New(Handle<T> that) { |
| 2662 if (that.IsEmpty()) return Persistent<T>(); | 2777 if (that.IsEmpty()) return Persistent<T>(); |
| 2663 void** p = reinterpret_cast<void**>(*that); | 2778 internal::Object** p = reinterpret_cast<internal::Object**>(*that); |
| 2664 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); | 2779 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); |
| 2665 } | 2780 } |
| 2666 | 2781 |
| 2667 | 2782 |
| 2668 template <class T> | 2783 template <class T> |
| 2669 bool Persistent<T>::IsNearDeath() const { | 2784 bool Persistent<T>::IsNearDeath() const { |
| 2670 if (this->IsEmpty()) return false; | 2785 if (this->IsEmpty()) return false; |
| 2671 return V8::IsGlobalNearDeath(reinterpret_cast<void**>(**this)); | 2786 return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this)); |
| 2672 } | 2787 } |
| 2673 | 2788 |
| 2674 | 2789 |
| 2675 template <class T> | 2790 template <class T> |
| 2676 bool Persistent<T>::IsWeak() const { | 2791 bool Persistent<T>::IsWeak() const { |
| 2677 if (this->IsEmpty()) return false; | 2792 if (this->IsEmpty()) return false; |
| 2678 return V8::IsGlobalWeak(reinterpret_cast<void**>(**this)); | 2793 return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); |
| 2679 } | 2794 } |
| 2680 | 2795 |
| 2681 | 2796 |
| 2682 template <class T> | 2797 template <class T> |
| 2683 void Persistent<T>::Dispose() { | 2798 void Persistent<T>::Dispose() { |
| 2684 if (this->IsEmpty()) return; | 2799 if (this->IsEmpty()) return; |
| 2685 V8::DisposeGlobal(reinterpret_cast<void**>(**this)); | 2800 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); |
| 2686 } | 2801 } |
| 2687 | 2802 |
| 2688 | 2803 |
| 2689 template <class T> | 2804 template <class T> |
| 2690 Persistent<T>::Persistent() : Handle<T>() { } | 2805 Persistent<T>::Persistent() : Handle<T>() { } |
| 2691 | 2806 |
| 2692 template <class T> | 2807 template <class T> |
| 2693 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { | 2808 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { |
| 2694 V8::MakeWeak(reinterpret_cast<void**>(**this), parameters, callback); | 2809 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), |
| 2810 parameters, | |
| 2811 callback); | |
| 2695 } | 2812 } |
| 2696 | 2813 |
| 2697 template <class T> | 2814 template <class T> |
| 2698 void Persistent<T>::ClearWeak() { | 2815 void Persistent<T>::ClearWeak() { |
| 2699 V8::ClearWeak(reinterpret_cast<void**>(**this)); | 2816 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); |
| 2700 } | 2817 } |
| 2701 | 2818 |
| 2702 Local<Value> Arguments::operator[](int i) const { | 2819 Local<Value> Arguments::operator[](int i) const { |
| 2703 if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); | 2820 if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); |
| 2704 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); | 2821 return Local<Value>(reinterpret_cast<Value*>(values_ - i)); |
| 2705 } | 2822 } |
| 2706 | 2823 |
| 2707 | 2824 |
| 2708 Local<Function> Arguments::Callee() const { | 2825 Local<Function> Arguments::Callee() const { |
| 2709 return callee_; | 2826 return callee_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2745 } | 2862 } |
| 2746 | 2863 |
| 2747 | 2864 |
| 2748 Local<Object> AccessorInfo::Holder() const { | 2865 Local<Object> AccessorInfo::Holder() const { |
| 2749 return holder_; | 2866 return holder_; |
| 2750 } | 2867 } |
| 2751 | 2868 |
| 2752 | 2869 |
| 2753 template <class T> | 2870 template <class T> |
| 2754 Local<T> HandleScope::Close(Handle<T> value) { | 2871 Local<T> HandleScope::Close(Handle<T> value) { |
| 2755 void** after = RawClose(reinterpret_cast<void**>(*value)); | 2872 internal::Object** before = reinterpret_cast<internal::Object**>(*value); |
| 2873 internal::Object** after = RawClose(before); | |
| 2756 return Local<T>(reinterpret_cast<T*>(after)); | 2874 return Local<T>(reinterpret_cast<T*>(after)); |
| 2757 } | 2875 } |
| 2758 | 2876 |
| 2759 Handle<Value> ScriptOrigin::ResourceName() const { | 2877 Handle<Value> ScriptOrigin::ResourceName() const { |
| 2760 return resource_name_; | 2878 return resource_name_; |
| 2761 } | 2879 } |
| 2762 | 2880 |
| 2763 | 2881 |
| 2764 Handle<Integer> ScriptOrigin::ResourceLineOffset() const { | 2882 Handle<Integer> ScriptOrigin::ResourceLineOffset() const { |
| 2765 return resource_line_offset_; | 2883 return resource_line_offset_; |
| 2766 } | 2884 } |
| 2767 | 2885 |
| 2768 | 2886 |
| 2769 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { | 2887 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const { |
| 2770 return resource_column_offset_; | 2888 return resource_column_offset_; |
| 2771 } | 2889 } |
| 2772 | 2890 |
| 2773 | 2891 |
| 2774 Handle<Boolean> Boolean::New(bool value) { | 2892 Handle<Boolean> Boolean::New(bool value) { |
| 2775 return value ? True() : False(); | 2893 return value ? True() : False(); |
| 2776 } | 2894 } |
| 2777 | 2895 |
| 2778 | 2896 |
| 2779 void Template::Set(const char* name, v8::Handle<Data> value) { | 2897 void Template::Set(const char* name, v8::Handle<Data> value) { |
| 2780 Set(v8::String::New(name), value); | 2898 Set(v8::String::New(name), value); |
| 2781 } | 2899 } |
| 2782 | 2900 |
| 2783 | 2901 |
| 2902 Local<Value> Object::GetInternalField(int index) { | |
| 2903 #ifndef V8_ENABLE_CHECKS | |
| 2904 Local<Value> quick_result = UncheckedGetInternalField(index); | |
| 2905 if (!quick_result.IsEmpty()) return quick_result; | |
| 2906 #endif | |
| 2907 return CheckedGetInternalField(index); | |
| 2908 } | |
| 2909 | |
| 2910 | |
| 2911 Local<Value> Object::UncheckedGetInternalField(int index) { | |
| 2912 typedef internal::Object O; | |
| 2913 typedef internal::Internals I; | |
| 2914 O* obj = *reinterpret_cast<O**>(this); | |
| 2915 O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); | |
| 2916 int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); | |
| 2917 if (instance_type == I::kJSObjectType) { | |
| 2918 // If the object is a plain JSObject, which is the common case, | |
| 2919 // we know where to find the internal fields and can return the | |
| 2920 // value directly. | |
| 2921 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index); | |
| 2922 O* value = I::ReadField<O*>(obj, offset); | |
| 2923 O** result = HandleScope::CreateHandle(value); | |
| 2924 return Local<Value>(reinterpret_cast<Value*>(result)); | |
| 2925 } else { | |
| 2926 return Local<Value>(); | |
| 2927 } | |
| 2928 } | |
| 2929 | |
| 2930 | |
| 2931 void* External::Unwrap(Handle<v8::Value> obj) { | |
| 2932 #ifdef V8_ENABLE_CHECKS | |
| 2933 return FullUnwrap(obj); | |
| 2934 #else | |
| 2935 return QuickUnwrap(obj); | |
| 2936 #endif | |
| 2937 } | |
| 2938 | |
| 2939 | |
| 2940 void* External::QuickUnwrap(Handle<v8::Value> wrapper) { | |
| 2941 typedef internal::Object O; | |
| 2942 typedef internal::Internals I; | |
| 2943 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); | |
| 2944 if (I::HasSmiTag(obj)) { | |
| 2945 int value = I::SmiValue(obj) << I::kAlignedPointerShift; | |
| 2946 return reinterpret_cast<void*>(value); | |
| 2947 } else { | |
| 2948 O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); | |
| 2949 int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); | |
| 2950 if (instance_type == I::kProxyType) { | |
| 2951 return I::ReadField<void*>(obj, I::kProxyProxyOffset); | |
| 2952 } else { | |
| 2953 return NULL; | |
| 2954 } | |
| 2955 } | |
| 2956 } | |
| 2957 | |
| 2958 | |
| 2959 void* Object::GetPointerFromInternalField(int index) { | |
| 2960 return External::Unwrap(GetInternalField(index)); | |
| 2961 } | |
| 2962 | |
| 2963 | |
| 2964 String* String::Cast(v8::Value* value) { | |
| 2965 #ifdef V8_ENABLE_CHECKS | |
| 2966 CheckCast(value); | |
| 2967 #endif | |
| 2968 return static_cast<String*>(value); | |
| 2969 } | |
| 2970 | |
| 2971 | |
| 2972 String::ExternalStringResource* String::GetExternalStringResource() const { | |
| 2973 typedef internal::Object O; | |
| 2974 typedef internal::Internals I; | |
| 2975 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); | |
| 2976 O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); | |
| 2977 int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); | |
| 2978 String::ExternalStringResource* result; | |
| 2979 if (I::IsExternalTwoByteString(instance_type)) { | |
| 2980 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); | |
| 2981 result = reinterpret_cast<String::ExternalStringResource*>(value); | |
| 2982 } else { | |
| 2983 result = NULL; | |
| 2984 } | |
| 2985 #ifdef V8_ENABLE_CHECKS | |
| 2986 VerifyExternalStringResource(result); | |
| 2987 #endif | |
| 2988 return result; | |
| 2989 } | |
| 2990 | |
| 2991 | |
| 2992 bool Value::IsString() const { | |
| 2993 #ifdef V8_ENABLE_CHECKS | |
| 2994 return FullIsString(); | |
| 2995 #else | |
| 2996 return QuickIsString(); | |
| 2997 #endif | |
| 2998 } | |
| 2999 | |
| 3000 bool Value::QuickIsString() const { | |
| 3001 typedef internal::Object O; | |
| 3002 typedef internal::Internals I; | |
| 3003 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); | |
| 3004 if (!I::HasHeapObjectTag(obj)) return false; | |
| 3005 O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); | |
| 3006 int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); | |
| 3007 return (instance_type < I::kFirstNonstringType); | |
| 3008 } | |
| 3009 | |
| 3010 | |
| 3011 Number* Number::Cast(v8::Value* value) { | |
| 3012 #ifdef V8_ENABLE_CHECKS | |
| 3013 CheckCast(value); | |
| 3014 #endif | |
| 3015 return static_cast<Number*>(value); | |
| 3016 } | |
| 3017 | |
| 3018 | |
| 3019 Integer* Integer::Cast(v8::Value* value) { | |
| 3020 #ifdef V8_ENABLE_CHECKS | |
| 3021 CheckCast(value); | |
| 3022 #endif | |
| 3023 return static_cast<Integer*>(value); | |
| 3024 } | |
| 3025 | |
| 3026 | |
| 3027 Date* Date::Cast(v8::Value* value) { | |
| 3028 #ifdef V8_ENABLE_CHECKS | |
| 3029 CheckCast(value); | |
| 3030 #endif | |
| 3031 return static_cast<Date*>(value); | |
| 3032 } | |
| 3033 | |
| 3034 | |
| 3035 Object* Object::Cast(v8::Value* value) { | |
| 3036 #ifdef V8_ENABLE_CHECKS | |
| 3037 CheckCast(value); | |
| 3038 #endif | |
| 3039 return static_cast<Object*>(value); | |
| 3040 } | |
| 3041 | |
| 3042 | |
| 3043 Array* Array::Cast(v8::Value* value) { | |
| 3044 #ifdef V8_ENABLE_CHECKS | |
| 3045 CheckCast(value); | |
| 3046 #endif | |
| 3047 return static_cast<Array*>(value); | |
| 3048 } | |
| 3049 | |
| 3050 | |
| 3051 Function* Function::Cast(v8::Value* value) { | |
| 3052 #ifdef V8_ENABLE_CHECKS | |
| 3053 CheckCast(value); | |
| 3054 #endif | |
| 3055 return static_cast<Function*>(value); | |
| 3056 } | |
| 3057 | |
| 3058 | |
| 3059 External* External::Cast(v8::Value* value) { | |
| 3060 #ifdef V8_ENABLE_CHECKS | |
| 3061 CheckCast(value); | |
| 3062 #endif | |
| 3063 return static_cast<External*>(value); | |
| 3064 } | |
| 3065 | |
| 3066 | |
| 2784 /** | 3067 /** |
| 2785 * \example shell.cc | 3068 * \example shell.cc |
| 2786 * A simple shell that takes a list of expressions on the | 3069 * A simple shell that takes a list of expressions on the |
| 2787 * command-line and executes them. | 3070 * command-line and executes them. |
| 2788 */ | 3071 */ |
| 2789 | 3072 |
| 2790 | 3073 |
| 2791 /** | 3074 /** |
| 2792 * \example process.cc | 3075 * \example process.cc |
| 2793 */ | 3076 */ |
| 2794 | 3077 |
| 2795 | 3078 |
| 2796 } // namespace v8 | 3079 } // namespace v8 |
| 2797 | 3080 |
| 2798 | 3081 |
| 2799 #undef V8EXPORT | 3082 #undef V8EXPORT |
| 2800 #undef V8EXPORT_INLINE | 3083 #undef V8EXPORT_INLINE |
| 2801 #undef TYPE_CHECK | 3084 #undef TYPE_CHECK |
| 2802 | 3085 |
| 2803 | 3086 |
| 2804 #endif // V8_H_ | 3087 #endif // V8_H_ |
| OLD | NEW |