Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: cdd970b5238b5d61fd2c6914a0698d57543d2829
      
https://github.com/WebKit/WebKit/commit/cdd970b5238b5d61fd2c6914a0698d57543d2829
  Author: Andrew Fryer <[email protected]>
  Date:   2026-04-20 (Mon, 20 Apr 2026)

  Changed paths:
    A 
LayoutTests/fast/dom/NodeList/nodelist-array-prototype-indexOf-expected.txt
    A LayoutTests/fast/dom/NodeList/nodelist-array-prototype-indexOf.html
    M Source/JavaScriptCore/CMakeLists.txt
    M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
    M Source/JavaScriptCore/runtime/ArrayPrototype.cpp
    A Source/JavaScriptCore/runtime/EmbedderArrayLike.h
    A Source/JavaScriptCore/runtime/JSEmbedderArrayLike.h
    M Source/JavaScriptCore/runtime/JSType.h
    M Source/WebCore/bindings/js/JSDOMWrapper.h
    M Source/WebCore/bindings/js/JSDOMWrapperCache.h
    M Source/WebCore/bindings/js/JSNodeListCustom.cpp
    M Source/WebCore/bindings/js/ScriptWrappable.h
    M Source/WebCore/bindings/js/ScriptWrappableInlines.h
    M Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
    M Source/WebCore/bindings/scripts/IDLAttributes.json
    M Source/WebCore/bindings/scripts/test/BindingTestGlobalConstructors.idl
    A Source/WebCore/bindings/scripts/test/JS/JSTestEmbedderArrayLike.cpp
    A Source/WebCore/bindings/scripts/test/JS/JSTestEmbedderArrayLike.h
    M Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp
    M Source/WebCore/bindings/scripts/test/SupplementalDependencies.dep
    A Source/WebCore/bindings/scripts/test/TestEmbedderArrayLike.idl
    M Source/WebCore/dom/NodeList.cpp
    M Source/WebCore/dom/NodeList.h
    M Source/WebCore/dom/NodeList.idl

  Log Message:
  -----------
  Add fast path for Array.prototype.indexOf on NodeList
https://bugs.webkit.org/show_bug.cgi?id=311457
rdar://173158637

Reviewed by Yusuke Suzuki.

When Array.prototype.indexOf is called on a NodeList, the existing path
wraps every element into a JS object just to do a pointer comparison.
Add a fast path that unwraps the search element once and compares native
Node pointers directly, skipping wrapper creation.

In JSC:
- Add EmbedderArrayLike, a reference counted abstract class with a
  virtual fastIndexOf() method, allowing JSC to call into embedder
  implementations.
- Add JSEmbedderArrayLike, which holds an EmbedderArrayLike* pointer.
- Add EmbedderArrayLikeType, a new JSType for JSEmbedderArrayLike.

In WebCore:
- NodeList now also inherits from EmbedderArrayLike and implements
  fastIndexOf() using native Node* pointer comparison.
- Add JSDOMEmbedderArrayLikeWrapper<T>, which mirrors JSDOMWrapper<T>
  but inherits JSEmbedderArrayLike instead of JSDOMObject. This gives
  JSC access to the EmbedderArrayLike* while providing the same
  wrapped()/globalObject()/scriptExecutionContext() interface that
  generated bindings expect.
- Add [EmbedderArrayLike] IDL attribute, allowing NodeList to opt into
  JSDOMEmbedderArrayLikeWrapper rather than JSDOMWrapper.
- Widen ScriptWrappable from JSDOMObject* to JSC::JSObject*. This is
  necessary because JSDOMEmbedderArrayLikeWrapper inherits
  JSEmbedderArrayLike (a JSDestructibleObject), not JSDOMObject, so the
  wrapper cache must accept both hierarchies.

Test: fast/dom/NodeList/nodelist-array-prototype-indexOf.html
      bindings/scripts/test/TestEmbedderArrayLike.idl

