Skip to content

Commit 57cf50c

Browse files
committed
Address Safer C++ static analysis warnings in WebCore/bindings after 2026-10-06 rollout
https://bugs.webkit.org/show_bug.cgi?id=327654 Reviewed by Ryosuke Niwa. Fix the Safer C++ warnings in WebCore/bindings, including the ones in generated bindings code, and update the corresponding expectations files. The generated wrapped() downcast is safe by construction since a JSFoo always wraps a Foo, so it is suppressed instead of adding a type check to every DOM call. Code that may run on a GC thread suppresses its warnings since it cannot ref objects. * Source/WebCore/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations: * Source/WebCore/SaferCPPExpectations/UncountedCallArgsCheckerExpectations: * Source/WebCore/bindings/js/IDBBindingUtilities.cpp: * Source/WebCore/bindings/js/JSCustomElementInterface.cpp: * Source/WebCore/bindings/js/JSDOMAsyncIterator.h: * Source/WebCore/bindings/js/JSDOMGuardedObject.cpp: * Source/WebCore/bindings/js/JSEventTargetCustom.h: * Source/WebCore/bindings/js/JSFetchEventCustom.cpp: * Source/WebCore/bindings/js/JSIDBCursorWithValueCustom.cpp: * Source/WebCore/bindings/js/JSIntersectionObserverCustom.cpp: * Source/WebCore/bindings/js/JSMutationObserverCustom.cpp: * Source/WebCore/bindings/js/JSResizeObserverCustom.cpp: * Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp: * Source/WebCore/bindings/js/JSWebCodecsAudioDecoderCustom.cpp: * Source/WebCore/bindings/js/JSWebCodecsAudioEncoderCustom.cpp: * Source/WebCore/bindings/js/JSWebCodecsVideoDecoderCustom.cpp: * Source/WebCore/bindings/js/JSWebCodecsVideoEncoderCustom.cpp: * Source/WebCore/bindings/js/ScriptController.cpp: * Source/WebCore/bindings/js/WindowProxy.cpp: * Source/WebCore/bindings/scripts/CodeGeneratorJS.pm: * Source/WebCore/bindings/scripts/test/JS/JSDOMWindow.h: * Source/WebCore/bindings/scripts/test/JS/JSDedicatedWorkerGlobalScope.h: * Source/WebCore/bindings/scripts/test/JS/JSExposedStar.h: * Source/WebCore/bindings/scripts/test/JS/JSPaintWorkletGlobalScope.h: * Source/WebCore/bindings/scripts/test/JS/JSServiceWorkerGlobalScope.h: * Source/WebCore/bindings/scripts/test/JS/JSSharedWorkerGlobalScope.h: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackFunction.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackFunctionGenerateIsReachable.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackFunctionWithThisObject.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackFunctionWithTypedefs.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackFunctionWithVariadic.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackInterface.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestCallbackWithFunctionOrDict.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestDOMJIT.h: * Source/WebCore/bindings/scripts/test/JS/JSTestDefaultToJSONIndirectInheritance.h: * Source/WebCore/bindings/scripts/test/JS/JSTestDefaultToJSONInherit.h: * Source/WebCore/bindings/scripts/test/JS/JSTestDefaultToJSONInheritFinal.h: * Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.h: * Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.h: * Source/WebCore/bindings/scripts/test/JS/JSTestExceptionSubclass.h: * Source/WebCore/bindings/scripts/test/JS/JSTestNode.h: * Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp: * Source/WebCore/bindings/scripts/test/JS/JSTestPromiseRejectionEvent.h: * Source/WebCore/bindings/scripts/test/JS/JSTestVoidCallbackFunction.cpp: * Source/WebCore/bindings/scripts/test/JS/JSWorkerGlobalScope.h: * Source/WebCore/bindings/scripts/test/JS/JSWorkletGlobalScope.h: Canonical link: https://commits.webkit.org/323894@main
1 parent a9fa7d8 commit 57cf50c

46 files changed

