This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 11191 - Run scripts based on a parser flag rather than on being a fragment parser
Summary: Run scripts based on a parser flag rather than on being a fragment parser
Status: RESOLVED NEEDSINFO
Alias: None
Product: HTML WG
Classification: Unclassified
Component: LC1 HTML5 spec (show other bugs)
Version: unspecified
Hardware: All All
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 11190
  Show dependency treegraph
 
Reported: 2010-11-01 21:25 UTC by Ms2ger
Modified: 2011-08-06 03:44 UTC (History)
5 users (show)

See Also:


Attachments

Description Ms2ger 2010-11-01 21:25:05 UTC
Please add a flag to the parser to allow running scripts from Range.createContextualFragment.
Comment 1 Ian 'Hixie' Hickson 2010-12-27 23:55:14 UTC
Can you clarify exactly what you need here?
Comment 2 Ms2ger 2010-12-28 19:11:48 UTC
I'd like to be able to say "Invoke the HTML fragment parsing algorithm with scripts enabled/disabled." or something similar.
Comment 3 Ian 'Hixie' Hickson 2011-01-20 20:30:31 UTC
Running the fragment parser with scripts enabled is likely to have very different results than what one might expect, since the fragment parser is defined as parsing into a new document and then regrafting the nodes. Could you elaborate further on what exactly you need? What are the semantics you want for running scripts? What scripts should run? How should they interact with document.write(), async scripts, the event loop, etc? What if there are re-entrant invokations of this algorithm? etc
Comment 4 Henri Sivonen 2011-01-21 12:15:28 UTC
(In reply to comment #3)
> Running the fragment parser with scripts enabled is likely to have very
> different results than what one might expect,

Indeed.

> since the fragment parser is
> defined as parsing into a new document and then regrafting the nodes. Could you
> elaborate further on what exactly you need?

That when scripts are enabled, the result of the fragment parsing algorithm is a document fragment that contain script element nodes whose 'already started' and 'parser-inserted' flags haven't been set.

> What are the semantics you want for
> running scripts?

The same as when inserting a manually-constructed DOM fragment into a document.

> What scripts should run? 

All scripts whose type is a supported language.

> How should they interact with
> document.write(), async scripts, the event loop, etc? What if there are
> re-entrant invokations of this algorithm? etc

Exactly as if the fragment had been constructed with document.createElement and appendChild.
Comment 5 Ian 'Hixie' Hickson 2011-02-09 01:14:51 UTC
So the requirement here is actually to have a flag to run the parser with scripts _disabled_ but to clear all the "already started" flags just before the nodes get inserted?

If I do this, then I should make sure to update the algorithms that rely on "the time the element's "already started" flag was set" to rely on the the time the flag was _last_ set.
Comment 6 Ian 'Hixie' Hickson 2011-02-09 21:09:24 UTC
Thinking about this some more, I think actually the current text is the right way to do it (but with the createContextualFragment() prose changed per sicking's editorial suggestion in [1], and the HTML spec changed per comment 5).

No?

[1] http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-December/029280.html
Comment 7 contributor 2011-02-09 21:22:09 UTC
Checked in as WHATWG revision r5866.
Check-in comment: Clarify that if 'already started' is set multiple times, the state the last time it was set is what matters.
http://html5.org/tools/web-apps-tracker?from=5865&to=5866
Comment 8 Henri Sivonen 2011-02-10 13:13:14 UTC
> So the requirement here is actually to have a flag to run the parser with
> scripts _disabled_ but to clear all the "already started" flags just before the
> nodes get inserted?

The requirement is ability to optionally parse a fragment so that "already started" doesn't get set and the parser doesn't invoke the "prepare the script" algorithm.
Comment 9 Ian 'Hixie' Hickson 2011-03-05 00:16:01 UTC
So basically, for HTML, skipping everything from "Increment the parser's script nesting level by one" down to the end of that block (inclusive), and for XML, skip all but the first sentence of the paragraph that says "When an XML parser creates a script element"?

Are we sure that's better than doing it as it's done now (per comment 6)?
Comment 10 Ms2ger 2011-03-07 20:36:34 UTC
I would really like to avoid depending on these flags. The reason that text is there now is because there was confusion as to which behaviour was preferred here, and you hadn't yet fixed this bug. I defer to Henri for the technical details.
Comment 11 Ian 'Hixie' Hickson 2011-05-06 00:43:56 UTC
I don't really understand why depending on the script flags is any better or worse than depending on the parser flags. I'm definitely not a fan of complicating the parser further by having yet more parser modes, especially here where it really doesn't make much difference one way or the other as far as I can tell.
Comment 12 Henri Sivonen 2011-05-06 07:31:54 UTC
Oops. I should have responded here earlier.

In Firefox, Range::createContextualFragment is equivalent to building the fragment manually using createElementNS and appendChild. The spec already informatively says that XSLTProcessor::transformToFragment works like this, too.

In Firefox, the parser has a "prevent execution" flag that can be set to true in the fragment case. If it is set to true, the parser sets the "already started" flag on script elements instead of attempting to run them. If it is not set, the parser doesn't set the "already started" flag on the scripts (and doesn't run the scripts, either, because they aren't in a document at the time of the parse).
Comment 13 Ian 'Hixie' Hickson 2011-06-10 22:25:55 UTC
Ms2ger, if you want this please ping me on IRC so you can try to convince me it's needed. I'm just not seeing the value here.
Comment 14 Michael[tm] Smith 2011-08-04 05:07:04 UTC
mass-moved component to LC1
Comment 15 Ian 'Hixie' Hickson 2011-08-06 03:44:39 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Did Not Understand Request
Change Description: no spec change
Rationale: see comment 13