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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index db625eeb4242be3d594628fdf8f2f450d0ef894e..d15a9ab41d0665cf06066f6c3cc7fd449f5bf872 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2034,11 +2034,16 @@ class V8_EXPORT Name : public Primitive {
};
+enum class NewStringType { kNormal, kInternalized };
+
+
/**
* A JavaScript string value (ECMA-262, 4.3.17).
*/
class V8_EXPORT String : public Name {
public:
+ static const int kMaxLength = (1 << 28) - 16;
+
enum Encoding {
UNKNOWN_ENCODING = 0x1,
TWO_BYTE_ENCODING = 0x0,
@@ -2235,26 +2240,52 @@ class V8_EXPORT String : public Name {
V8_INLINE static String* Cast(v8::Value* obj);
- enum NewStringType { kNormalString, kInternalizedString };
+ // TODO(dcarney): remove with deprecation of New functions.
+ enum NewStringType {
+ kNormalString = static_cast<int>(v8::NewStringType::kNormal),
+ kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
+ };
/** Allocates a new string from UTF-8 data.*/
- static Local<String> NewFromUtf8(Isolate* isolate, const char* data,
- NewStringType type = kNormalString,
- int length = -1);
+ static V8_DEPRECATE_SOON(
+ "Use maybe version",
+ Local<String> NewFromUtf8(Isolate* isolate, const char* data,
+ NewStringType type = kNormalString,
+ int length = -1));
+
+ /** Allocates a new string from UTF-8 data. Only returns an empty value when
+ * length > kMaxLength. **/
+ static MaybeLocal<String> NewFromUtf8(Isolate* isolate, const char* data,
+ v8::NewStringType type,
+ int length = -1);
/** Allocates a new string from Latin-1 data.*/
- static Local<String> NewFromOneByte(
- Isolate* isolate,
- const uint8_t* data,
- NewStringType type = kNormalString,
- int length = -1);
+ static V8_DEPRECATE_SOON(
+ "Use maybe version",
+ Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
+ NewStringType type = kNormalString,
+ int length = -1));
+
+ /** Allocates a new string from Latin-1 data. Only returns an empty value
+ * when length > kMaxLength. **/
+ static MaybeLocal<String> NewFromOneByte(Isolate* isolate,
+ const uint8_t* data,
+ v8::NewStringType type,
+ int length = -1);
/** Allocates a new string from UTF-16 data.*/
- static Local<String> NewFromTwoByte(
- Isolate* isolate,
- const uint16_t* data,
- NewStringType type = kNormalString,
- int length = -1);
+ static V8_DEPRECATE_SOON(
+ "Use maybe version",
+ Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
+ NewStringType type = kNormalString,
+ int length = -1));
+
+ /** Allocates a new string from UTF-16 data. Only returns an empty value when
+ * length > kMaxLength. **/
+ static MaybeLocal<String> NewFromTwoByte(Isolate* isolate,
+ const uint16_t* data,
+ v8::NewStringType type,
+ int length = -1);
/**
* Creates a new string by concatenating the left and the right strings
@@ -2270,8 +2301,12 @@ class V8_EXPORT String : public Name {
* should the underlying buffer be deallocated or modified except through the
* destructor of the external string resource.
*/
- static Local<String> NewExternal(Isolate* isolate,
- ExternalStringResource* resource);
+ static V8_DEPRECATE_SOON(
+ "Use maybe version",
+ Local<String> NewExternal(Isolate* isolate,
+ ExternalStringResource* resource));
+ static MaybeLocal<String> NewExternalTwoByte(
+ Isolate* isolate, ExternalStringResource* resource);
/**
* Associate an external string resource with this string by transforming it
@@ -2292,8 +2327,12 @@ class V8_EXPORT String : public Name {
* should the underlying buffer be deallocated or modified except through the
* destructor of the external string resource.
*/
- static Local<String> NewExternal(Isolate* isolate,
- ExternalOneByteStringResource* resource);
+ static V8_DEPRECATE_SOON(
+ "Use maybe version",
+ Local<String> NewExternal(Isolate* isolate,
+ ExternalOneByteStringResource* resource));
+ static MaybeLocal<String> NewExternalOneByte(
+ Isolate* isolate, ExternalOneByteStringResource* resource);
/**
* Associate an external string resource with this string by transforming it
« 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