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 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 V8EXPORT bool Value() const; | 1011 V8EXPORT bool Value() const; |
1012 static inline Handle<Boolean> New(bool value); | 1012 static inline Handle<Boolean> New(bool value); |
1013 }; | 1013 }; |
1014 | 1014 |
1015 | 1015 |
1016 /** | 1016 /** |
1017 * A JavaScript string value (ECMA-262, 4.3.17). | 1017 * A JavaScript string value (ECMA-262, 4.3.17). |
1018 */ | 1018 */ |
1019 class String : public Primitive { | 1019 class String : public Primitive { |
1020 public: | 1020 public: |
| 1021 static const int kExternalAsciiStringType = 0x06; |
| 1022 static const int kExternalTwoByteStringType = 0x02; |
1021 /** | 1023 /** |
1022 * Returns the number of characters in this string. | 1024 * Returns the number of characters in this string. |
1023 */ | 1025 */ |
1024 V8EXPORT int Length() const; | 1026 V8EXPORT int Length() const; |
1025 | 1027 |
1026 /** | 1028 /** |
1027 * Returns the number of bytes in the UTF-8 encoded | 1029 * Returns the number of bytes in the UTF-8 encoded |
1028 * representation of this string. | 1030 * representation of this string. |
1029 */ | 1031 */ |
1030 V8EXPORT int Utf8Length() const; | 1032 V8EXPORT int Utf8Length() const; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 virtual ~ExternalAsciiStringResource() {} | 1176 virtual ~ExternalAsciiStringResource() {} |
1175 /** The string data from the underlying buffer.*/ | 1177 /** The string data from the underlying buffer.*/ |
1176 virtual const char* data() const = 0; | 1178 virtual const char* data() const = 0; |
1177 /** The number of ASCII characters in the string.*/ | 1179 /** The number of ASCII characters in the string.*/ |
1178 virtual size_t length() const = 0; | 1180 virtual size_t length() const = 0; |
1179 protected: | 1181 protected: |
1180 ExternalAsciiStringResource() {} | 1182 ExternalAsciiStringResource() {} |
1181 }; | 1183 }; |
1182 | 1184 |
1183 /** | 1185 /** |
| 1186 * Get any type of external string resource. |
| 1187 * Returns 0 if there is no external string and does not modify resource or |
| 1188 * returns either kExternalAsciiStringType or kExternalTwoByteStringType and |
| 1189 * sets the resource pointer. |
| 1190 */ |
| 1191 inline int GetExternalStringResourceBase( |
| 1192 ExternalStringResourceBase*& resource) const; |
| 1193 |
| 1194 /** |
1184 * Get the ExternalStringResource for an external string. Returns | 1195 * Get the ExternalStringResource for an external string. Returns |
1185 * NULL if IsExternal() doesn't return true. | 1196 * NULL if IsExternal() doesn't return true. |
1186 */ | 1197 */ |
1187 inline ExternalStringResource* GetExternalStringResource() const; | 1198 inline ExternalStringResource* GetExternalStringResource() const; |
1188 | 1199 |
1189 /** | 1200 /** |
1190 * Get the ExternalAsciiStringResource for an external ASCII string. | 1201 * Get the ExternalAsciiStringResource for an external ASCII string. |
1191 * Returns NULL if IsExternalAscii() doesn't return true. | 1202 * Returns NULL if IsExternalAscii() doesn't return true. |
1192 */ | 1203 */ |
1193 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() | 1204 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 private: | 1347 private: |
1337 uint16_t* str_; | 1348 uint16_t* str_; |
1338 int length_; | 1349 int length_; |
1339 | 1350 |
1340 // Disallow copying and assigning. | 1351 // Disallow copying and assigning. |
1341 Value(const Value&); | 1352 Value(const Value&); |
1342 void operator=(const Value&); | 1353 void operator=(const Value&); |
1343 }; | 1354 }; |
1344 | 1355 |
1345 private: | 1356 private: |
| 1357 V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| 1358 int type) const; |
1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; | 1359 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; |
1347 V8EXPORT static void CheckCast(v8::Value* obj); | 1360 V8EXPORT static void CheckCast(v8::Value* obj); |
1348 }; | 1361 }; |
1349 | 1362 |
1350 | 1363 |
1351 /** | 1364 /** |
1352 * A JavaScript number value (ECMA-262, 4.3.20) | 1365 * A JavaScript number value (ECMA-262, 4.3.20) |
1353 */ | 1366 */ |
1354 class Number : public Primitive { | 1367 class Number : public Primitive { |
1355 public: | 1368 public: |
(...skipping 2671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4027 // the implementation of v8. | 4040 // the implementation of v8. |
4028 static const int kHeapObjectMapOffset = 0; | 4041 static const int kHeapObjectMapOffset = 0; |
4029 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4042 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
4030 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4043 static const int kStringResourceOffset = 3 * kApiPointerSize; |
4031 | 4044 |
4032 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4045 static const int kOddballKindOffset = 3 * kApiPointerSize; |
4033 static const int kForeignAddressOffset = kApiPointerSize; | 4046 static const int kForeignAddressOffset = kApiPointerSize; |
4034 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4047 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
4035 static const int kFullStringRepresentationMask = 0x07; | 4048 static const int kFullStringRepresentationMask = 0x07; |
4036 static const int kExternalTwoByteRepresentationTag = 0x02; | 4049 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 4050 static const int kExternalAsciiRepresentationTag = 0x06; |
4037 | 4051 |
4038 static const int kIsolateStateOffset = 0; | 4052 static const int kIsolateStateOffset = 0; |
4039 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4053 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
4040 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4054 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
4041 static const int kUndefinedValueRootIndex = 5; | 4055 static const int kUndefinedValueRootIndex = 5; |
4042 static const int kNullValueRootIndex = 7; | 4056 static const int kNullValueRootIndex = 7; |
4043 static const int kTrueValueRootIndex = 8; | 4057 static const int kTrueValueRootIndex = 8; |
4044 static const int kFalseValueRootIndex = 9; | 4058 static const int kFalseValueRootIndex = 9; |
4045 static const int kEmptySymbolRootIndex = 116; | 4059 static const int kEmptySymbolRootIndex = 116; |
4046 | 4060 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4380 result = reinterpret_cast<String::ExternalStringResource*>(value); | 4394 result = reinterpret_cast<String::ExternalStringResource*>(value); |
4381 } else { | 4395 } else { |
4382 result = NULL; | 4396 result = NULL; |
4383 } | 4397 } |
4384 #ifdef V8_ENABLE_CHECKS | 4398 #ifdef V8_ENABLE_CHECKS |
4385 VerifyExternalStringResource(result); | 4399 VerifyExternalStringResource(result); |
4386 #endif | 4400 #endif |
4387 return result; | 4401 return result; |
4388 } | 4402 } |
4389 | 4403 |
| 4404 int String::GetExternalStringResourceBase( |
| 4405 String::ExternalStringResourceBase*& resource) const { |
| 4406 typedef internal::Object O; |
| 4407 typedef internal::Internals I; |
| 4408 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 4409 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| 4410 if (type == I::kExternalAsciiRepresentationTag |
| 4411 || type == I::kExternalTwoByteRepresentationTag) { |
| 4412 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 4413 resource = static_cast<String::ExternalStringResourceBase*>(value); |
| 4414 #ifdef V8_ENABLE_CHECKS |
| 4415 VerifyExternalStringResourceBase(resource, type); |
| 4416 #endif |
| 4417 return type; |
| 4418 } else { |
| 4419 #ifdef V8_ENABLE_CHECKS |
| 4420 VerifyExternalStringResourceBase(NULL, 0); |
| 4421 #endif |
| 4422 return 0; |
| 4423 } |
| 4424 } |
4390 | 4425 |
4391 bool Value::IsUndefined() const { | 4426 bool Value::IsUndefined() const { |
4392 #ifdef V8_ENABLE_CHECKS | 4427 #ifdef V8_ENABLE_CHECKS |
4393 return FullIsUndefined(); | 4428 return FullIsUndefined(); |
4394 #else | 4429 #else |
4395 return QuickIsUndefined(); | 4430 return QuickIsUndefined(); |
4396 #endif | 4431 #endif |
4397 } | 4432 } |
4398 | 4433 |
4399 bool Value::QuickIsUndefined() const { | 4434 bool Value::QuickIsUndefined() const { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4610 | 4645 |
4611 | 4646 |
4612 } // namespace v8 | 4647 } // namespace v8 |
4613 | 4648 |
4614 | 4649 |
4615 #undef V8EXPORT | 4650 #undef V8EXPORT |
4616 #undef TYPE_CHECK | 4651 #undef TYPE_CHECK |
4617 | 4652 |
4618 | 4653 |
4619 #endif // V8_H_ | 4654 #endif // V8_H_ |
OLD | NEW |