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

Side by Side 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, 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/V8InjectedScriptHost.h" 5 #include "platform/v8_inspector/V8InjectedScriptHost.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/v8_inspector/InjectedScriptNative.h" 8 #include "platform/v8_inspector/InjectedScriptNative.h"
9 #include "platform/v8_inspector/V8Compat.h" 9 #include "platform/v8_inspector/V8Compat.h"
10 #include "platform/v8_inspector/V8DebuggerImpl.h" 10 #include "platform/v8_inspector/V8DebuggerImpl.h"
(...skipping 27 matching lines...) Expand all
38 38
39 } // namespace 39 } // namespace
40 40
41 v8::Local<v8::Object> V8InjectedScriptHost::create(v8::Local<v8::Context> contex t, V8DebuggerImpl* debugger) 41 v8::Local<v8::Object> V8InjectedScriptHost::create(v8::Local<v8::Context> contex t, V8DebuggerImpl* debugger)
42 { 42 {
43 v8::Isolate* isolate = debugger->isolate(); 43 v8::Isolate* isolate = debugger->isolate();
44 v8::Local<v8::Object> injectedScriptHost = v8::Object::New(isolate); 44 v8::Local<v8::Object> injectedScriptHost = v8::Object::New(isolate);
45 v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, debugg er); 45 v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, debugg er);
46 setFunctionProperty(context, injectedScriptHost, "internalConstructorName", V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal); 46 setFunctionProperty(context, injectedScriptHost, "internalConstructorName", V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal);
47 setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsPropertie s", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal); 47 setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsPropertie s", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal);
48 setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedS criptHost::isTypedArrayCallback, debuggerExternal);
49 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript Host::subtypeCallback, debuggerExternal); 48 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript Host::subtypeCallback, debuggerExternal);
50 setFunctionProperty(context, injectedScriptHost, "collectionEntries", V8Inje ctedScriptHost::collectionEntriesCallback, debuggerExternal); 49 setFunctionProperty(context, injectedScriptHost, "collectionEntries", V8Inje ctedScriptHost::collectionEntriesCallback, debuggerExternal);
51 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8 InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal); 50 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8 InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal);
52 setFunctionProperty(context, injectedScriptHost, "getEventListeners", V8Inje ctedScriptHost::getEventListenersCallback, debuggerExternal); 51 setFunctionProperty(context, injectedScriptHost, "getEventListeners", V8Inje ctedScriptHost::getEventListenersCallback, debuggerExternal);
53 setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFun ction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerE xternal); 52 setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFun ction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerE xternal);
54 setFunctionProperty(context, injectedScriptHost, "setNonEnumProperty", V8Inj ectedScriptHost::setNonEnumPropertyCallback, debuggerExternal); 53 setFunctionProperty(context, injectedScriptHost, "setNonEnumProperty", V8Inj ectedScriptHost::setNonEnumPropertyCallback, debuggerExternal);
55 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos t::bindCallback, debuggerExternal); 54 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos t::bindCallback, debuggerExternal);
56 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec tedScriptHost::proxyTargetValueCallback, debuggerExternal); 55 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec tedScriptHost::proxyTargetValueCallback, debuggerExternal);
56 setFunctionProperty(context, injectedScriptHost, "ownPropertyNames", V8Injec tedScriptHost::ownPropertyNamesCallback, debuggerExternal);
57 setFunctionProperty(context, injectedScriptHost, "prototype", V8InjectedScri ptHost::prototypeCallback, debuggerExternal);
57 return injectedScriptHost; 58 return injectedScriptHost;
58 } 59 }
59 60
60 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal lbackInfo<v8::Value>& info) 61 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal lbackInfo<v8::Value>& info)
61 { 62 {
62 if (info.Length() < 1 || !info[0]->IsObject()) 63 if (info.Length() < 1 || !info[0]->IsObject())
63 return; 64 return;
64 65
65 v8::Local<v8::Object> object = info[0].As<v8::Object>(); 66 v8::Local<v8::Object> object = info[0].As<v8::Object>();
66 info.GetReturnValue().Set(object->GetConstructorName()); 67 info.GetReturnValue().Set(object->GetConstructorName());
67 } 68 }
68 69
69 void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac kInfo<v8::Value>& info) 70 void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac kInfo<v8::Value>& info)
70 { 71 {
71 if (info.Length() < 1) 72 if (info.Length() < 1)
72 return; 73 return;
73 74
74 info.GetReturnValue().Set(unwrapDebugger(info)->client()->formatAccessorsAsP roperties(info[0])); 75 info.GetReturnValue().Set(unwrapDebugger(info)->client()->formatAccessorsAsP roperties(info[0]));
75 } 76 }
76 77
77 void V8InjectedScriptHost::isTypedArrayCallback(const v8::FunctionCallbackInfo<v 8::Value>& info)
78 {
79 if (info.Length() < 1)
80 return;
81
82 info.GetReturnValue().Set(info[0]->IsTypedArray());
83 }
84
85 void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info) 78 void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info)
86 { 79 {
87 if (info.Length() < 1) 80 if (info.Length() < 1)
88 return; 81 return;
89 82
90 v8::Isolate* isolate = info.GetIsolate(); 83 v8::Isolate* isolate = info.GetIsolate();
91 v8::Local<v8::Value> value = info[0]; 84 v8::Local<v8::Value> value = info[0];
92 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject()) { 85 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject()) {
93 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array")); 86 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array"));
94 return; 87 return;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (info.Length() != 1 || !info[0]->IsProxy()) { 256 if (info.Length() != 1 || !info[0]->IsProxy()) {
264 ASSERT_NOT_REACHED(); 257 ASSERT_NOT_REACHED();
265 return; 258 return;
266 } 259 }
267 v8::Local<v8::Object> target = info[0].As<v8::Proxy>(); 260 v8::Local<v8::Object> target = info[0].As<v8::Proxy>();
268 while (target->IsProxy()) 261 while (target->IsProxy())
269 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget(); 262 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget();
270 info.GetReturnValue().Set(target); 263 info.GetReturnValue().Set(target);
271 } 264 }
272 265
266 static uint32_t objectLength(v8::Local<v8::Object> object)
267 {
268 if (object->IsString()) {
pfeldman 2016/05/04 23:01:48 We only use length to detect array, you should not
269 int length = object.As<v8::String>()->Length();
270 return length > 0 ? static_cast<uint32_t>(object.As<v8::String>()->Lengt h()) : 0;
271 }
272 if (object->IsArray())
273 return object.As<v8::Array>()->Length();
274 if (object->IsTypedArray())
275 return object.As<v8::TypedArray>()->Length();
276 return 0;
277 }
278
279 void V8InjectedScriptHost::ownPropertyNamesCallback(const v8::FunctionCallbackIn fo<v8::Value>& info)
280 {
281 ASSERT(info.Length() > 0 && info[0]->IsObject());
282
283 v8::Isolate* isolate = info.GetIsolate();
284 v8::Local<v8::Context> context = isolate->GetCurrentContext();
285 info.GetReturnValue().Set(v8::Array::New(isolate));
286 v8::Local<v8::Object> object = info[0].As<v8::Object>();
287
288 if (object->IsProxy())
289 return;
290
291 size_t length = objectLength(object);
292 const int kMaxIndexPropertyCount = 9999;
293 if (length > kMaxIndexPropertyCount) {
294 v8::Local<v8::Array> indexes = v8::Array::New(isolate, kMaxIndexProperty Count);
295 for (size_t i = 0; i < kMaxIndexPropertyCount; ++i) {
296 if (!indexes->Set(context, i, v8::Integer::NewFromUnsigned(isolate, i)).FromMaybe(false))
297 return;
298 }
299 info.GetReturnValue().Set(indexes);
300 return;
301 }
302
303 v8::PropertyFilter filters[] = {
304 static_cast<v8::PropertyFilter>(v8::PropertyFilter::ONLY_ENUMERABLE | v8 ::PropertyFilter::SKIP_SYMBOLS),
305 static_cast<v8::PropertyFilter>(v8::PropertyFilter::ALL_PROPERTIES | v8: :PropertyFilter::SKIP_SYMBOLS),
306 v8::PropertyFilter::ALL_PROPERTIES
307 };
308
309 v8::Local<v8::Set> output = v8::Set::New(isolate);
310 for (size_t i = 0; i < WTF_ARRAY_LENGTH(filters); ++i) {
311 v8::Local<v8::Array> properties;
312 if (!object->GetOwnPropertyNames(context, filters[i]).ToLocal(&propertie s))
313 return;
314 for (size_t i = 0; i < properties->Length(); ++i) {
315 v8::Local<v8::Value> value;
316 if (!properties->Get(context, i).ToLocal(&value))
317 return;
318 if (!output->Add(context, value).ToLocal(&output))
319 return;
320 }
321 }
322 info.GetReturnValue().Set(output->AsArray());
323 }
324
325 void V8InjectedScriptHost::prototypeCallback(const v8::FunctionCallbackInfo<v8:: Value>& info)
326 {
327 ASSERT(info.Length() > 0 && info[0]->IsObject());
328 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype());
329 }
330
273 v8::Local<v8::Private> V8Debugger::scopeExtensionPrivate(v8::Isolate* isolate) 331 v8::Local<v8::Private> V8Debugger::scopeExtensionPrivate(v8::Isolate* isolate)
274 { 332 {
275 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Debug ger#scopeExtension")); 333 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Debug ger#scopeExtension"));
276 } 334 }
277 335
278 bool V8Debugger::isRemoteObjectAPIMethod(const String16& name) 336 bool V8Debugger::isRemoteObjectAPIMethod(const String16& name)
279 { 337 {
280 return name == "bindRemoteObject"; 338 return name == "bindRemoteObject";
281 } 339 }
282 340
283 } // namespace blink 341 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698