You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/08/11 15:30:46 UTC

svn commit: r984400 - in /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl: _util/ core/ xhrCore/

Author: werpu
Date: Wed Aug 11 13:30:45 2010
New Revision: 984400

URL: http://svn.apache.org/viewvc?rev=984400&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2872

Modified:
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ListenerQueue.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_BaseRequest.js
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js Wed Aug 11 13:30:45 2010
@@ -264,6 +264,7 @@ myfaces._impl.core._Runtime.singletonExt
             //note this is triggered only in htmlunit no other browser
             //so we are save here
             evalNodes = dummyPlaceHolder.childNodes[0].childNodes;
+            delete dummyPlaceHolder;
         }
 
         //ie throws also an error on length requests
@@ -290,6 +291,7 @@ myfaces._impl.core._Runtime.singletonExt
      */
     replaceElement: function(item, evalNode) {
         evalNode = item.parentNode.replaceChild(evalNode, item);
+        delete item;
         return evalNode;
     },
 
@@ -313,6 +315,7 @@ myfaces._impl.core._Runtime.singletonExt
         for (var cnt = 0; cnt < resultArr.length; cnt++) {
             if (cnt == 0) {
                 parentNode.replaceChild(resultArr[cnt], item);
+                delete item;
             } else {
                 if (sibling) {
                     parentNode.insertBefore(resultArr[cnt], sibling);
@@ -796,8 +799,9 @@ myfaces._impl.core._Runtime.singletonExt
 
         if (attr === "class") {
             node.setAttribute("className", val);
+        } else if (attr === "name") {
+            node[attr] = val;
         } else if (attr === "for") {
-
             node.setAttribute("htmlFor", val);
         } else if (attr === "style") {
             //We have to split the styles here and assign them one by one

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js Wed Aug 11 13:30:45 2010
@@ -354,10 +354,10 @@ myfaces._impl.core._Runtime.singletonDel
     arrToMap: function(arr, offset) {
         var ret = new Array(arr.length);
         var len = arr.length;
-        offset = (offset)? offset: 0;
+        offset = (offset) ? offset : 0;
 
         for (var cnt = 0; cnt < len; cnt++) {
-            ret[arr[cnt]] = cnt+offset;
+            ret[arr[cnt]] = cnt + offset;
         }
 
         return ret;
@@ -424,24 +424,28 @@ myfaces._impl.core._Runtime.singletonDel
      * @param scope (optional) the scope to apply the closure to
      */
     arrForEach: function(arr, func /*startPos, scope*/) {
-        var startPos = Number(arguments[2]) || 0;
-        var thisObj = arguments[3];
+        try {
+            var startPos = Number(arguments[2]) || 0;
+            var thisObj = arguments[3];
 
-        //check for an existing foreach mapping on array prototypes
-        if (Array.prototype.forEach) {
-            (startPos) ? arr.slice(startPos).forEach(func, thisObj) : arr.forEach(func, thisObj);
-        } else {
-            startPos = (startPos < 0) ? Math.ceil(startPos) : Math.floor(startPos);
-            if (typeof func != "function") {
-                throw new TypeError();
-            }
-            for (var cnt = 0; cnt < arr.length; cnt++) {
-                if (thisObj) {
-                    func.call(thisObj, arr[cnt], cnt, arr);
-                } else {
-                    func(arr[cnt], cnt, arr);
+            //check for an existing foreach mapping on array prototypes
+            if (Array.prototype.forEach) {
+                (startPos) ? arr.slice(startPos).forEach(func, thisObj) : arr.forEach(func, thisObj);
+            } else {
+                startPos = (startPos < 0) ? Math.ceil(startPos) : Math.floor(startPos);
+                if (typeof func != "function") {
+                    throw new TypeError();
+                }
+                for (var cnt = 0; cnt < arr.length; cnt++) {
+                    if (thisObj) {
+                        func.call(thisObj, arr[cnt], cnt, arr);
+                    } else {
+                        func(arr[cnt], cnt, arr);
+                    }
                 }
             }
+        } finally {
+            func = null;
         }
     }
     ,
@@ -460,28 +464,32 @@ myfaces._impl.core._Runtime.singletonDel
      *
      */
     arrFilter: function(arr, func /*startPos, scope*/) {
-        var startPos = Number(arguments[2]) || 0;
-        var thisObj = arguments[3];
+        try {
+            var startPos = Number(arguments[2]) || 0;
+            var thisObj = arguments[3];
 
-        //check for an existing foreach mapping on array prototypes
-        if (Array.prototype.filter) {
-            return ((startPos) ? arr.slice(startPos).filter(func, thisObj) : arr.filter(func, thisObj));
-        } else {
-            if (typeof func != "function") {
-                throw new TypeError();
-            }
-            var ret = [];
-            startPos = (startPos < 0) ? Math.ceil(startPos) : Math.floor(startPos);
+            //check for an existing foreach mapping on array prototypes
+            if (Array.prototype.filter) {
+                return ((startPos) ? arr.slice(startPos).filter(func, thisObj) : arr.filter(func, thisObj));
+            } else {
+                if (typeof func != "function") {
+                    throw new TypeError();
+                }
+                var ret = [];
+                startPos = (startPos < 0) ? Math.ceil(startPos) : Math.floor(startPos);
 
-            for (var cnt = startPos; cnt < arr.length; cnt++) {
-                if (thisObj) {
-                    var elem = arr[cnt];
-                    if (func.call(thisObj, elem, cnt, arr)) ret.push(elem);
-                } else {
-                    var elem = arr[cnt];
-                    if (func(arr[cnt], cnt, arr)) ret.push(elem);
+                for (var cnt = startPos; cnt < arr.length; cnt++) {
+                    if (thisObj) {
+                        var elem = arr[cnt];
+                        if (func.call(thisObj, elem, cnt, arr)) ret.push(elem);
+                    } else {
+                        var elem = arr[cnt];
+                        if (func(arr[cnt], cnt, arr)) ret.push(elem);
+                    }
                 }
             }
+        } finally {
+            func = null;
         }
     }
     ,

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ListenerQueue.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ListenerQueue.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ListenerQueue.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_ListenerQueue.js Wed Aug 11 13:30:45 2010
@@ -13,7 +13,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
-*/
+ */
 /*
  * a classical listener queue pattern
  */
@@ -77,6 +77,10 @@ myfaces._impl.core._Runtime.extendClass(
         var broadCastFunc = function(element) {
             element.apply(null, _args);
         };
-        this.each(broadCastFunc);
+        try {
+            this.each(broadCastFunc);
+        } finally {
+            broadCastFunc = null;
+        }
     }
 });
\ No newline at end of file

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Queue.js Wed Aug 11 13:30:45 2010
@@ -59,8 +59,9 @@ myfaces._impl.core._Runtime.extendClass(
     },
 
     _readjust: function() {
-        while (null != this._size && 'undefined' != typeof this._size &&
-                this._size > -1 && this.length() > this._size) {
+        var size = this._size;
+        while (null != size && 'undefined' != typeof size &&
+                size > -1 && this.length() > size) {
             this.dequeue();
         }
     },
@@ -84,17 +85,20 @@ myfaces._impl.core._Runtime.extendClass(
         var element = null;
 
         // check whether the queue is empty
-        if (this._q.length) {
+        var qLen = this._q.length;
+        var queue = this._q;
+        
+        if (qLen) {
 
             // fetch the oldest element in the queue
-            element = this._q[this._space];
+            element = queue[this._space];
 
             // update the amount of space and check whether a shift should occur
             //added here a max limit of 30
-            if (++this._space * 2 >= this._q.length) {
+            if ((++this._space) << 1 >= qLen) {
 
                 // set the queue equal to the non-empty portion of the queue
-                this._q = this._q.slice(this._space);
+                this._q = queue.slice(this._space);
 
                 // reset the amount of space at the front of the queue
                 this._space = 0;

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/_Runtime.js Wed Aug 11 13:30:45 2010
@@ -600,12 +600,21 @@ if (!myfaces._impl.core._Runtime) {
                 newCls = _reserveClsNms(newCls, protoFuncs);
                 if (!newCls) return null;
             }
-            if (extendCls._mfProto) {
-                extendCls = extendCls._mfProto;
+            //if the type information is known we use that one
+            //with this info we can inherit from objects also
+            //instead of only from classes
+            //sort of like   this.extendClass(newCls, extendObj._mfClazz...
+            if (extendCls._mfClazz) {
+                extendCls = extendCls._mfClazz;
             }
 
             if ('undefined' != typeof extendCls && null != extendCls) {
-                newCls.prototype = new extendCls;
+                //first we have to get rid of the constructor calling problem
+                //problem
+                var tmpFunc = function() {};
+                tmpFunc.prototype = extendCls.prototype;
+                newCls.prototype = new tmpFunc();
+                tmpFunc = null;
                 newCls.prototype.constructor = newCls;
                 newCls.prototype._parentCls = extendCls.prototype;
 
@@ -615,8 +624,12 @@ if (!myfaces._impl.core._Runtime) {
                     //we store the descension level of each method under a mapped
                     //name to avoid name clashes
                     //to avoid name clashes with internal methods of array
+                    //if we don't do this we trap the callSuper in an endless
+                    //loop after descending one level
                     var _mappedName = ["_",methodName,"_mf_r"].join("");
                     this._mfClsDescLvl = this._mfClsDescLvl || new Array();
+                    var descLevel = this._mfClsDescLvl;
+
                     //we have to detect the descension level
                     //we now check if we are in a super descension for the current method already
                     //if not we are on this level
@@ -626,13 +639,15 @@ if (!myfaces._impl.core._Runtime) {
 
                     try {
                         //we now store the level position as new descension level for callSuper
-                        this._mfClsDescLvl[_mappedName] = _parentCls;
+                        descLevel[_mappedName] = _parentCls;
                         //and call the code on this
                         _parentCls[methodName].apply(this, passThrough);
                     } finally {
-                        this._mfClsDescLvl[_mappedName] = _oldDescLevel;
+                        descLevel[_mappedName] = _oldDescLevel;
                     }
                 };
+                //reference to its own type
+                newCls.prototype._mfClazz = newCls;
             }
 
             //we now map the function map in
@@ -681,11 +696,11 @@ if (!myfaces._impl.core._Runtime) {
                 return;
             }
 
-            var clazz = ooFunc(newCls + "._mfProto", delegateObj, protoFuncs, nmsFuncs);
+            var clazz = ooFunc(newCls + "._mfClazz", delegateObj, protoFuncs, nmsFuncs);
             if (clazz != null) {
                 _this.applyToGlobalNamespace(newCls, new clazz());
             }
-            _this.fetchNamespace(newCls)["_mfProto"] = clazz;
+            _this.fetchNamespace(newCls)["_mfClazz"] = clazz;
         };
 
         //internal class namespace reservation depending on the type (string or function)

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js Wed Aug 11 13:30:45 2010
@@ -188,6 +188,9 @@ myfaces._impl.core._Runtime.extendClass(
                 alert(e.toString());
         } finally {
             //final cleanup to terminate everything
+            if(this._xhr.readyState == this._READY_STATE_DONE) {
+                this._callSuper("_finalize");
+            }
         }
     },
 

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Wed Aug 11 13:30:45 2010
@@ -172,15 +172,17 @@ myfaces._impl.core._Runtime.extendClass(
         if (null != viewStateField) {
             this._Dom.setAttribute(viewStateField, "value", this.appliedViewState);
         } else {
-            var element = document.createElement("input");
-            this._Dom.setAttribute(element, "type", "hidden");
-            this._Dom.setAttribute(element, "name", this.P_VIEWSTATE);
-            elem.appendChild(element);
-
-            this._Dom.setAttribute(element, "value", this.appliedViewState);
+            this._appendViewStateElem(elem, this.appliedViewState);
         }
     },
 
+    _appendViewStateElem: function(parent, viewStateVal) {
+        var element = document.createElement("div");
+        element.innerHTML = "<input type='hidden' name='"+this.P_VIEWSTATE+"' value='"+viewStateVal+"' />";
+        //now we go to proper dom handling after having to deal with another ie screwup
+        parent.appendChild(element.childNodes[0]);
+    },
+
     _setVSTInnerForms: function(elem) {
         var replacedForms = this._Dom.findByTagName(elem, "form", false);
         this._Lang.arrForEach(replacedForms, this._setVSTInnerForm, 0, this);
@@ -197,12 +199,7 @@ myfaces._impl.core._Runtime.extendClass(
         //if the viewstate field is present we can rely on the viewstate being
         //at the current state no further updates have to be done
         if (null == viewStateField) {
-            var element = document.createElement("input");
-            this._Dom.setAttribute(element, "type", "hidden");
-            this._Dom.setAttribute(element, "name", this.P_VIEWSTATE);
-            appliedReplacedFrom.appendChild(element);
-
-            this._Dom.setAttribute(element, "value", this.appliedViewState);
+            this._appendViewStateElem(appliedReplacedFrom, this.appliedViewState);
         }  //else form already has a delivered viewstate field
     },
 
@@ -299,7 +296,12 @@ myfaces._impl.core._Runtime.extendClass(
             // The source form has to be pulled out of the CURRENT document first because the context object
             // may refer to an invalid document if an update of the entire body has occurred before this point.
             var viewStateValue = node.firstChild.nodeValue;
-            var sourceForm = this._Dom.fuzzyFormDetection(context.source);
+            var elementId = context.source.id || context.source.name;
+            if ((elementId == null || elementId == '') && context.source.name) {
+                elementId = context.source.name;
+            }
+
+            var sourceForm = this._Dom.fuzzyFormDetection(elementId);
 
 
             //the source form could be determined absolutely by either the form, the identifier of the node, or the name
@@ -313,30 +315,29 @@ myfaces._impl.core._Runtime.extendClass(
             /*we check for an element and include a namesearch, but only within the bounds of the committing form*/
             //we now should have the form, if not the viewstate fixup code at the end of the list
             //will also be able to recover in almost all instances
+            this.appliedViewState = viewStateValue;
+
             if (null != sourceForm) {
                 var element = null;
                 try {
                     element = this._Dom.findFormElement(sourceForm, this.P_VIEWSTATE);
+                    this._Dom.setAttribute(element, "value", viewStateValue);
                 } catch (e) {
                     //in case of an error here we try an early recovery but throw an error to our error handler
                     this._onException(request, context, "_AjaxResponse", "processUpdate('javax.faces.ViewState')", e);
                 }
 
                 if (!element) {//no element found we have to append a hidden field
-                    element = document.createElement("input");
-                    this._Dom.setAttribute(element, "type", "hidden");
-                    this._Dom.setAttribute(element, "name", this.P_VIEWSTATE);
-                    sourceForm.appendChild(element);
+                    this._appendViewStateElem(sourceForm, viewStateValue);
                 }
                 //viewState cannot have split cdata blocks so we can skip the costlier operation
 
-                this._Dom.setAttribute(element, "value", viewStateValue);
             }
             //note due to a missing spec we have to apply the viewstate as well
             //to any form which might be rerendered within the render cycle
             //hence we store the viewstate element for later refererence
             //to fix up all elements effected by the cycle
-            this.appliedViewState = viewStateValue;
+
         }
         else
         {

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_BaseRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_BaseRequest.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_BaseRequest.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_BaseRequest.js Wed Aug 11 13:30:45 2010
@@ -27,6 +27,7 @@ myfaces._impl.core._Runtime.extendClass(
 
     _Dom: myfaces._impl._util._Dom,
     _Lang: myfaces._impl._util._Lang,
+    _RT: myfaces._impl.core._Runtime,
 
     _contentType: "application/x-www-form-urlencoded",
     _source: null,
@@ -78,6 +79,36 @@ myfaces._impl.core._Runtime.extendClass(
 
     _VAL_AJAX: "partial/ajax",
 
+
+    /**
+     * ie6 cleanup
+     */
+    _finalize: function() {
+        if(!this._RT.browser.isIE) {
+            //no ie, no broken garbage collector
+            return;
+        }
+        var resultArr = [];
+        for(var key in this) {
+            if(key != "_finalize" && key != "callback" && key.indexOf("_") == 0) {
+                resultArr.push(key);
+            }
+        }
+        //ie has a problem with its gc it cannot cleanup
+        //circular references between javascript and com
+        //to the worse every xhr object is a com object
+        //and some but not all inpucd Tcd cdt elements as well
+        //i cannot fix all mem leaks but at least I can
+        //reduce them , I cannot help with event handlers set
+        //on dom elements replaced, but ie7 gcs them at least
+        //during the window unload phase
+        for(var cnt = 0; cnt < resultArr.length; cnt++) {
+            if(this[resultArr[cnt]])
+            delete this[resultArr[cnt]];
+        }
+
+    },
+
     //abstract methods which have to be implemented
     //since we do not have abstract methods we simulate them
     //by using empty ones

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js?rev=984400&r1=984399&r2=984400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js (original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_Transports.js Wed Aug 11 13:30:45 2010
@@ -325,6 +325,8 @@ myfaces._impl.core._Runtime.extendClass(
             this._Impl.sendEvent(request, context, this._Impl.SUCCESS);
         } finally {
             this._q.processQueue();
+            //ie6 helper cleanup
+            delete context.source;
         }
     },
 
@@ -357,6 +359,9 @@ myfaces._impl.core._Runtime.extendClass(
                         this._Impl.HTTPERROR, errorText);
             } finally {
                 this._q.processQueue();
+                //ie6 helper cleanup
+                delete context.source;
+                
             }
         }
         //_onError