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

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

Issue 6246078: Add an optional set_hook argument to defineProperty. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/resources
Patch Set: Rename to setHook; pass value to hook. Created 9 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 | chrome/browser/resources/shared/js/cr_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/shared/js/cr.js
diff --git a/chrome/browser/resources/shared/js/cr.js b/chrome/browser/resources/shared/js/cr.js
index 6686269d897f1ddd7c7f396529506bdbf3e49e4b..e6d7aaebdf64f18be3bf011b0f81466e9c1300ac 100644
--- a/chrome/browser/resources/shared/js/cr.js
+++ b/chrome/browser/resources/shared/js/cr.js
@@ -170,9 +170,11 @@ const cr = (function() {
* for.
* @param {cr.PropertyKind} kind The kind of property we are getting the
* setter for.
+ * @param {function():void} opt_setHook A function to run after the property
arv (Not doing code reviews) 2011/02/04 20:13:10 This type annotation is no longer correct.
nduca 2011/02/08 18:48:52 Done.
+ * is set, but before the propertyChange event is fired.
* @return {function(*):void} The function to use as a setter.
*/
- function getSetter(name, kind) {
+ function getSetter(name, kind, opt_setHook) {
switch (kind) {
case PropertyKind.JS:
var privateName = name + '_';
@@ -180,6 +182,8 @@ const cr = (function() {
var oldValue = this[privateName];
if (value !== oldValue) {
this[privateName] = value;
+ if (opt_setHook)
+ opt_setHook.call(this, value);
dispatchPropertyChange(this, name, value, oldValue);
}
};
@@ -189,6 +193,8 @@ const cr = (function() {
var oldValue = this[name];
if (value !== oldValue) {
this.setAttribute(name, value);
+ if (opt_setHook)
+ opt_setHook.call(this, value);
dispatchPropertyChange(this, name, value, oldValue);
}
};
@@ -201,6 +207,8 @@ const cr = (function() {
this.setAttribute(name, name);
else
this.removeAttribute(name);
+ if (opt_setHook)
+ opt_setHook.call(this, value);
dispatchPropertyChange(this, name, value, oldValue);
}
};
@@ -213,9 +221,11 @@ const cr = (function() {
* @param {!Object} The object to define the property for.
* @param {string} The name of the property.
* @param {cr.PropertyKind=} opt_kind What kind of underlying storage to use.
- * @param {*} opt_defaultValue The default value.
+ * @param {*} opt_default The default value.
+ * @param {function(newVal):void} opt_setHook A function to run after the
arv (Not doing code reviews) 2011/02/04 20:13:10 newVal is not a type. You probebly meant function
nduca 2011/02/08 18:48:52 Done.
+ * property is set, but before the propertyChange event is fired.
*/
- function defineProperty(obj, name, opt_kind, opt_default) {
+ function defineProperty(obj, name, opt_kind, opt_default, opt_setHook) {
if (typeof obj == 'function')
obj = obj.prototype;
@@ -231,7 +241,9 @@ const cr = (function() {
}
if (!obj.__lookupSetter__(name)) {
- obj.__defineSetter__(name, getSetter(name, kind));
+ if(opt_kind == PropertyKind.BOOL_ATTR && opt_default)
arv (Not doing code reviews) 2011/02/04 20:13:10 whitespace after if
nduca 2011/02/08 18:48:52 Done.
+ throw Error('opt_default for BOOl_ATTR properties must be false');
arv (Not doing code reviews) 2011/02/04 20:13:10 I dissagre. I think it is completely legit to do t
nduca 2011/02/08 18:48:52 I think you misread the check here... This is a bu
+ obj.__defineSetter__(name, getSetter(name, kind, opt_setHook));
}
}
« no previous file with comments | « no previous file | chrome/browser/resources/shared/js/cr_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698