Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the owner document for all element constructors #1168

Merged
merged 1 commit into from
May 4, 2016

Conversation

domenic
Copy link
Member

@domenic domenic commented May 2, 2016

Fixes #1154, which originally covered only the undefined "document"
variable in the HTMLElement constructor, but expanded on further
investigation to reveal that the spec's current choice of node document
for Audio, Image, and Option was strange and not implemented in
browsers.

While there, cleans up all three of these named constructors to
correctly use "create an element," and to be in numbered algorithm form
instead of giant-prose-block form.


/cc @bzbarsky @dominiccooney since they were involved in/started that discussion. The end result is probably not worth your time reviewing; the substance of it is the change from #1154 (comment) (A) to (B), which seems to match Chrome and Firefox at least.

@bzbarsky
Copy link
Contributor

bzbarsky commented May 3, 2016

We really should check what Edge and WebKit do here, but I think the (B) behavior is the only remotely sane one.

@annevk
Copy link
Member

annevk commented May 3, 2016

Safari matches Firefox/Chrome, both stable and technology preview. Don't have Edge.

data-x="concept-custom-element-definition-local-name">local name</span>.</p></li>

<li><p>Let <var>document</var> be <var>realm</var>'s <span data-x="concept-realm-global">global
object</span>'s <span data-x="concept-document-window">newest <code>Document</code>
object</span>.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use "newest" twice so far. Window's document, document's Window, Window's associated, document's associated, are all more common. (By the way, should we have two separate pointers for those cases? I guess it's clear enough...)

@domenic domenic force-pushed the fix-various-owner-documents branch from 75da8f1 to 16bbe08 Compare May 3, 2016 14:21
@domenic
Copy link
Member Author

domenic commented May 3, 2016

@annevk editorial issues fixed. We can use "current global object" now instead of "current Realm Record's global object" :)

@domenic domenic assigned ajklein and annevk and unassigned ajklein May 3, 2016
@bzbarsky
Copy link
Contributor

bzbarsky commented May 3, 2016

Well, I can test Edge, with a bit of effort. Just have to let me know. On http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4122 Edge throws because Text is not actually constructible in Edge.

On http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4143 Edge throws on this line:

w("doc1 !== doc2 (should be true): " + (doc1 !== doc2));

and the exception is error: Permission denied on line 26.

On http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4144 Edge throws on this line:

w("Image owner document post-navigation (should be doc2, per spec): " + (new Image1()).ownerDocument.name);

and the exception is error: Can't execute code from a freed script on line 27. Note that Edge does not seem to be reusing the initial about:blank's window here per the someRandomThing test, and as I said recently in one of these issues Edge simply doesn't allow script in navigated-away-from documents to run.

On http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4146 Edge actually has the same document all along: the window.open call doesn't create an about:blank document but rather a document with the "http://software.hixie.ch/" URL and the object identity remains through onload. No idea what it does when an HTTP redirect then happens; maybe it goes ahead and creates a new document then.

On http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4147 Edge doesn't reuse the existing Window (and neither does Chrome). Firefox does.

@domenic
Copy link
Member Author

domenic commented May 3, 2016

Right, my conclusion when trying to test (although I didn't try as many variations as you did) was that Edge is so far from spec compliance here that we can't really count on their input.

@@ -9570,8 +9570,7 @@ interface <dfn>HTMLUnknownElement</dfn> : <span>HTMLElement</span> { };</pre>
<div w-nodev>

<ol>
<li><p>Let <var>realm</var> be the result of <span>GetFunctionRealm</span>(the currently
executing <code>HTMLElement</code> function).</p></li>
<li><p>Let <var>realm</var> be the <span>current Realm Record</span>.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this can become "Let global be [current global object]" given that we only get stuff from the global in two later steps.

@bzbarsky
Copy link
Contributor

bzbarsky commented May 3, 2016

I think the real question the Edge behavior raises is whether it's web-compatible to simplify things here from what the spec does. For example, Edge's approach to window.open seems like it would make it possible to get rid of the "reuse the same Window with a new Document" case...

@annevk
Copy link
Member

annevk commented May 3, 2016

@DigiTec @travisleithead, thoughts on Edge reusing documents rather than creating a new one? Sounds like you have a rather interesting simplification of the platform that no other browser has.

@domenic domenic force-pushed the fix-various-owner-documents branch from 16bbe08 to f5ac26d Compare May 3, 2016 14:51
@domenic
Copy link
Member Author

domenic commented May 3, 2016

@annevk fixed the HTMLElement constructor up a decent bit more, including making it cross-linkable. Kept that in a separate fixup commit.

<li><p>Let <var>element</var> be a new element that implements the <code>HTMLElement</code>
interface, with no attributes, namespace set to the <span>HTML namespace</span>, local name set
to <var>localName</var>, and <span>node document</span> set to <var>document</var>.</p></li>
to <var>definition</var>'s <span data-x="concept-custom-element-definition-local-name">local
name</span>, and <span>node document</span> set to <var>document</var>.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just inline <span>current global object</span>'s <code>Document</code> object here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I guess we should use concept-document-window?

@annevk annevk assigned domenic and unassigned annevk May 4, 2016
@annevk
Copy link
Member

annevk commented May 4, 2016

LGTM with those nits fixed.

Unsure whether we should open a separate issue to investigate Edge's simplification more.

Fixes #1154, which originally covered only the undefined "document"
variable in the HTMLElement constructor, but expanded on further
investigation to reveal that the spec's current choice of node document
for Audio, Image, and Option was strange and not implemented in
browsers.

While there, cleans up all three of these named constructors to
correctly use "create an element," and to be in numbered algorithm form
instead of giant-prose-block form; also gives the HTMLElement constructor
its own <dfn> and inline some of its steps.
@domenic domenic force-pushed the fix-various-owner-documents branch from f5ac26d to c9d8983 Compare May 4, 2016 16:14
@domenic domenic merged commit c9d8983 into master May 4, 2016
@annevk annevk deleted the fix-various-owner-documents branch May 12, 2016 08:47
@domenic domenic added the topic: custom elements Relates to custom elements (as defined in DOM and HTML) label Jun 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
normative change topic: custom elements Relates to custom elements (as defined in DOM and HTML)
Development

Successfully merging this pull request may close these issues.

4 participants