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

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

Issue 858453002: Require a type for SkyElement attributes. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Handle null attr. 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/sky-element.sky
diff --git a/sky/framework/sky-element/sky-element.sky b/sky/framework/sky-element/sky-element.sky
index d1dfcbb9b1ff26d1b9b06d2418f2bf11e4558318..17b5a4e238bf556049ca64ab9789b85289cef368 100644
--- a/sky/framework/sky-element/sky-element.sky
+++ b/sky/framework/sky-element/sky-element.sky
@@ -23,13 +23,31 @@ var attributeConverters = {
function parseAttributeSpec(spec) {
var attributes = new Map();
- var attributeTokens = (spec || '').split(',');
+
+ if (!spec)
+ return attributes;
+
+ var attributeTokens = spec.split(',');
for (var i = 0; i < attributeTokens.length; ++i) {
var parts = attributeTokens[i].split(':');
+
+ if (parts.length != 2) {
+ console.error('Invalid attribute spec "' + spec + '", attributes must' +
+ ' be {name}:{type}, where type is one of boolean, number or' +
+ ' string.');
+ continue;
+ }
+
var name = parts[0].trim();
- var type = (parts[1] || '').trim();
- var converter = attributeConverters[type] || attributeConverters.string;
+ var type = parts[1].trim();
+ var converter = attributeConverters[type];
+
+ if (!converter) {
+ console.error('Invalid attribute spec "' + spec + '", type must be one'
+ + ' of boolean, number or string.');
+ continue;
+ }
attributes.set(name, converter);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698