Lines changed: 91 additions & 78 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Source/WebCore/SaferCPPExpectations/UncheckedCallArgsCheckerExpectations‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ StyleBuilderGenerated.cpp
33
[ macOS ] animation/KeyframeEffectStack.cpp
44
[ macOS ] animation/StyleOriginatedAnimation.cpp
55
[ macOS ] animation/WebAnimation.cpp
6-
[ macOS ] bindings/js/JSCustomElementInterface.cpp
7-
[ macOS ] bindings/js/JSDOMGuardedObject.cpp
8-
[ macOS ] bindings/js/ScriptController.cpp
96
[ macOS ] css/CSSStyleProperties.cpp
107
[ macOS ] css/FontFace.cpp
118
[ macOS ] css/MediaQueryMatcher.cpp

‎Source/WebCore/SaferCPPExpectations/UncountedCallArgsCheckerExpectations‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@ StyleChangedAnimatablePropertiesGenerated.cpp
44
[ macOS ] animation/KeyframeEffectStack.cpp
55
[ macOS ] animation/StyleOriginatedAnimation.cpp
66
[ macOS ] animation/WebAnimation.cpp
7-
[ macOS ] bindings/js/IDBBindingUtilities.cpp
8-
[ macOS ] bindings/js/JSCustomElementInterface.cpp
9-
[ macOS ] bindings/js/JSDOMAsyncIterator.h
10-
[ macOS ] bindings/js/JSDOMGuardedObject.cpp
11-
[ macOS ] bindings/js/JSFetchEventCustom.cpp
12-
[ macOS ] bindings/js/JSIDBCursorWithValueCustom.cpp
13-
[ macOS ] bindings/js/JSIntersectionObserverCustom.cpp
14-
[ macOS ] bindings/js/JSMutationObserverCustom.cpp
15-
[ macOS ] bindings/js/JSResizeObserverCustom.cpp
16-
[ macOS ] bindings/js/JSServiceWorkerGlobalScopeCustom.cpp
17-
[ macOS ] bindings/js/JSWebCodecsAudioDecoderCustom.cpp
18-
[ macOS ] bindings/js/JSWebCodecsAudioEncoderCustom.cpp
19-
[ macOS ] bindings/js/JSWebCodecsVideoDecoderCustom.cpp
20-
[ macOS ] bindings/js/JSWebCodecsVideoEncoderCustom.cpp
21-
[ macOS ] bindings/js/ScriptController.cpp
22-
[ macOS ] bindings/js/WindowProxy.cpp
237
[ macOS ] css/CSSCounterStyleDescriptors.cpp
248
[ macOS ] css/CSSStyleProperties.cpp
259
[ macOS ] css/CSSValue.cpp

‎Source/WebCore/bindings/js/IDBBindingUtilities.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ JSValue toJS(JSGlobalObject& lexicalGlobalObject, JSGlobalObject& globalObject,
145145
}
146146

147147
VM& vm = lexicalGlobalObject.vm();
148-
Locker<JSLock> locker(vm.apiLock());
148+
JSLockHolder locker(vm);
149149
auto scope = DECLARE_THROW_SCOPE(vm);
150150

