Reviewers: Igor Sheludko,
Description:
Return MaybeHandle from NewExternalStringFrom*.
[email protected]
Please review this at https://codereview.chromium.org/223653003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+23, -22 lines):
M src/api.cc
M src/bootstrapper.cc
M src/factory.h
M src/factory.cc
M src/handles.h
M test/cctest/test-api.cc
M test/cctest/test-parsing.cc
M test/cctest/test-strings.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
1386a3a0a2b7787dbcf2c71e6ca0d49ffbe6faac..c319c3aa5dfd4f0406d2304f848998765d95f6fd
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -5470,22 +5470,18 @@ Local<String> v8::String::Concat(Handle<String>
left, Handle<String> right) {
static i::Handle<i::String> NewExternalStringHandle(
i::Isolate* isolate,
v8::String::ExternalStringResource* resource) {
- i::Handle<i::String> result =
- isolate->factory()->NewExternalStringFromTwoByte(resource);
// We do not expect this to fail. Change this if it does.
- CHECK(!result.is_null());
- return result;
+ return isolate->factory()->NewExternalStringFromTwoByte(
+ resource).ToHandleChecked();
}
static i::Handle<i::String> NewExternalAsciiStringHandle(
i::Isolate* isolate,
v8::String::ExternalAsciiStringResource* resource) {
- i::Handle<i::String> result =
- isolate->factory()->NewExternalStringFromAscii(resource);
// We do not expect this to fail. Change this if it does.
- CHECK(!result.is_null());
- return result;
+ return isolate->factory()->NewExternalStringFromAscii(
+ resource).ToHandleChecked();
}
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index
da70f59d2d697295d3128776fe5a6654fb4dd9ef..1da742eea6c788e7da9213de7b121c22ee78febf
100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -53,10 +53,10 @@ Handle<String> Bootstrapper::NativesSourceLookup(int
index) {
new NativesExternalStringResource(this,
source.start(),
source.length());
- Handle<String> source_code =
- isolate_->factory()->NewExternalStringFromAscii(resource);
// We do not expect this to throw an exception. Change this if it does.
- CHECK_NOT_EMPTY_HANDLE(isolate_, source_code);
+ Handle<String> source_code =
+ isolate_->factory()->NewExternalStringFromAscii(
+ resource).ToHandleChecked();
heap->natives_source_cache()->set(index, *source_code);
}
Handle<Object> cached_source(heap->natives_source_cache()->get(index),
@@ -2319,10 +2319,10 @@ bool Genesis::InstallExtension(Isolate* isolate,
return false;
}
}
- Handle<String> source_code =
- isolate->factory()->NewExternalStringFromAscii(extension->source());
// We do not expect this to throw an exception. Change this if it does.
- CHECK_NOT_EMPTY_HANDLE(isolate, source_code);
+ Handle<String> source_code =
+ isolate->factory()->NewExternalStringFromAscii(
+ extension->source()).ToHandleChecked();
bool result = CompileScriptCached(isolate,
CStrVector(extension->name()),
source_code,
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index
52a194180be30b9c675b83ef45d7ce06f137f45e..cfbd738d91ebd4337989e277c645fc8561666f23
100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -518,7 +518,7 @@ Handle<String>
Factory::NewProperSubString(Handle<String> str,
}
-Handle<String> Factory::NewExternalStringFromAscii(
+MaybeHandle<String> Factory::NewExternalStringFromAscii(
const ExternalAsciiString::Resource* resource) {
CALL_HEAP_FUNCTION(
isolate(),
@@ -527,7 +527,7 @@ Handle<String> Factory::NewExternalStringFromAscii(
}
-Handle<String> Factory::NewExternalStringFromTwoByte(
+MaybeHandle<String> Factory::NewExternalStringFromTwoByte(
const ExternalTwoByteString::Resource* resource) {
CALL_HEAP_FUNCTION(
isolate(),
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index
6321132f441f17564262d73b47ec49cc9852f407..e2293ff675ff342af07a9abf92dfaadd5a870983
100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -166,9 +166,9 @@ class Factory V8_FINAL {
// in the system: ASCII and two byte. Unlike other String types, it does
// not make sense to have a UTF-8 factory function for external strings,
// because we cannot change the underlying buffer.
- Handle<String> NewExternalStringFromAscii(
+ MaybeHandle<String> NewExternalStringFromAscii(
const ExternalAsciiString::Resource* resource);
- Handle<String> NewExternalStringFromTwoByte(
+ MaybeHandle<String> NewExternalStringFromTwoByte(
const ExternalTwoByteString::Resource* resource);
// Create a symbol.
Index: src/handles.h
diff --git a/src/handles.h b/src/handles.h
index
77e5e528da6e2fa04ea7386fe6ff00bd79394401..21c399009c95ff41d0bbd5b1600732ae4e8fb335
100644
--- a/src/handles.h
+++ b/src/handles.h
@@ -82,6 +82,8 @@ class MaybeHandle {
}
}
+ bool is_null() const { return location_ == NULL; }
+
protected:
T** location_;
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
3e307175cc334879794cfed4a39a8e845e40d3a6..52a71ac1b2c8e3bd3ac490626b119cb2937567e7
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -15122,9 +15122,11 @@ THREADED_TEST(MorphCompositeStringTest) {
i::StrLength(c_string)));
Local<String> lhs(v8::Utils::ToLocal(
- factory->NewExternalStringFromAscii(&ascii_resource)));
+ factory->NewExternalStringFromAscii(&ascii_resource)
+ .ToHandleChecked()));
Local<String> rhs(v8::Utils::ToLocal(
- factory->NewExternalStringFromAscii(&ascii_resource)));
+ factory->NewExternalStringFromAscii(&ascii_resource)
+ .ToHandleChecked()));
env->Global()->Set(v8_str("lhs"), lhs);
env->Global()->Set(v8_str("rhs"), rhs);
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
e9429bf3858bffced84e5e6f73d2f194617efd6e..56d20f0b344db4db14ad7608780e2bc0f4e5819a
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -655,7 +655,7 @@ void TestCharacterStream(const char* ascii_source,
factory->NewStringFromAscii(ascii_vector));
TestExternalResource resource(uc16_buffer.get(), length);
i::Handle<i::String> uc16_string(
- factory->NewExternalStringFromTwoByte(&resource));
+ factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked());
i::ExternalTwoByteStringUtf16CharacterStream uc16_stream(
i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end);
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index
6ff52003b8412ca1c8fc694df847f6ac475e3a38..4a60dcf811835579be207afa769ee167bdd8a208
100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -1127,7 +1127,8 @@ TEST(SliceFromExternal) {
v8::HandleScope scope(CcTest::isolate());
AsciiVectorResource resource(
i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26));
- Handle<String> string = factory->NewExternalStringFromAscii(&resource);
+ Handle<String> string =
+ factory->NewExternalStringFromAscii(&resource).ToHandleChecked();
CHECK(string->IsExternalString());
Handle<String> slice = factory->NewSubString(string, 1, 25);
CHECK(slice->IsSlicedString());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.