Changeset 289058 in webkit
- Timestamp:
- Feb 3, 2022 9:58:13 AM (6 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any-expected.txt (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any.js (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any.worker-expected.txt (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/dom/abort/abort-signal-timeout-expected.txt (added)
-
LayoutTests/imported/w3c/web-platform-tests/dom/abort/abort-signal-timeout.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/dom/abort/w3c-import.log (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/bindings/js/JSAbortSignalCustom.cpp (modified) (2 diffs)
-
Source/WebCore/dom/AbortSignal.cpp (modified) (5 diffs)
-
Source/WebCore/dom/AbortSignal.h (modified) (6 diffs)
-
Source/WebCore/dom/AbortSignal.idl (modified) (2 diffs)
-
Source/WebCore/page/DOMTimer.cpp (modified) (4 diffs)
-
Source/WebCore/page/DOMTimer.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r289048 r289058 1 2022-02-03 Chris Dumez <cdumez@apple.com> 2 3 Implement AbortSignal.timeout() 4 https://bugs.webkit.org/show_bug.cgi?id=236039 5 6 Reviewed by Darin Adler. 7 8 Import AbortSignal.timeout() tests from upstream WPT. 9 10 * web-platform-tests/dom/abort/AbortSignal.any-expected.txt: 11 * web-platform-tests/dom/abort/AbortSignal.any.js: 12 (async_test.t.signal.onabort.t.step_func_done): 13 (async_test.t.string_appeared_here.signal.onabort.t.step_func): 14 * web-platform-tests/dom/abort/AbortSignal.any.worker-expected.txt: 15 * web-platform-tests/dom/abort/abort-signal-timeout-expected.txt: Added. 16 * web-platform-tests/dom/abort/abort-signal-timeout.html: Added. 17 * web-platform-tests/dom/abort/w3c-import.log: 18 1 19 2022-02-03 Antoine Quint <graouts@webkit.org> 2 20 -
trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any-expected.txt
r279015 r289058 2 2 PASS the AbortSignal.abort() static returns an already aborted signal 3 3 PASS signal returned by AbortSignal.abort() should not fire abort event 4 PASS AbortSignal.timeout() returns a non-aborted signal 5 PASS Signal returned by AbortSignal.timeout() times out 6 PASS AbortSignal timeouts fire in order 4 7 -
trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any.js
r279015 r289058 11 11 t.step_timeout(() => { t.done(); }, 2000); 12 12 }, "signal returned by AbortSignal.abort() should not fire abort event"); 13 14 test(t => { 15 const signal = AbortSignal.timeout(0); 16 assert_true(signal instanceof AbortSignal, "returned object is an AbortSignal"); 17 assert_false(signal.aborted, "returned signal is not already aborted"); 18 }, "AbortSignal.timeout() returns a non-aborted signal"); 19 20 async_test(t => { 21 const signal = AbortSignal.timeout(5); 22 signal.onabort = t.step_func_done(() => { 23 assert_true(signal.aborted, "signal is aborted"); 24 assert_true(signal.reason instanceof DOMException, "signal.reason is a DOMException"); 25 assert_equals(signal.reason.name, "TimeoutError", "signal.reason is a TimeoutError"); 26 }); 27 }, "Signal returned by AbortSignal.timeout() times out"); 28 29 async_test(t => { 30 let result = ""; 31 for (const value of ["1", "2", "3"]) { 32 const signal = AbortSignal.timeout(5); 33 signal.onabort = t.step_func(() => { result += value; }); 34 } 35 36 const signal = AbortSignal.timeout(5); 37 signal.onabort = t.step_func_done(() => { 38 assert_equals(result, "123", "Timeout order should be 123"); 39 }); 40 }, "AbortSignal timeouts fire in order"); -
trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any.worker-expected.txt
r279015 r289058 2 2 PASS the AbortSignal.abort() static returns an already aborted signal 3 3 PASS signal returned by AbortSignal.abort() should not fire abort event 4 PASS AbortSignal.timeout() returns a non-aborted signal 5 PASS Signal returned by AbortSignal.timeout() times out 6 PASS AbortSignal timeouts fire in order 4 7 -
trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/w3c-import.log
r287788 r289058 16 16 List of files: 17 17 /LayoutTests/imported/w3c/web-platform-tests/dom/abort/AbortSignal.any.js 18 /LayoutTests/imported/w3c/web-platform-tests/dom/abort/abort-signal-timeout.html 18 19 /LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js 19 20 /LayoutTests/imported/w3c/web-platform-tests/dom/abort/reason-constructor.html -
trunk/Source/WebCore/ChangeLog
r289057 r289058 1 2022-02-03 Chris Dumez <cdumez@apple.com> 2 3 Implement AbortSignal.timeout() 4 https://bugs.webkit.org/show_bug.cgi?id=236039 5 6 Reviewed by Darin Adler. 7 8 Implement the new AbortSignal.timeout() as per: 9 - https://dom.spec.whatwg.org/#dom-abortsignal-timeout 10 11 Test: imported/w3c/web-platform-tests/dom/abort/abort-signal-timeout.html 12 13 * bindings/js/JSAbortSignalCustom.cpp: 14 (WebCore::JSAbortSignalOwner::isReachableFromOpaqueRoots): 15 * dom/AbortSignal.cpp: 16 (WebCore::AbortSignal::timeout): 17 (WebCore::AbortSignal::eventListenersDidChange): 18 * dom/AbortSignal.h: 19 * dom/AbortSignal.idl: 20 * page/DOMTimer.cpp: 21 (WebCore::DOMTimer::DOMTimer): 22 (WebCore::DOMTimer::install): 23 (WebCore::DOMTimer::fired): 24 * page/DOMTimer.h: 25 1 26 2022-02-03 Mark Lam <mark.lam@apple.com> 2 27 -
trunk/Source/WebCore/bindings/js/JSAbortSignalCustom.cpp
r285428 r289058 1 1 /* 2 * Copyright (C) 2019-202 1Apple Inc. All rights reserved.2 * Copyright (C) 2019-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 44 44 return true; 45 45 46 if (abortSignal.hasAbortEventListener() && abortSignal.hasActiveTimeoutTimer()) 47 return true; 48 46 49 return visitor.containsOpaqueRoot(&abortSignal); 47 50 } -
trunk/Source/WebCore/dom/AbortSignal.cpp
r287532 r289058 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #include "AbortAlgorithm.h" 30 30 #include "DOMException.h" 31 #include "DOMTimer.h" 31 32 #include "Event.h" 32 33 #include "EventNames.h" … … 54 55 } 55 56 57 // https://dom.spec.whatwg.org/#dom-abortsignal-timeout 58 Ref<AbortSignal> AbortSignal::timeout(ScriptExecutionContext& context, uint64_t milliseconds) 59 { 60 auto signal = adoptRef(*new AbortSignal(&context)); 61 signal->setHasActiveTimeoutTimer(true); 62 auto action = [signal](ScriptExecutionContext& context) mutable { 63 signal->setHasActiveTimeoutTimer(false); 64 65 auto* globalObject = jsCast<JSDOMGlobalObject*>(context.globalObject()); 66 if (!globalObject) 67 return; 68 69 auto& vm = globalObject->vm(); 70 Locker locker { vm.apiLock() }; 71 signal->signalAbort(toJS(globalObject, globalObject, DOMException::create(TimeoutError))); 72 }; 73 DOMTimer::install(context, WTFMove(action), Seconds::fromMilliseconds(milliseconds), true); 74 return signal; 75 } 76 56 77 AbortSignal::AbortSignal(ScriptExecutionContext* context, Aborted aborted, JSC::JSValue reason) 57 78 : ContextDestructionObserver(context) … … 61 82 ASSERT(reason); 62 83 } 84 85 AbortSignal::~AbortSignal() = default; 63 86 64 87 // https://dom.spec.whatwg.org/#abortsignal-signal-abort … … 103 126 } 104 127 128 void AbortSignal::eventListenersDidChange() 129 { 130 m_hasAbortEventListener = hasEventListeners(eventNames().abortEvent); 131 } 132 105 133 bool AbortSignal::whenSignalAborted(AbortSignal& signal, Ref<AbortAlgorithm>&& algorithm) 106 134 { -
trunk/Source/WebCore/dom/AbortSignal.h
r287532 r289058 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 44 44 public: 45 45 static Ref<AbortSignal> create(ScriptExecutionContext*); 46 WEBCORE_EXPORT ~AbortSignal(); 46 47 47 48 static Ref<AbortSignal> abort(JSDOMGlobalObject&, ScriptExecutionContext&, JSC::JSValue reason); 49 static Ref<AbortSignal> timeout(ScriptExecutionContext&, uint64_t milliseconds); 48 50 49 51 static bool whenSignalAborted(AbortSignal&, Ref<AbortAlgorithm>&&); … … 54 56 bool aborted() const { return m_aborted; } 55 57 const JSValueInWrappedObject& reason() const { return m_reason; } 58 59 bool hasActiveTimeoutTimer() const { return m_hasActiveTimeoutTimer; } 60 bool hasAbortEventListener() const { return m_hasAbortEventListener; } 56 61 57 62 using RefCounted::ref; … … 69 74 explicit AbortSignal(ScriptExecutionContext*, Aborted = Aborted::No, JSC::JSValue reason = JSC::jsUndefined()); 70 75 76 void setHasActiveTimeoutTimer(bool hasActiveTimeoutTimer) { m_hasActiveTimeoutTimer = hasActiveTimeoutTimer; } 77 71 78 // EventTarget. 72 79 EventTargetInterface eventTargetInterface() const final { return AbortSignalEventTargetInterfaceType; } … … 74 81 void refEventTarget() final { ref(); } 75 82 void derefEventTarget() final { deref(); } 83 void eventListenersDidChange() final; 76 84 77 85 bool m_aborted { false }; … … 79 87 WeakPtr<AbortSignal> m_followingSignal; 80 88 JSValueInWrappedObject m_reason; 89 bool m_hasActiveTimeoutTimer { false }; 90 bool m_hasAbortEventListener { false }; 81 91 }; 82 92 -
trunk/Source/WebCore/dom/AbortSignal.idl
r286904 r289058 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 34 34 35 35 [NewObject, CallWith=ScriptExecutionContext&GlobalObject] static AbortSignal abort(optional any reason); 36 [NewObject, CallWith=ScriptExecutionContext] static AbortSignal timeout([EnforceRange] unsigned long long milliseconds); 37 36 38 readonly attribute boolean aborted; 37 39 readonly attribute any reason; -
trunk/Source/WebCore/page/DOMTimer.cpp
r288069 r289058 156 156 bool NestedTimersMap::isTrackingNestedTimers = false; 157 157 158 DOMTimer::DOMTimer(ScriptExecutionContext& context, std::unique_ptr<ScheduledAction>action, Seconds interval, bool singleShot)158 DOMTimer::DOMTimer(ScriptExecutionContext& context, Function<void(ScriptExecutionContext&)>&& action, Seconds interval, bool singleShot) 159 159 : SuspendableTimerBase(&context) 160 160 , m_nestingLevel(context.timerNestingLevel()) … … 174 174 175 175 int DOMTimer::install(ScriptExecutionContext& context, std::unique_ptr<ScheduledAction> action, Seconds timeout, bool singleShot) 176 { 177 auto actionFunction = [action = WTFMove(action)](ScriptExecutionContext& context) mutable { 178 action->execute(context); 179 }; 180 return DOMTimer::install(context, WTFMove(actionFunction), timeout, singleShot); 181 } 182 183 int DOMTimer::install(ScriptExecutionContext& context, Function<void(ScriptExecutionContext&)>&& action, Seconds timeout, bool singleShot) 176 184 { 177 185 Ref<DOMTimer> timer = adoptRef(*new DOMTimer(context, WTFMove(action), timeout, singleShot)); … … 317 325 } 318 326 319 m_action ->execute(context);327 m_action(context); 320 328 321 329 InspectorInstrumentation::didFireTimer(context, m_timeoutId, oneShot); … … 335 343 ContentChangeObserver::DOMTimerScope observingScope(dynamicDowncast<Document>(context), *this); 336 344 #endif 337 m_action ->execute(context);345 m_action(context); 338 346 339 347 InspectorInstrumentation::didFireTimer(context, m_timeoutId, oneShot); -
trunk/Source/WebCore/page/DOMTimer.h
r278253 r289058 56 56 // and returns its Id. 57 57 static int install(ScriptExecutionContext&, std::unique_ptr<ScheduledAction>, Seconds timeout, bool singleShot); 58 static int install(ScriptExecutionContext&, Function<void(ScriptExecutionContext&)>&&, Seconds timeout, bool singleShot); 58 59 static void removeById(ScriptExecutionContext&, int timeoutId); 59 60 … … 65 66 66 67 private: 67 DOMTimer(ScriptExecutionContext&, std::unique_ptr<ScheduledAction>, Seconds interval, bool singleShot);68 DOMTimer(ScriptExecutionContext&, Function<void(ScriptExecutionContext&)>&&, Seconds interval, bool singleShot); 68 69 friend class Internals; 69 70 … … 89 90 int m_timeoutId; 90 91 int m_nestingLevel; 91 std::unique_ptr<ScheduledAction> m_action;92 Function<void(ScriptExecutionContext&)> m_action; 92 93 Seconds m_originalInterval; 93 94 TimerThrottleState m_throttleState;
Note: See TracChangeset
for help on using the changeset viewer.