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

Unified Diff: chrome/browser/resources/shared/js/load_time_data.js

Issue 10141005: switch ntp to jstemplate v2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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
Index: chrome/browser/resources/shared/js/load_time_data.js
diff --git a/chrome/browser/resources/shared/js/load_time_data.js b/chrome/browser/resources/shared/js/load_time_data.js
index 77aa490e7cfd3e414d7aa08bc836a912767d6ebd..66a83f44ead58da0f1038dfb98db9ea5a1b85077 100644
--- a/chrome/browser/resources/shared/js/load_time_data.js
+++ b/chrome/browser/resources/shared/js/load_time_data.js
@@ -29,6 +29,13 @@ var loadTimeData;
},
/**
+ * @return {boolean} True if |id| is a key in the dictionary.
+ */
+ valueExists: function(id) {
+ return id in this.data_;
+ },
+
+ /**
* Fetches a value, asserting that it exists.
* @param {string} id The key that identifies the desired value.
* @return {*} The corresponding value.
@@ -47,8 +54,30 @@ var loadTimeData;
*/
getString: function(id) {
var value = this.getValue(id);
- assert(typeof value == 'string', '[' + value + '] (' + id +
- ') is not a string');
+ assertIsType(id, value, 'string');
+ return value;
+ },
+
+ /**
+ * As above, but also makes sure that the value is a boolean.
+ * @param {string} id The key that identifies the desired boolean.
+ * @return {boolean} The corresponding boolean value.
+ */
+ getBoolean: function(id) {
+ var value = this.getValue(id);
+ assertIsType(id, value, 'boolean');
+ return value;
+ },
+
+ /**
+ * As above, but also makes sure that the value is an integer.
+ * @param {string} id The key that identifies the desired number.
+ * @return {number} The corresponding number value.
+ */
+ getInteger: function(id) {
+ var value = this.getValue(id);
+ assertIsType(id, value, 'number');
+ assert(value == Math.floor(value), 'Number isn\'t integer: ' + value);
return value;
},
};
@@ -64,6 +93,17 @@ var loadTimeData;
}
}
+ /**
+ * Asserts that the given value has the given type.
+ * @param {string} id The id of the value (only used for error message).
+ * @param {*} value The value to check the type on.
+ * @param {string} type The type we expect |value| to be.
+ */
+ function assertIsType(id, value, type) {
+ assert(typeof value == type, '[' + value + '] (' + id +
+ ') is not a ' + type);
+ }
+
assert(!loadTimeData, 'should only include this file once');
loadTimeData = new LoadTimeData;
})();
« no previous file with comments | « chrome/browser/resources/ntp4/suggestions_page.js ('k') | chrome/browser/ui/webui/chrome_web_ui_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698