Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: include/v8.h

Issue 10905075: Revert r12430, r12432, r12433 (basic support for Latin1). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 1072 // 16-bit character codes.
1073 enum StringEncoding {
1074 INVALID_ENCODING = 0,
1075 UTF_8_ENCODING = 1,
1076 LATIN1_ENCODING = 2,
1077 UTF_16_ENCODING = 3,
1078
1079 ASCII_HINT = 1 << 16,
1080 NOT_ASCII_HINT = 1 << 17
1081 };
1082
1083 static const int kStringEncodingMask = 3;
1084 static const int kAsciiHintMask = String::ASCII_HINT | String::NOT_ASCII_HINT;
1085
1086 static const int kUndefinedLength = -1;
1087
1088
1089 // 16-bit UTF16 code units. PRESERVE_ASCII_NULL is not supported as option,
1090 // null-characters are never converted to spaces.
1091 V8EXPORT int Write(uint16_t* buffer, 1073 V8EXPORT int Write(uint16_t* buffer,
1092 int start = 0, 1074 int start = 0,
1093 int length = kUndefinedLength, 1075 int length = -1,
1094 int options = NO_OPTIONS) const; 1076 int options = NO_OPTIONS) const;
1095 1077 // ASCII characters.
1096 // ASCII characters. Null-characters are converted to spaces unless
1097 // PRESERVE_ASCII_NULL is set as option.
1098 V8EXPORT int WriteAscii(char* buffer, 1078 V8EXPORT int WriteAscii(char* buffer,
1099 int start = 0, 1079 int start = 0,
1100 int length = kUndefinedLength, 1080 int length = -1,
1101 int options = NO_OPTIONS) const; 1081 int options = NO_OPTIONS) const;
1102 1082 // UTF-8 encoded characters.
1103 // Latin1 characters. PRESERVE_ASCII_NULL is not supported as option,
1104 // null-characters are never converted to spaces.
1105 V8EXPORT int WriteLatin1(char* buffer,
1106 int start = 0,
1107 int length = kUndefinedLength,
1108 int options = NO_OPTIONS) const;
1109
1110 // UTF-8 encoded characters. PRESERVE_ASCII_NULL is not supported as option,
1111 // null-characters are never converted to spaces.
1112 V8EXPORT int WriteUtf8(char* buffer, 1083 V8EXPORT int WriteUtf8(char* buffer,
1113 int length = kUndefinedLength, 1084 int length = -1,
1114 int* nchars_ref = NULL, 1085 int* nchars_ref = NULL,
1115 int options = NO_OPTIONS) const; 1086 int options = NO_OPTIONS) const;
1116 1087
1117 /** 1088 /**
1118 * A zero length string. 1089 * A zero length string.
1119 */ 1090 */
1120 V8EXPORT static v8::Local<v8::String> Empty(); 1091 V8EXPORT static v8::Local<v8::String> Empty();
1121 inline static v8::Local<v8::String> Empty(Isolate* isolate); 1092 inline static v8::Local<v8::String> Empty(Isolate* isolate);
1122 1093
1123 /** 1094 /**
(...skipping 20 matching lines...) Expand all
1144 * control how allocated external string resources are disposed. 1115 * control how allocated external string resources are disposed.
1145 */ 1116 */
1146 virtual void Dispose() { delete this; } 1117 virtual void Dispose() { delete this; }
1147 1118
1148 private: 1119 private:
1149 // Disallow copying and assigning. 1120 // Disallow copying and assigning.
1150 ExternalStringResourceBase(const ExternalStringResourceBase&); 1121 ExternalStringResourceBase(const ExternalStringResourceBase&);
1151 void operator=(const ExternalStringResourceBase&); 1122 void operator=(const ExternalStringResourceBase&);
1152 1123
1153 friend class v8::internal::Heap; 1124 friend class v8::internal::Heap;
1154 friend class v8::String;
1155 }; 1125 };
1156 1126
1157 /** 1127 /**
1158 * An ExternalStringResource is a wrapper around a two-byte string 1128 * An ExternalStringResource is a wrapper around a two-byte string
1159 * buffer that resides outside V8's heap. Implement an 1129 * buffer that resides outside V8's heap. Implement an
1160 * ExternalStringResource to manage the life cycle of the underlying 1130 * ExternalStringResource to manage the life cycle of the underlying
1161 * buffer. Note that the string data must be immutable. 1131 * buffer. Note that the string data must be immutable.
1162 */ 1132 */
1163 class V8EXPORT ExternalStringResource 1133 class V8EXPORT ExternalStringResource
1164 : public ExternalStringResourceBase { 1134 : public ExternalStringResourceBase {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 virtual ~ExternalAsciiStringResource() {} 1174 virtual ~ExternalAsciiStringResource() {}
1205 /** The string data from the underlying buffer.*/ 1175 /** The string data from the underlying buffer.*/
1206 virtual const char* data() const = 0; 1176 virtual const char* data() const = 0;
1207 /** The number of ASCII characters in the string.*/ 1177 /** The number of ASCII characters in the string.*/
1208 virtual size_t length() const = 0; 1178 virtual size_t length() const = 0;
1209 protected: 1179 protected:
1210 ExternalAsciiStringResource() {} 1180 ExternalAsciiStringResource() {}
1211 }; 1181 };
1212 1182
1213 /** 1183 /**
1214 * An ExternalLatin1StringResource is a wrapper around an Latin1-encoded
1215 * string buffer that resides outside V8's heap. For usage in V8, a Latin1
1216 * string is converted to ASCII or two-byte string depending on whether
1217 * it contains non-ASCII characters.
1218 */
1219 class V8EXPORT ExternalLatin1StringResource
1220 : public ExternalAsciiStringResource {
1221 };
1222
1223 /**
1224 * Get the ExternalStringResource for an external string. Returns 1184 * Get the ExternalStringResource for an external string. Returns
1225 * NULL if IsExternal() doesn't return true. 1185 * NULL if IsExternal() doesn't return true.
1226 */ 1186 */
1227 inline ExternalStringResource* GetExternalStringResource() const; 1187 inline ExternalStringResource* GetExternalStringResource() const;
1228 1188
1229 /** 1189 /**
1230 * Get the ExternalAsciiStringResource for an external ASCII string. 1190 * Get the ExternalAsciiStringResource for an external ASCII string.
1231 * Returns NULL if IsExternalAscii() doesn't return true. 1191 * Returns NULL if IsExternalAscii() doesn't return true.
1232 */ 1192 */
1233 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() 1193 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource()
1234 const; 1194 const;
1235 1195
1236 /**
1237 * If the string is external, return its encoding (Latin1 or UTF16)
1238 * and possibly a hint on whether the content is ASCII.
1239 * Return String::INVALID_ENCODING otherwise.
1240 */
1241 inline int GetExternalStringEncoding() const;
1242
1243
1244 /**
1245 * Return the resource of the external string regardless of encoding.
1246 * Call this only after having made sure that the string is indeed external!
1247 */
1248 inline ExternalStringResourceBase* GetExternalStringResourceBase() const;
1249
1250 static inline String* Cast(v8::Value* obj); 1196 static inline String* Cast(v8::Value* obj);
1251 1197
1252 /** 1198 /**
1253 * Allocates a new string from either UTF-8 or Latin1-encoded data. 1199 * Allocates a new string from either UTF-8 encoded or ASCII data.
1254 * The second parameter 'length' gives the buffer length. If the data may 1200 * The second parameter 'length' gives the buffer length.
1255 * contain zero bytes, the caller must be careful to supply the length 1201 * If the data is UTF-8 encoded, the caller must
1256 * parameter. If it is not given, the function calls 'strlen' to determine 1202 * be careful to supply the length parameter.
1257 * the buffer length, it might be wrong if 'data' contains a null character. 1203 * If it is not given, the function calls
1258 * The third parameter specifies the encoding, which may include an hint 1204 * 'strlen' to determine the buffer length, it might be
1259 * whether the string contains ASCII characters. In the case of Latin1, the 1205 * wrong if 'data' contains a null character.
1260 * appropriate internal representation (UTF16 or ASCII) is chosen.
1261 */ 1206 */
1262 V8EXPORT static Local<String> New(const char* data, 1207 V8EXPORT static Local<String> New(const char* data, int length = -1);
1263 int length = kUndefinedLength,
1264 int encoding = UTF_8_ENCODING);
1265 1208
1266 /** Allocates a new string from 16-bit UTF-16 code units.*/ 1209 /** Allocates a new string from 16-bit character codes.*/
1267 V8EXPORT static Local<String> New(const uint16_t* data, 1210 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
1268 int length = kUndefinedLength);
1269 1211
1270 /** Creates a symbol. Returns one if it exists already.*/ 1212 /** Creates a symbol. Returns one if it exists already.*/
1271 V8EXPORT static Local<String> NewSymbol(const char* data, 1213 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
1272 int length = kUndefinedLength,
1273 int encoding = UTF_8_ENCODING);
1274 1214
1275 /** 1215 /**
1276 * Creates a new string by concatenating the left and the right strings 1216 * Creates a new string by concatenating the left and the right strings
1277 * passed in as parameters. 1217 * passed in as parameters.
1278 */ 1218 */
1279 V8EXPORT static Local<String> Concat(Handle<String> left, 1219 V8EXPORT static Local<String> Concat(Handle<String> left,
1280 Handle<String> right); 1220 Handle<String> right);
1281 1221
1282 /** 1222 /**
1283 * Creates a new external string using the data defined in the given 1223 * Creates a new external string using the data defined in the given
(...skipping 16 matching lines...) Expand all
1300 */ 1240 */
1301 V8EXPORT bool MakeExternal(ExternalStringResource* resource); 1241 V8EXPORT bool MakeExternal(ExternalStringResource* resource);
1302 1242
1303 /** 1243 /**
1304 * Creates a new external string using the ASCII data defined in the given 1244 * Creates a new external string using the ASCII data defined in the given
1305 * resource. When the external string is no longer live on V8's heap the 1245 * resource. When the external string is no longer live on V8's heap the
1306 * resource will be disposed by calling its Dispose method. The caller of 1246 * resource will be disposed by calling its Dispose method. The caller of
1307 * this function should not otherwise delete or modify the resource. Neither 1247 * this function should not otherwise delete or modify the resource. Neither
1308 * should the underlying buffer be deallocated or modified except through the 1248 * should the underlying buffer be deallocated or modified except through the
1309 * destructor of the external string resource. 1249 * destructor of the external string resource.
1310 */ 1250 */ V8EXPORT static Local<String> NewExternal(
1311 V8EXPORT static Local<String> NewExternal(
1312 ExternalAsciiStringResource* resource); 1251 ExternalAsciiStringResource* resource);
1313 1252
1314 /** 1253 /**
1315 * Associate an external string resource with this string by transforming it 1254 * Associate an external string resource with this string by transforming it
1316 * in place so that existing references to this string in the JavaScript heap 1255 * in place so that existing references to this string in the JavaScript heap
1317 * will use the external string resource. The external string resource's 1256 * will use the external string resource. The external string resource's
1318 * character contents need to be equivalent to this string. 1257 * character contents need to be equivalent to this string.
1319 * Returns true if the string has been changed to be an external string. 1258 * Returns true if the string has been changed to be an external string.
1320 * The string is not modified if the operation fails. See NewExternal for 1259 * The string is not modified if the operation fails. See NewExternal for
1321 * information on the lifetime of the resource. 1260 * information on the lifetime of the resource.
1322 */ 1261 */
1323 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); 1262 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
1324 1263
1325
1326 /**
1327 * Creates a new external string using the Latin1-encoded data defined in the
1328 * given resource. When the external string is no longer live on V8's heap
1329 * the resource will be disposed by calling its Dispose method. The caller of
1330 * this function should not otherwise delete or modify the resource. Neither
1331 * should the underlying buffer be deallocated or modified except through the
1332 * destructor of the external string resource.
1333 * If the data contains a non-ASCII character, the string is created as a new
1334 * string object on the V8 heap and the Dispose method is called on the
1335 * resource immediately. This is because V8 is unable to handle non-ASCII
1336 * Latin1-encoded strings internally.
1337 */
1338 V8EXPORT static Local<String> NewExternal(
1339 ExternalLatin1StringResource* resource,
1340 int encoding = String::LATIN1_ENCODING);
1341
1342
1343 /** 1264 /**
1344 * Returns true if this string can be made external. 1265 * Returns true if this string can be made external.
1345 */ 1266 */
1346 V8EXPORT bool CanMakeExternal(); 1267 V8EXPORT bool CanMakeExternal();
1347 1268
1348 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ 1269 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
1349 V8EXPORT static Local<String> NewUndetectable(const char* data, 1270 V8EXPORT static Local<String> NewUndetectable(const char* data,
1350 int length = kUndefinedLength, 1271 int length = -1);
1351 int encoding = UTF_8_ENCODING);
1352 1272
1353 /** Creates an undetectable string from the supplied 16-bit UTF16 code units. 1273 /** Creates an undetectable string from the supplied 16-bit character codes.*/
1354 */
1355 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, 1274 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
1356 int length = kUndefinedLength); 1275 int length = -1);
1357 1276
1358 /** 1277 /**
1359 * Converts an object to a UTF-8-encoded character array. Useful if 1278 * Converts an object to a UTF-8-encoded character array. Useful if
1360 * you want to print the object. If conversion to a string fails 1279 * you want to print the object. If conversion to a string fails
1361 * (e.g. due to an exception in the toString() method of the object) 1280 * (e.g. due to an exception in the toString() method of the object)
1362 * then the length() method returns 0 and the * operator returns 1281 * then the length() method returns 0 and the * operator returns
1363 * NULL. 1282 * NULL.
1364 */ 1283 */
1365 class V8EXPORT Utf8Value { 1284 class V8EXPORT Utf8Value {
1366 public: 1285 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 private: 1336 private:
1418 uint16_t* str_; 1337 uint16_t* str_;
1419 int length_; 1338 int length_;
1420 1339
1421 // Disallow copying and assigning. 1340 // Disallow copying and assigning.
1422 Value(const Value&); 1341 Value(const Value&);
1423 void operator=(const Value&); 1342 void operator=(const Value&);
1424 }; 1343 };
1425 1344
1426 private: 1345 private:
1427 V8EXPORT void VerifyExternalStringEncoding(int encoding) const; 1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
1428 V8EXPORT void VerifyExternalStringResourceBase(
1429 ExternalStringResourceBase* val) const;
1430 V8EXPORT static void CheckCast(v8::Value* obj); 1347 V8EXPORT static void CheckCast(v8::Value* obj);
1431 }; 1348 };
1432 1349
1433 1350
1434 /** 1351 /**
1435 * A JavaScript number value (ECMA-262, 4.3.20) 1352 * A JavaScript number value (ECMA-262, 4.3.20)
1436 */ 1353 */
1437 class Number : public Primitive { 1354 class Number : public Primitive {
1438 public: 1355 public:
1439 V8EXPORT double Value() const; 1356 V8EXPORT double Value() const;
(...skipping 2670 matching lines...) Expand 10 before | Expand all | Expand 10 after
4110 // the implementation of v8. 4027 // the implementation of v8.
4111 static const int kHeapObjectMapOffset = 0; 4028 static const int kHeapObjectMapOffset = 0;
4112 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; 4029 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
4113 static const int kStringResourceOffset = 3 * kApiPointerSize; 4030 static const int kStringResourceOffset = 3 * kApiPointerSize;
4114 4031
4115 static const int kOddballKindOffset = 3 * kApiPointerSize; 4032 static const int kOddballKindOffset = 3 * kApiPointerSize;
4116 static const int kForeignAddressOffset = kApiPointerSize; 4033 static const int kForeignAddressOffset = kApiPointerSize;
4117 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 4034 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
4118 static const int kFullStringRepresentationMask = 0x07; 4035 static const int kFullStringRepresentationMask = 0x07;
4119 static const int kExternalTwoByteRepresentationTag = 0x02; 4036 static const int kExternalTwoByteRepresentationTag = 0x02;
4120 static const int kExternalAsciiRepresentationTag = 0x06;
4121 static const int kExternalAsciiDataHintMask = 0x08;
4122 static const int kExternalAsciiDataHintTag = 0x08;
4123 4037
4124 static const int kIsolateStateOffset = 0; 4038 static const int kIsolateStateOffset = 0;
4125 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 4039 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
4126 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 4040 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
4127 static const int kUndefinedValueRootIndex = 5; 4041 static const int kUndefinedValueRootIndex = 5;
4128 static const int kNullValueRootIndex = 7; 4042 static const int kNullValueRootIndex = 7;
4129 static const int kTrueValueRootIndex = 8; 4043 static const int kTrueValueRootIndex = 8;
4130 static const int kFalseValueRootIndex = 9; 4044 static const int kFalseValueRootIndex = 9;
4131 static const int kEmptySymbolRootIndex = 115; 4045 static const int kEmptySymbolRootIndex = 115;
4132 4046
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4170 static inline void* GetExternalPointer(internal::Object* obj) { 4084 static inline void* GetExternalPointer(internal::Object* obj) {
4171 if (HasSmiTag(obj)) { 4085 if (HasSmiTag(obj)) {
4172 return GetExternalPointerFromSmi(obj); 4086 return GetExternalPointerFromSmi(obj);
4173 } else if (GetInstanceType(obj) == kForeignType) { 4087 } else if (GetInstanceType(obj) == kForeignType) {
4174 return ReadField<void*>(obj, kForeignAddressOffset); 4088 return ReadField<void*>(obj, kForeignAddressOffset);
4175 } else { 4089 } else {
4176 return NULL; 4090 return NULL;
4177 } 4091 }
4178 } 4092 }
4179 4093
4094 static inline bool IsExternalTwoByteString(int instance_type) {
4095 int representation = (instance_type & kFullStringRepresentationMask);
4096 return representation == kExternalTwoByteRepresentationTag;
4097 }
4098
4180 static inline bool IsInitialized(v8::Isolate* isolate) { 4099 static inline bool IsInitialized(v8::Isolate* isolate) {
4181 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; 4100 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
4182 return *reinterpret_cast<int*>(addr) == 1; 4101 return *reinterpret_cast<int*>(addr) == 1;
4183 } 4102 }
4184 4103
4185 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { 4104 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) {
4186 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 4105 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4187 kIsolateEmbedderDataOffset; 4106 kIsolateEmbedderDataOffset;
4188 *reinterpret_cast<void**>(addr) = data; 4107 *reinterpret_cast<void**>(addr) = data;
4189 } 4108 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4447 typedef internal::Internals I; 4366 typedef internal::Internals I;
4448 if (!I::IsInitialized(isolate)) return Empty(); 4367 if (!I::IsInitialized(isolate)) return Empty();
4449 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); 4368 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex);
4450 return Local<String>(reinterpret_cast<String*>(slot)); 4369 return Local<String>(reinterpret_cast<String*>(slot));
4451 } 4370 }
4452 4371
4453 4372
4454 String::ExternalStringResource* String::GetExternalStringResource() const { 4373 String::ExternalStringResource* String::GetExternalStringResource() const {
4455 typedef internal::Object O; 4374 typedef internal::Object O;
4456 typedef internal::Internals I; 4375 typedef internal::Internals I;
4457 String::ExternalStringResource* result = NULL;
4458 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); 4376 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4459 if ((I::GetInstanceType(obj) & I::kFullStringRepresentationMask) == 4377 String::ExternalStringResource* result;
4460 I::kExternalTwoByteRepresentationTag) { 4378 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
4461 result = reinterpret_cast<String::ExternalStringResource*>( 4379 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4462 GetExternalStringResourceBase()); 4380 result = reinterpret_cast<String::ExternalStringResource*>(value);
4463 } 4381 } else {
4464 return result; 4382 result = NULL;
4465 }
4466
4467
4468 int String::GetExternalStringEncoding() const {
4469 typedef internal::Object O;
4470 typedef internal::Internals I;
4471 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4472 static const int kRepresentationAndHintMask =
4473 I::kFullStringRepresentationMask | I::kExternalAsciiDataHintMask;
4474
4475 int encoding;
4476 switch (I::GetInstanceType(obj) & kRepresentationAndHintMask) {
4477 case I::kExternalTwoByteRepresentationTag | I::kExternalAsciiDataHintTag:
4478 encoding = UTF_16_ENCODING | ASCII_HINT;
4479 break;
4480 case I::kExternalTwoByteRepresentationTag:
4481 encoding = UTF_16_ENCODING | NOT_ASCII_HINT;
4482 break;
4483 case I::kExternalAsciiRepresentationTag:
4484 encoding = LATIN1_ENCODING | ASCII_HINT;
4485 break;
4486 default:
4487 encoding = INVALID_ENCODING;
4488 break;
4489 } 4383 }
4490 #ifdef V8_ENABLE_CHECKS 4384 #ifdef V8_ENABLE_CHECKS
4491 VerifyExternalStringEncoding(encoding); 4385 VerifyExternalStringResource(result);
4492 #endif
4493 return encoding;
4494 }
4495
4496
4497 String::ExternalStringResourceBase* String::GetExternalStringResourceBase()
4498 const {
4499 typedef internal::Object O;
4500 typedef internal::Internals I;
4501 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4502 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4503 ExternalStringResourceBase* result =
4504 reinterpret_cast<String::ExternalStringResourceBase*>(value);
4505 #ifdef V8_ENABLE_CHECKS
4506 VerifyExternalStringResourceBase(result);
4507 #endif 4386 #endif
4508 return result; 4387 return result;
4509 } 4388 }
4510 4389
4511 4390
4512 bool Value::IsUndefined() const { 4391 bool Value::IsUndefined() const {
4513 #ifdef V8_ENABLE_CHECKS 4392 #ifdef V8_ENABLE_CHECKS
4514 return FullIsUndefined(); 4393 return FullIsUndefined();
4515 #else 4394 #else
4516 return QuickIsUndefined(); 4395 return QuickIsUndefined();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
4731 4610
4732 4611
4733 } // namespace v8 4612 } // namespace v8
4734 4613
4735 4614
4736 #undef V8EXPORT 4615 #undef V8EXPORT
4737 #undef TYPE_CHECK 4616 #undef TYPE_CHECK
4738 4617
4739 4618
4740 #endif // V8_H_ 4619 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698