Re: [custom-elements] Steps inside HTMLElement's constructor

> On Feb 22, 2016, at 10:46 PM, Ryosuke Niwa <> wrote:
> Here are steps to construct a custom element as agreed during Jan F2F as I promised to write down [1] [2]:

There's a very appealing alternative to this, which doesn't involve having a element construction stack per definition.

We add an extra argument, let us call it exoticNewTarget, to [[Construct]] internal method [7], which is initially Null.  More precisely, [[Construct]] now takes arguments (a List of any, Object, Object) where the third argument is a newly created exotic object.

Add a new environmental records field, [[ExoticNewTarget]], which is either an Object or undefined. If this Environment Record was created by the [[Construct]] internal method, [[ExoticNewTarget]] is the value of the [[ExoticNewTarget]] exoticNewTarget parameter. Otherwise, its value is undefined.

Add a new abstract operation GetExoticNewTarget(), which performs the following steps:
1. Let envRec be GetThisEnvironment().
2. Assert: envRec has a [[ExoticNewTarget]] field.
3. Return envRec.[[ExoticNewTarget]].

We also modify step 7 of runtime semantics of SuperCall from:
7. Let result be Construct(func, argList, newTarget).
7. Let result be Construct(func, argList, newTarget, GetExoticNewTarget()).

With these simple changes, we can simplify the algorithm as follows and it would ALWYAS construct the right element:

== Custom Element Construction Algorithm ==

 NAME, the custom element name.
 DOCUMENT, the owner document for new custom element.
 EXOTIC-TARGET, the target Element to be constructed / upgraded.
 ELEMENT, new custom element instance.
 ERROR, could be either "None", "NotFound", "InvalidStateError", or an ECMAScript exception.

1. Let ERROR be "None".
2. Let REGISTRY be the (custom element) registry of DOCUMENT.
3. If DOCUMENT is an HTML document, let NAME be converted to ASCII lowercase.
4. Let DEFINITION be the element definition of with the local name, NAME, in REGISTRY.
5. If there is no matching definition, set ERROR to "NotFound" and terminate these steps.
7. Invoke the [[Construct]] internal method [3] on the custom element interface, INTERFACE, of DEFINITION
   with (INTERFACE, an empty list, INTERFACE, EXOTIC-TARGET)
9. If the [[Construct]] invocation resulted in an exception, set ERROR to the raised exception, and terminate these steps.
10. Otherwise, let ELEMENT be the result of the invocation.
11. If ELEMENT is not an instance of INTERFACE with local name, NAME, set ERROR to "InvalidStateError", and terminate these steps.

== HTMLElement constructor ==

1. Let TARGET be GetNewTarget(). [4]
2. Let EXOTIC-TARGET be GetExoticNewTarget().
3. If EXOTIC-TARGET is not undefined, return EXOTIC-TARGET and terminate these steps.
4. Let DOCUMENT be the associated document of the global object (the result of GetGlobalObject() [5]).
5. Let REGISTRY be the (custom element) registry of DOCUMENT.
6. Let DEFINITION be the element definition with the element interface, TARGET, in REGISTRY.
7. If there is no matching definition, throw TypeError and terminate these steps.
8. Let NAME be the local name of DEFINITION.
9. Return a new element that implements HTMLElement, with no attributes, namespace set to the HTML namespace,
   local name set to NAME, and node document set to DOCUMENT.


Received on Tuesday, 23 February 2016 07:07:31 UTC