Commit be0d2f5d authored by yangguo@chromium.org's avatar yangguo@chromium.org

Return MaybeHandle from NewConsString.

R=ishell@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20473 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fe370261
...@@ -5459,10 +5459,9 @@ Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) { ...@@ -5459,10 +5459,9 @@ Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) {
LOG_API(isolate, "String::New(char)"); LOG_API(isolate, "String::New(char)");
ENTER_V8(isolate); ENTER_V8(isolate);
i::Handle<i::String> right_string = Utils::OpenHandle(*right); i::Handle<i::String> right_string = Utils::OpenHandle(*right);
i::Handle<i::String> result = isolate->factory()->NewConsString(left_string,
right_string);
// We do not expect this to fail. Change this if it does. // We do not expect this to fail. Change this if it does.
CHECK(!result.is_null()); i::Handle<i::String> result = isolate->factory()->NewConsString(
left_string, right_string).ToHandleChecked();
return Utils::ToLocal(result); return Utils::ToLocal(result);
} }
...@@ -7033,15 +7032,15 @@ Handle<String> CpuProfileNode::GetFunctionName() const { ...@@ -7033,15 +7032,15 @@ Handle<String> CpuProfileNode::GetFunctionName() const {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
const i::CodeEntry* entry = node->entry(); const i::CodeEntry* entry = node->entry();
i::Handle<i::String> name =
isolate->factory()->InternalizeUtf8String(entry->name());
if (!entry->has_name_prefix()) { if (!entry->has_name_prefix()) {
return ToApiHandle<String>( return ToApiHandle<String>(name);
isolate->factory()->InternalizeUtf8String(entry->name()));
} else { } else {
// We do not expect this to fail. Change this if it does.
i::Handle<i::String> cons = isolate->factory()->NewConsString( i::Handle<i::String> cons = isolate->factory()->NewConsString(
isolate->factory()->InternalizeUtf8String(entry->name_prefix()), isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
isolate->factory()->InternalizeUtf8String(entry->name())); name).ToHandleChecked();
// We do not expect this to fail. Change this if it does.
CHECK(!cons.is_null());
return ToApiHandle<String>(cons); return ToApiHandle<String>(cons);
} }
} }
......
...@@ -334,8 +334,8 @@ Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) { ...@@ -334,8 +334,8 @@ Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) {
} }
Handle<String> Factory::NewConsString(Handle<String> left, MaybeHandle<String> Factory::NewConsString(Handle<String> left,
Handle<String> right) { Handle<String> right) {
int left_length = left->length(); int left_length = left->length();
if (left_length == 0) return right; if (left_length == 0) return right;
int right_length = right->length(); int right_length = right->length();
...@@ -352,8 +352,8 @@ Handle<String> Factory::NewConsString(Handle<String> left, ...@@ -352,8 +352,8 @@ Handle<String> Factory::NewConsString(Handle<String> left,
// Make sure that an out of memory exception is thrown if the length // Make sure that an out of memory exception is thrown if the length
// of the new cons string is too large. // of the new cons string is too large.
if (length > String::kMaxLength || length < 0) { if (length > String::kMaxLength || length < 0) {
isolate()->ThrowInvalidStringLength(); return isolate()->Throw<String>(
return Handle<String>::null(); isolate()->factory()->NewInvalidStringLengthError());
} }
bool left_is_one_byte = left->IsOneByteRepresentation(); bool left_is_one_byte = left->IsOneByteRepresentation();
......
...@@ -140,8 +140,8 @@ class Factory V8_FINAL { ...@@ -140,8 +140,8 @@ class Factory V8_FINAL {
PretenureFlag pretenure = NOT_TENURED); PretenureFlag pretenure = NOT_TENURED);
// Create a new cons string object which consists of a pair of strings. // Create a new cons string object which consists of a pair of strings.
Handle<String> NewConsString(Handle<String> left, MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
Handle<String> right); Handle<String> right);
Handle<ConsString> NewRawConsString(String::Encoding encoding); Handle<ConsString> NewRawConsString(String::Encoding encoding);
...@@ -436,6 +436,11 @@ class Factory V8_FINAL { ...@@ -436,6 +436,11 @@ class Factory V8_FINAL {
Vector< Handle<Object> > args); Vector< Handle<Object> > args);
Handle<Object> NewRangeError(Handle<String> message); Handle<Object> NewRangeError(Handle<String> message);
Handle<Object> NewInvalidStringLengthError() {
return NewRangeError("invalid_string_length",
HandleVector<Object>(NULL, 0));
}
Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args); Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
Handle<Object> NewSyntaxError(Handle<String> message); Handle<Object> NewSyntaxError(Handle<String> message);
......
...@@ -86,10 +86,9 @@ Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos, ...@@ -86,10 +86,9 @@ Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos,
Handle<String> name = names_stack_.at(pos).name; Handle<String> name = names_stack_.at(pos).name;
if (prev->length() + name->length() + 1 > String::kMaxLength) return prev; if (prev->length() + name->length() + 1 > String::kMaxLength) return prev;
Factory* factory = isolate()->factory(); Factory* factory = isolate()->factory();
Handle<String> curr = factory->NewConsString(factory->dot_string(), name); Handle<String> curr =
CHECK_NOT_EMPTY_HANDLE(isolate(), curr); factory->NewConsString(factory->dot_string(), name).ToHandleChecked();
curr = factory->NewConsString(prev, curr); curr = factory->NewConsString(prev, curr).ToHandleChecked();
CHECK_NOT_EMPTY_HANDLE(isolate(), curr);
return MakeNameFromStackHelper(pos + 1, curr); return MakeNameFromStackHelper(pos + 1, curr);
} else { } else {
return MakeNameFromStackHelper(pos + 1, names_stack_.at(pos).name); return MakeNameFromStackHelper(pos + 1, names_stack_.at(pos).name);
......
...@@ -37,6 +37,7 @@ namespace internal { ...@@ -37,6 +37,7 @@ namespace internal {
// A Handle can be converted into a MaybeHandle. Converting a MaybeHandle // A Handle can be converted into a MaybeHandle. Converting a MaybeHandle
// into a Handle requires checking that it does not point to NULL. This // into a Handle requires checking that it does not point to NULL. This
// ensures NULL checks before use. // ensures NULL checks before use.
// Do not use MaybeHandle as argument type.
template<typename T> template<typename T>
class MaybeHandle { class MaybeHandle {
......
...@@ -179,7 +179,7 @@ typedef ZoneList<Handle<Object> > ZoneObjectList; ...@@ -179,7 +179,7 @@ typedef ZoneList<Handle<Object> > ZoneObjectList;
#define RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \ #define RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
do { \ do { \
if (call.is_null()) { \ if ((call).is_null()) { \
ASSERT((isolate)->has_pending_exception()); \ ASSERT((isolate)->has_pending_exception()); \
return value; \ return value; \
} \ } \
......
...@@ -501,8 +501,11 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric( ...@@ -501,8 +501,11 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric(
part_length_ = kInitialPartLength; // Allocate conservatively. part_length_ = kInitialPartLength; // Allocate conservatively.
Extend(); // Attach current part and allocate new part. Extend(); // Attach current part and allocate new part.
// Attach result string to the accumulator. // Attach result string to the accumulator.
Handle<String> cons = factory_->NewConsString(accumulator(), result_string); Handle<String> cons;
RETURN_IF_EMPTY_HANDLE_VALUE(isolate_, cons, EXCEPTION); ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, cons,
factory_->NewConsString(accumulator(), result_string),
EXCEPTION);
set_accumulator(cons); set_accumulator(cons);
return SUCCESS; return SUCCESS;
} }
...@@ -731,7 +734,8 @@ void BasicJsonStringifier::Accumulate() { ...@@ -731,7 +734,8 @@ void BasicJsonStringifier::Accumulate() {
set_accumulator(factory_->empty_string()); set_accumulator(factory_->empty_string());
overflowed_ = true; overflowed_ = true;
} else { } else {
set_accumulator(factory_->NewConsString(accumulator(), current_part_)); set_accumulator(factory_->NewConsString(accumulator(),
current_part_).ToHandleChecked());
} }
} }
......
...@@ -2974,9 +2974,11 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2974,9 +2974,11 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
// TODO(keuchel): Move the temporary variable to the block scope, after // TODO(keuchel): Move the temporary variable to the block scope, after
// implementing stack allocated block scoped variables. // implementing stack allocated block scoped variables.
Factory* heap_factory = isolate()->factory(); Factory* heap_factory = isolate()->factory();
Handle<String> tempstr = Handle<String> tempstr;
heap_factory->NewConsString(heap_factory->dot_for_string(), name); ASSIGN_RETURN_ON_EXCEPTION_VALUE(
RETURN_IF_EMPTY_HANDLE_VALUE(isolate(), tempstr, 0); isolate(), tempstr,
heap_factory->NewConsString(heap_factory->dot_for_string(), name),
0);
Handle<String> tempname = heap_factory->InternalizeString(tempstr); Handle<String> tempname = heap_factory->InternalizeString(tempstr);
Variable* temp = scope_->DeclarationScope()->NewTemporary(tempname); Variable* temp = scope_->DeclarationScope()->NewTemporary(tempname);
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
......
...@@ -4236,35 +4236,34 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceGlobalRegExpWithString) { ...@@ -4236,35 +4236,34 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceGlobalRegExpWithString) {
} }
Handle<String> StringReplaceOneCharWithString(Isolate* isolate, // This may return an empty MaybeHandle if an exception is thrown or
Handle<String> subject, // we abort due to reaching the recursion limit.
Handle<String> search, MaybeHandle<String> StringReplaceOneCharWithString(Isolate* isolate,
Handle<String> replace, Handle<String> subject,
bool* found, Handle<String> search,
int recursion_limit) { Handle<String> replace,
if (recursion_limit == 0) return Handle<String>::null(); bool* found,
int recursion_limit) {
if (recursion_limit == 0) return MaybeHandle<String>();
recursion_limit--;
if (subject->IsConsString()) { if (subject->IsConsString()) {
ConsString* cons = ConsString::cast(*subject); ConsString* cons = ConsString::cast(*subject);
Handle<String> first = Handle<String>(cons->first()); Handle<String> first = Handle<String>(cons->first());
Handle<String> second = Handle<String>(cons->second()); Handle<String> second = Handle<String>(cons->second());
Handle<String> new_first = Handle<String> new_first;
StringReplaceOneCharWithString(isolate, if (!StringReplaceOneCharWithString(
first, isolate, first, search, replace, found, recursion_limit)
search, .ToHandle(&new_first)) {
replace, return MaybeHandle<String>();
found, }
recursion_limit - 1);
if (new_first.is_null()) return new_first;
if (*found) return isolate->factory()->NewConsString(new_first, second); if (*found) return isolate->factory()->NewConsString(new_first, second);
Handle<String> new_second = Handle<String> new_second;
StringReplaceOneCharWithString(isolate, if (!StringReplaceOneCharWithString(
second, isolate, second, search, replace, found, recursion_limit)
search, .ToHandle(&new_second)) {
replace, return MaybeHandle<String>();
found, }
recursion_limit - 1);
if (new_second.is_null()) return new_second;
if (*found) return isolate->factory()->NewConsString(first, new_second); if (*found) return isolate->factory()->NewConsString(first, new_second);
return subject; return subject;
...@@ -4273,8 +4272,11 @@ Handle<String> StringReplaceOneCharWithString(Isolate* isolate, ...@@ -4273,8 +4272,11 @@ Handle<String> StringReplaceOneCharWithString(Isolate* isolate,
if (index == -1) return subject; if (index == -1) return subject;
*found = true; *found = true;
Handle<String> first = isolate->factory()->NewSubString(subject, 0, index); Handle<String> first = isolate->factory()->NewSubString(subject, 0, index);
Handle<String> cons1 = isolate->factory()->NewConsString(first, replace); Handle<String> cons1;
RETURN_IF_EMPTY_HANDLE_VALUE(isolate, cons1, Handle<String>()); ASSIGN_RETURN_ON_EXCEPTION(
isolate, cons1,
isolate->factory()->NewConsString(first, replace),
String);
Handle<String> second = Handle<String> second =
isolate->factory()->NewSubString(subject, index + 1, subject->length()); isolate->factory()->NewSubString(subject, index + 1, subject->length());
return isolate->factory()->NewConsString(cons1, second); return isolate->factory()->NewConsString(cons1, second);
...@@ -4293,20 +4295,20 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceOneCharWithString) { ...@@ -4293,20 +4295,20 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceOneCharWithString) {
// retry with a flattened subject string. // retry with a flattened subject string.
const int kRecursionLimit = 0x1000; const int kRecursionLimit = 0x1000;
bool found = false; bool found = false;
Handle<String> result = StringReplaceOneCharWithString(isolate, Handle<String> result;
subject, if (StringReplaceOneCharWithString(
search, isolate, subject, search, replace, &found, kRecursionLimit)
replace, .ToHandle(&result)) {
&found, return *result;
kRecursionLimit); }
if (!result.is_null()) return *result;
if (isolate->has_pending_exception()) return Failure::Exception(); if (isolate->has_pending_exception()) return Failure::Exception();
return *StringReplaceOneCharWithString(isolate,
FlattenGetString(subject), subject = FlattenGetString(subject);
search, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
replace, isolate, result,
&found, StringReplaceOneCharWithString(
kRecursionLimit); isolate, subject, search, replace, &found, kRecursionLimit));
return *result;
} }
...@@ -6295,9 +6297,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) { ...@@ -6295,9 +6297,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) {
CONVERT_ARG_HANDLE_CHECKED(String, source, 0); CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
Handle<String> string = FlattenGetString(source); Handle<String> string = FlattenGetString(source);
ASSERT(string->IsFlat()); ASSERT(string->IsFlat());
return string->IsOneByteRepresentationUnderneath() Handle<String> result;
? *URIUnescape::Unescape<uint8_t>(isolate, source) ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
: *URIUnescape::Unescape<uc16>(isolate, source); isolate, result,
string->IsOneByteRepresentationUnderneath()
? URIUnescape::Unescape<uint8_t>(isolate, source)
: URIUnescape::Unescape<uc16>(isolate, source));
return *result;
} }
...@@ -7067,8 +7073,9 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringAdd) { ...@@ -7067,8 +7073,9 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringAdd) {
CONVERT_ARG_HANDLE_CHECKED(String, str1, 0); CONVERT_ARG_HANDLE_CHECKED(String, str1, 0);
CONVERT_ARG_HANDLE_CHECKED(String, str2, 1); CONVERT_ARG_HANDLE_CHECKED(String, str2, 1);
isolate->counters()->string_add_runtime()->Increment(); isolate->counters()->string_add_runtime()->Increment();
Handle<String> result = isolate->factory()->NewConsString(str1, str2); Handle<String> result;
RETURN_IF_EMPTY_HANDLE(isolate, result); ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, isolate->factory()->NewConsString(str1, str2));
return *result; return *result;
} }
......
...@@ -61,13 +61,13 @@ Vector<const uc16> GetCharVector(Handle<String> string) { ...@@ -61,13 +61,13 @@ Vector<const uc16> GetCharVector(Handle<String> string) {
class URIUnescape : public AllStatic { class URIUnescape : public AllStatic {
public: public:
template<typename Char> template<typename Char>
static Handle<String> Unescape(Isolate* isolate, Handle<String> source); static MaybeHandle<String> Unescape(Isolate* isolate, Handle<String> source);
private: private:
static const signed char kHexValue['g']; static const signed char kHexValue['g'];
template<typename Char> template<typename Char>
static Handle<String> UnescapeSlow( static MaybeHandle<String> UnescapeSlow(
Isolate* isolate, Handle<String> string, int start_index); Isolate* isolate, Handle<String> string, int start_index);
static INLINE(int TwoDigitHex(uint16_t character1, uint16_t character2)); static INLINE(int TwoDigitHex(uint16_t character1, uint16_t character2));
...@@ -91,7 +91,8 @@ const signed char URIUnescape::kHexValue[] = { ...@@ -91,7 +91,8 @@ const signed char URIUnescape::kHexValue[] = {
template<typename Char> template<typename Char>
Handle<String> URIUnescape::Unescape(Isolate* isolate, Handle<String> source) { MaybeHandle<String> URIUnescape::Unescape(Isolate* isolate,
Handle<String> source) {
int index; int index;
{ DisallowHeapAllocation no_allocation; { DisallowHeapAllocation no_allocation;
StringSearch<uint8_t, Char> search(isolate, STATIC_ASCII_VECTOR("%")); StringSearch<uint8_t, Char> search(isolate, STATIC_ASCII_VECTOR("%"));
...@@ -103,7 +104,7 @@ Handle<String> URIUnescape::Unescape(Isolate* isolate, Handle<String> source) { ...@@ -103,7 +104,7 @@ Handle<String> URIUnescape::Unescape(Isolate* isolate, Handle<String> source) {
template <typename Char> template <typename Char>
Handle<String> URIUnescape::UnescapeSlow( MaybeHandle<String> URIUnescape::UnescapeSlow(
Isolate* isolate, Handle<String> string, int start_index) { Isolate* isolate, Handle<String> string, int start_index) {
bool one_byte = true; bool one_byte = true;
int length = string->length(); int length = string->length();
......
...@@ -445,7 +445,8 @@ TEST(HeapSnapshotConsString) { ...@@ -445,7 +445,8 @@ TEST(HeapSnapshotConsString) {
factory->NewStringFromAscii(i::CStrVector("0123456789")); factory->NewStringFromAscii(i::CStrVector("0123456789"));
i::Handle<i::String> second = i::Handle<i::String> second =
factory->NewStringFromAscii(i::CStrVector("0123456789")); factory->NewStringFromAscii(i::CStrVector("0123456789"));
i::Handle<i::String> cons_string = factory->NewConsString(first, second); i::Handle<i::String> cons_string =
factory->NewConsString(first, second).ToHandleChecked();
global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string)); global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string));
......
...@@ -447,7 +447,7 @@ static Handle<String> ConstructRandomString(ConsStringGenerationData* data, ...@@ -447,7 +447,7 @@ static Handle<String> ConstructRandomString(ConsStringGenerationData* data,
left = ConstructRandomString(data, max_recursion - 1); left = ConstructRandomString(data, max_recursion - 1);
} }
// Build the cons string. // Build the cons string.
Handle<String> root = factory->NewConsString(left, right); Handle<String> root = factory->NewConsString(left, right).ToHandleChecked();
CHECK(root->IsConsString() && !root->IsFlat()); CHECK(root->IsConsString() && !root->IsFlat());
// Special work needed for flat string. // Special work needed for flat string.
if (flat) { if (flat) {
...@@ -467,7 +467,8 @@ static Handle<String> ConstructLeft( ...@@ -467,7 +467,8 @@ static Handle<String> ConstructLeft(
data->stats_.leaves_++; data->stats_.leaves_++;
for (int i = 0; i < depth; i++) { for (int i = 0; i < depth; i++) {
Handle<String> block = data->block(i); Handle<String> block = data->block(i);
Handle<String> next = factory->NewConsString(answer, block); Handle<String> next =
factory->NewConsString(answer, block).ToHandleChecked();
if (next->IsConsString()) data->stats_.leaves_++; if (next->IsConsString()) data->stats_.leaves_++;
data->stats_.chars_ += block->length(); data->stats_.chars_ += block->length();
answer = next; answer = next;
...@@ -485,7 +486,8 @@ static Handle<String> ConstructRight( ...@@ -485,7 +486,8 @@ static Handle<String> ConstructRight(
data->stats_.leaves_++; data->stats_.leaves_++;
for (int i = depth - 1; i >= 0; i--) { for (int i = depth - 1; i >= 0; i--) {
Handle<String> block = data->block(i); Handle<String> block = data->block(i);
Handle<String> next = factory->NewConsString(block, answer); Handle<String> next =
factory->NewConsString(block, answer).ToHandleChecked();
if (next->IsConsString()) data->stats_.leaves_++; if (next->IsConsString()) data->stats_.leaves_++;
data->stats_.chars_ += block->length(); data->stats_.chars_ += block->length();
answer = next; answer = next;
...@@ -508,7 +510,8 @@ static Handle<String> ConstructBalancedHelper( ...@@ -508,7 +510,8 @@ static Handle<String> ConstructBalancedHelper(
if (to - from == 2) { if (to - from == 2) {
data->stats_.chars_ += data->block(from)->length(); data->stats_.chars_ += data->block(from)->length();
data->stats_.chars_ += data->block(from+1)->length(); data->stats_.chars_ += data->block(from+1)->length();
return factory->NewConsString(data->block(from), data->block(from+1)); return factory->NewConsString(data->block(from), data->block(from+1))
.ToHandleChecked();
} }
Handle<String> part1 = Handle<String> part1 =
ConstructBalancedHelper(data, from, from + ((to - from) / 2)); ConstructBalancedHelper(data, from, from + ((to - from) / 2));
...@@ -516,7 +519,7 @@ static Handle<String> ConstructBalancedHelper( ...@@ -516,7 +519,7 @@ static Handle<String> ConstructBalancedHelper(
ConstructBalancedHelper(data, from + ((to - from) / 2), to); ConstructBalancedHelper(data, from + ((to - from) / 2), to);
if (part1->IsConsString()) data->stats_.left_traversals_++; if (part1->IsConsString()) data->stats_.left_traversals_++;
if (part2->IsConsString()) data->stats_.right_traversals_++; if (part2->IsConsString()) data->stats_.right_traversals_++;
return factory->NewConsString(part1, part2); return factory->NewConsString(part1, part2).ToHandleChecked();
} }
...@@ -710,7 +713,8 @@ static Handle<String> BuildEdgeCaseConsString( ...@@ -710,7 +713,8 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.chars_ += data->block(0)->length(); data->stats_.chars_ += data->block(0)->length();
data->stats_.chars_ += data->block(1)->length(); data->stats_.chars_ += data->block(1)->length();
data->stats_.leaves_ += 2; data->stats_.leaves_ += 2;
return factory->NewConsString(data->block(0), data->block(1)); return factory->NewConsString(data->block(0), data->block(1))
.ToHandleChecked();
case 6: case 6:
// Simple flattened tree. // Simple flattened tree.
data->stats_.chars_ += data->block(0)->length(); data->stats_.chars_ += data->block(0)->length();
...@@ -719,7 +723,8 @@ static Handle<String> BuildEdgeCaseConsString( ...@@ -719,7 +723,8 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.empty_leaves_ += 1; data->stats_.empty_leaves_ += 1;
{ {
Handle<String> string = Handle<String> string =
factory->NewConsString(data->block(0), data->block(1)); factory->NewConsString(data->block(0), data->block(1))
.ToHandleChecked();
FlattenString(string); FlattenString(string);
return string; return string;
} }
...@@ -733,9 +738,10 @@ static Handle<String> BuildEdgeCaseConsString( ...@@ -733,9 +738,10 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.left_traversals_ += 1; data->stats_.left_traversals_ += 1;
{ {
Handle<String> left = Handle<String> left =
factory->NewConsString(data->block(0), data->block(1)); factory->NewConsString(data->block(0), data->block(1))
.ToHandleChecked();
FlattenString(left); FlattenString(left);
return factory->NewConsString(left, data->block(2)); return factory->NewConsString(left, data->block(2)).ToHandleChecked();
} }
case 8: case 8:
// Left node and right node flattened. // Left node and right node flattened.
...@@ -749,12 +755,14 @@ static Handle<String> BuildEdgeCaseConsString( ...@@ -749,12 +755,14 @@ static Handle<String> BuildEdgeCaseConsString(
data->stats_.right_traversals_ += 1; data->stats_.right_traversals_ += 1;
{ {
Handle<String> left = Handle<String> left =
factory->NewConsString(data->block(0), data->block(1)); factory->NewConsString(data->block(0), data->block(1))
.ToHandleChecked();
FlattenString(left); FlattenString(left);
Handle<String> right = Handle<String> right =
factory->NewConsString(data->block(2), data->block(2)); factory->NewConsString(data->block(2), data->block(2))
.ToHandleChecked();
FlattenString(right); FlattenString(right);
return factory->NewConsString(left, right); return factory->NewConsString(left, right).ToHandleChecked();
} }
} }
UNREACHABLE(); UNREACHABLE();
...@@ -866,9 +874,10 @@ TEST(DeepAscii) { ...@@ -866,9 +874,10 @@ TEST(DeepAscii) {
factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH));
Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo")); Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo"));
for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) {
string = factory->NewConsString(string, foo_string); string = factory->NewConsString(string, foo_string).ToHandleChecked();
} }
Handle<String> flat_string = factory->NewConsString(string, foo_string); Handle<String> flat_string =
factory->NewConsString(string, foo_string).ToHandleChecked();
FlattenString(flat_string); FlattenString(flat_string);
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
...@@ -1092,7 +1101,8 @@ TEST(SliceFromCons) { ...@@ -1092,7 +1101,8 @@ TEST(SliceFromCons) {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Handle<String> string = Handle<String> string =
factory->NewStringFromAscii(CStrVector("parentparentparent")); factory->NewStringFromAscii(CStrVector("parentparentparent"));
Handle<String> parent = factory->NewConsString(string, string); Handle<String> parent =
factory->NewConsString(string, string).ToHandleChecked();
CHECK(parent->IsConsString()); CHECK(parent->IsConsString());
CHECK(!parent->IsFlat()); CHECK(!parent->IsFlat());
Handle<String> slice = factory->NewSubString(parent, 1, 25); Handle<String> slice = factory->NewSubString(parent, 1, 25);
......
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