When called, the register method must run these steps:
ENVIRONMENT
, the unit of related similar-origin browsing contextsDOCUMENT
, the context object of the methodNAME
, the custom element name of the element being registeredFUNCTION
, the custom element constructor function, optional
- The
FUNCTION
is mutated to have a new@@create
function that creates a new Element object.
- If
NAME
is an invalid custom element name, throw an InvalidCharacterError and stop. - Let
NAMESPACE
be HTML Namespace - Let
TYPE
beNAME
- If
FUNCTION
is null: 1. LetFUNCTION
be the result of calling FunctionAllocate withHTMLElement
as the functionPrototype and true as strict. 2. LetPROTOTYPE
be the result of calling ObjectCreate withHTMLElement.prototype
as the proto. 3. Call DefinePropertyOrThrow(PROTOTYPE
, "constructor", PropertyDescriptor{[[Value]]:FUNCTION
, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false}). 4. Call DefinePropertyOrThrow(FUNCTION
, "prototype", PropertyDescriptor{[[Value]]:PROTOTYPE
, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false}). - Otherwise:
1. If
FUNCTION
andDOCUMENT
are from different browsing contexts, throw aNotSupportedError
and stop. 2. LetINTERFACE
beFUNCTION
's interface 3. IfINTERFACE
inherits fromSVGElement
, setNAMESPACE
to SVG Namespace 4. Otherwise, ifINTERFACE
does not inherit fromHTMLElement
, throw aNamespaceError
and stop. 5. LetBASE
beINTERFACE
's inherited interface that is nearest toBASE
in the prototype chain and that is an element interface 6. IfBASE
is notHTMLElement
orSVGElement
, letNAME
be the local name, associated withBASE
element interface 7. LetPROTOTYPE
be the result of Get(FUNCTION
, "prototype"). - If
DOCUMENT
is an HTML document, convert bothNAME
andTYPE
to lowercase - If there already exists a definition with the same
TYPE
, throw aNotSupportedError
and stop. - Let
LIFECYCLE
be lifecycle callbacks - Transfer callback named
ready
toLIFECYCLE
from property namedreadyCallback
onPROTOTYPE
- Transfer callback named
inserted
toLIFECYCLE
from property namedinsertedCallback
onPROTOTYPE
- Transfer callback named
removed
toLIFECYCLE
from property namedremovedCallback
onPROTOTYPE
- Let
DEFINITION
be the set of (TYPE
,NAME
,NAMESPACE
,FUNCTION
,LIFECYCLE
) - Register the
DEFINITION
withDOCUMENT
- Run element upgrade algorithm with
DOCUMENT
's browsing context andDEFINITION
as arguments - Invoke lifecycle callbacks with
ENVIRONMENT
as argument - Return result of running custom element constructor generation algorithm with
FUNCTION
as argument.
FUNCTION
, the custom element constructor function.
- The
FUNCTION
is mutated to have a new@@create
function that creates a new Element object.
- If
FUNCTION
is already an interface constructor object for any interface object throw aTypeError
and stop. - Let
DEFINITION
be an element definition that hasFUNCTION
as custom element prototype - Let
CREATE
be a function which when called executes the following steps: 1. LetTYPE
be the custom element name inDEFINITION
2. LetNAME
be the local name inDEFINITION
3. LetNAMESPACE
be the namespace inDEFINITION
4. LetELEMENT
be the context object 5. SetELEMENT
's local name toNAME
, namespace to theNAMESPACE
, and node document to the document with whichDEFINITION
is registered 6. IfTYPE
is not the same asNAME
, set the value ofELEMENT
's is attribute toTYPE
7. Run the element initialization algorithm withELEMENT
as argument 8. ReturnELEMENT
. - Call DefinePropertyOrThrow(
FUNCTION
,@@create
, PropertyDescriptor{[[Value]]:CREATE
, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false}).