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/07/08 16:40:29 UTC
svn commit: r961787 - in
/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl:
_util/_Dom.js core/_Runtime.js
Author: werpu
Date: Thu Jul 8 14:40:28 2010
New Revision: 961787
URL: http://svn.apache.org/viewvc?rev=961787&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2797
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/core/_Runtime.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=961787&r1=961786&r2=961787&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 Thu Jul 8 14:40:28 2010
@@ -67,6 +67,7 @@ myfaces._impl.core._Runtime.singletonExt
* @param {|Node|} item
*/
runScripts: function(item, xmlData) {
+ var finalScripts = [];
var execScrpt = this._Lang.hitch(this, function(item) {
if (item.tagName && this._Lang.equalsIgnoreCase(item.tagName, "script")) {
var src = item.getAttribute('src');
@@ -78,6 +79,12 @@ myfaces._impl.core._Runtime.singletonExt
//due to changing the and order instead of relying on left to right
if ((src.indexOf("ln=scripts") == -1 && src.indexOf("ln=javax.faces") == -1) || (src.indexOf("/jsf.js") == -1
&& src.indexOf("/jsf-uncompressed.js") == -1))
+ if(finalScripts.length) {
+ //script source means we have to eval the existing
+ //scripts before running the include
+ myfaces._impl.core._Runtime.globalEval(finalScripts.join("\n"));
+ finalScripts = [];
+ }
myfaces._impl.core._Runtime.loadScriptEval(src, item.getAttribute('type'), false, "UTF-8");
} else {
// embedded script auto eval
@@ -99,7 +106,9 @@ myfaces._impl.core._Runtime.singletonExt
}
}
// we have to run the script under a global context
- myfaces._impl.core._Runtime.globalEval(test); // run the script
+ //we store the script for less calls to eval
+ finalScripts.push(test);
+
}
}
});
@@ -109,6 +118,9 @@ myfaces._impl.core._Runtime.singletonExt
for (var cnt = 0; cnt < scriptElements.length; cnt++) {
execScrpt(scriptElements[cnt]);
}
+ if(finalScripts.length) {
+ myfaces._impl.core._Runtime.globalEval(finalScripts.join("\n"));
+ }
} finally {
//the usual ie6 fix code
//the IE6 garbage collector is broken
@@ -180,26 +192,43 @@ myfaces._impl.core._Runtime.singletonExt
_outerHTMLCompliant: function(item, markup) {
var evalNodes = null;
- var range = document.createRange();
- range.setStartBefore(item);
- var fragment = range.createContextualFragment(markup);
- //special case update body, we have to replace the placeholder
- //with the first element (the place holder is the the only child)
- //and then append additional elements as additional childs
- //the body itself then is the root for the eval part!
- if (item.id == 'myfaces_bodyplaceholder') {
- parentNode = item.parentNode;
- parentNode.appendChild(fragment);
- evalNodes = parentNode;
+ var dummyPlaceHolder = document.createElement("div");
+ dummyPlaceHolder.innerHTML = markup;
+ evalNodes = dummyPlaceHolder.childNodes;
+ if('undefined' == typeof evalNodes.length) {
+ item.parentNode.replaceChild( evalNodes, item);
+ return evalNodes;
+ //return this.replaceElement(item, evalNodes);
+ } else if(evalNodes.length == 1) {
+ var ret = evalNodes[0];
+ item.parentNode.replaceChild(evalNodes[0], item);
+ return ret;
+ //return this.replaceElement(item, evalNodes[0]);
} else {
- //normal dom node case we replace only the client id fragment!
-
- parentNode = item.parentNode;
-
- //evalNode = fragment.childNodes[0];
- evalNodes = (fragment.childNodes) ? this._Lang.objToArray(fragment.childNodes) : fragment;
- parentNode.replaceChild(fragment, item);
+ return this.replaceElements(item, evalNodes)
}
+
+ /*var evalNodes = null;
+ var range = document.createRange();
+ range.setStartBefore(item);
+ var fragment = range.createContextualFragment(markup);
+ //special case update body, we have to replace the placeholder
+ //with the first element (the place holder is the the only child)
+ //and then append additional elements as additional childs
+ //the body itself then is the root for the eval part!
+ if (item.id == 'myfaces_bodyplaceholder') {
+ parentNode = item.parentNode;
+ parentNode.appendChild(fragment);
+ evalNodes = parentNode;
+ } else {
+ //normal dom node case we replace only the client id fragment!
+
+ parentNode = item.parentNode;
+
+ //evalNode = fragment.childNodes[0];
+ evalNodes = (fragment.childNodes) ? this._Lang.objToArray(fragment.childNodes) : fragment;
+ parentNode.replaceChild(fragment, item);
+ } */
return evalNodes;
},
@@ -238,16 +267,34 @@ myfaces._impl.core._Runtime.singletonExt
evalNodes = dummyPlaceHolder.childNodes[0].childNodes;
}
- evalNodes = this.replaceElement(item, evalNodes);
+ //ie throws also an error on length requests
+ evalNodes = this._Lang.objToArray(evalNodes);
+ if(evalNodes.length == 1) {
+ item.parentNode.replaceChild(evalNodes[0], item);
+ delete item;
+ return evalNodes[0];
+ //return this.replaceElement(item, evalNodes[0]);
+ } else {
+ return this.replaceElements(item, evalNodes)
+ }
+ },
+
- //if this as well will fail in the future, we can let ie parse a proper xml
- //extract the script elements and then create the script elements manually
- //but for now we will not need it, and this solution is faster
- //the downside of that solution would be that the fragment itself
- //must resolve to a valid xml
- return evalNodes;
+ /**
+ * for performance reasons we work with replaceElement and replaceElements here
+ * after measuring performance it has shown that passing down an array instead
+ * of a single node makes replaceElement twice as slow, however
+ * a single node case is the 95% case
+ *
+ * @param item
+ * @param evalNodes
+ */
+ replaceElement: function(item, evalNode) {
+ evalNode = item.parentNode.replaceChild(evalNode, item);
+ return evalNode;
},
+
/**
* replaces an element with another element or a set of elements
*
@@ -255,31 +302,29 @@ myfaces._impl.core._Runtime.singletonExt
*
* @param evalNodes the elements
*/
- replaceElement: function (item, evalNodes) {
-
+ replaceElements: function (item, evalNodes) {
var parentNode = item.parentNode;
-
- if ('undefined' != typeof evalNodes.length) {
- var oldNode = item;
- var resultArr = this._Lang.objToArray(evalNodes);
-
- for (var cnt = 0; cnt < resultArr.length; cnt++) {
- if (cnt == 0) {
- oldNode = parentNode.replaceChild(resultArr[cnt], oldNode);
+ var evalNodesDefined = 'undefined' != typeof evalNodes.length;
+ if(!evalNodesDefined) {
+ throw new Error("replaceElements called while evalNodes is not an array");
+ }
+ var oldNode = item;
+ var resultArr = this._Lang.objToArray(evalNodes);
+
+ for (var cnt = 0; cnt < resultArr.length; cnt++) {
+ if (cnt == 0) {
+ oldNode = parentNode.replaceChild(resultArr[cnt], oldNode);
+ } else {
+ if (oldNode.nextSibling) {
+ oldNode = parentNode.insertBefore(resultArr[cnt], oldNode.nextSibling);
} else {
- if (oldNode.nextSibling) {
- oldNode = parentNode.insertBefore(resultArr[cnt], oldNode.nextSibling);
- } else {
- oldNode = parentNode.appendChild(resultArr[cnt]);
+ oldNode = parentNode.appendChild(resultArr[cnt]);
- }
}
- evalNodes = resultArr;
}
-
- } else {
- evalNodes = parentNode.replaceChild(evalNodes, item);
+ evalNodes = resultArr;
}
+
return evalNodes;
},
@@ -1154,21 +1199,21 @@ myfaces._impl.core._Runtime.singletonExt
this._Lang.reserveNamespace("myfaces.config._autoeval");
//null not swallowed
myfaces.config._autoeval = false;
-
+
var markup = "<script type='text/javascript'> myfaces.config._autoeval = true; </script>";
//now we rely on the same replacement mechanisms as outerhtml because
//some browsers have different behavior of embedded scripts in the contextualfragment
//or innerhtml case (opera for instance), this way we make sure the
//eval detection is covered correctly
- this.setAttribute(evalDiv, "style","display:none");
+ this.setAttribute(evalDiv, "style", "display:none");
//it is less critical in some browsers (old ie versions)
//to append as first element than as last
//it should not make any difference layoutwise since we are on display none anyway.
- if(document.body.childNodes.length > 0) {
- document.body.insertBefore( evalDiv, document.body.firstChild);
+ if (document.body.childNodes.length > 0) {
+ document.body.insertBefore(evalDiv, document.body.firstChild);
} else {
- document.body.appendChild( evalDiv );
+ document.body.appendChild(evalDiv);
}
//we remap it into a real boolean value
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=961787&r1=961786&r2=961787&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 Thu Jul 8 14:40:28 2010
@@ -48,6 +48,9 @@ if (!myfaces._impl.core._Runtime) {
//the rest of the namespaces can be handled by our namespace feature
//helper to avoid unneeded hitches
var _this = this;
+
+ //namespace idx to speed things up by hitting eval way less
+ _this._reservedNMS = {};
/**
* global eval on scripts
*
@@ -119,7 +122,7 @@ if (!myfaces._impl.core._Runtime) {
* @return the object the namespace points to or null if nothing is found
*/
this.fetchNamespace = function(nms) {
- if ('undefined' == typeof nms || null == nms) {
+ if ('undefined' == typeof nms || null == nms || !_this._reservedNMS[nms]) {
return null;
}
@@ -194,13 +197,16 @@ if (!myfaces._impl.core._Runtime) {
if (!_this.isString(nms)) {
throw Error("Namespace must be a string with . as delimiter");
}
- if (null != _this.fetchNamespace(nms)) {
+ if (_this._reservedNMS[nms] || null != _this.fetchNamespace(nms)) {
return false;
}
+
var entries = nms.split(/\./);
var currNms = window;
+ var tmpNmsName = [];
for (var cnt = 0; cnt < entries.length; cnt++) {
var subNamespace = entries[cnt];
+ tmpNmsName.push(subNamespace)
if ('undefined' == typeof currNms[subNamespace]) {
currNms[subNamespace] = {};
}
@@ -209,6 +215,8 @@ if (!myfaces._impl.core._Runtime) {
} else {
currNms = currNms[subNamespace];
}
+ _this._reservedNMS[tmpNmsName.join(".")] = true;
+
}
@@ -227,6 +235,10 @@ if (!myfaces._impl.core._Runtime) {
if (!root) {
return false;
}
+ //special case locally reserved namespace
+ if(root == window && _this._reservedNMS[subNms]) {
+ return true;
+ }
//initial condition root set element not set or null
//equals to element exists
@@ -480,8 +492,7 @@ if (!myfaces._impl.core._Runtime) {
//up internally
if (key && typeof delFn == "function") {
proto[key] = function(/*arguments*/) {
- var ret = delFn.apply(delegateObj, arguments);
- if ('undefined' != typeof ret) return ret;
+ return delFn.apply(delegateObj, arguments);
};
}
})(key, delegateObj[key]);
@@ -541,6 +552,9 @@ if (!myfaces._impl.core._Runtime) {
if (!_this.isString(newCls)) {
throw Error("new class namespace must be of type String");
}
+ if(_this._reservedNMS[newCls]) {
+ return;
+ }
if ('function' != typeof newCls) {
newCls = _reserveClsNms(newCls, protoFuncs);
@@ -592,6 +606,9 @@ if (!myfaces._impl.core._Runtime) {
* @param nmsFuncs the functions which are attached on the classes namespace level
*/
this.singletonDelegateObj = function(newCls, delegateObj, protoFuncs, nmsFuncs) {
+ if(_this._reservedNMS[newCls]) {
+ return;
+ }
return _makeSingleton(this.delegateObj, newCls, delegateObj, protoFuncs, nmsFuncs);
};
@@ -600,9 +617,10 @@ if (!myfaces._impl.core._Runtime) {
//functions here, the other parts of the
//system have to emulate them via _ prefixes
var _makeSingleton = function(ooFunc, newCls, delegateObj, protoFuncs, nmsFuncs) {
- if (_this.fetchNamespace(newCls)) {
- return null;
+ if(_this._reservedNMS[newCls]) {
+ return;
}
+
var clazz = ooFunc(newCls + "._mfProto", delegateObj, protoFuncs, nmsFuncs);
if (clazz != null) {
_this.applyToGlobalNamespace(newCls, new clazz());