Bug 74193
Summary: | typeof Node should be function | ||
---|---|---|---|
Product: | WebKit | Reporter: | Erik Arvidsson <arv> |
Component: | DOM | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | Normal | CC: | ap, cdumez, dominicc, ggaren, haraken, joe, kaustubh.ra, oliver, rniwa, sam |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | All | ||
OS: | All |
Erik Arvidsson
https://www.w3.org/Bugs/Public/show_bug.cgi?id=12458
Related:
Node instanceof Function // should be true
Function.prototype.isPrototypeOf(Node) // should be true
typeof Object.getPrototypeOf(Node) // should be "function"
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Oliver Hunt
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.
Erik Arvidsson
ES6 classes have a [[Call]] but it throws immediately.
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-call-thisargument-argumentslist
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.
Joe Pea
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:
```js
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.
Chris Dumez
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 ***