Web Inspector: Implement `queryObjects` Command Line API
authorwebkit@devinrousso.com <webkit@devinrousso.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Jan 2019 03:48:19 +0000 (03:48 +0000)
committerwebkit@devinrousso.com <webkit@devinrousso.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Jan 2019 03:48:19 +0000 (03:48 +0000)
commit4189956e592e68dadc2155682d5144892f3995a9
tree42ca6662cfdf4188fdc1b12c8bbe0a2715ac48d4
parenta02496184e3f3d34e8ee31b5d6defd87bb882121
Web Inspector: Implement `queryObjects` Command Line API
https://bugs.webkit.org/show_bug.cgi?id=176766
<rdar://problem/34890689>

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

Introduces a new Command Line function called `queryObjects` that will return an array of
object that have the given constructor/prototype argument in their prototype chain.
 - `queryObjects(Promise)` will return an array of all Promises.
 - `queryObjects(Foo)` will return all objects created with the constructor `Foo`.

Currently, an error is thrown if the first argument is one of the following:
 - Object
 - Object.prototype
 - Function
 - Function.prototype
 - Array
 - Array.prototype
 - Map
 - Map.prototype
 - Set
 - Set.prototype
 - Proxy

The reason for this is that we don't want to expose any internal/builtin objects, as some of
them are highly sensitive and undefined behaviour can occur if they are modified.

* inspector/JSInjectedScriptHost.h:
* inspector/JSInjectedScriptHost.cpp:
(Inspector::checkForbiddenPrototype): Added.
(Inspector::JSInjectedScriptHost::queryObjects): Added.
Does a GC and then iterates over all live JSCell in the heap to find these objects.

* inspector/JSInjectedScriptHostPrototype.cpp:
(Inspector::JSInjectedScriptHostPrototype::finishCreation):
(Inspector::jsInjectedScriptHostPrototypeFunctionQueryObjects): Added.

* inspector/InjectedScriptSource.js:
(queryObjects): Added.

* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::promisePrototype): Added.

Source/WebCore:

Test: inspector/console/queryObjects.html

* inspector/CommandLineAPIModuleSource.js:
(CommandLineAPI):
(CommandLineAPIImpl.prototype.queryObjects): Added.

Source/WebInspectorUI:

* UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
(WI.JavaScriptRuntimeCompletionProvider.completionControllerCompletionsNeeded.receivedPropertyNames):
Add `queryObjects` to the list of command line functions.

LayoutTests:

* inspector/console/queryObjects-expected.html: Added.
* inspector/console/queryObjects.html: Added.

* http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239583 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/dom/cross-domain-inspected-node-access-expected.txt
LayoutTests/inspector/console/queryObjects-expected.txt [new file with mode: 0644]
LayoutTests/inspector/console/queryObjects.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/InjectedScriptSource.js
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Source/JavaScriptCore/inspector/JSInjectedScriptHost.h
Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/WebCore/ChangeLog
Source/WebCore/inspector/CommandLineAPIModuleSource.js
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js