OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 * \return The number of characters copied to the buffer excluding the null | 1044 * \return The number of characters copied to the buffer excluding the null |
1045 * terminator. For WriteUtf8: The number of bytes copied to the buffer | 1045 * terminator. For WriteUtf8: The number of bytes copied to the buffer |
1046 * including the null terminator (if written). | 1046 * including the null terminator (if written). |
1047 */ | 1047 */ |
1048 enum WriteOptions { | 1048 enum WriteOptions { |
1049 NO_OPTIONS = 0, | 1049 NO_OPTIONS = 0, |
1050 HINT_MANY_WRITES_EXPECTED = 1, | 1050 HINT_MANY_WRITES_EXPECTED = 1, |
1051 NO_NULL_TERMINATION = 2 | 1051 NO_NULL_TERMINATION = 2 |
1052 }; | 1052 }; |
1053 | 1053 |
| 1054 // 16-bit character codes. |
1054 V8EXPORT int Write(uint16_t* buffer, | 1055 V8EXPORT int Write(uint16_t* buffer, |
1055 int start = 0, | 1056 int start = 0, |
1056 int length = -1, | 1057 int length = -1, |
1057 int options = NO_OPTIONS) const; // UTF-16 | 1058 int options = NO_OPTIONS) const; |
| 1059 // ASCII characters. |
1058 V8EXPORT int WriteAscii(char* buffer, | 1060 V8EXPORT int WriteAscii(char* buffer, |
1059 int start = 0, | 1061 int start = 0, |
1060 int length = -1, | 1062 int length = -1, |
1061 int options = NO_OPTIONS) const; // ASCII | 1063 int options = NO_OPTIONS) const; |
| 1064 // UTF-8 encoded characters. |
1062 V8EXPORT int WriteUtf8(char* buffer, | 1065 V8EXPORT int WriteUtf8(char* buffer, |
1063 int length = -1, | 1066 int length = -1, |
1064 int* nchars_ref = NULL, | 1067 int* nchars_ref = NULL, |
1065 int options = NO_OPTIONS) const; // UTF-8 | 1068 int options = NO_OPTIONS) const; |
1066 | 1069 |
1067 /** | 1070 /** |
1068 * A zero length string. | 1071 * A zero length string. |
1069 */ | 1072 */ |
1070 V8EXPORT static v8::Local<v8::String> Empty(); | 1073 V8EXPORT static v8::Local<v8::String> Empty(); |
1071 | 1074 |
1072 /** | 1075 /** |
1073 * Returns true if the string is external | 1076 * Returns true if the string is external |
1074 */ | 1077 */ |
1075 V8EXPORT bool IsExternal() const; | 1078 V8EXPORT bool IsExternal() const; |
1076 | 1079 |
1077 /** | 1080 /** |
1078 * Returns true if the string is both external and ascii | 1081 * Returns true if the string is both external and ASCII |
1079 */ | 1082 */ |
1080 V8EXPORT bool IsExternalAscii() const; | 1083 V8EXPORT bool IsExternalAscii() const; |
1081 | 1084 |
1082 class V8EXPORT ExternalStringResourceBase { // NOLINT | 1085 class V8EXPORT ExternalStringResourceBase { // NOLINT |
1083 public: | 1086 public: |
1084 virtual ~ExternalStringResourceBase() {} | 1087 virtual ~ExternalStringResourceBase() {} |
1085 | 1088 |
1086 protected: | 1089 protected: |
1087 ExternalStringResourceBase() {} | 1090 ExternalStringResourceBase() {} |
1088 | 1091 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 /** | 1128 /** |
1126 * The length of the string. That is, the number of two-byte characters. | 1129 * The length of the string. That is, the number of two-byte characters. |
1127 */ | 1130 */ |
1128 virtual size_t length() const = 0; | 1131 virtual size_t length() const = 0; |
1129 | 1132 |
1130 protected: | 1133 protected: |
1131 ExternalStringResource() {} | 1134 ExternalStringResource() {} |
1132 }; | 1135 }; |
1133 | 1136 |
1134 /** | 1137 /** |
1135 * An ExternalAsciiStringResource is a wrapper around an ascii | 1138 * An ExternalAsciiStringResource is a wrapper around an ASCII |
1136 * string buffer that resides outside V8's heap. Implement an | 1139 * string buffer that resides outside V8's heap. Implement an |
1137 * ExternalAsciiStringResource to manage the life cycle of the | 1140 * ExternalAsciiStringResource to manage the life cycle of the |
1138 * underlying buffer. Note that the string data must be immutable | 1141 * underlying buffer. Note that the string data must be immutable |
1139 * and that the data must be strict 7-bit ASCII, not Latin1 or | 1142 * and that the data must be strict (7-bit) ASCII, not Latin-1 or |
1140 * UTF-8, which would require special treatment internally in the | 1143 * UTF-8, which would require special treatment internally in the |
1141 * engine and, in the case of UTF-8, do not allow efficient indexing. | 1144 * engine and, in the case of UTF-8, do not allow efficient indexing. |
1142 * Use String::New or convert to 16 bit data for non-ASCII. | 1145 * Use String::New or convert to 16 bit data for non-ASCII. |
1143 */ | 1146 */ |
1144 | 1147 |
1145 class V8EXPORT ExternalAsciiStringResource | 1148 class V8EXPORT ExternalAsciiStringResource |
1146 : public ExternalStringResourceBase { | 1149 : public ExternalStringResourceBase { |
1147 public: | 1150 public: |
1148 /** | 1151 /** |
1149 * Override the destructor to manage the life cycle of the underlying | 1152 * Override the destructor to manage the life cycle of the underlying |
1150 * buffer. | 1153 * buffer. |
1151 */ | 1154 */ |
1152 virtual ~ExternalAsciiStringResource() {} | 1155 virtual ~ExternalAsciiStringResource() {} |
1153 /** The string data from the underlying buffer.*/ | 1156 /** The string data from the underlying buffer.*/ |
1154 virtual const char* data() const = 0; | 1157 virtual const char* data() const = 0; |
1155 /** The number of ascii characters in the string.*/ | 1158 /** The number of ASCII characters in the string.*/ |
1156 virtual size_t length() const = 0; | 1159 virtual size_t length() const = 0; |
1157 protected: | 1160 protected: |
1158 ExternalAsciiStringResource() {} | 1161 ExternalAsciiStringResource() {} |
1159 }; | 1162 }; |
1160 | 1163 |
1161 /** | 1164 /** |
1162 * Get the ExternalStringResource for an external string. Returns | 1165 * Get the ExternalStringResource for an external string. Returns |
1163 * NULL if IsExternal() doesn't return true. | 1166 * NULL if IsExternal() doesn't return true. |
1164 */ | 1167 */ |
1165 inline ExternalStringResource* GetExternalStringResource() const; | 1168 inline ExternalStringResource* GetExternalStringResource() const; |
1166 | 1169 |
1167 /** | 1170 /** |
1168 * Get the ExternalAsciiStringResource for an external ascii string. | 1171 * Get the ExternalAsciiStringResource for an external ASCII string. |
1169 * Returns NULL if IsExternalAscii() doesn't return true. | 1172 * Returns NULL if IsExternalAscii() doesn't return true. |
1170 */ | 1173 */ |
1171 V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const; | 1174 V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const; |
1172 | 1175 |
1173 static inline String* Cast(v8::Value* obj); | 1176 static inline String* Cast(v8::Value* obj); |
1174 | 1177 |
1175 /** | 1178 /** |
1176 * Allocates a new string from either utf-8 encoded or ascii data. | 1179 * Allocates a new string from either UTF-8 encoded or ASCII data. |
1177 * The second parameter 'length' gives the buffer length. | 1180 * The second parameter 'length' gives the buffer length. |
1178 * If the data is utf-8 encoded, the caller must | 1181 * If the data is UTF-8 encoded, the caller must |
1179 * be careful to supply the length parameter. | 1182 * be careful to supply the length parameter. |
1180 * If it is not given, the function calls | 1183 * If it is not given, the function calls |
1181 * 'strlen' to determine the buffer length, it might be | 1184 * 'strlen' to determine the buffer length, it might be |
1182 * wrong if 'data' contains a null character. | 1185 * wrong if 'data' contains a null character. |
1183 */ | 1186 */ |
1184 V8EXPORT static Local<String> New(const char* data, int length = -1); | 1187 V8EXPORT static Local<String> New(const char* data, int length = -1); |
1185 | 1188 |
1186 /** Allocates a new string from utf16 data.*/ | 1189 /** Allocates a new string from 16-bit character codes.*/ |
1187 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); | 1190 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); |
1188 | 1191 |
1189 /** Creates a symbol. Returns one if it exists already.*/ | 1192 /** Creates a symbol. Returns one if it exists already.*/ |
1190 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); | 1193 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); |
1191 | 1194 |
1192 /** | 1195 /** |
1193 * Creates a new string by concatenating the left and the right strings | 1196 * Creates a new string by concatenating the left and the right strings |
1194 * passed in as parameters. | 1197 * passed in as parameters. |
1195 */ | 1198 */ |
1196 V8EXPORT static Local<String> Concat(Handle<String> left, | 1199 V8EXPORT static Local<String> Concat(Handle<String> left, |
(...skipping 14 matching lines...) Expand all Loading... |
1211 * in place so that existing references to this string in the JavaScript heap | 1214 * in place so that existing references to this string in the JavaScript heap |
1212 * will use the external string resource. The external string resource's | 1215 * will use the external string resource. The external string resource's |
1213 * character contents need to be equivalent to this string. | 1216 * character contents need to be equivalent to this string. |
1214 * Returns true if the string has been changed to be an external string. | 1217 * Returns true if the string has been changed to be an external string. |
1215 * The string is not modified if the operation fails. See NewExternal for | 1218 * The string is not modified if the operation fails. See NewExternal for |
1216 * information on the lifetime of the resource. | 1219 * information on the lifetime of the resource. |
1217 */ | 1220 */ |
1218 V8EXPORT bool MakeExternal(ExternalStringResource* resource); | 1221 V8EXPORT bool MakeExternal(ExternalStringResource* resource); |
1219 | 1222 |
1220 /** | 1223 /** |
1221 * Creates a new external string using the ascii data defined in the given | 1224 * Creates a new external string using the ASCII data defined in the given |
1222 * resource. When the external string is no longer live on V8's heap the | 1225 * resource. When the external string is no longer live on V8's heap the |
1223 * resource will be disposed by calling its Dispose method. The caller of | 1226 * resource will be disposed by calling its Dispose method. The caller of |
1224 * this function should not otherwise delete or modify the resource. Neither | 1227 * this function should not otherwise delete or modify the resource. Neither |
1225 * should the underlying buffer be deallocated or modified except through the | 1228 * should the underlying buffer be deallocated or modified except through the |
1226 * destructor of the external string resource. | 1229 * destructor of the external string resource. |
1227 */ | 1230 */ |
1228 V8EXPORT static Local<String> NewExternal( | 1231 V8EXPORT static Local<String> NewExternal( |
1229 ExternalAsciiStringResource* resource); | 1232 ExternalAsciiStringResource* resource); |
1230 | 1233 |
1231 /** | 1234 /** |
1232 * Associate an external string resource with this string by transforming it | 1235 * Associate an external string resource with this string by transforming it |
1233 * in place so that existing references to this string in the JavaScript heap | 1236 * in place so that existing references to this string in the JavaScript heap |
1234 * will use the external string resource. The external string resource's | 1237 * will use the external string resource. The external string resource's |
1235 * character contents need to be equivalent to this string. | 1238 * character contents need to be equivalent to this string. |
1236 * Returns true if the string has been changed to be an external string. | 1239 * Returns true if the string has been changed to be an external string. |
1237 * The string is not modified if the operation fails. See NewExternal for | 1240 * The string is not modified if the operation fails. See NewExternal for |
1238 * information on the lifetime of the resource. | 1241 * information on the lifetime of the resource. |
1239 */ | 1242 */ |
1240 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); | 1243 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); |
1241 | 1244 |
1242 /** | 1245 /** |
1243 * Returns true if this string can be made external. | 1246 * Returns true if this string can be made external. |
1244 */ | 1247 */ |
1245 V8EXPORT bool CanMakeExternal(); | 1248 V8EXPORT bool CanMakeExternal(); |
1246 | 1249 |
1247 /** Creates an undetectable string from the supplied ascii or utf-8 data.*/ | 1250 /** Creates an undetectable string from the supplied ASCII or UTF-8 data.*/ |
1248 V8EXPORT static Local<String> NewUndetectable(const char* data, | 1251 V8EXPORT static Local<String> NewUndetectable(const char* data, |
1249 int length = -1); | 1252 int length = -1); |
1250 | 1253 |
1251 /** Creates an undetectable string from the supplied utf-16 data.*/ | 1254 /** Creates an undetectable string from the supplied 16-bit character codes.*/ |
1252 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, | 1255 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, |
1253 int length = -1); | 1256 int length = -1); |
1254 | 1257 |
1255 /** | 1258 /** |
1256 * Converts an object to a utf8-encoded character array. Useful if | 1259 * Converts an object to a UTF-8-encoded character array. Useful if |
1257 * you want to print the object. If conversion to a string fails | 1260 * you want to print the object. If conversion to a string fails |
1258 * (eg. due to an exception in the toString() method of the object) | 1261 * (e.g. due to an exception in the toString() method of the object) |
1259 * then the length() method returns 0 and the * operator returns | 1262 * then the length() method returns 0 and the * operator returns |
1260 * NULL. | 1263 * NULL. |
1261 */ | 1264 */ |
1262 class V8EXPORT Utf8Value { | 1265 class V8EXPORT Utf8Value { |
1263 public: | 1266 public: |
1264 explicit Utf8Value(Handle<v8::Value> obj); | 1267 explicit Utf8Value(Handle<v8::Value> obj); |
1265 ~Utf8Value(); | 1268 ~Utf8Value(); |
1266 char* operator*() { return str_; } | 1269 char* operator*() { return str_; } |
1267 const char* operator*() const { return str_; } | 1270 const char* operator*() const { return str_; } |
1268 int length() const { return length_; } | 1271 int length() const { return length_; } |
1269 private: | 1272 private: |
1270 char* str_; | 1273 char* str_; |
1271 int length_; | 1274 int length_; |
1272 | 1275 |
1273 // Disallow copying and assigning. | 1276 // Disallow copying and assigning. |
1274 Utf8Value(const Utf8Value&); | 1277 Utf8Value(const Utf8Value&); |
1275 void operator=(const Utf8Value&); | 1278 void operator=(const Utf8Value&); |
1276 }; | 1279 }; |
1277 | 1280 |
1278 /** | 1281 /** |
1279 * Converts an object to an ascii string. | 1282 * Converts an object to an ASCII string. |
1280 * Useful if you want to print the object. | 1283 * Useful if you want to print the object. |
1281 * If conversion to a string fails (eg. due to an exception in the toString() | 1284 * If conversion to a string fails (eg. due to an exception in the toString() |
1282 * method of the object) then the length() method returns 0 and the * operator | 1285 * method of the object) then the length() method returns 0 and the * operator |
1283 * returns NULL. | 1286 * returns NULL. |
1284 */ | 1287 */ |
1285 class V8EXPORT AsciiValue { | 1288 class V8EXPORT AsciiValue { |
1286 public: | 1289 public: |
1287 explicit AsciiValue(Handle<v8::Value> obj); | 1290 explicit AsciiValue(Handle<v8::Value> obj); |
1288 ~AsciiValue(); | 1291 ~AsciiValue(); |
1289 char* operator*() { return str_; } | 1292 char* operator*() { return str_; } |
(...skipping 2908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4198 | 4201 |
4199 | 4202 |
4200 } // namespace v8 | 4203 } // namespace v8 |
4201 | 4204 |
4202 | 4205 |
4203 #undef V8EXPORT | 4206 #undef V8EXPORT |
4204 #undef TYPE_CHECK | 4207 #undef TYPE_CHECK |
4205 | 4208 |
4206 | 4209 |
4207 #endif // V8_H_ | 4210 #endif // V8_H_ |
OLD | NEW |