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

Unified Diff: content/child/v8_value_converter_impl.cc

Issue 1930953002: V8ValueConverter::ToV8Value should not trigger setters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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 | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/v8_value_converter_impl.cc
diff --git a/content/child/v8_value_converter_impl.cc b/content/child/v8_value_converter_impl.cc
index dc32d9fd94961e2ea40ef9fd1bc756349b5fd999..c37160fe5979486981024510777ddf779dbb9040 100644
--- a/content/child/v8_value_converter_impl.cc
+++ b/content/child/v8_value_converter_impl.cc
@@ -230,6 +230,9 @@ v8::Local<v8::Value> V8ValueConverterImpl::ToV8Array(
const base::ListValue* val) const {
v8::Local<v8::Array> result(v8::Array::New(isolate, val->GetSize()));
+ // TODO(robwu): Callers should pass in the context.
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+
for (size_t i = 0; i < val->GetSize(); ++i) {
const base::Value* child = NULL;
CHECK(val->Get(i, &child));
@@ -238,10 +241,10 @@ v8::Local<v8::Value> V8ValueConverterImpl::ToV8Array(
ToV8ValueImpl(isolate, creation_context, child);
CHECK(!child_v8.IsEmpty());
- v8::TryCatch try_catch(isolate);
- result->Set(static_cast<uint32_t>(i), child_v8);
- if (try_catch.HasCaught())
- LOG(ERROR) << "Setter for index " << i << " threw an exception.";
+ v8::Maybe<bool> maybe =
+ result->CreateDataProperty(context, static_cast<uint32_t>(i), child_v8);
+ if (!maybe.IsJust() || !maybe.FromJust())
+ LOG(ERROR) << "Failed to set value at index " << i;
}
return result;
@@ -253,6 +256,9 @@ v8::Local<v8::Value> V8ValueConverterImpl::ToV8Object(
const base::DictionaryValue* val) const {
v8::Local<v8::Object> result(v8::Object::New(isolate));
+ // TODO(robwu): Callers should pass in the context.
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+
for (base::DictionaryValue::Iterator iter(*val);
!iter.IsAtEnd(); iter.Advance()) {
const std::string& key = iter.key();
@@ -260,15 +266,13 @@ v8::Local<v8::Value> V8ValueConverterImpl::ToV8Object(
ToV8ValueImpl(isolate, creation_context, &iter.value());
CHECK(!child_v8.IsEmpty());
- v8::TryCatch try_catch(isolate);
- result->Set(
- v8::String::NewFromUtf8(
- isolate, key.c_str(), v8::String::kNormalString, key.length()),
+ v8::Maybe<bool> maybe = result->CreateDataProperty(
+ context,
+ v8::String::NewFromUtf8(isolate, key.c_str(), v8::String::kNormalString,
+ key.length()),
child_v8);
- if (try_catch.HasCaught()) {
- LOG(ERROR) << "Setter for property " << key.c_str() << " threw an "
- << "exception.";
- }
+ if (!maybe.IsJust() || !maybe.FromJust())
+ LOG(ERROR) << "Failed to set property with key " << key;
}
return result;
« no previous file with comments | « no previous file | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698