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

Unified Diff: sky/framework/sky-element/element-registry.sky

Issue 807243003: Be more strict about attributes in sky-binder. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix sky-box Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/sky-box/sky-box.sky ('k') | sky/framework/sky-element/sky-binder.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/element-registry.sky
diff --git a/sky/framework/sky-element/element-registry.sky b/sky/framework/sky-element/element-registry.sky
index 8af18534585bdf73d9fc6d40e9650b3b9c960ef3..a38f22b37fe358a666efc46a89aa64305689d0a1 100644
--- a/sky/framework/sky-element/element-registry.sky
+++ b/sky/framework/sky-element/element-registry.sky
@@ -7,33 +7,15 @@
<script>
// TODO(esprehn): It would be nice if these were exposed by the platform so
// the framework didn't need to hard code a list.
-var defaultAttributesNames = new Set([
- 'accesskey',
- 'alt',
- 'as',
- 'async',
+var globalAttributesNames = new Set([
'class',
'contenteditable',
- 'crossorigin',
'dir',
- 'height',
- 'href',
'id',
- 'is',
'lang',
- 'media',
- 'name',
- 'rel',
- 'select',
- 'sizes',
'spellcheck',
- 'src',
- 'srcset',
- 'style',
'tabindex',
- 'title',
- 'type',
- 'width',
+ 'style',
]);
var attributeConverters = {
@@ -76,7 +58,7 @@ class ElementRegistration {
allowsAttribute(name) {
if (name.startsWith('data-'))
return true;
- if (defaultAttributesNames.has(name))
+ if (globalAttributesNames.has(name))
return true;
if (this.attributes.has(name))
return true;
@@ -119,10 +101,13 @@ class ElementRegistration {
var registrations = new Map();
-function registerElement(tagName) {
+function registerElement(tagName, attributes) {
if (registrations.has(tagName))
throw new Error('tagName "' + tagName + '" registered twice.');
var registration = new ElementRegistration(tagName);
+ for (var name in attributes) {
+ registration.defineAttribute(name, attributes[name]);
+ }
registrations.set(tagName, registration);
return registration;
}
@@ -135,11 +120,43 @@ function checkAttribute(tagName, attrName) {
var registration = getRegistration(tagName);
if (!registration)
- return defaultAttributesNames.has(attrName);
+ return globalAttributesNames.has(attrName);
return registration.allowsAttribute(attrName);
}
+registerElement('img', {
+ 'width': 'number',
+ 'height': 'number',
+ // TODO(esprehn): Sky probably doesn't want the crossorign attr.
+ 'crossorigin': 'string',
+ 'src': 'string',
+});
+
+registerElement('import', {
+ 'as': 'string',
+ 'src': 'string',
+ 'async': 'boolean',
+});
+
+registerElement('a', {
+ 'href': 'string',
+ 'async': 'boolean',
+});
+
+registerElement('content', {
+ 'select': 'string',
+});
+
+registerElement('style', {
+ 'media': 'string',
+});
+
+registerElement('template', {
+ 'if': 'string',
+ 'repeat': 'string',
+});
+
module.exports = {
registerElement: registerElement,
getRegistration: getRegistration,
« no previous file with comments | « sky/framework/sky-box/sky-box.sky ('k') | sky/framework/sky-element/sky-binder.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698