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 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 * terminator. For WriteUtf8: The number of bytes copied to the buffer | 1062 * terminator. For WriteUtf8: The number of bytes copied to the buffer |
1063 * including the null terminator (if written). | 1063 * including the null terminator (if written). |
1064 */ | 1064 */ |
1065 enum WriteOptions { | 1065 enum WriteOptions { |
1066 NO_OPTIONS = 0, | 1066 NO_OPTIONS = 0, |
1067 HINT_MANY_WRITES_EXPECTED = 1, | 1067 HINT_MANY_WRITES_EXPECTED = 1, |
1068 NO_NULL_TERMINATION = 2, | 1068 NO_NULL_TERMINATION = 2, |
1069 PRESERVE_ASCII_NULL = 4 | 1069 PRESERVE_ASCII_NULL = 4 |
1070 }; | 1070 }; |
1071 | 1071 |
1072 // 16-bit character codes. | 1072 |
| 1073 enum StringEncoding { |
| 1074 INVALID_ENCODING = 0, |
| 1075 UTF8_ENCODING = 1, |
| 1076 LATIN1_ENCODING = 2, |
| 1077 UTF16_ENCODING = 3, |
| 1078 |
| 1079 STRICT_ASCII_HINT = 1 << 16, |
| 1080 NOT_ASCII_HINT = 1 << 17 |
| 1081 }; |
| 1082 |
| 1083 static const int kStringEncodingMask = 3; |
| 1084 static const int kAsciiHintMask = |
| 1085 String::STRICT_ASCII_HINT | String::NOT_ASCII_HINT; |
| 1086 |
| 1087 static const int kUndefinedLength = -1; |
| 1088 |
| 1089 |
| 1090 // 16-bit UTF16 code units. |
1073 V8EXPORT int Write(uint16_t* buffer, | 1091 V8EXPORT int Write(uint16_t* buffer, |
1074 int start = 0, | 1092 int start = 0, |
1075 int length = -1, | 1093 int length = kUndefinedLength, |
1076 int options = NO_OPTIONS) const; | 1094 int options = NO_OPTIONS) const; |
1077 // ASCII characters. | 1095 // ASCII characters. |
1078 V8EXPORT int WriteAscii(char* buffer, | 1096 V8EXPORT int WriteAscii(char* buffer, |
1079 int start = 0, | 1097 int start = 0, |
1080 int length = -1, | 1098 int length = kUndefinedLength, |
1081 int options = NO_OPTIONS) const; | 1099 int options = NO_OPTIONS) const; |
| 1100 // Latin1 characters. |
| 1101 V8EXPORT int WriteLatin1(char* buffer, |
| 1102 int start = 0, |
| 1103 int length = kUndefinedLength, |
| 1104 int options = NO_OPTIONS) const; |
| 1105 |
1082 // UTF-8 encoded characters. | 1106 // UTF-8 encoded characters. |
1083 V8EXPORT int WriteUtf8(char* buffer, | 1107 V8EXPORT int WriteUtf8(char* buffer, |
1084 int length = -1, | 1108 int length = kUndefinedLength, |
1085 int* nchars_ref = NULL, | 1109 int* nchars_ref = NULL, |
1086 int options = NO_OPTIONS) const; | 1110 int options = NO_OPTIONS) const; |
1087 | 1111 |
1088 /** | 1112 /** |
1089 * A zero length string. | 1113 * A zero length string. |
1090 */ | 1114 */ |
1091 V8EXPORT static v8::Local<v8::String> Empty(); | 1115 V8EXPORT static v8::Local<v8::String> Empty(); |
1092 inline static v8::Local<v8::String> Empty(Isolate* isolate); | 1116 inline static v8::Local<v8::String> Empty(Isolate* isolate); |
1093 | 1117 |
1094 /** | 1118 /** |
(...skipping 20 matching lines...) Expand all Loading... |
1115 * control how allocated external string resources are disposed. | 1139 * control how allocated external string resources are disposed. |
1116 */ | 1140 */ |
1117 virtual void Dispose() { delete this; } | 1141 virtual void Dispose() { delete this; } |
1118 | 1142 |
1119 private: | 1143 private: |
1120 // Disallow copying and assigning. | 1144 // Disallow copying and assigning. |
1121 ExternalStringResourceBase(const ExternalStringResourceBase&); | 1145 ExternalStringResourceBase(const ExternalStringResourceBase&); |
1122 void operator=(const ExternalStringResourceBase&); | 1146 void operator=(const ExternalStringResourceBase&); |
1123 | 1147 |
1124 friend class v8::internal::Heap; | 1148 friend class v8::internal::Heap; |
| 1149 friend class v8::String; |
1125 }; | 1150 }; |
1126 | 1151 |
1127 /** | 1152 /** |
1128 * An ExternalStringResource is a wrapper around a two-byte string | 1153 * An ExternalStringResource is a wrapper around a two-byte string |
1129 * buffer that resides outside V8's heap. Implement an | 1154 * buffer that resides outside V8's heap. Implement an |
1130 * ExternalStringResource to manage the life cycle of the underlying | 1155 * ExternalStringResource to manage the life cycle of the underlying |
1131 * buffer. Note that the string data must be immutable. | 1156 * buffer. Note that the string data must be immutable. |
1132 */ | 1157 */ |
1133 class V8EXPORT ExternalStringResource | 1158 class V8EXPORT ExternalStringResource |
1134 : public ExternalStringResourceBase { | 1159 : public ExternalStringResourceBase { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 virtual ~ExternalAsciiStringResource() {} | 1199 virtual ~ExternalAsciiStringResource() {} |
1175 /** The string data from the underlying buffer.*/ | 1200 /** The string data from the underlying buffer.*/ |
1176 virtual const char* data() const = 0; | 1201 virtual const char* data() const = 0; |
1177 /** The number of ASCII characters in the string.*/ | 1202 /** The number of ASCII characters in the string.*/ |
1178 virtual size_t length() const = 0; | 1203 virtual size_t length() const = 0; |
1179 protected: | 1204 protected: |
1180 ExternalAsciiStringResource() {} | 1205 ExternalAsciiStringResource() {} |
1181 }; | 1206 }; |
1182 | 1207 |
1183 /** | 1208 /** |
| 1209 * An ExternalLatin1StringResource is a wrapper around an Latin1-encoded |
| 1210 * string buffer that resides outside V8's heap. For usage in V8, Latin1 |
| 1211 * strings are converted to ASCII or two-byte string depending on whether |
| 1212 * the string contains non-ASCII characters. |
| 1213 */ |
| 1214 class V8EXPORT ExternalLatin1StringResource |
| 1215 : public ExternalAsciiStringResource { |
| 1216 }; |
| 1217 |
| 1218 /** |
1184 * Get the ExternalStringResource for an external string. Returns | 1219 * Get the ExternalStringResource for an external string. Returns |
1185 * NULL if IsExternal() doesn't return true. | 1220 * NULL if IsExternal() doesn't return true. |
1186 */ | 1221 */ |
1187 inline ExternalStringResource* GetExternalStringResource() const; | 1222 inline ExternalStringResource* GetExternalStringResource() const; |
1188 | 1223 |
1189 /** | 1224 /** |
1190 * Get the ExternalAsciiStringResource for an external ASCII string. | 1225 * Get the ExternalAsciiStringResource for an external ASCII string. |
1191 * Returns NULL if IsExternalAscii() doesn't return true. | 1226 * Returns NULL if IsExternalAscii() doesn't return true. |
1192 */ | 1227 */ |
1193 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() | 1228 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() |
1194 const; | 1229 const; |
1195 | 1230 |
| 1231 /** |
| 1232 * If the string is external, return the its encoding (Latin1 or UTF16) |
| 1233 * and possibly a hint on whether the content is ASCII. |
| 1234 * Return String::INVALID_ENCODING otherwise. |
| 1235 */ |
| 1236 inline int GetExternalStringEncoding() const; |
| 1237 |
| 1238 |
| 1239 /** |
| 1240 * Return the resource of the external string regardless of encoding. |
| 1241 * Call this only after having made sure that the string is indeed external! |
| 1242 */ |
| 1243 inline ExternalStringResourceBase* GetExternalStringResourceBase() const; |
| 1244 |
1196 static inline String* Cast(v8::Value* obj); | 1245 static inline String* Cast(v8::Value* obj); |
1197 | 1246 |
1198 /** | 1247 /** |
1199 * Allocates a new string from either UTF-8 encoded or ASCII data. | 1248 * Allocates a new string from either UTF-8-, Latin1-encoded data. |
1200 * The second parameter 'length' gives the buffer length. | 1249 * The second parameter 'length' gives the buffer length. If the data is |
1201 * If the data is UTF-8 encoded, the caller must | 1250 * UTF-8 encoded, the caller must be careful to supply the length parameter. |
1202 * be careful to supply the length parameter. | 1251 * If it is not given, the function calls 'strlen' to determine the buffer |
1203 * If it is not given, the function calls | 1252 * length, it might be wrong if 'data' contains a null character. |
1204 * 'strlen' to determine the buffer length, it might be | 1253 * The third parameter specifies the encoding, which may include an hint |
1205 * wrong if 'data' contains a null character. | 1254 * whether the string contains ASCII characters. In case of Latin1, the |
| 1255 * appropriate internal representation (UTF16 or ASCII) is chosen. |
1206 */ | 1256 */ |
1207 V8EXPORT static Local<String> New(const char* data, int length = -1); | 1257 V8EXPORT static Local<String> New(const char* data, |
| 1258 int length = kUndefinedLength, |
| 1259 int encoding = UTF8_ENCODING); |
1208 | 1260 |
1209 /** Allocates a new string from 16-bit character codes.*/ | 1261 /** Allocates a new string from 16-bit UTF16 code units.*/ |
1210 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); | 1262 V8EXPORT static Local<String> New(const uint16_t* data, |
| 1263 int length = kUndefinedLength); |
1211 | 1264 |
1212 /** Creates a symbol. Returns one if it exists already.*/ | 1265 /** Creates a symbol. Returns one if it exists already.*/ |
1213 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); | 1266 V8EXPORT static Local<String> NewSymbol(const char* data, |
| 1267 int length = kUndefinedLength, |
| 1268 int encoding = UTF8_ENCODING); |
1214 | 1269 |
1215 /** | 1270 /** |
1216 * Creates a new string by concatenating the left and the right strings | 1271 * Creates a new string by concatenating the left and the right strings |
1217 * passed in as parameters. | 1272 * passed in as parameters. |
1218 */ | 1273 */ |
1219 V8EXPORT static Local<String> Concat(Handle<String> left, | 1274 V8EXPORT static Local<String> Concat(Handle<String> left, |
1220 Handle<String> right); | 1275 Handle<String> right); |
1221 | 1276 |
1222 /** | 1277 /** |
1223 * Creates a new external string using the data defined in the given | 1278 * Creates a new external string using the data defined in the given |
(...skipping 16 matching lines...) Expand all Loading... |
1240 */ | 1295 */ |
1241 V8EXPORT bool MakeExternal(ExternalStringResource* resource); | 1296 V8EXPORT bool MakeExternal(ExternalStringResource* resource); |
1242 | 1297 |
1243 /** | 1298 /** |
1244 * Creates a new external string using the ASCII data defined in the given | 1299 * Creates a new external string using the ASCII data defined in the given |
1245 * resource. When the external string is no longer live on V8's heap the | 1300 * resource. When the external string is no longer live on V8's heap the |
1246 * resource will be disposed by calling its Dispose method. The caller of | 1301 * resource will be disposed by calling its Dispose method. The caller of |
1247 * this function should not otherwise delete or modify the resource. Neither | 1302 * this function should not otherwise delete or modify the resource. Neither |
1248 * should the underlying buffer be deallocated or modified except through the | 1303 * should the underlying buffer be deallocated or modified except through the |
1249 * destructor of the external string resource. | 1304 * destructor of the external string resource. |
1250 */ V8EXPORT static Local<String> NewExternal( | 1305 */ |
| 1306 V8EXPORT static Local<String> NewExternal( |
1251 ExternalAsciiStringResource* resource); | 1307 ExternalAsciiStringResource* resource); |
1252 | 1308 |
1253 /** | 1309 /** |
1254 * Associate an external string resource with this string by transforming it | 1310 * Associate an external string resource with this string by transforming it |
1255 * in place so that existing references to this string in the JavaScript heap | 1311 * in place so that existing references to this string in the JavaScript heap |
1256 * will use the external string resource. The external string resource's | 1312 * will use the external string resource. The external string resource's |
1257 * character contents need to be equivalent to this string. | 1313 * character contents need to be equivalent to this string. |
1258 * Returns true if the string has been changed to be an external string. | 1314 * Returns true if the string has been changed to be an external string. |
1259 * The string is not modified if the operation fails. See NewExternal for | 1315 * The string is not modified if the operation fails. See NewExternal for |
1260 * information on the lifetime of the resource. | 1316 * information on the lifetime of the resource. |
1261 */ | 1317 */ |
1262 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); | 1318 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); |
1263 | 1319 |
| 1320 |
| 1321 /** |
| 1322 * Creates a new external string using the Latin1-encoded data defined in the |
| 1323 * given resource. When the external string is no longer live on V8's heap |
| 1324 * the resource will be disposed by calling its Dispose method. The caller of |
| 1325 * this function should not otherwise delete or modify the resource. Neither |
| 1326 * should the underlying buffer be deallocated or modified except through the |
| 1327 * destructor of the external string resource. |
| 1328 * If the data contains non-ASCII character, the string is created as new |
| 1329 * string object on the V8 heap and the Dispose method is called on the |
| 1330 * resource immediately. This is because V8 is currently unable to handle |
| 1331 * non-ASCII Latin1-encoded strings internally. |
| 1332 */ |
| 1333 V8EXPORT static Local<String> NewExternal( |
| 1334 ExternalLatin1StringResource* resource, |
| 1335 int encoding = String::LATIN1_ENCODING); |
| 1336 |
| 1337 |
1264 /** | 1338 /** |
1265 * Returns true if this string can be made external. | 1339 * Returns true if this string can be made external. |
1266 */ | 1340 */ |
1267 V8EXPORT bool CanMakeExternal(); | 1341 V8EXPORT bool CanMakeExternal(); |
1268 | 1342 |
1269 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ | 1343 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ |
1270 V8EXPORT static Local<String> NewUndetectable(const char* data, | 1344 V8EXPORT static Local<String> NewUndetectable(const char* data, |
1271 int length = -1); | 1345 int length = kUndefinedLength, |
| 1346 int encoding = UTF8_ENCODING); |
1272 | 1347 |
1273 /** Creates an undetectable string from the supplied 16-bit character codes.*/ | 1348 /** Creates an undetectable string from the supplied 16-bit UTF16 code units. |
| 1349 */ |
1274 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, | 1350 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, |
1275 int length = -1); | 1351 int length = kUndefinedLength); |
1276 | 1352 |
1277 /** | 1353 /** |
1278 * Converts an object to a UTF-8-encoded character array. Useful if | 1354 * Converts an object to a UTF-8-encoded character array. Useful if |
1279 * you want to print the object. If conversion to a string fails | 1355 * you want to print the object. If conversion to a string fails |
1280 * (e.g. due to an exception in the toString() method of the object) | 1356 * (e.g. due to an exception in the toString() method of the object) |
1281 * then the length() method returns 0 and the * operator returns | 1357 * then the length() method returns 0 and the * operator returns |
1282 * NULL. | 1358 * NULL. |
1283 */ | 1359 */ |
1284 class V8EXPORT Utf8Value { | 1360 class V8EXPORT Utf8Value { |
1285 public: | 1361 public: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 private: | 1412 private: |
1337 uint16_t* str_; | 1413 uint16_t* str_; |
1338 int length_; | 1414 int length_; |
1339 | 1415 |
1340 // Disallow copying and assigning. | 1416 // Disallow copying and assigning. |
1341 Value(const Value&); | 1417 Value(const Value&); |
1342 void operator=(const Value&); | 1418 void operator=(const Value&); |
1343 }; | 1419 }; |
1344 | 1420 |
1345 private: | 1421 private: |
1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; | 1422 V8EXPORT void VerifyExternalStringEncoding(int encoding) const; |
| 1423 V8EXPORT void VerifyExternalStringResourceBase( |
| 1424 ExternalStringResourceBase* val) const; |
1347 V8EXPORT static void CheckCast(v8::Value* obj); | 1425 V8EXPORT static void CheckCast(v8::Value* obj); |
1348 }; | 1426 }; |
1349 | 1427 |
1350 | 1428 |
1351 /** | 1429 /** |
1352 * A JavaScript number value (ECMA-262, 4.3.20) | 1430 * A JavaScript number value (ECMA-262, 4.3.20) |
1353 */ | 1431 */ |
1354 class Number : public Primitive { | 1432 class Number : public Primitive { |
1355 public: | 1433 public: |
1356 V8EXPORT double Value() const; | 1434 V8EXPORT double Value() const; |
(...skipping 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3953 // the implementation of v8. | 4031 // the implementation of v8. |
3954 static const int kHeapObjectMapOffset = 0; | 4032 static const int kHeapObjectMapOffset = 0; |
3955 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4033 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
3956 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4034 static const int kStringResourceOffset = 3 * kApiPointerSize; |
3957 | 4035 |
3958 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4036 static const int kOddballKindOffset = 3 * kApiPointerSize; |
3959 static const int kForeignAddressOffset = kApiPointerSize; | 4037 static const int kForeignAddressOffset = kApiPointerSize; |
3960 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4038 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
3961 static const int kFullStringRepresentationMask = 0x07; | 4039 static const int kFullStringRepresentationMask = 0x07; |
3962 static const int kExternalTwoByteRepresentationTag = 0x02; | 4040 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 4041 static const int kExternalAsciiRepresentationTag = 0x06; |
| 4042 static const int kExternalAsciiDataHintMask = 0x08; |
| 4043 static const int kExternalAsciiDataHintTag = 0x08; |
3963 | 4044 |
3964 static const int kIsolateStateOffset = 0; | 4045 static const int kIsolateStateOffset = 0; |
3965 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4046 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
3966 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4047 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
3967 static const int kUndefinedValueRootIndex = 5; | 4048 static const int kUndefinedValueRootIndex = 5; |
3968 static const int kNullValueRootIndex = 7; | 4049 static const int kNullValueRootIndex = 7; |
3969 static const int kTrueValueRootIndex = 8; | 4050 static const int kTrueValueRootIndex = 8; |
3970 static const int kFalseValueRootIndex = 9; | 4051 static const int kFalseValueRootIndex = 9; |
3971 static const int kEmptySymbolRootIndex = 112; | 4052 static const int kEmptySymbolRootIndex = 112; |
3972 | 4053 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4010 static inline void* GetExternalPointer(internal::Object* obj) { | 4091 static inline void* GetExternalPointer(internal::Object* obj) { |
4011 if (HasSmiTag(obj)) { | 4092 if (HasSmiTag(obj)) { |
4012 return GetExternalPointerFromSmi(obj); | 4093 return GetExternalPointerFromSmi(obj); |
4013 } else if (GetInstanceType(obj) == kForeignType) { | 4094 } else if (GetInstanceType(obj) == kForeignType) { |
4014 return ReadField<void*>(obj, kForeignAddressOffset); | 4095 return ReadField<void*>(obj, kForeignAddressOffset); |
4015 } else { | 4096 } else { |
4016 return NULL; | 4097 return NULL; |
4017 } | 4098 } |
4018 } | 4099 } |
4019 | 4100 |
4020 static inline bool IsExternalTwoByteString(int instance_type) { | |
4021 int representation = (instance_type & kFullStringRepresentationMask); | |
4022 return representation == kExternalTwoByteRepresentationTag; | |
4023 } | |
4024 | |
4025 static inline bool IsInitialized(v8::Isolate* isolate) { | 4101 static inline bool IsInitialized(v8::Isolate* isolate) { |
4026 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; | 4102 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
4027 return *reinterpret_cast<int*>(addr) == 1; | 4103 return *reinterpret_cast<int*>(addr) == 1; |
4028 } | 4104 } |
4029 | 4105 |
4030 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { | 4106 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { |
4031 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + | 4107 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
4032 kIsolateEmbedderDataOffset; | 4108 kIsolateEmbedderDataOffset; |
4033 *reinterpret_cast<void**>(addr) = data; | 4109 *reinterpret_cast<void**>(addr) = data; |
4034 } | 4110 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4292 typedef internal::Internals I; | 4368 typedef internal::Internals I; |
4293 if (!I::IsInitialized(isolate)) return Empty(); | 4369 if (!I::IsInitialized(isolate)) return Empty(); |
4294 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); | 4370 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); |
4295 return Local<String>(reinterpret_cast<String*>(slot)); | 4371 return Local<String>(reinterpret_cast<String*>(slot)); |
4296 } | 4372 } |
4297 | 4373 |
4298 | 4374 |
4299 String::ExternalStringResource* String::GetExternalStringResource() const { | 4375 String::ExternalStringResource* String::GetExternalStringResource() const { |
4300 typedef internal::Object O; | 4376 typedef internal::Object O; |
4301 typedef internal::Internals I; | 4377 typedef internal::Internals I; |
| 4378 String::ExternalStringResource* result = NULL; |
4302 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); | 4379 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
4303 String::ExternalStringResource* result; | 4380 if ((I::GetInstanceType(obj) & I::kFullStringRepresentationMask) == |
4304 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { | 4381 I::kExternalTwoByteRepresentationTag) { |
4305 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); | 4382 result = reinterpret_cast<String::ExternalStringResource*>( |
4306 result = reinterpret_cast<String::ExternalStringResource*>(value); | 4383 GetExternalStringResourceBase()); |
4307 } else { | 4384 } |
4308 result = NULL; | 4385 return result; |
| 4386 } |
| 4387 |
| 4388 |
| 4389 int String::GetExternalStringEncoding() const { |
| 4390 typedef internal::Object O; |
| 4391 typedef internal::Internals I; |
| 4392 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 4393 static const int kRepresentationAndHintMask = |
| 4394 I::kFullStringRepresentationMask | I::kExternalAsciiDataHintMask; |
| 4395 |
| 4396 int encoding; |
| 4397 switch (I::GetInstanceType(obj) & kRepresentationAndHintMask) { |
| 4398 case I::kExternalTwoByteRepresentationTag | I::kExternalAsciiDataHintTag: |
| 4399 encoding = UTF16_ENCODING | STRICT_ASCII_HINT; |
| 4400 break; |
| 4401 case I::kExternalTwoByteRepresentationTag: |
| 4402 encoding = UTF16_ENCODING | NOT_ASCII_HINT; |
| 4403 break; |
| 4404 case I::kExternalAsciiRepresentationTag: |
| 4405 encoding = LATIN1_ENCODING | STRICT_ASCII_HINT; |
| 4406 break; |
| 4407 default: |
| 4408 encoding = INVALID_ENCODING; |
| 4409 break; |
4309 } | 4410 } |
4310 #ifdef V8_ENABLE_CHECKS | 4411 #ifdef V8_ENABLE_CHECKS |
4311 VerifyExternalStringResource(result); | 4412 VerifyExternalStringEncoding(encoding); |
| 4413 #endif |
| 4414 return encoding; |
| 4415 } |
| 4416 |
| 4417 |
| 4418 String::ExternalStringResourceBase* String::GetExternalStringResourceBase() |
| 4419 const { |
| 4420 typedef internal::Object O; |
| 4421 typedef internal::Internals I; |
| 4422 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| 4423 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| 4424 ExternalStringResourceBase* result = |
| 4425 reinterpret_cast<String::ExternalStringResourceBase*>(value); |
| 4426 #ifdef V8_ENABLE_CHECKS |
| 4427 VerifyExternalStringResourceBase(result); |
4312 #endif | 4428 #endif |
4313 return result; | 4429 return result; |
4314 } | 4430 } |
4315 | 4431 |
4316 | 4432 |
4317 bool Value::IsUndefined() const { | 4433 bool Value::IsUndefined() const { |
4318 #ifdef V8_ENABLE_CHECKS | 4434 #ifdef V8_ENABLE_CHECKS |
4319 return FullIsUndefined(); | 4435 return FullIsUndefined(); |
4320 #else | 4436 #else |
4321 return QuickIsUndefined(); | 4437 return QuickIsUndefined(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4536 | 4652 |
4537 | 4653 |
4538 } // namespace v8 | 4654 } // namespace v8 |
4539 | 4655 |
4540 | 4656 |
4541 #undef V8EXPORT | 4657 #undef V8EXPORT |
4542 #undef TYPE_CHECK | 4658 #undef TYPE_CHECK |
4543 | 4659 |
4544 | 4660 |
4545 #endif // V8_H_ | 4661 #endif // V8_H_ |
OLD | NEW |