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

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

Issue 19730002: V8ValueConverter for the activity logger that does not invoke interceptors and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ben's comments Created 7 years, 4 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 | Annotate | Revision Log
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/renderer/v8_value_converter_impl.h" 5 #include "content/renderer/v8_value_converter_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/float_util.h" 9 #include "base/float_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 V8ValueConverter* V8ValueConverter::create() { 80 V8ValueConverter* V8ValueConverter::create() {
81 return new V8ValueConverterImpl(); 81 return new V8ValueConverterImpl();
82 } 82 }
83 83
84 V8ValueConverterImpl::V8ValueConverterImpl() 84 V8ValueConverterImpl::V8ValueConverterImpl()
85 : date_allowed_(false), 85 : date_allowed_(false),
86 reg_exp_allowed_(false), 86 reg_exp_allowed_(false),
87 function_allowed_(false), 87 function_allowed_(false),
88 strip_null_from_objects_(false), 88 strip_null_from_objects_(false),
89 avoid_identity_hash_for_testing_(false) {} 89 avoid_identity_hash_for_testing_(false),
90 strategy_(NULL) {}
90 91
91 void V8ValueConverterImpl::SetDateAllowed(bool val) { 92 void V8ValueConverterImpl::SetDateAllowed(bool val) {
92 date_allowed_ = val; 93 date_allowed_ = val;
93 } 94 }
94 95
95 void V8ValueConverterImpl::SetRegExpAllowed(bool val) { 96 void V8ValueConverterImpl::SetRegExpAllowed(bool val) {
96 reg_exp_allowed_ = val; 97 reg_exp_allowed_ = val;
97 } 98 }
98 99
99 void V8ValueConverterImpl::SetFunctionAllowed(bool val) { 100 void V8ValueConverterImpl::SetFunctionAllowed(bool val) {
100 function_allowed_ = val; 101 function_allowed_ = val;
101 } 102 }
102 103
103 void V8ValueConverterImpl::SetStripNullFromObjects(bool val) { 104 void V8ValueConverterImpl::SetStripNullFromObjects(bool val) {
104 strip_null_from_objects_ = val; 105 strip_null_from_objects_ = val;
105 } 106 }
106 107
108 void V8ValueConverterImpl::SetStrategy(Strategy* strategy) {
109 strategy_ = strategy;
110 }
111
107 v8::Handle<v8::Value> V8ValueConverterImpl::ToV8Value( 112 v8::Handle<v8::Value> V8ValueConverterImpl::ToV8Value(
108 const base::Value* value, v8::Handle<v8::Context> context) const { 113 const base::Value* value, v8::Handle<v8::Context> context) const {
109 v8::Context::Scope context_scope(context); 114 v8::Context::Scope context_scope(context);
110 v8::HandleScope handle_scope; 115 v8::HandleScope handle_scope;
111 return handle_scope.Close(ToV8ValueImpl(value)); 116 return handle_scope.Close(ToV8ValueImpl(value));
112 } 117 }
113 118
114 Value* V8ValueConverterImpl::FromV8Value( 119 Value* V8ValueConverterImpl::FromV8Value(
115 v8::Handle<v8::Value> val, 120 v8::Handle<v8::Value> val,
116 v8::Handle<v8::Context> context) const { 121 v8::Handle<v8::Context> context) const {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 return NULL; 294 return NULL;
290 } 295 }
291 296
292 base::Value* V8ValueConverterImpl::FromV8Array( 297 base::Value* V8ValueConverterImpl::FromV8Array(
293 v8::Handle<v8::Array> val, 298 v8::Handle<v8::Array> val,
294 FromV8ValueState* state) const { 299 FromV8ValueState* state) const {
295 if (!state->UpdateAndCheckUniqueness(val)) 300 if (!state->UpdateAndCheckUniqueness(val))
296 return base::Value::CreateNullValue(); 301 return base::Value::CreateNullValue();
297 302
298 scoped_ptr<v8::Context::Scope> scope; 303 scoped_ptr<v8::Context::Scope> scope;
304
305 if (strategy_) {
306 Value* out = NULL;
307 if (strategy_->FromV8Array(val, &out))
308 return out;
309 }
not at google - send to devlin 2013/08/08 01:02:21 it needs to be after scope is reset() below.
pmarch 2013/08/08 03:20:18 gotcha
310
299 // If val was created in a different context than our current one, change to 311 // If val was created in a different context than our current one, change to
300 // that context, but change back after val is converted. 312 // that context, but change back after val is converted.
301 if (!val->CreationContext().IsEmpty() && 313 if (!val->CreationContext().IsEmpty() &&
302 val->CreationContext() != v8::Context::GetCurrent()) 314 val->CreationContext() != v8::Context::GetCurrent())
303 scope.reset(new v8::Context::Scope(val->CreationContext())); 315 scope.reset(new v8::Context::Scope(val->CreationContext()));
304 316
305 base::ListValue* result = new base::ListValue(); 317 base::ListValue* result = new base::ListValue();
306 318
307 // Only fields with integer keys are carried over to the ListValue. 319 // Only fields with integer keys are carried over to the ListValue.
308 for (uint32 i = 0; i < val->Length(); ++i) { 320 for (uint32 i = 0; i < val->Length(); ++i) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return base::BinaryValue::CreateWithCopiedBuffer(data, length); 362 return base::BinaryValue::CreateWithCopiedBuffer(data, length);
351 else 363 else
352 return NULL; 364 return NULL;
353 } 365 }
354 366
355 base::Value* V8ValueConverterImpl::FromV8Object( 367 base::Value* V8ValueConverterImpl::FromV8Object(
356 v8::Handle<v8::Object> val, 368 v8::Handle<v8::Object> val,
357 FromV8ValueState* state) const { 369 FromV8ValueState* state) const {
358 if (!state->UpdateAndCheckUniqueness(val)) 370 if (!state->UpdateAndCheckUniqueness(val))
359 return base::Value::CreateNullValue(); 371 return base::Value::CreateNullValue();
372
360 scoped_ptr<v8::Context::Scope> scope; 373 scoped_ptr<v8::Context::Scope> scope;
374
375 if (strategy_) {
376 Value* out = NULL;
377 if (strategy_->FromV8Object(val, &out))
378 return out;
379 }
not at google - send to devlin 2013/08/08 01:02:21 ditto
pmarch 2013/08/08 03:20:18 Done.
380
361 // If val was created in a different context than our current one, change to 381 // If val was created in a different context than our current one, change to
362 // that context, but change back after val is converted. 382 // that context, but change back after val is converted.
363 if (!val->CreationContext().IsEmpty() && 383 if (!val->CreationContext().IsEmpty() &&
364 val->CreationContext() != v8::Context::GetCurrent()) 384 val->CreationContext() != v8::Context::GetCurrent())
365 scope.reset(new v8::Context::Scope(val->CreationContext())); 385 scope.reset(new v8::Context::Scope(val->CreationContext()));
366 386
367 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 387 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
368 v8::Handle<v8::Array> property_names(val->GetOwnPropertyNames()); 388 v8::Handle<v8::Array> property_names(val->GetOwnPropertyNames());
369 389
370 for (uint32 i = 0; i < property_names->Length(); ++i) { 390 for (uint32 i = 0; i < property_names->Length(); ++i) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 continue; 439 continue;
420 440
421 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 441 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
422 child.release()); 442 child.release());
423 } 443 }
424 444
425 return result.release(); 445 return result.release();
426 } 446 }
427 447
428 } // namespace content 448 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698