| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 856 |
| 857 /** | 857 /** |
| 858 * The superclass of all JavaScript values and objects. | 858 * The superclass of all JavaScript values and objects. |
| 859 */ | 859 */ |
| 860 class Value : public Data { | 860 class Value : public Data { |
| 861 public: | 861 public: |
| 862 /** | 862 /** |
| 863 * Returns true if this value is the undefined value. See ECMA-262 | 863 * Returns true if this value is the undefined value. See ECMA-262 |
| 864 * 4.3.10. | 864 * 4.3.10. |
| 865 */ | 865 */ |
| 866 V8EXPORT bool IsUndefined() const; | 866 inline bool IsUndefined() const; |
| 867 | 867 |
| 868 /** | 868 /** |
| 869 * Returns true if this value is the null value. See ECMA-262 | 869 * Returns true if this value is the null value. See ECMA-262 |
| 870 * 4.3.11. | 870 * 4.3.11. |
| 871 */ | 871 */ |
| 872 V8EXPORT bool IsNull() const; | 872 inline bool IsNull() const; |
| 873 | 873 |
| 874 /** | 874 /** |
| 875 * Returns true if this value is true. | 875 * Returns true if this value is true. |
| 876 */ | 876 */ |
| 877 V8EXPORT bool IsTrue() const; | 877 V8EXPORT bool IsTrue() const; |
| 878 | 878 |
| 879 /** | 879 /** |
| 880 * Returns true if this value is false. | 880 * Returns true if this value is false. |
| 881 */ | 881 */ |
| 882 V8EXPORT bool IsFalse() const; | 882 V8EXPORT bool IsFalse() const; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 V8EXPORT double NumberValue() const; | 976 V8EXPORT double NumberValue() const; |
| 977 V8EXPORT int64_t IntegerValue() const; | 977 V8EXPORT int64_t IntegerValue() const; |
| 978 V8EXPORT uint32_t Uint32Value() const; | 978 V8EXPORT uint32_t Uint32Value() const; |
| 979 V8EXPORT int32_t Int32Value() const; | 979 V8EXPORT int32_t Int32Value() const; |
| 980 | 980 |
| 981 /** JS == */ | 981 /** JS == */ |
| 982 V8EXPORT bool Equals(Handle<Value> that) const; | 982 V8EXPORT bool Equals(Handle<Value> that) const; |
| 983 V8EXPORT bool StrictEquals(Handle<Value> that) const; | 983 V8EXPORT bool StrictEquals(Handle<Value> that) const; |
| 984 | 984 |
| 985 private: | 985 private: |
| 986 inline bool QuickIsUndefined() const; |
| 987 inline bool QuickIsNull() const; |
| 986 inline bool QuickIsString() const; | 988 inline bool QuickIsString() const; |
| 989 V8EXPORT bool FullIsUndefined() const; |
| 990 V8EXPORT bool FullIsNull() const; |
| 987 V8EXPORT bool FullIsString() const; | 991 V8EXPORT bool FullIsString() const; |
| 988 }; | 992 }; |
| 989 | 993 |
| 990 | 994 |
| 991 /** | 995 /** |
| 992 * The superclass of primitive values. See ECMA-262 4.3.2. | 996 * The superclass of primitive values. See ECMA-262 4.3.2. |
| 993 */ | 997 */ |
| 994 class Primitive : public Value { }; | 998 class Primitive : public Value { }; |
| 995 | 999 |
| 996 | 1000 |
| (...skipping 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3884 */ | 3888 */ |
| 3885 class Internals { | 3889 class Internals { |
| 3886 public: | 3890 public: |
| 3887 // These values match non-compiler-dependent values defined within | 3891 // These values match non-compiler-dependent values defined within |
| 3888 // the implementation of v8. | 3892 // the implementation of v8. |
| 3889 static const int kHeapObjectMapOffset = 0; | 3893 static const int kHeapObjectMapOffset = 0; |
| 3890 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 3894 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
| 3891 static const int kStringResourceOffset = | 3895 static const int kStringResourceOffset = |
| 3892 InternalConstants<kApiPointerSize>::kStringResourceOffset; | 3896 InternalConstants<kApiPointerSize>::kStringResourceOffset; |
| 3893 | 3897 |
| 3898 static const int kOddballKindOffset = 3 * kApiPointerSize; |
| 3894 static const int kForeignAddressOffset = kApiPointerSize; | 3899 static const int kForeignAddressOffset = kApiPointerSize; |
| 3895 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 3900 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
| 3896 static const int kFullStringRepresentationMask = 0x07; | 3901 static const int kFullStringRepresentationMask = 0x07; |
| 3897 static const int kExternalTwoByteRepresentationTag = 0x02; | 3902 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 3898 | 3903 |
| 3899 static const int kJSObjectType = 0xaa; | 3904 static const int kJSObjectType = 0xaa; |
| 3900 static const int kFirstNonstringType = 0x80; | 3905 static const int kFirstNonstringType = 0x80; |
| 3906 static const int kOddballType = 0x82; |
| 3901 static const int kForeignType = 0x85; | 3907 static const int kForeignType = 0x85; |
| 3902 | 3908 |
| 3909 static const int kUndefinedOddballKind = 5; |
| 3910 static const int kNullOddballKind = 3; |
| 3911 |
| 3903 static inline bool HasHeapObjectTag(internal::Object* value) { | 3912 static inline bool HasHeapObjectTag(internal::Object* value) { |
| 3904 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 3913 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 3905 kHeapObjectTag); | 3914 kHeapObjectTag); |
| 3906 } | 3915 } |
| 3907 | 3916 |
| 3908 static inline bool HasSmiTag(internal::Object* value) { | 3917 static inline bool HasSmiTag(internal::Object* value) { |
| 3909 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 3918 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 3910 } | 3919 } |
| 3911 | 3920 |
| 3912 static inline int SmiValue(internal::Object* value) { | 3921 static inline int SmiValue(internal::Object* value) { |
| 3913 return PlatformSmiTagging::SmiToInt(value); | 3922 return PlatformSmiTagging::SmiToInt(value); |
| 3914 } | 3923 } |
| 3915 | 3924 |
| 3916 static inline int GetInstanceType(internal::Object* obj) { | 3925 static inline int GetInstanceType(internal::Object* obj) { |
| 3917 typedef internal::Object O; | 3926 typedef internal::Object O; |
| 3918 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3927 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3919 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3928 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3920 } | 3929 } |
| 3921 | 3930 |
| 3931 static inline int GetOddballKind(internal::Object* obj) { |
| 3932 typedef internal::Object O; |
| 3933 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 3934 } |
| 3935 |
| 3922 static inline void* GetExternalPointerFromSmi(internal::Object* value) { | 3936 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 3923 const uintptr_t address = reinterpret_cast<uintptr_t>(value); | 3937 const uintptr_t address = reinterpret_cast<uintptr_t>(value); |
| 3924 return reinterpret_cast<void*>(address >> kPointerToSmiShift); | 3938 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 3925 } | 3939 } |
| 3926 | 3940 |
| 3927 static inline void* GetExternalPointer(internal::Object* obj) { | 3941 static inline void* GetExternalPointer(internal::Object* obj) { |
| 3928 if (HasSmiTag(obj)) { | 3942 if (HasSmiTag(obj)) { |
| 3929 return GetExternalPointerFromSmi(obj); | 3943 return GetExternalPointerFromSmi(obj); |
| 3930 } else if (GetInstanceType(obj) == kForeignType) { | 3944 } else if (GetInstanceType(obj) == kForeignType) { |
| 3931 return ReadField<void*>(obj, kForeignAddressOffset); | 3945 return ReadField<void*>(obj, kForeignAddressOffset); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4193 } else { | 4207 } else { |
| 4194 result = NULL; | 4208 result = NULL; |
| 4195 } | 4209 } |
| 4196 #ifdef V8_ENABLE_CHECKS | 4210 #ifdef V8_ENABLE_CHECKS |
| 4197 VerifyExternalStringResource(result); | 4211 VerifyExternalStringResource(result); |
| 4198 #endif | 4212 #endif |
| 4199 return result; | 4213 return result; |
| 4200 } | 4214 } |
| 4201 | 4215 |
| 4202 | 4216 |
| 4217 bool Value::IsUndefined() const { |
| 4218 #ifdef V8_ENABLE_CHECKS |
| 4219 return FullIsUndefined(); |
| 4220 #else |
| 4221 return QuickIsUndefined(); |
| 4222 #endif |
| 4223 } |
| 4224 |
| 4225 bool Value::QuickIsUndefined() const { |
| 4226 typedef internal::Object O; |
| 4227 typedef internal::Internals I; |
| 4228 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 4229 if (!I::HasHeapObjectTag(obj)) return false; |
| 4230 if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 4231 return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); |
| 4232 } |
| 4233 |
| 4234 |
| 4235 bool Value::IsNull() const { |
| 4236 #ifdef V8_ENABLE_CHECKS |
| 4237 return FullIsNull(); |
| 4238 #else |
| 4239 return QuickIsNull(); |
| 4240 #endif |
| 4241 } |
| 4242 |
| 4243 bool Value::QuickIsNull() const { |
| 4244 typedef internal::Object O; |
| 4245 typedef internal::Internals I; |
| 4246 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); |
| 4247 if (!I::HasHeapObjectTag(obj)) return false; |
| 4248 if (I::GetInstanceType(obj) != I::kOddballType) return false; |
| 4249 return (I::GetOddballKind(obj) == I::kNullOddballKind); |
| 4250 } |
| 4251 |
| 4252 |
| 4203 bool Value::IsString() const { | 4253 bool Value::IsString() const { |
| 4204 #ifdef V8_ENABLE_CHECKS | 4254 #ifdef V8_ENABLE_CHECKS |
| 4205 return FullIsString(); | 4255 return FullIsString(); |
| 4206 #else | 4256 #else |
| 4207 return QuickIsString(); | 4257 return QuickIsString(); |
| 4208 #endif | 4258 #endif |
| 4209 } | 4259 } |
| 4210 | 4260 |
| 4211 bool Value::QuickIsString() const { | 4261 bool Value::QuickIsString() const { |
| 4212 typedef internal::Object O; | 4262 typedef internal::Object O; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4338 | 4388 |
| 4339 | 4389 |
| 4340 } // namespace v8 | 4390 } // namespace v8 |
| 4341 | 4391 |
| 4342 | 4392 |
| 4343 #undef V8EXPORT | 4393 #undef V8EXPORT |
| 4344 #undef TYPE_CHECK | 4394 #undef TYPE_CHECK |
| 4345 | 4395 |
| 4346 | 4396 |
| 4347 #endif // V8_H_ | 4397 #endif // V8_H_ |
| OLD | NEW |