Commit 85a0e807 authored by dcarney's avatar dcarney Committed by Commit bot

convert String::New functions to maybe

R=svenpanne@chromium.org
BUG=v8:3929
LOG=n

Review URL: https://codereview.chromium.org/1010803008

Cr-Commit-Position: refs/heads/master@{#27236}
parent 34a1a76d
......@@ -2031,11 +2031,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,
......@@ -2232,26 +2237,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
......@@ -2267,8 +2298,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
......@@ -2289,8 +2324,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
......
This diff is collapsed.
......@@ -694,28 +694,23 @@ class RandomLengthOneByteResource
THREADED_TEST(NewExternalForVeryLongString) {
auto isolate = CcTest::isolate();
{
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HandleScope scope(isolate);
v8::TryCatch try_catch;
RandomLengthOneByteResource r(1 << 30);
v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r);
v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r);
CHECK(str.IsEmpty());
CHECK(try_catch.HasCaught());
String::Utf8Value exception_value(try_catch.Exception());
CHECK_EQ(0, strcmp("RangeError: Invalid string length", *exception_value));
CHECK(!try_catch.HasCaught());
}
{
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HandleScope scope(isolate);
v8::TryCatch try_catch;
RandomLengthResource r(1 << 30);
v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r);
v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r);
CHECK(str.IsEmpty());
CHECK(try_catch.HasCaught());
String::Utf8Value exception_value(try_catch.Exception());
CHECK_EQ(0, strcmp("RangeError: Invalid string length", *exception_value));
CHECK(!try_catch.HasCaught());
}
}
......@@ -21618,7 +21613,6 @@ TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
TEST(NewStringRangeError) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;
const int length = i::String::kMaxLength + 1;
const int buffer_size = length * sizeof(uint16_t);
void* buffer = malloc(buffer_size);
......@@ -21629,21 +21623,21 @@ TEST(NewStringRangeError) {
char* data = reinterpret_cast<char*>(buffer);
CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString,
length).IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(!try_catch.HasCaught());
}
{
v8::TryCatch try_catch;
uint8_t* data = reinterpret_cast<uint8_t*>(buffer);
CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString,
length).IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(!try_catch.HasCaught());
}
{
v8::TryCatch try_catch;
uint16_t* data = reinterpret_cast<uint16_t*>(buffer);
CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString,
length).IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(!try_catch.HasCaught());
}
free(buffer);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment