Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4221ed

Browse files
committed
fixup! use .then and give up sync guarantee
Fixesgh-1823
1 parent1152e47 commite4221ed

File tree

3 files changed

+32
-36
lines changed

3 files changed

+32
-36
lines changed

‎src/core/ready-no-deferred.js‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ var readyCallbacks = [],
77
readyFiring=false,
88
whenReady=function(fn){
99
readyCallbacks.push(fn);
10+
},
11+
executeReady=function(fn){
12+
13+
// Prevent errors from freezing future callback execution (gh-1823)
14+
// Not backwards-compatible as this does not execute sync
15+
window.setTimeout(function(){
16+
fn.call(document,jQuery);
17+
});
1018
};
1119

1220
jQuery.fn.ready=function(fn){
@@ -53,28 +61,13 @@ jQuery.extend( {
5361
if(!readyFiring){
5462
readyFiring=true;
5563

56-
// Prevent errors from freezing future callback execution (gh-1823)
57-
try{
58-
while(readyCallbacks.length){
59-
fn=readyCallbacks.shift();
60-
if(jQuery.isFunction(fn)){
61-
62-
// For backwards compatibility,
63-
// invoke synchronously and with document context
64-
fn.call(document,jQuery);
65-
}
66-
}
67-
}finally{
68-
readyFiring=false;
69-
70-
// If there was an error in a ready callback,
71-
// continue with the rest (gh-1823)
72-
if(readyCallbacks.length){
73-
74-
// Retry async to allow the error to propagate to console
75-
window.setTimeout(whenReady);
64+
while(readyCallbacks.length){
65+
fn=readyCallbacks.shift();
66+
if(jQuery.isFunction(fn)){
67+
executeReady(fn);
7668
}
7769
}
70+
readyFiring=false;
7871
}
7972
};
8073

‎src/core/ready.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ var readyList = jQuery.Deferred();
99

1010
jQuery.fn.ready=function(fn){
1111

12-
// Add the callback
13-
readyList.done(fn);
12+
readyList.then(fn);
1413

1514
returnthis;
1615
};

‎test/unit/ready.js‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,20 @@ QUnit.module( "ready" );
7979

8080
order=[];
8181

82-
// Now that the ready event has fired, again bind to the ready event
83-
// in every possible way. These event handlers should execute immediately.
82+
// Now that the ready event has fired, again bind to the ready event.
83+
// These ready handlers should execute asynchronously.
84+
vardone=assert.async();
8485
jQuery(makeHandler("g"));
85-
assert.equal(order.pop(),"g","Event handler should execute immediately");
86-
assert.equal(args.g,jQuery,"Argument passed to fn in jQuery( fn ) should be jQuery");
87-
8886
jQuery(document).ready(makeHandler("h"));
89-
assert.equal(order.pop(),"h","Event handler should execute immediately");
90-
assert.equal(args.h,jQuery,
91-
"Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
87+
window.setTimeout(function(){
88+
assert.equal(order.shift(),"g","Event handler should execute immediately, but async");
89+
assert.equal(args.g,jQuery,"Argument passed to fn in jQuery( fn ) should be jQuery");
90+
91+
assert.equal(order.shift(),"h","Event handler should execute immediately, but async");
92+
assert.equal(args.h,jQuery,
93+
"Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
94+
done();
95+
});
9296
});
9397

9498
QUnit.test("Promise.resolve(jQuery.ready)",function(assert){
@@ -107,16 +111,16 @@ QUnit.module( "ready" );
107111
});
108112

109113
QUnit.test("Error in ready callback does not halt all future executions (gh-1823)",function(assert){
110-
assert.expect(2);
114+
assert.expect(1);
115+
vardone=assert.async();
111116

112-
assert.throws(function(){
113-
jQuery(function(){
114-
thrownewError("Ready error");
115-
});
116-
},"First ready handler throws an error");
117+
jQuery(function(){
118+
throwError(3);
119+
});
117120

118121
jQuery(function(){
119122
assert.ok(true,"Subsequent handler called");
123+
done();
120124
});
121125
});
122126
})();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp