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 type_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 25 matching lines...) Expand all Loading... | |
1219 V8EXPORT static Local<String> Concat(Handle<String> left, | 1232 V8EXPORT static Local<String> Concat(Handle<String> left, |
1220 Handle<String> right); | 1233 Handle<String> right); |
1221 | 1234 |
1222 /** | 1235 /** |
1223 * Creates a new external string using the data defined in the given | 1236 * Creates a new external string using the data defined in the given |
1224 * resource. When the external string is no longer live on V8's heap the | 1237 * resource. When the external string is no longer live on V8's heap the |
1225 * resource will be disposed by calling its Dispose method. The caller of | 1238 * resource will be disposed by calling its Dispose method. The caller of |
1226 * this function should not otherwise delete or modify the resource. Neither | 1239 * this function should not otherwise delete or modify the resource. Neither |
1227 * should the underlying buffer be deallocated or modified except through the | 1240 * should the underlying buffer be deallocated or modified except through the |
1228 * destructor of the external string resource. | 1241 * destructor of the external string resource. |
1242 * The optional encoding argument provides a hint on whether scanning for | |
1243 * ASCII content is necessary. | |
drcarney
2012/09/12 11:27:09
Looks like this comment accidentally slipped in.
Yang
2012/09/12 11:28:50
Done.
| |
1229 */ | 1244 */ |
1230 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); | 1245 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); |
1231 | 1246 |
1232 /** | 1247 /** |
1233 * Associate an external string resource with this string by transforming it | 1248 * Associate an external string resource with this string by transforming it |
1234 * in place so that existing references to this string in the JavaScript heap | 1249 * in place so that existing references to this string in the JavaScript heap |
1235 * will use the external string resource. The external string resource's | 1250 * will use the external string resource. The external string resource's |
1236 * character contents need to be equivalent to this string. | 1251 * character contents need to be equivalent to this string. |
1237 * Returns true if the string has been changed to be an external string. | 1252 * Returns true if the string has been changed to be an external string. |
1238 * The string is not modified if the operation fails. See NewExternal for | 1253 * The string is not modified if the operation fails. See NewExternal for |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1336 private: | 1351 private: |
1337 uint16_t* str_; | 1352 uint16_t* str_; |
1338 int length_; | 1353 int length_; |
1339 | 1354 |
1340 // Disallow copying and assigning. | 1355 // Disallow copying and assigning. |
1341 Value(const Value&); | 1356 Value(const Value&); |
1342 void operator=(const Value&); | 1357 void operator=(const Value&); |
1343 }; | 1358 }; |
1344 | 1359 |
1345 private: | 1360 private: |
1361 V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, | |
1362 Encoding encoding_out) const; | |
1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; | 1363 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; |
1347 V8EXPORT static void CheckCast(v8::Value* obj); | 1364 V8EXPORT static void CheckCast(v8::Value* obj); |
1348 }; | 1365 }; |
1349 | 1366 |
1350 | 1367 |
1351 /** | 1368 /** |
1352 * A JavaScript number value (ECMA-262, 4.3.20) | 1369 * A JavaScript number value (ECMA-262, 4.3.20) |
1353 */ | 1370 */ |
1354 class Number : public Primitive { | 1371 class Number : public Primitive { |
1355 public: | 1372 public: |
(...skipping 2670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4026 // These values match non-compiler-dependent values defined within | 4043 // These values match non-compiler-dependent values defined within |
4027 // the implementation of v8. | 4044 // the implementation of v8. |
4028 static const int kHeapObjectMapOffset = 0; | 4045 static const int kHeapObjectMapOffset = 0; |
4029 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4046 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
4030 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4047 static const int kStringResourceOffset = 3 * kApiPointerSize; |
4031 | 4048 |
4032 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4049 static const int kOddballKindOffset = 3 * kApiPointerSize; |
4033 static const int kForeignAddressOffset = kApiPointerSize; | 4050 static const int kForeignAddressOffset = kApiPointerSize; |
4034 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4051 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
4035 static const int kFullStringRepresentationMask = 0x07; | 4052 static const int kFullStringRepresentationMask = 0x07; |
4053 static const int kStringEncodingMask = 0x4; | |
4036 static const int kExternalTwoByteRepresentationTag = 0x02; | 4054 static const int kExternalTwoByteRepresentationTag = 0x02; |
4055 static const int kExternalAsciiRepresentationTag = 0x06; | |
4037 | 4056 |
4038 static const int kIsolateStateOffset = 0; | 4057 static const int kIsolateStateOffset = 0; |
4039 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4058 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
4040 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4059 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
4041 static const int kUndefinedValueRootIndex = 5; | 4060 static const int kUndefinedValueRootIndex = 5; |
4042 static const int kNullValueRootIndex = 7; | 4061 static const int kNullValueRootIndex = 7; |
4043 static const int kTrueValueRootIndex = 8; | 4062 static const int kTrueValueRootIndex = 8; |
4044 static const int kFalseValueRootIndex = 9; | 4063 static const int kFalseValueRootIndex = 9; |
4045 static const int kEmptySymbolRootIndex = 116; | 4064 static const int kEmptySymbolRootIndex = 116; |
4046 | 4065 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4381 } else { | 4400 } else { |
4382 result = NULL; | 4401 result = NULL; |
4383 } | 4402 } |
4384 #ifdef V8_ENABLE_CHECKS | 4403 #ifdef V8_ENABLE_CHECKS |
4385 VerifyExternalStringResource(result); | 4404 VerifyExternalStringResource(result); |
4386 #endif | 4405 #endif |
4387 return result; | 4406 return result; |
4388 } | 4407 } |
4389 | 4408 |
4390 | 4409 |
4410 String::ExternalStringResourceBase* String::GetExternalStringResourceBase( | |
4411 String::Encoding* encoding_out) const { | |
4412 typedef internal::Object O; | |
4413 typedef internal::Internals I; | |
4414 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); | |
4415 int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; | |
4416 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); | |
4417 ExternalStringResourceBase* resource = NULL; | |
4418 if (type == I::kExternalAsciiRepresentationTag || | |
4419 type == I::kExternalTwoByteRepresentationTag) { | |
4420 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); | |
4421 resource = static_cast<ExternalStringResourceBase*>(value); | |
4422 } | |
4423 #ifdef V8_ENABLE_CHECKS | |
4424 VerifyExternalStringResourceBase(resource, *encoding_out); | |
4425 #endif | |
4426 return resource; | |
4427 } | |
4428 | |
4429 | |
4391 bool Value::IsUndefined() const { | 4430 bool Value::IsUndefined() const { |
4392 #ifdef V8_ENABLE_CHECKS | 4431 #ifdef V8_ENABLE_CHECKS |
4393 return FullIsUndefined(); | 4432 return FullIsUndefined(); |
4394 #else | 4433 #else |
4395 return QuickIsUndefined(); | 4434 return QuickIsUndefined(); |
4396 #endif | 4435 #endif |
4397 } | 4436 } |
4398 | 4437 |
4399 bool Value::QuickIsUndefined() const { | 4438 bool Value::QuickIsUndefined() const { |
4400 typedef internal::Object O; | 4439 typedef internal::Object O; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4610 | 4649 |
4611 | 4650 |
4612 } // namespace v8 | 4651 } // namespace v8 |
4613 | 4652 |
4614 | 4653 |
4615 #undef V8EXPORT | 4654 #undef V8EXPORT |
4616 #undef TYPE_CHECK | 4655 #undef TYPE_CHECK |
4617 | 4656 |
4618 | 4657 |
4619 #endif // V8_H_ | 4658 #endif // V8_H_ |
OLD | NEW |