Author: scottbw
Date: Wed Jan 20 18:47:20 2010
New Revision: 901325

URL: http://svn.apache.org/viewvc?rev=901325&view=rev
Log:
Implemented exception handling using window.DOMException as per W3C Widget 
Interface spec

Modified:
    incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js

Modified: incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js?rev=901325&r1=901324&r2=901325&view=diff
==============================================================================
--- incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js (original)
+++ incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js Wed Jan 20 
18:47:20 2010
@@ -50,7 +50,10 @@
         
            var existing = this.prefs[key];
         if (existing){
-            if (existing["readOnly"] == true) throw 
"NO_MODIFICATION_ALLOWED_ERR";
+            if (existing["readOnly"] == true){
+               window.DOMException.code = 
DOMException.NO_MODIFICATION_ALLOWED_ERR;
+               throw (window.DOMException);
+            }
         } else {
                // Setup prototype methods
             eval("Widget.preferences.__defineGetter__('"+key+"', 
function(){return Widget.preferences.getItem('"+key+"')})");
@@ -62,13 +65,25 @@
                this.calcLength();
        }
        this.removeItem = function(key){
-        this.prefs[key] = null;
-               Widget.setPreferenceForKey(key,null);
-               this.calcLength();
+               var existing = (this.prefs[key]);
+        if (existing){
+            if (existing["readOnly"] == true){
+               window.DOMException.code = 
DOMException.NO_MODIFICATION_ALLOWED_ERR;
+               throw (window.DOMException);
+            } else {
+               this.prefs[key] = null;
+               Widget.setPreferenceForKey(key,null);
+               this.calcLength();
+            }
+        }
        }
        this.clear = function(){
                for (key in this.prefs){
-                       this.removeItem(key);
+                       try{
+                               this.removeItem(key);
+                       } catch (e){
+                               // swallow errors, as this method must never 
throw them according to spec.
+                       }
                }
        }
 }
@@ -196,6 +211,10 @@
                
        proxify : function(url){
                        return this.proxyUrl + "?instanceid_key=" + 
this.instanceid_key + "&url=" + url;
+       },
+       
+       toString: function(){
+               return "[object Widget]";
        }
        
 }


Reply via email to