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

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

Issue 1942073002: [DevTools] Move getCompletions to native (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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 OwnPtr<protocol::Value> protocolValue = toProtocolValue(function.context(), resultValue); 134 OwnPtr<protocol::Value> protocolValue = toProtocolValue(function.context(), resultValue);
135 if (hasInternalError(errorString, !protocolValue)) 135 if (hasInternalError(errorString, !protocolValue))
136 return; 136 return;
137 protocol::ErrorSupport errors(errorString); 137 protocol::ErrorSupport errors(errorString);
138 OwnPtr<Array<PropertyDescriptor>> result = Array<PropertyDescriptor>::parse( protocolValue.get(), &errors); 138 OwnPtr<Array<PropertyDescriptor>> result = Array<PropertyDescriptor>::parse( protocolValue.get(), &errors);
139 if (!hasInternalError(errorString, errors.hasErrors())) 139 if (!hasInternalError(errorString, errors.hasErrors()))
140 *properties = result.release(); 140 *properties = result.release();
141 } 141 }
142 142
143 static v8::MaybeLocal<v8::Object> resolveObjectForCompletions(v8::Isolate* isola te, v8::Local<v8::Value> value)
144 {
145 while (true) {
146 if (value->IsProxy()) {
147 value = v8::Local<v8::Proxy>::Cast(value)->GetTarget();
148 continue;
149 }
150 if (value->IsArray() && v8::Local<v8::Array>::Cast(value)->Length() > 99 99) {
pfeldman 2016/05/03 18:07:25 We should be able to do this on the front-end side
151 value = value.As<v8::Object>()->GetPrototype();
152 continue;
153 }
154 if (value->IsTypedArray() && v8::Local<v8::TypedArray>::Cast(value)->Len gth() > 9999) {
155 value = value.As<v8::Object>()->GetPrototype();
156 continue;
157 }
158 break;
159 }
160 if (value->IsObject())
161 return value.As<v8::Object>();
162 if (value->IsString())
163 return v8::Local<v8::Object>::Cast(v8::StringObject::New(v8::String::Emp ty(isolate)));
164 if (value->IsSymbol())
165 return v8::Local<v8::Object>::Cast(v8::SymbolObject::New(isolate, v8::Sy mbol::New(isolate)));
166 if (value->IsNumber())
167 return v8::Local<v8::Object>::Cast(v8::NumberObject::New(isolate, 0.0));
168 if (value->IsBoolean())
169 return v8::Local<v8::Object>::Cast(v8::BooleanObject::New(isolate, false ));
170 if (value->IsUndefined() || value->IsNull())
171 return v8::MaybeLocal<v8::Object>();
172 ASSERT_NOT_REACHED();
173 return v8::MaybeLocal<v8::Object>();
174 }
175
176 void InjectedScript::getCompletions(ErrorString* errorString, v8::Local<v8::Valu e> value, OwnPtr<protocol::Array<String16>>* completions)
177 {
178 v8::Local<v8::Context> context = m_context->context();
pfeldman 2016/05/03 18:07:25 And use getProperties instead of this one.
179 v8::HandleScope handles(m_context->isolate());
180
181 protocol::HashSet<String16> result;
182 v8::Local<v8::Object> current;
183 while (resolveObjectForCompletions(m_context->isolate(), value).ToLocal(&cur rent)) {
184 v8::Local<v8::Array> propertyNames;
185 if (hasInternalError(errorString, !current->GetOwnPropertyNames(context, static_cast<v8::PropertyFilter>(v8::PropertyFilter::ALL_PROPERTIES | v8::Proper tyFilter::SKIP_SYMBOLS)).ToLocal(&propertyNames)))
186 return;
187 for (size_t i = 0; i < propertyNames->Length(); ++i) {
188 v8::Local<v8::Value> value;
189 if (hasInternalError(errorString, !propertyNames->Get(context, i).To Local(&value)))
190 return;
191 if (value->IsObject())
192 continue;
193
194 if (value->IsString()) {
195 result.add(toProtocolString(v8::Local<v8::String>::Cast(value))) ;
196 } else {
197 v8::Local<v8::String> propertyName;
198 if (hasInternalError(errorString, !value->ToString(context).ToLo cal(&propertyName)))
199 return;
200 result.add(toProtocolString(v8::Local<v8::String>::Cast(property Name)));
201 }
202 }
203 value = current->GetPrototype();
204 }
205
206 OwnPtr<Array<String16>> resultArray = Array<String16>::create();
207 for (auto it = result.begin(); it != result.end(); ++it)
208 resultArray->addItem(it->first);
209 *completions = resultArray.release();
210 }
211
212 void InjectedScript::getCompletions(ErrorString* errorString, const String16& pr imitiveType, OwnPtr<protocol::Array<String16>>* completions)
213 {
214 v8::Isolate* isolate = m_context->isolate();
215 v8::HandleScope handles(isolate);
216 if (primitiveType == "string")
217 getCompletions(errorString, v8::StringObject::New(v8::String::Empty(isol ate)), completions);
218 else if (primitiveType == "symbol")
219 getCompletions(errorString, v8::SymbolObject::New(isolate, v8::Symbol::N ew(isolate)), completions);
220 else if (primitiveType == "number")
221 getCompletions(errorString, v8::NumberObject::New(isolate, 0.0), complet ions);
222 else if (primitiveType == "boolean")
223 getCompletions(errorString, v8::BooleanObject::New(isolate, false), comp letions);
224 else
225 ASSERT_NOT_REACHED();
226 }
227
143 void InjectedScript::releaseObject(const String16& objectId) 228 void InjectedScript::releaseObject(const String16& objectId)
144 { 229 {
145 OwnPtr<protocol::Value> parsedObjectId = protocol::parseJSON(objectId); 230 OwnPtr<protocol::Value> parsedObjectId = protocol::parseJSON(objectId);
146 if (!parsedObjectId) 231 if (!parsedObjectId)
147 return; 232 return;
148 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get()); 233 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get());
149 if (!object) 234 if (!object)
150 return; 235 return;
151 int boundId = 0; 236 int boundId = 0;
152 if (!object->getNumber("id", &boundId)) 237 if (!object->getNumber("id", &boundId))
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session) 625 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session)
541 { 626 {
542 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); 627 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId);
543 if (!remoteId) 628 if (!remoteId)
544 return; 629 return;
545 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); 630 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
546 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() ); 631 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() );
547 } 632 }
548 633
549 } // namespace blink 634 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698