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

Unified Diff: third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp

Issue 1948583003: [DevTools] Runtime.getProperties on proxy object doesn't call traps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
index 6ff055bc552c07f3e38d545c7eea0b865e35c07f..b15db44c21703288b4e6047b7c00da5fb2eee47f 100644
--- a/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
+++ b/third_party/WebKit/Source/platform/v8_inspector/V8InjectedScriptHost.cpp
@@ -45,7 +45,6 @@ v8::Local<v8::Object> V8InjectedScriptHost::create(v8::Local<v8::Context> contex
v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, debugger);
setFunctionProperty(context, injectedScriptHost, "internalConstructorName", V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal);
setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal);
- setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedScriptHost::isTypedArrayCallback, debuggerExternal);
setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScriptHost::subtypeCallback, debuggerExternal);
setFunctionProperty(context, injectedScriptHost, "collectionEntries", V8InjectedScriptHost::collectionEntriesCallback, debuggerExternal);
setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal);
@@ -54,6 +53,8 @@ v8::Local<v8::Object> V8InjectedScriptHost::create(v8::Local<v8::Context> contex
setFunctionProperty(context, injectedScriptHost, "setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback, debuggerExternal);
setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHost::bindCallback, debuggerExternal);
setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8InjectedScriptHost::proxyTargetValueCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "ownPropertyNames", V8InjectedScriptHost::ownPropertyNamesCallback, debuggerExternal);
+ setFunctionProperty(context, injectedScriptHost, "prototype", V8InjectedScriptHost::prototypeCallback, debuggerExternal);
return injectedScriptHost;
}
@@ -74,14 +75,6 @@ void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac
info.GetReturnValue().Set(unwrapDebugger(info)->client()->formatAccessorsAsProperties(info[0]));
}
-void V8InjectedScriptHost::isTypedArrayCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
-{
- if (info.Length() < 1)
- return;
-
- info.GetReturnValue().Set(info[0]->IsTypedArray());
-}
-
void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (info.Length() < 1)
@@ -270,6 +263,71 @@ void V8InjectedScriptHost::proxyTargetValueCallback(const v8::FunctionCallbackIn
info.GetReturnValue().Set(target);
}
+static uint32_t objectLength(v8::Local<v8::Object> object)
+{
+ if (object->IsString()) {
pfeldman 2016/05/04 23:01:48 We only use length to detect array, you should not
+ int length = object.As<v8::String>()->Length();
+ return length > 0 ? static_cast<uint32_t>(object.As<v8::String>()->Length()) : 0;
+ }
+ if (object->IsArray())
+ return object.As<v8::Array>()->Length();
+ if (object->IsTypedArray())
+ return object.As<v8::TypedArray>()->Length();
+ return 0;
+}
+
+void V8InjectedScriptHost::ownPropertyNamesCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ ASSERT(info.Length() > 0 && info[0]->IsObject());
+
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ info.GetReturnValue().Set(v8::Array::New(isolate));
+ v8::Local<v8::Object> object = info[0].As<v8::Object>();
+
+ if (object->IsProxy())
+ return;
+
+ size_t length = objectLength(object);
+ const int kMaxIndexPropertyCount = 9999;
+ if (length > kMaxIndexPropertyCount) {
+ v8::Local<v8::Array> indexes = v8::Array::New(isolate, kMaxIndexPropertyCount);
+ for (size_t i = 0; i < kMaxIndexPropertyCount; ++i) {
+ if (!indexes->Set(context, i, v8::Integer::NewFromUnsigned(isolate, i)).FromMaybe(false))
+ return;
+ }
+ info.GetReturnValue().Set(indexes);
+ return;
+ }
+
+ v8::PropertyFilter filters[] = {
+ static_cast<v8::PropertyFilter>(v8::PropertyFilter::ONLY_ENUMERABLE | v8::PropertyFilter::SKIP_SYMBOLS),
+ static_cast<v8::PropertyFilter>(v8::PropertyFilter::ALL_PROPERTIES | v8::PropertyFilter::SKIP_SYMBOLS),
+ v8::PropertyFilter::ALL_PROPERTIES
+ };
+
+ v8::Local<v8::Set> output = v8::Set::New(isolate);
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(filters); ++i) {
+ v8::Local<v8::Array> properties;
+ if (!object->GetOwnPropertyNames(context, filters[i]).ToLocal(&properties))
+ return;
+ for (size_t i = 0; i < properties->Length(); ++i) {
+ v8::Local<v8::Value> value;
+ if (!properties->Get(context, i).ToLocal(&value))
+ return;
+ if (!output->Add(context, value).ToLocal(&output))
+ return;
+ }
+ }
+ info.GetReturnValue().Set(output->AsArray());
+}
+
+void V8InjectedScriptHost::prototypeCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ ASSERT(info.Length() > 0 && info[0]->IsObject());
+ info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype());
+}
+
v8::Local<v8::Private> V8Debugger::scopeExtensionPrivate(v8::Isolate* isolate)
{
return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Debugger#scopeExtension"));

Powered by Google App Engine
This is Rietveld 408576698