Skip to content

Commit

Permalink
Implement self.reportError()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=228316
<rdar://problem/81446162>

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

Import test coverage from:
- web-platform-tests/wpt#29738

* web-platform-tests/html/webappapis/scripting/reporterror.any-expected.txt: Added.
* web-platform-tests/html/webappapis/scripting/reporterror.any.html: Added.
* web-platform-tests/html/webappapis/scripting/reporterror.any.js: Added.
(undefined.forEach.throwable.test.t.assert_equals):
(test):
* web-platform-tests/html/webappapis/scripting/reporterror.any.worker-expected.txt: Added.
* web-platform-tests/html/webappapis/scripting/reporterror.any.worker.html: Added.
* web-platform-tests/html/webappapis/scripting/w3c-import.log: Added.

Source/WebCore:

Implement self.reportError() as per:
- whatwg/html#1196

Firefox already shipped this and Chrome will do so soon too.

Tests: imported/w3c/web-platform-tests/html/webappapis/scripting/reporterror.any.html
       imported/w3c/web-platform-tests/html/webappapis/scripting/reporterror.any.worker.html

* page/DOMWindow.cpp:
(WebCore::DOMWindow::reportError):
* page/DOMWindow.h:
* page/WindowOrWorkerGlobalScope.idl:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::reportError):
* workers/WorkerGlobalScope.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@281756 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed Aug 30, 2021
1 parent 2c3585c commit 1eb5a82
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 1 deletion.
20 changes: 20 additions & 0 deletions LayoutTests/imported/w3c/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
2021-08-30 Chris Dumez <[email protected]>

Implement self.reportError()
https://bugs.webkit.org/show_bug.cgi?id=228316
<rdar://problem/81446162>

Reviewed by Sam Weinig.

Import test coverage from:
- https://github.com/web-platform-tests/wpt/pull/29738

* web-platform-tests/html/webappapis/scripting/reporterror.any-expected.txt: Added.
* web-platform-tests/html/webappapis/scripting/reporterror.any.html: Added.
* web-platform-tests/html/webappapis/scripting/reporterror.any.js: Added.
(undefined.forEach.throwable.test.t.assert_equals):
(test):
* web-platform-tests/html/webappapis/scripting/reporterror.any.worker-expected.txt: Added.
* web-platform-tests/html/webappapis/scripting/reporterror.any.worker.html: Added.
* web-platform-tests/html/webappapis/scripting/w3c-import.log: Added.

2021-08-27 Antti Koivisto <[email protected]>

[CSS Cascade Layers] Initial support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONSOLE MESSAGE: 1
CONSOLE MESSAGE: TypeError
CONSOLE MESSAGE: undefined

PASS self.reportError(1)
PASS self.reportError(TypeError)
PASS self.reportError(undefined)
PASS self.reportError() (without arguments) throws

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
setup({ allow_uncaught_exception:true });

[
1,
new TypeError(),
undefined
].forEach(throwable => {
test(t => {
let happened = false;
self.addEventListener("error", t.step_func(e => {
assert_true(e.message !== "");
assert_equals(e.filename, new URL("reporterror.any.js", location.href).href);
assert_greater_than(e.lineno, 0);
assert_greater_than(e.colno, 0);
assert_equals(e.error, throwable);
happened = true;
}), { once:true });
self.reportError(throwable);
assert_true(happened);
}, `self.reportError(${throwable})`);
});

test(() => {
assert_throws_js(TypeError, () => self.reportError());
}, `self.reportError() (without arguments) throws`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

PASS self.reportError(1)
PASS self.reportError(TypeError)
PASS self.reportError(undefined)
PASS self.reportError() (without arguments) throws

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The tests in this directory were imported from the W3C repository.
Do NOT modify these tests directly in WebKit.
Instead, create a pull request on the WPT github:
https://github.com/web-platform-tests/wpt

Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport

Do NOT modify or remove this file.

------------------------------------------------------------------------
Properties requiring vendor prefixes:
None
Property values requiring vendor prefixes:
None
------------------------------------------------------------------------
List of files:
/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/reporterror.any.js
24 changes: 24 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
2021-08-30 Chris Dumez <[email protected]>

Implement self.reportError()
https://bugs.webkit.org/show_bug.cgi?id=228316
<rdar://problem/81446162>

Reviewed by Sam Weinig.

Implement self.reportError() as per:
- https://github.com/whatwg/html/pull/1196

Firefox already shipped this and Chrome will do so soon too.

Tests: imported/w3c/web-platform-tests/html/webappapis/scripting/reporterror.any.html
imported/w3c/web-platform-tests/html/webappapis/scripting/reporterror.any.worker.html

* page/DOMWindow.cpp:
(WebCore::DOMWindow::reportError):
* page/DOMWindow.h:
* page/WindowOrWorkerGlobalScope.idl:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::reportError):
* workers/WorkerGlobalScope.h:

