WICKET-4675 Process Ajax responses in one go

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/fc485be5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/fc485be5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/fc485be5

Branch: refs/heads/master
Commit: fc485be5b8af2f8a65dfd0275bb486d474ac8b3c
Parents: de34474
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Authored: Wed Aug 1 16:28:45 2012 +0300
Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Committed: Wed Aug 1 16:35:17 2012 +0300

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js       |   14 +-
 wicket-core/src/test/js/ajax.js                    |   29 +-
 .../test/js/data/ajax/manyEvaluationsResponse.xml  | 2146 +++++++++++++++
 3 files changed, 2181 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/fc485be5/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js 
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 58cebdc..3c267c2 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -109,10 +109,11 @@
        /**
         * Functions executer takes array of functions and executes them. Each 
function gets
         * the notify object, which needs to be called for the next function to 
be executed.
-        * This way the functions can be executed synchronously. Each function 
has to call
-        * the notify object at some point, otherwise the functions after it 
wont be executed.
-        * After the FunctionExecuter is initiatialized, the start methods 
triggers the
-        * first function.
+        * This way the functions can be executed synchronously.
+        * This is needed because header contributions need to do asynchronous 
download of JS and/or CSS
+        * and they have to let next function to run only after the download.
+        * Each function has to call the notify object at some point, otherwise 
the functions after it wont be executed.
+        * After the FunctionsExecuter is initiatialized, the start methods 
triggers the first function.
         */
        var FunctionsExecuter = function (functions) {
 
@@ -139,9 +140,8 @@
                                run = jQuery.proxy(run, this);
                                this.current++;
 
-                               if (this.depth > 50 || Wicket.Browser.isKHTML() 
|| Wicket.Browser.isSafari()) {
-                                       // to prevent khtml bug that crashes 
entire browser
-                                       // or to prevent stack overflow (safari 
has small call stack)
+                               if (this.depth > 1000) {
+                                       // to prevent stack overflow (see 
WICKET-4675)
                                        this.depth = 0;
                                        window.setTimeout(run, 1);
                                } else {

http://git-wip-us.apache.org/repos/asf/wicket/blob/fc485be5/wicket-core/src/test/js/ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/ajax.js b/wicket-core/src/test/js/ajax.js
index 055c866..eac6e33 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -988,7 +988,34 @@ jQuery(document).ready(function() {
 
                        Wicket.Ajax.ajax(attrs);
 
-                       jQuery('#'+ attrs.c).triggerHandler(attrs.e);
+                       jQuery('#'+ attrs.c).triggerHandler("nestedFormSubmit");
+               });
+
+               /**
+                * Tests that a huge response with more than 1000 evaluations 
is properly executed.
+                * FunctionsExecuter can execute at most 1000 functions in one 
go, the rest are executed
+                * in setTimeout() to prevent stack size exceeds.
+                * WICKET-4675
+                */
+               asyncTest('Process response with 2k+ evaluations.', function () 
{
+
+                       expect(2133);
+
+                       var attrs = {
+                               u:  "data/ajax/manyEvaluationsResponse.xml", // 
the mock response
+                               e:  "manyEvaluations", // the event
+                               bh: [ function(attrs) { ok(true, "Before 
handler executed"); } ],
+                               pre: [ function(attrs) {ok(true, "Precondition 
executed"); return true; } ],
+                               bsh: [ function(attrs) { ok(true, "BeforeSend 
handler executed"); } ],
+                               ah: [ function(attrs) { ok(true, "After handler 
executed"); } ],
+                               sh: [ function(attrs) { ok(true, "Success 
handler executed"); } ],
+                               fh: [ function(attrs) { ok(false, "Failure 
handler should not be executed"); } ],
+                               coh: [ function(attrs) { ok(true, "Complete 
handler executed"); } ]
+                       };
+
+                       Wicket.Ajax.ajax(attrs);
+
+                       jQuery(window).triggerHandler("manyEvaluations");
                });
        }
 });

Reply via email to