Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/README.md

Issue 1952893003: Implement custom element construction and some 'define' checks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not expose CustomElementsRegistry to isolated worlds. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Custom Elements
2
3 Custom elements let authors create their own elements, with their own
4 methods, behavior, and attribute handling. Custom elements shipped in
5 M33. We colloquially refer to that version as "v0."
6
7 Contact Dominic Cooney
8 ([dominicc@chromium.org](mailto:dominicc@chromium.org)) with
9 questions.
10
11 ## Design
12
13 ### Some Important Classes
14
15 ###### CustomElementDefinition
16
17 The definition of one ‘class’ of element; it consists of a
18 tag name, and a prototype.
19
20 ###### CustomElementsRegistry
21
22 Implements the `window.customElements` property. This maintains a list
23 of definitions, and a mapping from constructors to an index in this
24 list. The map is necessary for finding a custom element definition
25 given only a constructor.
26
27 ###### V8HTMLElement Constructor
28
29 The `HTMLElement` interface constructor. When a custom element is
30 created from JavaScript all we have to go on is the constructor (in
31 `new.target`); this uses CustomElementRegistry’s map to find
32 which definition to use.
33
34 ### Memory Management
35
36 Once defined, custom element constructors and prototypes have to be
37 kept around indefinitely because they could be created in future by
38 the parser. On the other hand, we must not leak when a window can no
39 longer run script.
40
41 The principle we follow is to only have C++ objects have weak
42 references to JavaScript objects, and have the wrapper objects keep
43 the JavaScript objects alive. Specifically, the CustomElementsRegistry
44 wrapper implements visitDOMWrapper to keep its constructor map alive;
45 this in turn references the constructor (via the map key) and the
46 prototype (via the constructor’s prototype property) in
47 JavaScript.
48
49 ## Style Guide
50
51 In comments and prose, write custom elements, not Custom Elements, to
52 match the HTML standard.
53
54 Prefix type names with CustomElement (singular). The one exception to
55 this rule is CustomElementsRegistry, which uses a plural to match the
56 name of the interface in the specification.
57
58 ## Testing
59
60 Custom elements have small C++ unit tests and medium
61 “layout” tests.
62
63 ###### C++ Unit Tests
64
65 These are in third_party/WebKit/Source/core/dom/*Test.cpp and are
66 built as part of the webkit_unit_tests target. The test names start
67 with CustomElement so you can run them with:
68
69 $ out/Debug/webkit_unit_tests --gtest_filter=CustomElement*
70
71 ###### Layout Tests
72
73 The custom element layout tests are generally in
74 third_party/WebKit/LayoutTests/custom-elements.
75
76 All custom elements layout tests use the [W3C web-platform-tests
77 harness](http://testthewebforward.org/docs/) and follow its style. The
78 W3C is not very prescriptive, so be consistent with other custom
79 elements tests.
80
81 When naming tests, use short names describing what the test is doing.
82 Avoid articles. For example, "HTMLElement constructor, invoke". When
83 writing assertion messages, start with a lowercase letter (unless the
84 word is a proper noun), use normal grammar and articles, and include
85 the word “should” to leave no doubt whate the expected
86 behavior is.
87
88 ###### Spec Tests
89
90 These will be upstreamed to the W3C, replacing [the tests for
91 registerElement](https://github.com/w3c/web-platform-tests/commits/master/custom -elements)
92 we contributed earlier. To facilitate that, follow these guidelines:
93
94 * Keep the tests together in the `spec` directory.
95 * Only test things required in a spec. The test should permit other
96 possible reasonable implementations.
97 * Avoid using Blink-specific test mechanisms. Don't use
98 `window.internals` for example.
99
100 ###### Implementation Tests
101
102 These are for testing Blink-specific details like object lifetimes,
103 crash regressions, interaction with registerElement and HTML Imports,
104 and so on.
105
106 These tests can use Blink-specific testing hooks like
107 `window.internals` and `testRunner`.
108
109 ###### Web Exposed Tests
110
111 Finally there are /TODO(dominicc): should be/ tests in
112 webexposed/custom-elements which assert that we HAVE NOT shipped
113 `window.customElements.define` yet. These tests need to be updated
114 when we ship `window.customElements.define` or remove
115 `registerElement`.
116
117 ## “V0” Deprecation
118
119 The plan is to:
120
121 1. Implement the ‘new’ kind of custom elements separately
122 from the existing implementation. We have renamed all of old
123 implementation so that the type names start with V0; it should be
124 easy to tell whether you are looking at the old or new
125 implementation.
126 1. When we ship `window.customElements.define`, add a deprecation
127 warning to `document.registerElement` directing authors to use the
128 new API.
129 1. Change the ‘web’ API to use the new kind of custom
130 elements. That API is used by extensions to implement the webview
131 tag and things like that.
132 1. When [the use counter for
133 registerElement](https://www.chromestatus.com/metrics/feature/timeline/popula rity/457)
134 drops below 0.03% of page loads, remove the old implementation. We
135 may remove it even sooner, if we have evidence that sites are using
136 feature detection correctly.
137
138 ## References
139
140 These have links to the parts of the DOM and HTML specs which define
141 custom elements:
142
143 * [WHATWG DOM Wiki: Custom Elements](https://github.com/whatwg/dom/wiki#custom-e lements)
144 * [WHATWG HTML Wiki: Custom Elements](https://github.com/whatwg/html/wiki#custom -elements)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698