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

Side by Side Diff: include/v8.h

Issue 10857030: Add basic support for Latin1 to the API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments. Created 8 years, 4 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 // 16-bit character codes. 1072
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.
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
1096 // ASCII characters. Null-characters are converted to spaces unless
1097 // PRESERVE_ASCII_NULL is set as option.
1078 V8EXPORT int WriteAscii(char* buffer, 1098 V8EXPORT int WriteAscii(char* buffer,
1079 int start = 0, 1099 int start = 0,
1080 int length = -1, 1100 int length = kUndefinedLength,
1081 int options = NO_OPTIONS) const; 1101 int options = NO_OPTIONS) const;
1082 // UTF-8 encoded characters. 1102
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.
1083 V8EXPORT int WriteUtf8(char* buffer, 1112 V8EXPORT int WriteUtf8(char* buffer,
1084 int length = -1, 1113 int length = kUndefinedLength,
1085 int* nchars_ref = NULL, 1114 int* nchars_ref = NULL,
1086 int options = NO_OPTIONS) const; 1115 int options = NO_OPTIONS) const;
1087 1116
1088 /** 1117 /**
1089 * A zero length string. 1118 * A zero length string.
1090 */ 1119 */
1091 V8EXPORT static v8::Local<v8::String> Empty(); 1120 V8EXPORT static v8::Local<v8::String> Empty();
1092 inline static v8::Local<v8::String> Empty(Isolate* isolate); 1121 inline static v8::Local<v8::String> Empty(Isolate* isolate);
1093 1122
1094 /** 1123 /**
(...skipping 20 matching lines...) Expand all
1115 * control how allocated external string resources are disposed. 1144 * control how allocated external string resources are disposed.
1116 */ 1145 */
1117 virtual void Dispose() { delete this; } 1146 virtual void Dispose() { delete this; }
1118 1147
1119 private: 1148 private:
1120 // Disallow copying and assigning. 1149 // Disallow copying and assigning.
1121 ExternalStringResourceBase(const ExternalStringResourceBase&); 1150 ExternalStringResourceBase(const ExternalStringResourceBase&);
1122 void operator=(const ExternalStringResourceBase&); 1151 void operator=(const ExternalStringResourceBase&);
1123 1152
1124 friend class v8::internal::Heap; 1153 friend class v8::internal::Heap;
1154 friend class v8::String;
1125 }; 1155 };
1126 1156
1127 /** 1157 /**
1128 * An ExternalStringResource is a wrapper around a two-byte string 1158 * An ExternalStringResource is a wrapper around a two-byte string
1129 * buffer that resides outside V8's heap. Implement an 1159 * buffer that resides outside V8's heap. Implement an
1130 * ExternalStringResource to manage the life cycle of the underlying 1160 * ExternalStringResource to manage the life cycle of the underlying
1131 * buffer. Note that the string data must be immutable. 1161 * buffer. Note that the string data must be immutable.
1132 */ 1162 */
1133 class V8EXPORT ExternalStringResource 1163 class V8EXPORT ExternalStringResource
1134 : public ExternalStringResourceBase { 1164 : public ExternalStringResourceBase {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 virtual ~ExternalAsciiStringResource() {} 1204 virtual ~ExternalAsciiStringResource() {}
1175 /** The string data from the underlying buffer.*/ 1205 /** The string data from the underlying buffer.*/
1176 virtual const char* data() const = 0; 1206 virtual const char* data() const = 0;
1177 /** The number of ASCII characters in the string.*/ 1207 /** The number of ASCII characters in the string.*/
1178 virtual size_t length() const = 0; 1208 virtual size_t length() const = 0;
1179 protected: 1209 protected:
1180 ExternalAsciiStringResource() {} 1210 ExternalAsciiStringResource() {}
1181 }; 1211 };
1182 1212
1183 /** 1213 /**
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 /**
1184 * Get the ExternalStringResource for an external string. Returns 1224 * Get the ExternalStringResource for an external string. Returns
1185 * NULL if IsExternal() doesn't return true. 1225 * NULL if IsExternal() doesn't return true.
1186 */ 1226 */
1187 inline ExternalStringResource* GetExternalStringResource() const; 1227 inline ExternalStringResource* GetExternalStringResource() const;
1188 1228
1189 /** 1229 /**
1190 * Get the ExternalAsciiStringResource for an external ASCII string. 1230 * Get the ExternalAsciiStringResource for an external ASCII string.
1191 * Returns NULL if IsExternalAscii() doesn't return true. 1231 * Returns NULL if IsExternalAscii() doesn't return true.
1192 */ 1232 */
1193 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource() 1233 V8EXPORT const ExternalAsciiStringResource* GetExternalAsciiStringResource()
1194 const; 1234 const;
1195 1235
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
1196 static inline String* Cast(v8::Value* obj); 1250 static inline String* Cast(v8::Value* obj);
1197 1251
1198 /** 1252 /**
1199 * Allocates a new string from either UTF-8 encoded or ASCII data. 1253 * Allocates a new string from either UTF-8 or Latin1-encoded data.
1200 * The second parameter 'length' gives the buffer length. 1254 * The second parameter 'length' gives the buffer length. If the data may
1201 * If the data is UTF-8 encoded, the caller must 1255 * contain zero bytes, the caller must be careful to supply the length
1202 * be careful to supply the length parameter. 1256 * parameter. If it is not given, the function calls 'strlen' to determine
1203 * If it is not given, the function calls 1257 * the buffer length, it might be wrong if 'data' contains a null character.
1204 * 'strlen' to determine the buffer length, it might be 1258 * The third parameter specifies the encoding, which may include an hint
1205 * wrong if 'data' contains a null character. 1259 * whether the string contains ASCII characters. In the case of Latin1, the
1260 * appropriate internal representation (UTF16 or ASCII) is chosen.
1206 */ 1261 */
1207 V8EXPORT static Local<String> New(const char* data, int length = -1); 1262 V8EXPORT static Local<String> New(const char* data,
1263 int length = kUndefinedLength,
1264 int encoding = UTF_8_ENCODING);
1208 1265
1209 /** Allocates a new string from 16-bit character codes.*/ 1266 /** Allocates a new string from 16-bit UTF-16 code units.*/
1210 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); 1267 V8EXPORT static Local<String> New(const uint16_t* data,
1268 int length = kUndefinedLength);
1211 1269
1212 /** Creates a symbol. Returns one if it exists already.*/ 1270 /** Creates a symbol. Returns one if it exists already.*/
1213 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); 1271 V8EXPORT static Local<String> NewSymbol(const char* data,
1272 int length = kUndefinedLength,
1273 int encoding = UTF_8_ENCODING);
1214 1274
1215 /** 1275 /**
1216 * Creates a new string by concatenating the left and the right strings 1276 * Creates a new string by concatenating the left and the right strings
1217 * passed in as parameters. 1277 * passed in as parameters.
1218 */ 1278 */
1219 V8EXPORT static Local<String> Concat(Handle<String> left, 1279 V8EXPORT static Local<String> Concat(Handle<String> left,
1220 Handle<String> right); 1280 Handle<String> right);
1221 1281
1222 /** 1282 /**
1223 * Creates a new external string using the data defined in the given 1283 * Creates a new external string using the data defined in the given
(...skipping 16 matching lines...) Expand all
1240 */ 1300 */
1241 V8EXPORT bool MakeExternal(ExternalStringResource* resource); 1301 V8EXPORT bool MakeExternal(ExternalStringResource* resource);
1242 1302
1243 /** 1303 /**
1244 * Creates a new external string using the ASCII data defined in the given 1304 * 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 1305 * 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 1306 * resource will be disposed by calling its Dispose method. The caller of
1247 * this function should not otherwise delete or modify the resource. Neither 1307 * this function should not otherwise delete or modify the resource. Neither
1248 * should the underlying buffer be deallocated or modified except through the 1308 * should the underlying buffer be deallocated or modified except through the
1249 * destructor of the external string resource. 1309 * destructor of the external string resource.
1250 */ V8EXPORT static Local<String> NewExternal( 1310 */
1311 V8EXPORT static Local<String> NewExternal(
1251 ExternalAsciiStringResource* resource); 1312 ExternalAsciiStringResource* resource);
1252 1313
1253 /** 1314 /**
1254 * Associate an external string resource with this string by transforming it 1315 * 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 1316 * 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 1317 * will use the external string resource. The external string resource's
1257 * character contents need to be equivalent to this string. 1318 * character contents need to be equivalent to this string.
1258 * Returns true if the string has been changed to be an external string. 1319 * 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 1320 * The string is not modified if the operation fails. See NewExternal for
1260 * information on the lifetime of the resource. 1321 * information on the lifetime of the resource.
1261 */ 1322 */
1262 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); 1323 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
1263 1324
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
1264 /** 1343 /**
1265 * Returns true if this string can be made external. 1344 * Returns true if this string can be made external.
1266 */ 1345 */
1267 V8EXPORT bool CanMakeExternal(); 1346 V8EXPORT bool CanMakeExternal();
1268 1347
1269 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ 1348 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/
1270 V8EXPORT static Local<String> NewUndetectable(const char* data, 1349 V8EXPORT static Local<String> NewUndetectable(const char* data,
1271 int length = -1); 1350 int length = kUndefinedLength,
1351 int encoding = UTF_8_ENCODING);
1272 1352
1273 /** Creates an undetectable string from the supplied 16-bit character codes.*/ 1353 /** Creates an undetectable string from the supplied 16-bit UTF16 code units.
1354 */
1274 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, 1355 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
1275 int length = -1); 1356 int length = kUndefinedLength);
1276 1357
1277 /** 1358 /**
1278 * Converts an object to a UTF-8-encoded character array. Useful if 1359 * 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 1360 * 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) 1361 * (e.g. due to an exception in the toString() method of the object)
1281 * then the length() method returns 0 and the * operator returns 1362 * then the length() method returns 0 and the * operator returns
1282 * NULL. 1363 * NULL.
1283 */ 1364 */
1284 class V8EXPORT Utf8Value { 1365 class V8EXPORT Utf8Value {
1285 public: 1366 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 private: 1417 private:
1337 uint16_t* str_; 1418 uint16_t* str_;
1338 int length_; 1419 int length_;
1339 1420
1340 // Disallow copying and assigning. 1421 // Disallow copying and assigning.
1341 Value(const Value&); 1422 Value(const Value&);
1342 void operator=(const Value&); 1423 void operator=(const Value&);
1343 }; 1424 };
1344 1425
1345 private: 1426 private:
1346 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; 1427 V8EXPORT void VerifyExternalStringEncoding(int encoding) const;
1428 V8EXPORT void VerifyExternalStringResourceBase(
1429 ExternalStringResourceBase* val) const;
1347 V8EXPORT static void CheckCast(v8::Value* obj); 1430 V8EXPORT static void CheckCast(v8::Value* obj);
1348 }; 1431 };
1349 1432
1350 1433
1351 /** 1434 /**
1352 * A JavaScript number value (ECMA-262, 4.3.20) 1435 * A JavaScript number value (ECMA-262, 4.3.20)
1353 */ 1436 */
1354 class Number : public Primitive { 1437 class Number : public Primitive {
1355 public: 1438 public:
1356 V8EXPORT double Value() const; 1439 V8EXPORT double Value() const;
(...skipping 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after
3953 // the implementation of v8. 4036 // the implementation of v8.
3954 static const int kHeapObjectMapOffset = 0; 4037 static const int kHeapObjectMapOffset = 0;
3955 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; 4038 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
3956 static const int kStringResourceOffset = 3 * kApiPointerSize; 4039 static const int kStringResourceOffset = 3 * kApiPointerSize;
3957 4040
3958 static const int kOddballKindOffset = 3 * kApiPointerSize; 4041 static const int kOddballKindOffset = 3 * kApiPointerSize;
3959 static const int kForeignAddressOffset = kApiPointerSize; 4042 static const int kForeignAddressOffset = kApiPointerSize;
3960 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 4043 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
3961 static const int kFullStringRepresentationMask = 0x07; 4044 static const int kFullStringRepresentationMask = 0x07;
3962 static const int kExternalTwoByteRepresentationTag = 0x02; 4045 static const int kExternalTwoByteRepresentationTag = 0x02;
4046 static const int kExternalAsciiRepresentationTag = 0x06;
4047 static const int kExternalAsciiDataHintMask = 0x08;
4048 static const int kExternalAsciiDataHintTag = 0x08;
3963 4049
3964 static const int kIsolateStateOffset = 0; 4050 static const int kIsolateStateOffset = 0;
3965 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 4051 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
3966 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 4052 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
3967 static const int kUndefinedValueRootIndex = 5; 4053 static const int kUndefinedValueRootIndex = 5;
3968 static const int kNullValueRootIndex = 7; 4054 static const int kNullValueRootIndex = 7;
3969 static const int kTrueValueRootIndex = 8; 4055 static const int kTrueValueRootIndex = 8;
3970 static const int kFalseValueRootIndex = 9; 4056 static const int kFalseValueRootIndex = 9;
3971 static const int kEmptySymbolRootIndex = 112; 4057 static const int kEmptySymbolRootIndex = 112;
3972 4058
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4010 static inline void* GetExternalPointer(internal::Object* obj) { 4096 static inline void* GetExternalPointer(internal::Object* obj) {
4011 if (HasSmiTag(obj)) { 4097 if (HasSmiTag(obj)) {
4012 return GetExternalPointerFromSmi(obj); 4098 return GetExternalPointerFromSmi(obj);
4013 } else if (GetInstanceType(obj) == kForeignType) { 4099 } else if (GetInstanceType(obj) == kForeignType) {
4014 return ReadField<void*>(obj, kForeignAddressOffset); 4100 return ReadField<void*>(obj, kForeignAddressOffset);
4015 } else { 4101 } else {
4016 return NULL; 4102 return NULL;
4017 } 4103 }
4018 } 4104 }
4019 4105
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) { 4106 static inline bool IsInitialized(v8::Isolate* isolate) {
4026 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; 4107 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
4027 return *reinterpret_cast<int*>(addr) == 1; 4108 return *reinterpret_cast<int*>(addr) == 1;
4028 } 4109 }
4029 4110
4030 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { 4111 static inline void SetEmbedderData(v8::Isolate* isolate, void* data) {
4031 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 4112 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
4032 kIsolateEmbedderDataOffset; 4113 kIsolateEmbedderDataOffset;
4033 *reinterpret_cast<void**>(addr) = data; 4114 *reinterpret_cast<void**>(addr) = data;
4034 } 4115 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4292 typedef internal::Internals I; 4373 typedef internal::Internals I;
4293 if (!I::IsInitialized(isolate)) return Empty(); 4374 if (!I::IsInitialized(isolate)) return Empty();
4294 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex); 4375 S* slot = I::GetRoot(isolate, I::kEmptySymbolRootIndex);
4295 return Local<String>(reinterpret_cast<String*>(slot)); 4376 return Local<String>(reinterpret_cast<String*>(slot));
4296 } 4377 }
4297 4378
4298 4379
4299 String::ExternalStringResource* String::GetExternalStringResource() const { 4380 String::ExternalStringResource* String::GetExternalStringResource() const {
4300 typedef internal::Object O; 4381 typedef internal::Object O;
4301 typedef internal::Internals I; 4382 typedef internal::Internals I;
4383 String::ExternalStringResource* result = NULL;
4302 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); 4384 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4303 String::ExternalStringResource* result; 4385 if ((I::GetInstanceType(obj) & I::kFullStringRepresentationMask) ==
4304 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { 4386 I::kExternalTwoByteRepresentationTag) {
4305 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); 4387 result = reinterpret_cast<String::ExternalStringResource*>(
4306 result = reinterpret_cast<String::ExternalStringResource*>(value); 4388 GetExternalStringResourceBase());
4307 } else { 4389 }
4308 result = NULL; 4390 return result;
4391 }
4392
4393
4394 int String::GetExternalStringEncoding() const {
4395 typedef internal::Object O;
4396 typedef internal::Internals I;
4397 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4398 static const int kRepresentationAndHintMask =
4399 I::kFullStringRepresentationMask | I::kExternalAsciiDataHintMask;
4400
4401 int encoding;
4402 switch (I::GetInstanceType(obj) & kRepresentationAndHintMask) {
4403 case I::kExternalTwoByteRepresentationTag | I::kExternalAsciiDataHintTag:
4404 encoding = UTF_16_ENCODING | ASCII_HINT;
4405 break;
4406 case I::kExternalTwoByteRepresentationTag:
4407 encoding = UTF_16_ENCODING | NOT_ASCII_HINT;
4408 break;
4409 case I::kExternalAsciiRepresentationTag:
4410 encoding = LATIN1_ENCODING | ASCII_HINT;
4411 break;
4412 default:
4413 encoding = INVALID_ENCODING;
4414 break;
4309 } 4415 }
4310 #ifdef V8_ENABLE_CHECKS 4416 #ifdef V8_ENABLE_CHECKS
4311 VerifyExternalStringResource(result); 4417 VerifyExternalStringEncoding(encoding);
4418 #endif
4419 return encoding;
4420 }
4421
4422
4423 String::ExternalStringResourceBase* String::GetExternalStringResourceBase()
4424 const {
4425 typedef internal::Object O;
4426 typedef internal::Internals I;
4427 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
4428 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
4429 ExternalStringResourceBase* result =
4430 reinterpret_cast<String::ExternalStringResourceBase*>(value);
4431 #ifdef V8_ENABLE_CHECKS
4432 VerifyExternalStringResourceBase(result);
4312 #endif 4433 #endif
4313 return result; 4434 return result;
4314 } 4435 }
4315 4436
4316 4437
4317 bool Value::IsUndefined() const { 4438 bool Value::IsUndefined() const {
4318 #ifdef V8_ENABLE_CHECKS 4439 #ifdef V8_ENABLE_CHECKS
4319 return FullIsUndefined(); 4440 return FullIsUndefined();
4320 #else 4441 #else
4321 return QuickIsUndefined(); 4442 return QuickIsUndefined();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
4536 4657
4537 4658
4538 } // namespace v8 4659 } // namespace v8
4539 4660
4540 4661
4541 #undef V8EXPORT 4662 #undef V8EXPORT
4542 #undef TYPE_CHECK 4663 #undef TYPE_CHECK
4543 4664
4544 4665
4545 #endif // V8_H_ 4666 #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