Bug 156730

Summary: MediaQueryList.addListener does not support Object with handleEvent() method
Product: WebKit Reporter: nkronlage
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ashvayka
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description nkronlage 2016-04-18 22:18:56 PDT
Repro:

    var query = matchMedia("(min-width: 400px)");

    var listener = {
      handleEvent: function() {
        document.body.style.background = query.matches ? 'red' : 'blue';
      }
    }

    query.addListener(listener);
    listener.handleEvent();

Runnable:  https://jsfiddle.net/j4278otv/

Running this results in the error: "[Error] TypeError: Argument 1 ('listener') to MediaQueryList.addListener must be a function"

The spec (https://drafts.csswg.org/cssom-view/#mediaquerylist) says the parameter to addListener is an EventListener (https://dom.spec.whatwg.org/#callbackdef-eventlistener): 

    callback interface EventListener {
      void handleEvent(Event event);
    };

but the implementation only allows functions.

The Node.addEventListener method does support the Object with handleEvent() method:  See https://jsfiddle.net/6nL0epf3/
Comment 1 Alexey Shvayka 2020-04-03 09:41:56 PDT

*** This bug has been marked as a duplicate of bug 203288 ***