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