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

Side by Side Diff: include/v8.h

Issue 1010803008: convert String::New functions to maybe (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 * unique. 2027 * unique.
2028 */ 2028 */
2029 int GetIdentityHash(); 2029 int GetIdentityHash();
2030 2030
2031 V8_INLINE static Name* Cast(v8::Value* obj); 2031 V8_INLINE static Name* Cast(v8::Value* obj);
2032 private: 2032 private:
2033 static void CheckCast(v8::Value* obj); 2033 static void CheckCast(v8::Value* obj);
2034 }; 2034 };
2035 2035
2036 2036
2037 enum class NewStringType { kNormal, kInternalized };
2038
2039
2037 /** 2040 /**
2038 * A JavaScript string value (ECMA-262, 4.3.17). 2041 * A JavaScript string value (ECMA-262, 4.3.17).
2039 */ 2042 */
2040 class V8_EXPORT String : public Name { 2043 class V8_EXPORT String : public Name {
2041 public: 2044 public:
2045 static const int kMaxLength = (1 << 28) - 16;
2046
2042 enum Encoding { 2047 enum Encoding {
2043 UNKNOWN_ENCODING = 0x1, 2048 UNKNOWN_ENCODING = 0x1,
2044 TWO_BYTE_ENCODING = 0x0, 2049 TWO_BYTE_ENCODING = 0x0,
2045 ONE_BYTE_ENCODING = 0x4 2050 ONE_BYTE_ENCODING = 0x4
2046 }; 2051 };
2047 /** 2052 /**
2048 * Returns the number of characters in this string. 2053 * Returns the number of characters in this string.
2049 */ 2054 */
2050 int Length() const; 2055 int Length() const;
2051 2056
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 V8_INLINE ExternalStringResource* GetExternalStringResource() const; 2233 V8_INLINE ExternalStringResource* GetExternalStringResource() const;
2229 2234
2230 /** 2235 /**
2231 * Get the ExternalOneByteStringResource for an external one-byte string. 2236 * Get the ExternalOneByteStringResource for an external one-byte string.
2232 * Returns NULL if IsExternalOneByte() doesn't return true. 2237 * Returns NULL if IsExternalOneByte() doesn't return true.
2233 */ 2238 */
2234 const ExternalOneByteStringResource* GetExternalOneByteStringResource() const; 2239 const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
2235 2240
2236 V8_INLINE static String* Cast(v8::Value* obj); 2241 V8_INLINE static String* Cast(v8::Value* obj);
2237 2242
2238 enum NewStringType { kNormalString, kInternalizedString }; 2243 // TODO(dcarney): remove with deprecation of New functions.
2244 enum NewStringType {
2245 kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2246 kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
2247 };
2239 2248
2240 /** Allocates a new string from UTF-8 data.*/ 2249 /** Allocates a new string from UTF-8 data.*/
2241 static Local<String> NewFromUtf8(Isolate* isolate, const char* data, 2250 static V8_DEPRECATE_SOON(
2242 NewStringType type = kNormalString, 2251 "Use maybe version",
2243 int length = -1); 2252 Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2253 NewStringType type = kNormalString,
2254 int length = -1));
2255
2256 /** Allocates a new string from UTF-8 data. Only returns an empty value when
2257 * length > kMaxLength. **/
2258 static MaybeLocal<String> NewFromUtf8(Isolate* isolate, const char* data,
2259 v8::NewStringType type,
2260 int length = -1);
2244 2261
2245 /** Allocates a new string from Latin-1 data.*/ 2262 /** Allocates a new string from Latin-1 data.*/
2246 static Local<String> NewFromOneByte( 2263 static V8_DEPRECATE_SOON(
2247 Isolate* isolate, 2264 "Use maybe version",
2248 const uint8_t* data, 2265 Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2249 NewStringType type = kNormalString, 2266 NewStringType type = kNormalString,
2250 int length = -1); 2267 int length = -1));
2268
2269 /** Allocates a new string from Latin-1 data. Only returns an empty value
2270 * when length > kMaxLength. **/
2271 static MaybeLocal<String> NewFromOneByte(Isolate* isolate,
2272 const uint8_t* data,
2273 v8::NewStringType type,
2274 int length = -1);
2251 2275
2252 /** Allocates a new string from UTF-16 data.*/ 2276 /** Allocates a new string from UTF-16 data.*/
2253 static Local<String> NewFromTwoByte( 2277 static V8_DEPRECATE_SOON(
2254 Isolate* isolate, 2278 "Use maybe version",
2255 const uint16_t* data, 2279 Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2256 NewStringType type = kNormalString, 2280 NewStringType type = kNormalString,
2257 int length = -1); 2281 int length = -1));
2282
2283 /** Allocates a new string from UTF-16 data. Only returns an empty value when
2284 * length > kMaxLength. **/
2285 static MaybeLocal<String> NewFromTwoByte(Isolate* isolate,
2286 const uint16_t* data,
2287 v8::NewStringType type,
2288 int length = -1);
2258 2289
2259 /** 2290 /**
2260 * Creates a new string by concatenating the left and the right strings 2291 * Creates a new string by concatenating the left and the right strings
2261 * passed in as parameters. 2292 * passed in as parameters.
2262 */ 2293 */
2263 static Local<String> Concat(Handle<String> left, Handle<String> right); 2294 static Local<String> Concat(Handle<String> left, Handle<String> right);
2264 2295
2265 /** 2296 /**
2266 * Creates a new external string using the data defined in the given 2297 * Creates a new external string using the data defined in the given
2267 * resource. When the external string is no longer live on V8's heap the 2298 * resource. When the external string is no longer live on V8's heap the
2268 * resource will be disposed by calling its Dispose method. The caller of 2299 * resource will be disposed by calling its Dispose method. The caller of
2269 * this function should not otherwise delete or modify the resource. Neither 2300 * this function should not otherwise delete or modify the resource. Neither
2270 * should the underlying buffer be deallocated or modified except through the 2301 * should the underlying buffer be deallocated or modified except through the
2271 * destructor of the external string resource. 2302 * destructor of the external string resource.
2272 */ 2303 */
2273 static Local<String> NewExternal(Isolate* isolate, 2304 static V8_DEPRECATE_SOON(
2274 ExternalStringResource* resource); 2305 "Use maybe version",
2306 Local<String> NewExternal(Isolate* isolate,
2307 ExternalStringResource* resource));
2308 static MaybeLocal<String> NewExternalTwoByte(
2309 Isolate* isolate, ExternalStringResource* resource);
2275 2310
2276 /** 2311 /**
2277 * Associate an external string resource with this string by transforming it 2312 * Associate an external string resource with this string by transforming it
2278 * in place so that existing references to this string in the JavaScript heap 2313 * in place so that existing references to this string in the JavaScript heap
2279 * will use the external string resource. The external string resource's 2314 * will use the external string resource. The external string resource's
2280 * character contents need to be equivalent to this string. 2315 * character contents need to be equivalent to this string.
2281 * Returns true if the string has been changed to be an external string. 2316 * Returns true if the string has been changed to be an external string.
2282 * The string is not modified if the operation fails. See NewExternal for 2317 * The string is not modified if the operation fails. See NewExternal for
2283 * information on the lifetime of the resource. 2318 * information on the lifetime of the resource.
2284 */ 2319 */
2285 bool MakeExternal(ExternalStringResource* resource); 2320 bool MakeExternal(ExternalStringResource* resource);
2286 2321
2287 /** 2322 /**
2288 * Creates a new external string using the one-byte data defined in the given 2323 * Creates a new external string using the one-byte data defined in the given
2289 * resource. When the external string is no longer live on V8's heap the 2324 * resource. When the external string is no longer live on V8's heap the
2290 * resource will be disposed by calling its Dispose method. The caller of 2325 * resource will be disposed by calling its Dispose method. The caller of
2291 * this function should not otherwise delete or modify the resource. Neither 2326 * this function should not otherwise delete or modify the resource. Neither
2292 * should the underlying buffer be deallocated or modified except through the 2327 * should the underlying buffer be deallocated or modified except through the
2293 * destructor of the external string resource. 2328 * destructor of the external string resource.
2294 */ 2329 */
2295 static Local<String> NewExternal(Isolate* isolate, 2330 static V8_DEPRECATE_SOON(
2296 ExternalOneByteStringResource* resource); 2331 "Use maybe version",
2332 Local<String> NewExternal(Isolate* isolate,
2333 ExternalOneByteStringResource* resource));
2334 static MaybeLocal<String> NewExternalOneByte(
2335 Isolate* isolate, ExternalOneByteStringResource* resource);
2297 2336
2298 /** 2337 /**
2299 * Associate an external string resource with this string by transforming it 2338 * Associate an external string resource with this string by transforming it
2300 * in place so that existing references to this string in the JavaScript heap 2339 * in place so that existing references to this string in the JavaScript heap
2301 * will use the external string resource. The external string resource's 2340 * will use the external string resource. The external string resource's
2302 * character contents need to be equivalent to this string. 2341 * character contents need to be equivalent to this string.
2303 * Returns true if the string has been changed to be an external string. 2342 * Returns true if the string has been changed to be an external string.
2304 * The string is not modified if the operation fails. See NewExternal for 2343 * The string is not modified if the operation fails. See NewExternal for
2305 * information on the lifetime of the resource. 2344 * information on the lifetime of the resource.
2306 */ 2345 */
(...skipping 5561 matching lines...) Expand 10 before | Expand all | Expand 10 after
7868 */ 7907 */
7869 7908
7870 7909
7871 } // namespace v8 7910 } // namespace v8
7872 7911
7873 7912
7874 #undef TYPE_CHECK 7913 #undef TYPE_CHECK
7875 7914
7876 7915
7877 #endif // V8_H_ 7916 #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