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 | |
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 | |
1072 // 16-bit character codes. | 1090 // 16-bit character codes. |
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, UTF8 or UTF16) | |
1233 * and possibly a hint on whether the content is ASCII. | |
Erik Corry
2012/08/10 11:28:51
Comment seems wrong as it can't return a UTF8 enco
Yang
2012/08/10 13:14:45
Done.
| |
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); | |
Erik Corry
2012/08/10 11:28:51
No point in making the second argument optional.
Yang
2012/08/10 13:14:45
I see your point here. But then I also feel a cer
| |
1208 | 1260 |
1209 /** Allocates a new string from 16-bit character codes.*/ | 1261 /** Allocates a new string from 16-bit character codes.*/ |
Erik Corry
2012/08/10 11:28:51
Not your error, but:
16-bit character codes -> 16-
Yang
2012/08/10 13:14:45
Done.
| |
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 | |
Erik Corry
2012/08/10 11:28:51
is called ->is called immediately
?
Yang
2012/08/10 13:14:45
Done.
| |
1330 * resource. This is because V8 is unable to handle non-ASCII Latin1-encoded | |
1331 * strings internally at this time. | |
1332 */ | |
1333 V8EXPORT static Local<String> NewExternal( | |
1334 ExternalLatin1StringResource* resource, | |
1335 int encoding = String::LATIN1_ENCODING); | |
1336 | |
1337 /** | |
1338 * Associate an external string resource with this string by transforming it | |
1339 * in place so that existing references to this string in the JavaScript heap | |
1340 * will use the external string resource. The external string resource's | |
1341 * character contents need to be equivalent to this string. | |
1342 * Returns true if the string has been changed to be an external string. | |
1343 * The string is not modified if the operation fails. See NewExternal for | |
1344 * information on the lifetime of the resource. | |
1345 * If the string to be externalized contains non-ASCII characters, use | |
1346 * the two-byte ExternalStringResource instead. | |
1347 */ | |
1348 V8EXPORT bool MakeExternal(ExternalLatin1StringResource* resource); | |
Erik Corry
2012/08/10 11:28:51
Seems like this should be an ExternalASCIIStringRe
Yang
2012/08/10 13:14:45
It's actually intended to be like this. I'm torn
| |
1349 | |
1350 | |
1264 /** | 1351 /** |
1265 * Returns true if this string can be made external. | 1352 * Returns true if this string can be made external. |
1266 */ | 1353 */ |
1267 V8EXPORT bool CanMakeExternal(); | 1354 V8EXPORT bool CanMakeExternal(); |
1268 | 1355 |
1269 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ | 1356 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ |
1270 V8EXPORT static Local<String> NewUndetectable(const char* data, | 1357 V8EXPORT static Local<String> NewUndetectable(const char* data, |
1271 int length = -1); | 1358 int length = kUndefinedLength, |
1359 int encoding = UTF8_ENCODING); | |
1272 | 1360 |
1273 /** Creates an undetectable string from the supplied 16-bit character codes.*/ | 1361 /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
1274 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, | 1362 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, |
1275 int length = -1); | 1363 int length = kUndefinedLength); |
1276 | 1364 |
1277 /** | 1365 /** |
1278 * Converts an object to a UTF-8-encoded character array. Useful if | 1366 * 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 | 1367 * 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) | 1368 * (e.g. due to an exception in the toString() method of the object) |
1281 * then the length() method returns 0 and the * operator returns | 1369 * then the length() method returns 0 and the * operator returns |
1282 * NULL. | 1370 * NULL. |
1283 */ | 1371 */ |
1284 class V8EXPORT Utf8Value { | 1372 class V8EXPORT Utf8Value { |
1285 public: | 1373 public: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1336 private: | 1424 private: |
1337 uint16_t* str_; | 1425 uint16_t* str_; |
1338 int length_; | 1426 int length_; |
1339 | 1427 |
1340 // Disallow copying and assigning. | 1428 // Disallow copying and assigning. |
1341 Value(const Value&); | 1429 Value(const Value&); |
1342 void operator=(const Value&); | 1430 void operator=(const Value&); |
1343 }; | 1431 }; |
1344 | 1432 |
1345 private: | 1433 private: |
1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; | 1434 V8EXPORT void VerifyExternalStringEncoding(int encoding) const; |
1435 V8EXPORT void VerifyExternalStringResourceBase( | |
1436 ExternalStringResourceBase* val) const; | |
1347 V8EXPORT static void CheckCast(v8::Value* obj); | 1437 V8EXPORT static void CheckCast(v8::Value* obj); |
1348 }; | 1438 }; |
1349 | 1439 |
1350 | 1440 |
1351 /** | 1441 /** |
1352 * A JavaScript number value (ECMA-262, 4.3.20) | 1442 * A JavaScript number value (ECMA-262, 4.3.20) |
1353 */ | 1443 */ |
1354 class Number : public Primitive { | 1444 class Number : public Primitive { |
1355 public: | 1445 public: |
1356 V8EXPORT double Value() const; | 1446 V8EXPORT double Value() const; |
(...skipping 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3953 // the implementation of v8. | 4043 // the implementation of v8. |
3954 static const int kHeapObjectMapOffset = 0; | 4044 static const int kHeapObjectMapOffset = 0; |
3955 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4045 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
3956 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4046 static const int kStringResourceOffset = 3 * kApiPointerSize; |
3957 | 4047 |
3958 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4048 static const int kOddballKindOffset = 3 * kApiPointerSize; |
3959 static const int kForeignAddressOffset = kApiPointerSize; | 4049 static const int kForeignAddressOffset = kApiPointerSize; |
3960 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4050 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
3961 static const int kFullStringRepresentationMask = 0x07; | 4051 static const int kFullStringRepresentationMask = 0x07; |
3962 static const int kExternalTwoByteRepresentationTag = 0x02; | 4052 static const int kExternalTwoByteRepresentationTag = 0x02; |
4053 static const int kExternalAsciiRepresentationTag = 0x06; | |
4054 static const int kExternalAsciiDataHintMask = 0x08; | |
4055 static const int kExternalAsciiDataHintTag = 0x08; | |
3963 | 4056 |
3964 static const int kIsolateStateOffset = 0; | 4057 static const int kIsolateStateOffset = 0; |
3965 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4058 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
3966 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4059 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
3967 static const int kUndefinedValueRootIndex = 5; | 4060 static const int kUndefinedValueRootIndex = 5; |
3968 static const int kNullValueRootIndex = 7; | 4061 static const int kNullValueRootIndex = 7; |
3969 static const int kTrueValueRootIndex = 8; | 4062 static const int kTrueValueRootIndex = 8; |
3970 static const int kFalseValueRootIndex = 9; | 4063 static const int kFalseValueRootIndex = 9; |
3971 static const int kEmptySymbolRootIndex = 112; | 4064 static const int kEmptySymbolRootIndex = 112; |
3972 | 4065 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4010 static inline void* GetExternalPointer(internal::Object* obj) { | 4103 static inline void* GetExternalPointer(internal::Object* obj) { |
4011 if (HasSmiTag(obj)) { | 4104 if (HasSmiTag(obj)) { |
4012 return GetExternalPointerFromSmi(obj); | 4105 return GetExternalPointerFromSmi(obj); |
4013 } else if (GetInstanceType(obj) == kForeignType) { | 4106 } else if (GetInstanceType(obj) == kForeignType) { |
4014 return ReadField<void*>(obj, kForeignAddressOffset); | 4107 return ReadField<void*>(obj, kForeignAddressOffset); |
4015 } else { | 4108 } else { |
4016 return NULL; | 4109 return NULL; |
4017 } | 4110 } |
4018 } | 4111 } |
4019 | 4112 |
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) { | 4113 static inline bool IsInitialized(v8::Isolate* isolate) { |
4026 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; | 4114 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
4027 return *reinterpret_cast<int*>(addr) == 1; | 4115 return *reinterpret_cast<int*>(addr) == 1; |
4028 } | 4116 } |
4029 | 4117 |
4030 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { | 4118 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { |
4031 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + | 4119 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
4032 kIsolateEmbedderDataOffset; | 4120 kIsolateEmbedderDataOffset; |
4033 *reinterpret_cast<void**>(addr) = data; | 4121 *reinterpret_cast<void**>(addr) = data; |
4034 } | 4122 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4290 Local<String> String::Empty(Isolate* isolate) { | 4378 Local<String> String::Empty(Isolate* isolate) { |
4291 typedef internal::Object* S; | 4379 typedef internal::Object* S; |
4292 typedef internal::Internals I; | 4380 typedef internal::Internals I; |
4293 if (!I::IsInitialized(isolate)) return Empty(); | 4381 if (!I::IsInitialized(isolate)) return Empty(); |
4294 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); | 4382 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); |
4295 return Local<String>(reinterpret_cast<String*>(slot)); | 4383 return Local<String>(reinterpret_cast<String*>(slot)); |
4296 } | 4384 } |
4297 | 4385 |
4298 | 4386 |
4299 String::ExternalStringResource* String::GetExternalStringResource() const { | 4387 String::ExternalStringResource* String::GetExternalStringResource() const { |
4388 String::ExternalStringResource* result = NULL; | |
4389 if ((GetExternalStringEncoding() & kStringEncodingMask) == | |
Erik Corry
2012/08/10 11:28:51
This calls GetExternalStringEncoding which gets on
Yang
2012/08/10 13:14:45
Done.
| |
4390 UTF16_ENCODING) { | |
4391 result = reinterpret_cast<String::ExternalStringResource*>( | |
4392 GetExternalStringResourceBase()); | |
4393 } | |
4394 return result; | |
4395 } | |
4396 | |
4397 | |
4398 int String::GetExternalStringEncoding() const { | |
4300 typedef internal::Object O; | 4399 typedef internal::Object O; |
4301 typedef internal::Internals I; | 4400 typedef internal::Internals I; |
4302 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); | 4401 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
4303 String::ExternalStringResource* result; | 4402 static const int kRepresentationAndHintMask = |
4304 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { | 4403 I::kFullStringRepresentationMask | I::kExternalAsciiDataHintMask; |
4305 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); | 4404 |
4306 result = reinterpret_cast<String::ExternalStringResource*>(value); | 4405 int encoding; |
4307 } else { | 4406 switch (I::GetInstanceType(obj) & kRepresentationAndHintMask) { |
4308 result = NULL; | 4407 case I::kExternalTwoByteRepresentationTag | I::kExternalAsciiDataHintTag: |
Erik Corry
2012/08/10 11:28:51
Indentation looks wrong here.
Yang
2012/08/10 13:14:45
Done.
| |
4408 encoding = UTF16_ENCODING | STRICT_ASCII_HINT; | |
4409 break; | |
4410 case I::kExternalTwoByteRepresentationTag: | |
4411 encoding = UTF16_ENCODING | NOT_ASCII_HINT; | |
4412 break; | |
4413 case I::kExternalAsciiRepresentationTag: | |
4414 encoding = LATIN1_ENCODING | STRICT_ASCII_HINT; | |
4415 break; | |
4416 default: | |
4417 encoding = INVALID_ENCODING; | |
4418 break; | |
4309 } | 4419 } |
4310 #ifdef V8_ENABLE_CHECKS | 4420 #ifdef V8_ENABLE_CHECKS |
4311 VerifyExternalStringResource(result); | 4421 VerifyExternalStringEncoding(encoding); |
4422 #endif | |
4423 return encoding; | |
4424 } | |
4425 | |
4426 | |
4427 String::ExternalStringResourceBase* String::GetExternalStringResourceBase() | |
4428 const { | |
4429 typedef internal::Object O; | |
4430 typedef internal::Internals I; | |
4431 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); | |
4432 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); | |
4433 ExternalStringResourceBase* result = | |
4434 reinterpret_cast<String::ExternalStringResourceBase*>(value); | |
4435 #ifdef V8_ENABLE_CHECKS | |
4436 VerifyExternalStringResourceBase(result); | |
4312 #endif | 4437 #endif |
4313 return result; | 4438 return result; |
4314 } | 4439 } |
4315 | 4440 |
4316 | 4441 |
4317 bool Value::IsUndefined() const { | 4442 bool Value::IsUndefined() const { |
4318 #ifdef V8_ENABLE_CHECKS | 4443 #ifdef V8_ENABLE_CHECKS |
4319 return FullIsUndefined(); | 4444 return FullIsUndefined(); |
4320 #else | 4445 #else |
4321 return QuickIsUndefined(); | 4446 return QuickIsUndefined(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4536 | 4661 |
4537 | 4662 |
4538 } // namespace v8 | 4663 } // namespace v8 |
4539 | 4664 |
4540 | 4665 |
4541 #undef V8EXPORT | 4666 #undef V8EXPORT |
4542 #undef TYPE_CHECK | 4667 #undef TYPE_CHECK |
4543 | 4668 |
4544 | 4669 |
4545 #endif // V8_H_ | 4670 #endif // V8_H_ |
OLD | NEW |