Web Inspector: fake value descriptors for promises add a catch handler, preventing...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Apr 2019 00:02:32 +0000 (00:02 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Apr 2019 00:02:32 +0000 (00:02 +0000)
commit8c002ea702266ec2cf91efc81dff64144f8b6859
treef5bf281c82a27d28e922fd67e87283561f70a9c2
parent56fd370635a38da1fc340dcf74c5f580decd6105
Web Inspector: fake value descriptors for promises add a catch handler, preventing "rejectionhandled" events from being fired
https://bugs.webkit.org/show_bug.cgi?id=196484
<rdar://problem/49114725>

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

Only add a catch handler when the promise is reachable via a native getter and is known to
have rejected. A non-rejected promise doesn't need a catch handler, and any promise that
isn't reachable via a getter won't actually be reached, as `InjectedScript` doesn't call any
functions, instead only getting the function object itself.

* inspector/InjectedScriptSource.js:
(InjectedScript.prototype._propertyDescriptors.createFakeValueDescriptor):

* inspector/JSInjectedScriptHost.h:
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::isPromiseRejectedWithNativeGetterTypeError): Added.
* inspector/JSInjectedScriptHostPrototype.cpp:
(Inspector::JSInjectedScriptHostPrototype::finishCreation):
(Inspector::jsInjectedScriptHostPrototypeFunctionIsPromiseRejectedWithNativeGetterTypeError): Added.

* runtime/ErrorInstance.h:
(JSC::ErrorInstance::setNativeGetterTypeError): Added.
(JSC::ErrorInstance::isNativeGetterTypeError const): Added.

* runtime/Error.h:
(JSC::throwVMGetterTypeError): Added.
* runtime/Error.cpp:
(JSC::createGetterTypeError): Added.
(JSC::throwGetterTypeError): Added.
(JSC::throwDOMAttributeGetterTypeError):

Source/WebCore:

Test: inspector/runtime/promise-native-getter.html

Mark errors created from getters as being `isNativeGetterTypeError`.

* bindings/js/JSDOMExceptionHandling.cpp:
(WebCore::throwGetterTypeError):
(WebCore::rejectPromiseWithGetterTypeError):
(WebCore::rejectPromiseWithThisTypeError):

* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::makeGetterTypeErrorForBuiltins):

* bindings/js/JSDOMPromiseDeferred.h:
* bindings/js/JSDOMPromiseDeferred.cpp:
(WebCore::createRejectedPromiseWithTypeError):

* Modules/streams/WritableStream.js:
(getter.closed):
(getter.ready):

LayoutTests:

* inspector/runtime/promise-native-getter.html: Added.
* inspector/runtime/promise-native-getter-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244312 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/runtime/promise-native-getter-expected.txt [new file with mode: 0644]
LayoutTests/inspector/runtime/promise-native-getter.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/Error.cpp
Source/JavaScriptCore/runtime/Error.h
Source/JavaScriptCore/runtime/ErrorInstance.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/WritableStream.js
Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp
Source/WebCore/bindings/js/JSDOMPromiseDeferred.h