| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/activity_log_converter_strategy.h" | 5 #include "extensions/renderer/activity_log_converter_strategy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "extensions/renderer/v8_maybe_helpers.h" |
| 9 #include "v8/include/v8.h" | 10 #include "v8/include/v8.h" |
| 10 | 11 |
| 11 namespace extensions { | 12 namespace extensions { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Summarize a V8 value. This performs a shallow conversion in all cases, and | 16 // Summarize a V8 value. This performs a shallow conversion in all cases, and |
| 16 // returns only a string with a description of the value (e.g., | 17 // returns only a string with a description of the value (e.g., |
| 17 // "[HTMLElement]"). | 18 // "[HTMLElement]"). |
| 18 scoped_ptr<base::Value> SummarizeV8Value(v8::Isolate* isolate, | 19 scoped_ptr<base::Value> SummarizeV8Value(v8::Isolate* isolate, |
| 19 v8::Local<v8::Object> object) { | 20 v8::Local<v8::Object> object) { |
| 20 v8::TryCatch try_catch; | 21 v8::TryCatch try_catch(isolate); |
| 21 v8::Isolate::DisallowJavascriptExecutionScope scope( | 22 v8::Isolate::DisallowJavascriptExecutionScope scope( |
| 22 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); | 23 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 23 v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, "["); | 24 v8::Local<v8::String> name = ToV8String(isolate, "["); |
| 24 if (object->IsFunction()) { | 25 if (object->IsFunction()) { |
| 25 name = | 26 name = |
| 26 v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "Function")); | 27 v8::String::Concat(name, ToV8String(isolate, "Function")); |
| 27 v8::Local<v8::Value> fname = | 28 v8::Local<v8::Value> fname = |
| 28 v8::Local<v8::Function>::Cast(object)->GetName(); | 29 v8::Local<v8::Function>::Cast(object)->GetName(); |
| 29 if (fname->IsString() && v8::Local<v8::String>::Cast(fname)->Length()) { | 30 if (fname->IsString() && v8::Local<v8::String>::Cast(fname)->Length()) { |
| 30 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, " ")); | 31 name = v8::String::Concat(name, ToV8String(isolate, " ")); |
| 31 name = v8::String::Concat(name, v8::Local<v8::String>::Cast(fname)); | 32 name = v8::String::Concat(name, v8::Local<v8::String>::Cast(fname)); |
| 32 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "()")); | 33 name = v8::String::Concat(name, ToV8String(isolate, "()")); |
| 33 } | 34 } |
| 34 } else { | 35 } else { |
| 35 name = v8::String::Concat(name, object->GetConstructorName()); | 36 name = v8::String::Concat(name, object->GetConstructorName()); |
| 36 } | 37 } |
| 37 name = v8::String::Concat(name, v8::String::NewFromUtf8(isolate, "]")); | 38 name = v8::String::Concat(name, ToV8String(isolate, "]")); |
| 38 | 39 |
| 39 if (try_catch.HasCaught()) { | 40 if (try_catch.HasCaught()) { |
| 40 return scoped_ptr<base::Value>( | 41 return scoped_ptr<base::Value>( |
| 41 new base::StringValue("[JS Execution Exception]")); | 42 new base::StringValue("[JS Execution Exception]")); |
| 42 } | 43 } |
| 43 | 44 |
| 44 return scoped_ptr<base::Value>( | 45 return scoped_ptr<base::Value>( |
| 45 new base::StringValue(std::string(*v8::String::Utf8Value(name)))); | 46 new base::StringValue(std::string(*v8::String::Utf8Value(name)))); |
| 46 } | 47 } |
| 47 | 48 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 v8::Isolate* isolate, | 74 v8::Isolate* isolate, |
| 74 const FromV8ValueCallback& callback) const { | 75 const FromV8ValueCallback& callback) const { |
| 75 scoped_ptr<base::Value> parsed_value; | 76 scoped_ptr<base::Value> parsed_value; |
| 76 parsed_value = SummarizeV8Value(isolate, value); | 77 parsed_value = SummarizeV8Value(isolate, value); |
| 77 *out = parsed_value.release(); | 78 *out = parsed_value.release(); |
| 78 | 79 |
| 79 return true; | 80 return true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace extensions | 83 } // namespace extensions |
| OLD | NEW |