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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/public/V8ToProtocolValue.cpp

Issue 1745423002: DevTools: migrate protocol values from RefPtr to OwnPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/v8_inspector/public/V8ToProtocolValue.h" 5 #include "platform/v8_inspector/public/V8ToProtocolValue.h"
6 6
7 namespace blink { 7 namespace blink {
8 8
9 static String coreString(v8::Local<v8::String> v8String) 9 static String coreString(v8::Local<v8::String> v8String)
10 { 10 {
11 int length = v8String->Length(); 11 int length = v8String->Length();
12 UChar* buffer; 12 UChar* buffer;
13 String result = String::createUninitialized(length, buffer); 13 String result = String::createUninitialized(length, buffer);
14 v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length); 14 v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length);
15 return result; 15 return result;
16 } 16 }
17 17
18 PassRefPtr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, v8:: Local<v8::Value> value, int maxDepth) 18 PassOwnPtr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, v8:: Local<v8::Value> value, int maxDepth)
19 { 19 {
20 if (value.IsEmpty()) { 20 if (value.IsEmpty()) {
21 ASSERT_NOT_REACHED(); 21 ASSERT_NOT_REACHED();
22 return nullptr; 22 return nullptr;
23 } 23 }
24 24
25 if (!maxDepth) 25 if (!maxDepth)
26 return nullptr; 26 return nullptr;
27 maxDepth--; 27 maxDepth--;
28 28
29 if (value->IsNull() || value->IsUndefined()) 29 if (value->IsNull() || value->IsUndefined())
30 return protocol::Value::null(); 30 return protocol::Value::null();
31 if (value->IsBoolean()) 31 if (value->IsBoolean())
32 return protocol::FundamentalValue::create(value.As<v8::Boolean>()->Value ()); 32 return protocol::FundamentalValue::create(value.As<v8::Boolean>()->Value ());
33 if (value->IsNumber()) 33 if (value->IsNumber())
34 return protocol::FundamentalValue::create(value.As<v8::Number>()->Value( )); 34 return protocol::FundamentalValue::create(value.As<v8::Number>()->Value( ));
35 if (value->IsString()) 35 if (value->IsString())
36 return protocol::StringValue::create(coreString(value.As<v8::String>())) ; 36 return protocol::StringValue::create(coreString(value.As<v8::String>())) ;
37 if (value->IsArray()) { 37 if (value->IsArray()) {
38 v8::Local<v8::Array> array = value.As<v8::Array>(); 38 v8::Local<v8::Array> array = value.As<v8::Array>();
39 RefPtr<protocol::ListValue> inspectorArray = protocol::ListValue::create (); 39 OwnPtr<protocol::ListValue> inspectorArray = protocol::ListValue::create ();
40 uint32_t length = array->Length(); 40 uint32_t length = array->Length();
41 for (uint32_t i = 0; i < length; i++) { 41 for (uint32_t i = 0; i < length; i++) {
42 v8::Local<v8::Value> value; 42 v8::Local<v8::Value> value;
43 if (!array->Get(context, i).ToLocal(&value)) 43 if (!array->Get(context, i).ToLocal(&value))
44 return nullptr; 44 return nullptr;
45 RefPtr<protocol::Value> element = toProtocolValue(context, value, ma xDepth); 45 OwnPtr<protocol::Value> element = toProtocolValue(context, value, ma xDepth);
46 if (!element) 46 if (!element)
47 return nullptr; 47 return nullptr;
48 inspectorArray->pushValue(element); 48 inspectorArray->pushValue(element.release());
49 } 49 }
50 return inspectorArray; 50 return inspectorArray.release();
51 } 51 }
52 if (value->IsObject()) { 52 if (value->IsObject()) {
53 RefPtr<protocol::DictionaryValue> jsonObject = protocol::DictionaryValue ::create(); 53 OwnPtr<protocol::DictionaryValue> jsonObject = protocol::DictionaryValue ::create();
54 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 54 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
55 v8::Local<v8::Array> propertyNames; 55 v8::Local<v8::Array> propertyNames;
56 if (!object->GetPropertyNames(context).ToLocal(&propertyNames)) 56 if (!object->GetPropertyNames(context).ToLocal(&propertyNames))
57 return nullptr; 57 return nullptr;
58 uint32_t length = propertyNames->Length(); 58 uint32_t length = propertyNames->Length();
59 for (uint32_t i = 0; i < length; i++) { 59 for (uint32_t i = 0; i < length; i++) {
60 v8::Local<v8::Value> name; 60 v8::Local<v8::Value> name;
61 if (!propertyNames->Get(context, i).ToLocal(&name)) 61 if (!propertyNames->Get(context, i).ToLocal(&name))
62 return nullptr; 62 return nullptr;
63 // FIXME(yurys): v8::Object should support GetOwnPropertyNames 63 // FIXME(yurys): v8::Object should support GetOwnPropertyNames
64 if (name->IsString()) { 64 if (name->IsString()) {
65 v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedPrope rty(context, v8::Local<v8::String>::Cast(name)); 65 v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedPrope rty(context, v8::Local<v8::String>::Cast(name));
66 if (!hasRealNamedProperty.IsJust() || !hasRealNamedProperty.From Just()) 66 if (!hasRealNamedProperty.IsJust() || !hasRealNamedProperty.From Just())
67 continue; 67 continue;
68 } 68 }
69 v8::Local<v8::String> propertyName; 69 v8::Local<v8::String> propertyName;
70 if (!name->ToString(context).ToLocal(&propertyName)) 70 if (!name->ToString(context).ToLocal(&propertyName))
71 continue; 71 continue;
72 v8::Local<v8::Value> property; 72 v8::Local<v8::Value> property;
73 if (!object->Get(context, name).ToLocal(&property)) 73 if (!object->Get(context, name).ToLocal(&property))
74 return nullptr; 74 return nullptr;
75 RefPtr<protocol::Value> propertyValue = toProtocolValue(context, pro perty, maxDepth); 75 OwnPtr<protocol::Value> propertyValue = toProtocolValue(context, pro perty, maxDepth);
76 if (!propertyValue) 76 if (!propertyValue)
77 return nullptr; 77 return nullptr;
78 jsonObject->setValue(coreString(propertyName), propertyValue); 78 jsonObject->setValue(coreString(propertyName), propertyValue.release ());
79 } 79 }
80 return jsonObject; 80 return jsonObject.release();
81 } 81 }
82 ASSERT_NOT_REACHED(); 82 ASSERT_NOT_REACHED();
83 return nullptr; 83 return nullptr;
84 } 84 }
85 85
86 } // namespace blink 86 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698