Index: third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp |
diff --git a/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp b/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp |
index ec885f062b819275931fc189f8fc86bf9f55c8f3..061436f08ad7907b6ca597dd8529dfbac1f7ad45 100644 |
--- a/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp |
+++ b/third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp |
@@ -140,6 +140,91 @@ void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Objec |
*properties = result.release(); |
} |
+static v8::MaybeLocal<v8::Object> resolveObjectForCompletions(v8::Isolate* isolate, v8::Local<v8::Value> value) |
+{ |
+ while (true) { |
+ if (value->IsProxy()) { |
+ value = v8::Local<v8::Proxy>::Cast(value)->GetTarget(); |
+ continue; |
+ } |
+ if (value->IsArray() && v8::Local<v8::Array>::Cast(value)->Length() > 9999) { |
pfeldman
2016/05/03 18:07:25
We should be able to do this on the front-end side
|
+ value = value.As<v8::Object>()->GetPrototype(); |
+ continue; |
+ } |
+ if (value->IsTypedArray() && v8::Local<v8::TypedArray>::Cast(value)->Length() > 9999) { |
+ value = value.As<v8::Object>()->GetPrototype(); |
+ continue; |
+ } |
+ break; |
+ } |
+ if (value->IsObject()) |
+ return value.As<v8::Object>(); |
+ if (value->IsString()) |
+ return v8::Local<v8::Object>::Cast(v8::StringObject::New(v8::String::Empty(isolate))); |
+ if (value->IsSymbol()) |
+ return v8::Local<v8::Object>::Cast(v8::SymbolObject::New(isolate, v8::Symbol::New(isolate))); |
+ if (value->IsNumber()) |
+ return v8::Local<v8::Object>::Cast(v8::NumberObject::New(isolate, 0.0)); |
+ if (value->IsBoolean()) |
+ return v8::Local<v8::Object>::Cast(v8::BooleanObject::New(isolate, false)); |
+ if (value->IsUndefined() || value->IsNull()) |
+ return v8::MaybeLocal<v8::Object>(); |
+ ASSERT_NOT_REACHED(); |
+ return v8::MaybeLocal<v8::Object>(); |
+} |
+ |
+void InjectedScript::getCompletions(ErrorString* errorString, v8::Local<v8::Value> value, OwnPtr<protocol::Array<String16>>* completions) |
+{ |
+ v8::Local<v8::Context> context = m_context->context(); |
pfeldman
2016/05/03 18:07:25
And use getProperties instead of this one.
|
+ v8::HandleScope handles(m_context->isolate()); |
+ |
+ protocol::HashSet<String16> result; |
+ v8::Local<v8::Object> current; |
+ while (resolveObjectForCompletions(m_context->isolate(), value).ToLocal(¤t)) { |
+ v8::Local<v8::Array> propertyNames; |
+ if (hasInternalError(errorString, !current->GetOwnPropertyNames(context, static_cast<v8::PropertyFilter>(v8::PropertyFilter::ALL_PROPERTIES | v8::PropertyFilter::SKIP_SYMBOLS)).ToLocal(&propertyNames))) |
+ return; |
+ for (size_t i = 0; i < propertyNames->Length(); ++i) { |
+ v8::Local<v8::Value> value; |
+ if (hasInternalError(errorString, !propertyNames->Get(context, i).ToLocal(&value))) |
+ return; |
+ if (value->IsObject()) |
+ continue; |
+ |
+ if (value->IsString()) { |
+ result.add(toProtocolString(v8::Local<v8::String>::Cast(value))); |
+ } else { |
+ v8::Local<v8::String> propertyName; |
+ if (hasInternalError(errorString, !value->ToString(context).ToLocal(&propertyName))) |
+ return; |
+ result.add(toProtocolString(v8::Local<v8::String>::Cast(propertyName))); |
+ } |
+ } |
+ value = current->GetPrototype(); |
+ } |
+ |
+ OwnPtr<Array<String16>> resultArray = Array<String16>::create(); |
+ for (auto it = result.begin(); it != result.end(); ++it) |
+ resultArray->addItem(it->first); |
+ *completions = resultArray.release(); |
+} |
+ |
+void InjectedScript::getCompletions(ErrorString* errorString, const String16& primitiveType, OwnPtr<protocol::Array<String16>>* completions) |
+{ |
+ v8::Isolate* isolate = m_context->isolate(); |
+ v8::HandleScope handles(isolate); |
+ if (primitiveType == "string") |
+ getCompletions(errorString, v8::StringObject::New(v8::String::Empty(isolate)), completions); |
+ else if (primitiveType == "symbol") |
+ getCompletions(errorString, v8::SymbolObject::New(isolate, v8::Symbol::New(isolate)), completions); |
+ else if (primitiveType == "number") |
+ getCompletions(errorString, v8::NumberObject::New(isolate, 0.0), completions); |
+ else if (primitiveType == "boolean") |
+ getCompletions(errorString, v8::BooleanObject::New(isolate, false), completions); |
+ else |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
void InjectedScript::releaseObject(const String16& objectId) |
{ |
OwnPtr<protocol::Value> parsedObjectId = protocol::parseJSON(objectId); |