Bug 74193 - typeof Node should be function
Summary: typeof Node should be function
Status: RESOLVED DUPLICATE of bug 154038
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2011-12-09 11:50 PST by Erik Arvidsson
Modified: 2016-04-10 08:47 PDT (History)
10 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Erik Arvidsson 2011-12-09 11:50:26 PST


Node instanceof Function // should be true
Function.prototype.isPrototypeOf(Node)  // should be true

typeof Object.getPrototypeOf(Node)  // should be "function"
Comment 1 Oliver Hunt 2015-02-09 08:30:13 PST
Node is a constructor, not a function.

ES spec is fairly clear on this -- typeof x === "function" only if x is directly callable.

If the webidl spec now calls for element constructors to be callable directly (instead of via new) then the bug here is that NodeConstructor isn't a function, not any of the other things you're claiming.
Comment 2 Erik Arvidsson 2015-02-09 09:07:43 PST
ES6 classes have a [[Call]] but it throws immediately.


2. If F’s [[FunctionKind]] internal slot is "classConstructor", throw a TypeError exception.

For WebIDL all constructors have a [[Call]]. It used to do the same thing as [[Construct]], which was to throw if non constructable. There is an open WebIDL bug to throw on [[Call]], See https://www.w3.org/Bugs/Public/show_bug.cgi?id=22808, and Firefox just made that change too.
Comment 3 Joe Pea 2016-04-09 22:18:11 PDT
Can you guys please fix this? The reason for following the spec in such a way doesn't outweight the benefit of being able extend from HTMLElement, especially when using the new Custom Element API.

After applying a `document.registerElement` polyfill in Safari, this is what we have to do in order to make a Custom Element that extends from HTMLElement using ES6 classes:

import 'document-register-element' // polyfill

// hack for Safari.
if (typeof window.HTMLElement != 'function') {
    const _HTMLElement = function HTMLElement(){}
    _HTMLElement.prototype = window.HTMLElement.prototype
    window.HTMLElement = _HTMLElement

class MyElement extends window.HTMLElement {
    createdCallback() { ... }
    attachedCallback() { ... }
    detachedCallback() { ... }
    attributeChangedCallback(attribute, oldValue, newValue) { ... }
MyElement = document.registerElement('motor-node', MyElement)

export default MyElement

I think it's time to fix this and get Custom Elements working, and in general to be compatible with ES6 classes.
Comment 4 Chris Dumez 2016-04-10 08:47:38 PDT
This has already been fixed a while back via Bug 154038. You can give it a try in the Safari Technology Preview (all your 3 tests pass there).

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