151151
switch (key->type()) {

‎Source/WebCore/bindings/js/JSCustomElementInterface.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace WebCore {
5555
using namespace JSC;
5656

5757
JSCustomElementInterface::JSCustomElementInterface(const QualifiedName& name, JSObject* constructor, JSDOMGlobalObject* globalObject)
58-
: ActiveDOMCallback(globalObject->scriptExecutionContext())
58+
: ActiveDOMCallback(protect(globalObject->scriptExecutionContext()))
5959
, m_name(name)
6060
, m_constructor(constructor)
6161
, m_isolatedWorld(globalObject->world())

‎Source/WebCore/bindings/js/JSDOMAsyncIterator.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ template<typename IteratorValue, typename IteratorTraits>
173173
inline EnableIfMap<IteratorTraits, JSC::JSValue> convertToJS(JSC::JSGlobalObject& globalObject, JSDOMGlobalObject& domGlobalObject, IteratorValue& value, IteratorTraits, IterationKind kind)
174174
{
175175
JSC::VM& vm = globalObject.vm();
176-
Locker<JSC::JSLock> locker(vm.apiLock());
176+
JSC::JSLockHolder locker(vm);
177177

178178
switch (kind) {
179179
case IterationKind::Keys:

‎Source/WebCore/bindings/js/JSDOMGuardedObject.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "JSDOMGuardedObject.h"
2828

2929
#include "JSDOMGlobalObjectInlines.h"
30+
#include "ScriptExecutionContext.h"
3031
#include <JavaScriptCore/WeakInlines.h>
3132

3233
namespace WebCore {
@@ -35,7 +36,7 @@ using namespace JSC;
3536
JSDOMGlobalObject* DOMGuardedObject::globalObject() const { return m_globalObject.get(); }
3637

3738
DOMGuardedObject::DOMGuardedObject(JSDOMGlobalObject& globalObject, JSCell& guarded)
38-
: ActiveDOMCallback(globalObject.scriptExecutionContext())
39+
: ActiveDOMCallback(protect(globalObject.scriptExecutionContext()))
3940
, m_guarded(&guarded)
4041
, m_globalObject(&globalObject)
4142
{

‎Source/WebCore/bindings/js/JSEventTargetCustom.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class JSEventTargetWrapper {
4747
EventTarget& wrapped() { ASSERT(m_wrapped); return *m_wrapped; }
4848

4949
operator JSC::JSObject&() { ASSERT(m_wrapper); return *m_wrapper; }
50+
JSC::JSObject& wrapper() { ASSERT(m_wrapper); return *m_wrapper; }
5051

5152
private:
5253
// Only lives on the stack, while the JS wrapper keeps the wrapped object alive.

‎Source/WebCore/bindings/js/JSFetchEventCustom.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace WebCore {
3434
template<typename Visitor>
3535
void JSFetchEvent::visitAdditionalChildrenInGCThread(Visitor& visitor)
3636
{
37-
addWebCoreOpaqueRoot(visitor, wrapped().request());
37+
// This function may get called on a GC thread so we cannot ref the object.
38+
SUPPRESS_UNCOUNTED_ARG addWebCoreOpaqueRoot(visitor, wrapped().request());
3839
}
3940

4041
DEFINE_VISIT_ADDITIONAL_CHILDREN_IN_GC_THREAD(JSFetchEvent);

‎Source/WebCore/bindings/js/JSIDBCursorWithValueCustom.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ JSC::JSValue JSIDBCursorWithValue::value(JSC::JSGlobalObject& lexicalGlobalObjec
3838
{
3939
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
4040
return cachedPropertyValue(throwScope, lexicalGlobalObject, *this, wrapped().valueWrapper(), [&](JSC::ThrowScope&) {
41-
auto result = deserializeIDBValueWithKeyInjection(lexicalGlobalObject, protect(wrapped())->value(), wrapped().primaryKey(), wrapped().primaryKeyPath());
41+
auto result = deserializeIDBValueWithKeyInjection(lexicalGlobalObject, protect(wrapped())->value(), protect(wrapped().primaryKey()).get(), wrapped().primaryKeyPath());
4242
return result ? result.value() : jsNull();
4343
});
4444
}

‎Source/WebCore/bindings/js/JSIntersectionObserverCustom.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ DEFINE_VISIT_ADDITIONAL_CHILDREN_IN_GC_THREAD(JSIntersectionObserver);
4545

4646
bool JSIntersectionObserverOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, JSC::AbstractSlotVisitor& visitor, ASCIILiteral* reason)
4747
{
48-
if (downcast<JSIntersectionObserver>(handle.slot()->asCell())->wrapped().isReachableFromOpaqueRoots(visitor)) {
48+
// This function is called on a GC thread so we cannot ref the object.
49+
SUPPRESS_UNCOUNTED_ARG if (downcast<JSIntersectionObserver>(handle.slot()->asCell())->wrapped().isReachableFromOpaqueRoots(visitor)) {
4950
if (reason) [[unlikely]]
5051
*reason = "Reachable from observed nodes"_s;
5152
return true;

0 commit comments

Comments
 (0)