From 99be7bd226cee9e2b63017d45035d25fef7546c4 Mon Sep 17 00:00:00 2001 From: Hixie Date: Mon, 9 Feb 2015 16:10:41 -0800 Subject: [PATCH] Specs: Element registration in the Dart world Review URL: https://codereview.chromium.org/908983002 --- specs/dom.md | 21 +++++++-- specs/modules.md | 117 +++++++++++++++++------------------------------ specs/script.md | 75 ++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 80 deletions(-) diff --git a/specs/dom.md b/specs/dom.md index 34a5a159dc3..02070e0c4fd 100644 --- a/specs/dom.md +++ b/specs/dom.md @@ -79,16 +79,26 @@ class Attr { // @tagname annotation for registering elements // only useful when placed on classes that inherit from Element -class tagname { - const tagname(this.value); - @nonnull final String value; +class tagname extends AutomaticMetadata { + const tagname(this.name); + @nonnull final String name; + void init(DeclarationMirror target, Module module) { + assert(target is ClassMirror); + if (!target.isSubclassOf(reflectClass(Element))) + throw Error('@tagname can only be used on descendants of Element'); + module.registerElement(name, (target as ClassMirror).reflectedType); + } } abstract class FindRoot { } abstract class Element extends ParentNode with ChildNode implements FindRoot { - Element({Map attributes: null, - List nodes: null}); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants + external Element({Map attributes: null, + List nodes: null, + Module hostModule: null}); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants + // initialises the internal attributes table + // appends the given child nodes + // if this.needsShadow, creates a shadow tree @nonnull String get tagName { // O(N) in number of annotations on the class // throws a StateError if the class doesn't have an @tagname annotation @@ -104,6 +114,7 @@ abstract class Element extends ParentNode with ChildNode implements FindRoot { // Returns a new Array and new Attr instances every time. @nonnull external List getAttributes(); // O(N) in number of attributes + get bool needsShadow => false; // O(1) external ShadowRoot get shadowRoot; // O(1) // returns the shadow root // TODO(ianh): Should this be mutable? It would help explain how it gets set... diff --git a/specs/modules.md b/specs/modules.md index 691c761fa38..f20e0c7d70e 100644 --- a/specs/modules.md +++ b/specs/modules.md @@ -55,98 +55,65 @@ that were declared by that module except the aforementioned element tree library. At the end of the ``