2021-08-30 Alan Bujtas <[email protected]>

[LFC][IFC] Introduce Line::Run::Text to hold text content related properties
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/page/DOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "History.h"
#include "IdleRequestOptions.h"
#include "InspectorInstrumentation.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMPromiseDeferred.h"
#include "JSDOMWindowBase.h"
#include "JSExecState.h"
Expand Down Expand Up @@ -1801,6 +1802,17 @@ void DOMWindow::resizeTo(float width, float height) const
page->chrome().setWindowRect(adjustWindowRect(*page, update));
}

void DOMWindow::reportError(JSC::JSGlobalObject& globalObject, JSC::JSValue error)
{
auto& vm = globalObject.vm();
RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock());
auto* exception = JSC::jsDynamicCast<JSC::Exception*>(vm, error);
if (!exception)
exception = JSC::Exception::create(vm, error);

reportException(&globalObject, exception);
}

ExceptionOr<int> DOMWindow::setTimeout(JSC::JSGlobalObject& state, std::unique_ptr<ScheduledAction> action, int timeout, Vector<JSC::Strong<JSC::Unknown>>&& arguments)
{
RefPtr context = scriptExecutionContext();
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/page/DOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ class DOMWindow final
WebKitNamespace* webkitNamespace();
#endif

void reportError(JSC::JSGlobalObject&, JSC::JSValue);

// FIXME: When this DOMWindow is no longer the active DOMWindow (i.e.,
// when its document is no longer the document that is displayed in its
// frame), we would like to zero out m_frame to avoid being confused
Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/page/WindowOrWorkerGlobalScope.idl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ interface mixin WindowOrWorkerGlobalScope {
readonly attribute boolean isSecureContext;

[EnabledBySetting=CrossOriginOpenerPolicy] readonly attribute boolean crossOriginIsolated;


[CallWith=GlobalObject] undefined reportError(any error);

// Base64 utility methods.
DOMString atob(DOMString string);
DOMString btoa(DOMString string);
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/workers/WorkerGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "IDBConnectionProxy.h"
#include "ImageBitmapOptions.h"
#include "InspectorInstrumentation.h"
#include "JSDOMExceptionHandling.h"
#include "Performance.h"
#include "RuntimeEnabledFeatures.h"
#include "ScheduledAction.h"
Expand Down Expand Up @@ -547,6 +548,17 @@ void WorkerGlobalScope::deleteJSCodeAndGC(Synchronous synchronous)
#endif
}

void WorkerGlobalScope::reportError(JSC::JSGlobalObject& globalObject, JSC::JSValue error)
{
auto& vm = globalObject.vm();
RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock());
auto* exception = JSC::jsDynamicCast<JSC::Exception*>(vm, error);
if (!exception)
exception = JSC::Exception::create(vm, error);

WebCore::reportException(&globalObject, exception);
}

void WorkerGlobalScope::releaseMemoryInWorkers(Synchronous synchronous)
{
Locker locker { allWorkerGlobalScopeIdentifiersLock };
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/workers/WorkerGlobalScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class WorkerGlobalScope : public Supplementable<WorkerGlobalScope>, public Base6
std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource) final;
void beginLoadingFontSoon(FontLoadRequest&) final;

void reportError(JSC::JSGlobalObject&, JSC::JSValue);

ReferrerPolicy referrerPolicy() const final;

const Settings::Values& settingsValues() const final { return m_settingsValues; }
Expand Down

0 comments on commit 1eb5a82

Please sign in to comment.