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

Side by Side Diff: content/child/v8_value_converter_impl.cc

Issue 1918793003: V8ValueConverter::ToV8Value should not trigger setters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/v8_value_converter_impl.h" 5 #include "content/child/v8_value_converter_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return v8::Null(isolate); 223 return v8::Null(isolate);
224 } 224 }
225 } 225 }
226 226
227 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Array( 227 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Array(
228 v8::Isolate* isolate, 228 v8::Isolate* isolate,
229 v8::Local<v8::Object> creation_context, 229 v8::Local<v8::Object> creation_context,
230 const base::ListValue* val) const { 230 const base::ListValue* val) const {
231 v8::Local<v8::Array> result(v8::Array::New(isolate, val->GetSize())); 231 v8::Local<v8::Array> result(v8::Array::New(isolate, val->GetSize()));
232 232
233 // TODO(robwu): Callers should pass in the context.
234 v8::Local<v8::Context> context = isolate->GetCurrentContext();
235
233 for (size_t i = 0; i < val->GetSize(); ++i) { 236 for (size_t i = 0; i < val->GetSize(); ++i) {
234 const base::Value* child = NULL; 237 const base::Value* child = NULL;
235 CHECK(val->Get(i, &child)); 238 CHECK(val->Get(i, &child));
236 239
237 v8::Local<v8::Value> child_v8 = 240 v8::Local<v8::Value> child_v8 =
238 ToV8ValueImpl(isolate, creation_context, child); 241 ToV8ValueImpl(isolate, creation_context, child);
239 CHECK(!child_v8.IsEmpty()); 242 CHECK(!child_v8.IsEmpty());
240 243
241 v8::TryCatch try_catch(isolate); 244 v8::Maybe<bool> maybe =
242 result->Set(static_cast<uint32_t>(i), child_v8); 245 result->CreateDataProperty(context, static_cast<uint32_t>(i), child_v8);
243 if (try_catch.HasCaught()) 246 if (!maybe.IsJust() || !maybe.FromJust())
244 LOG(ERROR) << "Setter for index " << i << " threw an exception."; 247 LOG(ERROR) << "Failed to set value at index " << i;
245 } 248 }
246 249
247 return result; 250 return result;
248 } 251 }
249 252
250 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Object( 253 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Object(
251 v8::Isolate* isolate, 254 v8::Isolate* isolate,
252 v8::Local<v8::Object> creation_context, 255 v8::Local<v8::Object> creation_context,
253 const base::DictionaryValue* val) const { 256 const base::DictionaryValue* val) const {
254 v8::Local<v8::Object> result(v8::Object::New(isolate)); 257 v8::Local<v8::Object> result(v8::Object::New(isolate));
255 258
259 // TODO(robwu): Callers should pass in the context.
260 v8::Local<v8::Context> context = isolate->GetCurrentContext();
261
256 for (base::DictionaryValue::Iterator iter(*val); 262 for (base::DictionaryValue::Iterator iter(*val);
257 !iter.IsAtEnd(); iter.Advance()) { 263 !iter.IsAtEnd(); iter.Advance()) {
258 const std::string& key = iter.key(); 264 const std::string& key = iter.key();
259 v8::Local<v8::Value> child_v8 = 265 v8::Local<v8::Value> child_v8 =
260 ToV8ValueImpl(isolate, creation_context, &iter.value()); 266 ToV8ValueImpl(isolate, creation_context, &iter.value());
261 CHECK(!child_v8.IsEmpty()); 267 CHECK(!child_v8.IsEmpty());
262 268
263 v8::TryCatch try_catch(isolate); 269 v8::Maybe<bool> maybe = result->CreateDataProperty(
264 result->Set( 270 context,
265 v8::String::NewFromUtf8( 271 v8::String::NewFromUtf8(isolate, key.c_str(), v8::String::kNormalString,
266 isolate, key.c_str(), v8::String::kNormalString, key.length()), 272 key.length()),
267 child_v8); 273 child_v8);
268 if (try_catch.HasCaught()) { 274 if (!maybe.IsJust() || !maybe.FromJust())
269 LOG(ERROR) << "Setter for property " << key.c_str() << " threw an " 275 LOG(ERROR) << "Failed to set property with key " << key;
270 << "exception.";
271 }
272 } 276 }
273 277
274 return result; 278 return result;
275 } 279 }
276 280
277 v8::Local<v8::Value> V8ValueConverterImpl::ToArrayBuffer( 281 v8::Local<v8::Value> V8ValueConverterImpl::ToArrayBuffer(
278 v8::Isolate* isolate, 282 v8::Isolate* isolate,
279 v8::Local<v8::Object> creation_context, 283 v8::Local<v8::Object> creation_context,
280 const base::BinaryValue* value) const { 284 const base::BinaryValue* value) const {
281 blink::WebArrayBuffer buffer = 285 blink::WebArrayBuffer buffer =
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 continue; 556 continue;
553 557
554 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 558 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
555 child.release()); 559 child.release());
556 } 560 }
557 561
558 return result.release(); 562 return result.release();
559 } 563 }
560 564
561 } // namespace content 565 } // namespace content
OLDNEW
« 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