* LayoutTests/fast/dom/NodeList/nodelist-array-prototype-indexOf-expected.txt: 
Added.
* LayoutTests/fast/dom/NodeList/nodelist-array-prototype-indexOf.html: Added.
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/runtime/ArrayPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/EmbedderArrayLike.h: Copied from 
Source/WebCore/dom/NodeList.cpp.
* Source/JavaScriptCore/runtime/JSEmbedderArrayLike.h: Copied from 
Source/WebCore/dom/NodeList.cpp.
(JSC::JSEmbedderArrayLike::embeddedArrayLike const):
(JSC::JSEmbedderArrayLike::JSEmbedderArrayLike):
* Source/JavaScriptCore/runtime/JSType.h:
* Source/WebCore/bindings/js/JSDOMWrapper.h:
(WebCore::JSDOMEmbedderArrayLikeWrapper::subspaceFor):
(WebCore::JSDOMEmbedderArrayLikeWrapper::realm const):
(WebCore::JSDOMEmbedderArrayLikeWrapper::scriptExecutionContext const):
(WebCore::JSDOMEmbedderArrayLikeWrapper::wrapped const):
(WebCore::JSDOMEmbedderArrayLikeWrapper::hasCustomPtrTraits):
(WebCore::JSDOMEmbedderArrayLikeWrapper::JSDOMEmbedderArrayLikeWrapper):
* Source/WebCore/bindings/js/JSDOMWrapperCache.h:
(WebCore::setInlineCachedWrapper):
(WebCore::clearInlineCachedWrapper):
* Source/WebCore/bindings/js/JSNodeListCustom.cpp:
* Source/WebCore/bindings/js/ScriptWrappable.h:
* Source/WebCore/bindings/js/ScriptWrappableInlines.h:
(WebCore::ScriptWrappable::wrapper const):
(WebCore::ScriptWrappable::setWrapper):
(WebCore::ScriptWrappable::clearWrapper):
* Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:
(GetParentClassName):
(GenerateImplementation):
* Source/WebCore/bindings/scripts/IDLAttributes.json:
* Source/WebCore/bindings/scripts/test/BindingTestGlobalConstructors.idl:
* Source/WebCore/bindings/scripts/test/JS/JSTestEmbedderArrayLike.cpp: Added.
(WebCore::JSTestEmbedderArrayLikeDOMConstructor::prototypeForStructure):
(WebCore::JSTestEmbedderArrayLikeDOMConstructor::initializeProperties):
(WebCore::JSTestEmbedderArrayLikePrototype::createStructure):
(WebCore::JSTestEmbedderArrayLikePrototype::finishCreation):
(WebCore::JSTestEmbedderArrayLike::JSTestEmbedderArrayLike):
(WebCore::JSTestEmbedderArrayLike::create):
(WebCore::JSTestEmbedderArrayLike::createStructure):
(WebCore::JSTestEmbedderArrayLike::createPrototype):
(WebCore::JSTestEmbedderArrayLike::prototype):
(WebCore::JSTestEmbedderArrayLike::getConstructor):
(WebCore::JSTestEmbedderArrayLike::destroy):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
(WebCore::JSTestEmbedderArrayLike::subspaceForImpl):
(WebCore::JSTestEmbedderArrayLike::analyzeHeap):
(WebCore::JSTestEmbedderArrayLikeOwner::isReachableFromOpaqueRoots):
(WebCore::JSTestEmbedderArrayLikeOwner::finalize):
(WebCore::verifyVTable):
(WebCore::toJSNewlyCreated):
(WebCore::toJS):
(WebCore::JSTestEmbedderArrayLike::toWrapped):
* Source/WebCore/bindings/scripts/test/JS/JSTestEmbedderArrayLike.h: Added.
(WebCore::JSTestEmbedderArrayLike::subspaceFor):
(WebCore::wrapperOwner):
(WebCore::wrapperKey):
(WebCore::toJSNewlyCreated):
* Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp:
(WebCore::JSTestGlobalObjectDOMConstructor::prototypeForStructure):
(WebCore::jsTestGlobalObject_TestEmbedderArrayLikeConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* Source/WebCore/bindings/scripts/test/SupplementalDependencies.dep:
* Source/WebCore/bindings/scripts/test/TestEmbedderArrayLike.idl: Added.
* Source/WebCore/dom/NodeList.cpp:
(WebCore::NodeList::fastIndexOf):
* Source/WebCore/dom/NodeList.h:
* Source/WebCore/dom/NodeList.idl:

Canonical link: https://commits.webkit.org/311562@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to