Bug 188083 - The instanceof operator does not work as expected for classes that extend CustomEvent or Event
Summary: The instanceof operator does not work as expected for classes that extend Cus...
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari Technology Preview
Hardware: Mac Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-07-26 15:47 PDT by Eugene Kashida
Modified: 2020-03-22 10:25 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Kashida 2018-07-26 15:47:17 PDT
Overview:

class FooEvent extends CustomEvent {
  constructor() {
    super('foo');
  }
};
var foo = new FooEvent();
console.log('This evaluates to "false" which is unexpected', foo instanceof FooEvent);
console.log('This evaluates to "true" which is expected', foo instanceof CustomEvent);
console.log('This evaluates to "true" which is expected', foo instanceof Event);


Expected Results:

The instanceof operator, when given an instance of FooEvent which extends CustomEvent, and the FooEvent constructor, should evaluate to "true".

Build Date & Hardware:

Release 61 (Safari 12.0, WebKit 13606.1.25.1)
Mac OS 10.13.6
Comment 1 Ryosuke Niwa 2018-07-31 19:06:50 PDT
I don't think class inheritance ever worked with Event's.
Comment 2 Eugene Kashida 2018-08-01 15:12:28 PDT
It seems to be working as expected in Firefox and Chrome, and Edge has the following open issue:
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11923584/
Comment 3 Alexey Shvayka 2020-03-22 10:24:58 PDT
(In reply to Eugene Kashida from comment #0)
> Expected Results:
> 
> The instanceof operator, when given an instance of FooEvent which extends
> CustomEvent, and the FooEvent constructor, should evaluate to "true".

As of https://trac.webkit.org/changeset/256716, extending CustomEvent (as well as other DOM constructors) works as expected.
Comment 4 Radar WebKit Bug Importer 2020-03-22 10:25:17 PDT
<rdar://problem/60743143>