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

Side by Side Diff: src/inspector/StringUtil.cpp

Issue 2345263003: [inspector] provide more usefull error message for non serializable value (Closed)
Patch Set: addressed comments Created 4 years, 3 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 | « src/inspector/StringUtil.h ('k') | src/inspector/V8DebuggerAgentImpl.cpp » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/inspector/StringUtil.h" 5 #include "src/inspector/StringUtil.h"
6 6
7 #include "src/inspector/protocol/Protocol.h" 7 #include "src/inspector/protocol/Protocol.h"
8 8
9 namespace v8_inspector { 9 namespace v8_inspector {
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return protocol::parseJSON(string.characters16(), string.length()); 96 return protocol::parseJSON(string.characters16(), string.length());
97 } 97 }
98 98
99 std::unique_ptr<protocol::Value> parseJSON(const String16& string) { 99 std::unique_ptr<protocol::Value> parseJSON(const String16& string) {
100 if (!string.length()) return nullptr; 100 if (!string.length()) return nullptr;
101 return protocol::parseJSON(string.characters16(), string.length()); 101 return protocol::parseJSON(string.characters16(), string.length());
102 } 102 }
103 103
104 } // namespace protocol 104 } // namespace protocol
105 105
106 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, 106 std::unique_ptr<protocol::Value> toProtocolValue(protocol::String* errorString,
107 v8::Local<v8::Context> context,
107 v8::Local<v8::Value> value, 108 v8::Local<v8::Value> value,
108 int maxDepth) { 109 int maxDepth) {
109 if (value.IsEmpty()) { 110 if (value.IsEmpty()) {
110 UNREACHABLE(); 111 UNREACHABLE();
111 return nullptr; 112 return nullptr;
112 } 113 }
113 114
114 if (!maxDepth) return nullptr; 115 if (!maxDepth) {
116 *errorString = "Object reference chain is too long";
117 return nullptr;
118 }
115 maxDepth--; 119 maxDepth--;
116 120
117 if (value->IsNull() || value->IsUndefined()) return protocol::Value::null(); 121 if (value->IsNull() || value->IsUndefined()) return protocol::Value::null();
118 if (value->IsBoolean()) 122 if (value->IsBoolean())
119 return protocol::FundamentalValue::create(value.As<v8::Boolean>()->Value()); 123 return protocol::FundamentalValue::create(value.As<v8::Boolean>()->Value());
120 if (value->IsNumber()) { 124 if (value->IsNumber()) {
121 double doubleValue = value.As<v8::Number>()->Value(); 125 double doubleValue = value.As<v8::Number>()->Value();
122 int intValue = static_cast<int>(doubleValue); 126 int intValue = static_cast<int>(doubleValue);
123 if (intValue == doubleValue) 127 if (intValue == doubleValue)
124 return protocol::FundamentalValue::create(intValue); 128 return protocol::FundamentalValue::create(intValue);
125 return protocol::FundamentalValue::create(doubleValue); 129 return protocol::FundamentalValue::create(doubleValue);
126 } 130 }
127 if (value->IsString()) 131 if (value->IsString())
128 return protocol::StringValue::create( 132 return protocol::StringValue::create(
129 toProtocolString(value.As<v8::String>())); 133 toProtocolString(value.As<v8::String>()));
130 if (value->IsArray()) { 134 if (value->IsArray()) {
131 v8::Local<v8::Array> array = value.As<v8::Array>(); 135 v8::Local<v8::Array> array = value.As<v8::Array>();
132 std::unique_ptr<protocol::ListValue> inspectorArray = 136 std::unique_ptr<protocol::ListValue> inspectorArray =
133 protocol::ListValue::create(); 137 protocol::ListValue::create();
134 uint32_t length = array->Length(); 138 uint32_t length = array->Length();
135 for (uint32_t i = 0; i < length; i++) { 139 for (uint32_t i = 0; i < length; i++) {
136 v8::Local<v8::Value> value; 140 v8::Local<v8::Value> value;
137 if (!array->Get(context, i).ToLocal(&value)) return nullptr; 141 if (!array->Get(context, i).ToLocal(&value)) {
142 *errorString = "Internal error";
143 return nullptr;
144 }
138 std::unique_ptr<protocol::Value> element = 145 std::unique_ptr<protocol::Value> element =
139 toProtocolValue(context, value, maxDepth); 146 toProtocolValue(errorString, context, value, maxDepth);
140 if (!element) return nullptr; 147 if (!element) return nullptr;
141 inspectorArray->pushValue(std::move(element)); 148 inspectorArray->pushValue(std::move(element));
142 } 149 }
143 return std::move(inspectorArray); 150 return std::move(inspectorArray);
144 } 151 }
145 if (value->IsObject()) { 152 if (value->IsObject()) {
146 std::unique_ptr<protocol::DictionaryValue> jsonObject = 153 std::unique_ptr<protocol::DictionaryValue> jsonObject =
147 protocol::DictionaryValue::create(); 154 protocol::DictionaryValue::create();
148 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 155 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
149 v8::Local<v8::Array> propertyNames; 156 v8::Local<v8::Array> propertyNames;
150 if (!object->GetPropertyNames(context).ToLocal(&propertyNames)) 157 if (!object->GetPropertyNames(context).ToLocal(&propertyNames)) {
158 *errorString = "Internal error";
151 return nullptr; 159 return nullptr;
160 }
152 uint32_t length = propertyNames->Length(); 161 uint32_t length = propertyNames->Length();
153 for (uint32_t i = 0; i < length; i++) { 162 for (uint32_t i = 0; i < length; i++) {
154 v8::Local<v8::Value> name; 163 v8::Local<v8::Value> name;
155 if (!propertyNames->Get(context, i).ToLocal(&name)) return nullptr; 164 if (!propertyNames->Get(context, i).ToLocal(&name)) {
165 *errorString = "Internal error";
166 return nullptr;
167 }
156 // FIXME(yurys): v8::Object should support GetOwnPropertyNames 168 // FIXME(yurys): v8::Object should support GetOwnPropertyNames
157 if (name->IsString()) { 169 if (name->IsString()) {
158 v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedProperty( 170 v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedProperty(
159 context, v8::Local<v8::String>::Cast(name)); 171 context, v8::Local<v8::String>::Cast(name));
160 if (!hasRealNamedProperty.IsJust() || !hasRealNamedProperty.FromJust()) 172 if (!hasRealNamedProperty.IsJust() || !hasRealNamedProperty.FromJust())
161 continue; 173 continue;
162 } 174 }
163 v8::Local<v8::String> propertyName; 175 v8::Local<v8::String> propertyName;
164 if (!name->ToString(context).ToLocal(&propertyName)) continue; 176 if (!name->ToString(context).ToLocal(&propertyName)) continue;
165 v8::Local<v8::Value> property; 177 v8::Local<v8::Value> property;
166 if (!object->Get(context, name).ToLocal(&property)) return nullptr; 178 if (!object->Get(context, name).ToLocal(&property)) {
179 *errorString = "Internal error";
180 return nullptr;
181 }
167 std::unique_ptr<protocol::Value> propertyValue = 182 std::unique_ptr<protocol::Value> propertyValue =
168 toProtocolValue(context, property, maxDepth); 183 toProtocolValue(errorString, context, property, maxDepth);
169 if (!propertyValue) return nullptr; 184 if (!propertyValue) return nullptr;
170 jsonObject->setValue(toProtocolString(propertyName), 185 jsonObject->setValue(toProtocolString(propertyName),
171 std::move(propertyValue)); 186 std::move(propertyValue));
172 } 187 }
173 return std::move(jsonObject); 188 return std::move(jsonObject);
174 } 189 }
175 UNREACHABLE(); 190 *errorString = "Object couldn't be returned by value";
176 return nullptr; 191 return nullptr;
177 } 192 }
178 193
179 // static 194 // static
180 std::unique_ptr<StringBuffer> StringBuffer::create(const StringView& string) { 195 std::unique_ptr<StringBuffer> StringBuffer::create(const StringView& string) {
181 String16 owner = toString16(string); 196 String16 owner = toString16(string);
182 return StringBufferImpl::adopt(owner); 197 return StringBufferImpl::adopt(owner);
183 } 198 }
184 199
185 // static 200 // static
186 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) { 201 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) {
187 return wrapUnique(new StringBufferImpl(string)); 202 return wrapUnique(new StringBufferImpl(string));
188 } 203 }
189 204
190 StringBufferImpl::StringBufferImpl(String16& string) { 205 StringBufferImpl::StringBufferImpl(String16& string) {
191 m_owner.swap(string); 206 m_owner.swap(string);
192 m_string = toStringView(m_owner); 207 m_string = toStringView(m_owner);
193 } 208 }
194 209
195 } // namespace v8_inspector 210 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/StringUtil.h ('k') | src/inspector/V8DebuggerAgentImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698