mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "Deferred: Backwards-compatible standards interoperability"
This reverts commit 34f2563179
.
This commit is contained in:
parent
3b573a59d9
commit
5826cafb95
@ -80,8 +80,6 @@ module.exports = function( grunt ) {
|
||||
"sizzle/dist": "sizzle/dist",
|
||||
"sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
|
||||
|
||||
"npo/npo.js": "native-promise-only/npo.js",
|
||||
|
||||
"qunit/qunit.js": "qunitjs/qunit/qunit.js",
|
||||
"qunit/qunit.css": "qunitjs/qunit/qunit.css",
|
||||
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
|
||||
@ -205,9 +203,7 @@ module.exports = function( grunt ) {
|
||||
// jQuery on Windows. (see gh-2519)
|
||||
grunt.registerTask( "test_fast", runJsdomTests ? [ "node_smoke_tests" ] : [] );
|
||||
|
||||
grunt.registerTask( "test", [ "test_fast" ].concat(
|
||||
runJsdomTests ? [ "promises_aplus_tests" ] : []
|
||||
) );
|
||||
grunt.registerTask( "test", [ "test_fast" ] );
|
||||
|
||||
// Short list as a high frequency watch task
|
||||
grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] );
|
||||
|
4
external/requirejs/require.js
vendored
4
external/requirejs/require.js
vendored
@ -1,5 +1,5 @@
|
||||
/** vim: et:ts=4:sw=4:sts=4
|
||||
* @license RequireJS 2.1.15 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
||||
* @license RequireJS 2.1.14 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
@ -12,7 +12,7 @@ var requirejs, require, define;
|
||||
(function (global) {
|
||||
var req, s, head, baseElement, dataMain, src,
|
||||
interactiveScript, currentlyAddingScript, mainScript, subPath,
|
||||
version = '2.1.15',
|
||||
version = '2.1.14',
|
||||
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
|
||||
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
|
||||
jsSuffixRegExp = /\.js$/,
|
||||
|
@ -41,9 +41,7 @@
|
||||
"gzip-js": "0.3.2",
|
||||
"jsdom": "5.6.1",
|
||||
"load-grunt-tasks": "1.0.0",
|
||||
"native-promise-only": "0.7.8-a",
|
||||
"promises-aplus-tests": "2.1.0",
|
||||
"q": "1.1.2",
|
||||
"npm": "2.1.12",
|
||||
"qunitjs": "1.17.1",
|
||||
"qunit-assert-step": "1.0.3",
|
||||
"requirejs": "2.1.17",
|
||||
|
281
src/deferred.js
281
src/deferred.js
@ -4,26 +4,14 @@ define( [
|
||||
"./callbacks"
|
||||
], function( jQuery, slice ) {
|
||||
|
||||
function Identity( v ) {
|
||||
return v;
|
||||
}
|
||||
function Thrower( ex ) {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
jQuery.extend( {
|
||||
jQuery.extend({
|
||||
|
||||
Deferred: function( func ) {
|
||||
var tuples = [
|
||||
|
||||
// action, add listener, callbacks,
|
||||
// ... .then handlers, argument index, [final state]
|
||||
[ "notify", "progress", jQuery.Callbacks( "memory" ),
|
||||
jQuery.Callbacks( "memory" ), 2 ],
|
||||
[ "resolve", "done", jQuery.Callbacks( "once memory" ),
|
||||
jQuery.Callbacks( "once memory" ), 0, "resolved" ],
|
||||
[ "reject", "fail", jQuery.Callbacks( "once memory" ),
|
||||
jQuery.Callbacks( "once memory" ), 1, "rejected" ]
|
||||
// action, add listener, listener list, final state
|
||||
[ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
|
||||
[ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
|
||||
[ "notify", "progress", jQuery.Callbacks("memory") ]
|
||||
],
|
||||
state = "pending",
|
||||
promise = {
|
||||
@ -34,21 +22,13 @@ jQuery.extend( {
|
||||
deferred.done( arguments ).fail( arguments );
|
||||
return this;
|
||||
},
|
||||
|
||||
// Keep pipe for back-compat
|
||||
pipe: function( /* fnDone, fnFail, fnProgress */ ) {
|
||||
then: function( /* fnDone, fnFail, fnProgress */ ) {
|
||||
var fns = arguments;
|
||||
|
||||
return jQuery.Deferred( function( newDefer ) {
|
||||
return jQuery.Deferred(function( newDefer ) {
|
||||
jQuery.each( tuples, function( i, tuple ) {
|
||||
|
||||
// Map tuples (progress, done, fail) to arguments (done, fail, progress)
|
||||
var fn = jQuery.isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];
|
||||
|
||||
// deferred.progress(function() { bind to newDefer or newDefer.notify })
|
||||
// deferred.done(function() { bind to newDefer or newDefer.resolve })
|
||||
// deferred.fail(function() { bind to newDefer or newDefer.reject })
|
||||
deferred[ tuple[ 1 ] ]( function() {
|
||||
var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
|
||||
// deferred[ done | fail | progress ] for forwarding actions to newDefer
|
||||
deferred[ tuple[1] ](function() {
|
||||
var returned = fn && fn.apply( this, arguments );
|
||||
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
||||
returned.promise()
|
||||
@ -66,162 +46,6 @@ jQuery.extend( {
|
||||
fns = null;
|
||||
} ).promise();
|
||||
},
|
||||
then: function( onFulfilled, onRejected, onProgress ) {
|
||||
var maxDepth = 0;
|
||||
function resolve( depth, deferred, handler, special ) {
|
||||
return function() {
|
||||
var that = this === promise ? undefined : this,
|
||||
args = arguments,
|
||||
mightThrow = function() {
|
||||
var returned, then;
|
||||
|
||||
// Support: Promises/A+ section 2.3.3.3.3
|
||||
// https://promisesaplus.com/#point-59
|
||||
// Ignore double-resolution attempts
|
||||
if ( depth < maxDepth ) {
|
||||
return;
|
||||
}
|
||||
|
||||
returned = handler.apply( that, args );
|
||||
|
||||
// Support: Promises/A+ section 2.3.1
|
||||
// https://promisesaplus.com/#point-48
|
||||
if ( returned === deferred.promise() ) {
|
||||
throw new TypeError( "Thenable self-resolution" );
|
||||
}
|
||||
|
||||
// Support: Promises/A+ sections 2.3.3.1, 3.5
|
||||
// https://promisesaplus.com/#point-54
|
||||
// https://promisesaplus.com/#point-75
|
||||
// Retrieve `then` only once
|
||||
then = returned &&
|
||||
|
||||
// Support: Promises/A+ section 2.3.4
|
||||
// https://promisesaplus.com/#point-64
|
||||
// Only check objects and functions for thenability
|
||||
( typeof returned === "object" ||
|
||||
typeof returned === "function" ) &&
|
||||
returned.then;
|
||||
|
||||
// Handle a returned thenable
|
||||
if ( jQuery.isFunction( then ) ) {
|
||||
|
||||
// Special processors (notify) just wait for resolution
|
||||
if ( special ) {
|
||||
then.call(
|
||||
returned,
|
||||
resolve( maxDepth, deferred, Identity, special ),
|
||||
resolve( maxDepth, deferred, Thrower, special )
|
||||
);
|
||||
|
||||
// Normal processors (resolve) also hook into progress
|
||||
} else {
|
||||
|
||||
// ...and disregard older resolution values
|
||||
maxDepth++;
|
||||
|
||||
then.call(
|
||||
returned,
|
||||
resolve( maxDepth, deferred, Identity, special ),
|
||||
resolve( maxDepth, deferred, Thrower, special ),
|
||||
resolve( maxDepth, deferred, Identity,
|
||||
deferred.notify )
|
||||
);
|
||||
}
|
||||
|
||||
// Handle all other returned values
|
||||
} else {
|
||||
|
||||
// Only substitue handlers pass on context
|
||||
// and multiple values (non-spec behavior)
|
||||
if ( handler !== Identity ) {
|
||||
that = undefined;
|
||||
args = [ returned ];
|
||||
}
|
||||
|
||||
// Process the value(s)
|
||||
// Default process is resolve
|
||||
( special || deferred.resolveWith )(
|
||||
that || deferred.promise(), args );
|
||||
}
|
||||
},
|
||||
|
||||
// Only normal processors (resolve) catch and reject exceptions
|
||||
process = special ?
|
||||
mightThrow :
|
||||
function() {
|
||||
try {
|
||||
mightThrow();
|
||||
} catch ( e ) {
|
||||
|
||||
// Support: Promises/A+ section 2.3.3.3.4.1
|
||||
// https://promisesaplus.com/#point-61
|
||||
// Ignore post-resolution exceptions
|
||||
if ( depth + 1 >= maxDepth ) {
|
||||
|
||||
// Only substitue handlers pass on context
|
||||
// and multiple values (non-spec behavior)
|
||||
if ( handler !== Thrower ) {
|
||||
that = undefined;
|
||||
args = [ e ];
|
||||
}
|
||||
|
||||
deferred.rejectWith( that || deferred.promise(),
|
||||
args );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Support: Promises/A+ section 2.3.3.3.1
|
||||
// https://promisesaplus.com/#point-57
|
||||
// Re-resolve promises immediately to dodge false rejection from
|
||||
// subsequent errors
|
||||
if ( depth ) {
|
||||
process();
|
||||
} else {
|
||||
window.setTimeout( process );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return jQuery.Deferred( function( newDefer ) {
|
||||
|
||||
// progress_handlers.add( ... )
|
||||
tuples[ 0 ][ 3 ].add(
|
||||
resolve(
|
||||
0,
|
||||
newDefer,
|
||||
jQuery.isFunction( onProgress ) ?
|
||||
onProgress :
|
||||
Identity,
|
||||
newDefer.notifyWith
|
||||
)
|
||||
);
|
||||
|
||||
// fulfilled_handlers.add( ... )
|
||||
tuples[ 1 ][ 3 ].add(
|
||||
resolve(
|
||||
0,
|
||||
newDefer,
|
||||
jQuery.isFunction( onFulfilled ) ?
|
||||
onFulfilled :
|
||||
Identity
|
||||
)
|
||||
);
|
||||
|
||||
// rejected_handlers.add( ... )
|
||||
tuples[ 2 ][ 3 ].add(
|
||||
resolve(
|
||||
0,
|
||||
newDefer,
|
||||
jQuery.isFunction( onRejected ) ?
|
||||
onRejected :
|
||||
Thrower
|
||||
)
|
||||
);
|
||||
} ).promise();
|
||||
},
|
||||
|
||||
// Get a promise for this deferred
|
||||
// If obj is provided, the promise aspect is added to the object
|
||||
promise: function( obj ) {
|
||||
@ -230,53 +54,34 @@ jQuery.extend( {
|
||||
},
|
||||
deferred = {};
|
||||
|
||||
// Keep pipe for back-compat
|
||||
promise.pipe = promise.then;
|
||||
|
||||
// Add list-specific methods
|
||||
jQuery.each( tuples, function( i, tuple ) {
|
||||
var list = tuple[ 2 ],
|
||||
stateString = tuple[ 5 ];
|
||||
stateString = tuple[ 3 ];
|
||||
|
||||
// promise.progress = list.add
|
||||
// promise.done = list.add
|
||||
// promise.fail = list.add
|
||||
promise[ tuple[ 1 ] ] = list.add;
|
||||
// promise[ done | fail | progress ] = list.add
|
||||
promise[ tuple[1] ] = list.add;
|
||||
|
||||
// Handle state
|
||||
if ( stateString ) {
|
||||
list.add(
|
||||
function() {
|
||||
list.add(function() {
|
||||
// state = [ resolved | rejected ]
|
||||
state = stateString;
|
||||
|
||||
// state = "resolved" (i.e., fulfilled)
|
||||
// state = "rejected"
|
||||
state = stateString;
|
||||
},
|
||||
|
||||
// rejected_callbacks.disable
|
||||
// fulfilled_callbacks.disable
|
||||
tuples[ 3 - i ][ 2 ].disable,
|
||||
|
||||
// progress_callbacks.lock
|
||||
tuples[ 0 ][ 2 ].lock
|
||||
);
|
||||
// [ reject_list | resolve_list ].disable; progress_list.lock
|
||||
}, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
|
||||
}
|
||||
|
||||
// progress_handlers.fire
|
||||
// fulfilled_handlers.fire
|
||||
// rejected_handlers.fire
|
||||
list.add( tuple[ 3 ].fire );
|
||||
|
||||
// deferred.notify = function() { deferred.notifyWith(...) }
|
||||
// deferred.resolve = function() { deferred.resolveWith(...) }
|
||||
// deferred.reject = function() { deferred.rejectWith(...) }
|
||||
deferred[ tuple[ 0 ] ] = function() {
|
||||
deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments );
|
||||
// deferred[ resolve | reject | notify ]
|
||||
deferred[ tuple[0] ] = function() {
|
||||
deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
|
||||
return this;
|
||||
};
|
||||
|
||||
// deferred.notifyWith = list.fireWith
|
||||
// deferred.resolveWith = list.fireWith
|
||||
// deferred.rejectWith = list.fireWith
|
||||
deferred[ tuple[ 0 ] + "With" ] = list.fireWith;
|
||||
} );
|
||||
deferred[ tuple[0] + "With" ] = list.fireWith;
|
||||
});
|
||||
|
||||
// Make the deferred a promise
|
||||
promise.promise( deferred );
|
||||
@ -292,8 +97,7 @@ jQuery.extend( {
|
||||
|
||||
// Deferred helper
|
||||
when: function( subordinate /* , ..., subordinateN */ ) {
|
||||
var method,
|
||||
i = 0,
|
||||
var i = 0,
|
||||
resolveValues = slice.call( arguments ),
|
||||
length = resolveValues.length,
|
||||
|
||||
@ -303,7 +107,7 @@ jQuery.extend( {
|
||||
|
||||
// the master Deferred.
|
||||
// If resolveValues consist of only a single Deferred, just use that.
|
||||
master = remaining === 1 ? subordinate : jQuery.Deferred(),
|
||||
deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
|
||||
|
||||
// Update function for both resolve and progress values
|
||||
updateFunc = function( i, contexts, values ) {
|
||||
@ -311,12 +115,14 @@ jQuery.extend( {
|
||||
contexts[ i ] = this;
|
||||
values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
|
||||
if ( values === progressValues ) {
|
||||
master.notifyWith( contexts, values );
|
||||
} else if ( !( --remaining ) ) {
|
||||
master.resolveWith( contexts, values );
|
||||
deferred.notifyWith( contexts, values );
|
||||
|
||||
} else if ( !(--remaining) ) {
|
||||
deferred.resolveWith( contexts, values );
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
progressValues, progressContexts, resolveContexts;
|
||||
|
||||
// add listeners to Deferred subordinates; treat others as resolved
|
||||
@ -325,22 +131,11 @@ jQuery.extend( {
|
||||
progressContexts = new Array( length );
|
||||
resolveContexts = new Array( length );
|
||||
for ( ; i < length; i++ ) {
|
||||
if ( resolveValues[ i ] &&
|
||||
jQuery.isFunction( ( method = resolveValues[ i ].promise ) ) ) {
|
||||
|
||||
method.call( resolveValues[ i ] )
|
||||
if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
|
||||
resolveValues[ i ].promise()
|
||||
.progress( updateFunc( i, progressContexts, progressValues ) )
|
||||
.done( updateFunc( i, resolveContexts, resolveValues ) )
|
||||
.fail( master.reject );
|
||||
} else if ( resolveValues[ i ] &&
|
||||
jQuery.isFunction( ( method = resolveValues[ i ].then ) ) ) {
|
||||
|
||||
method.call(
|
||||
resolveValues[ i ],
|
||||
updateFunc( i, resolveContexts, resolveValues ),
|
||||
master.reject,
|
||||
updateFunc( i, progressContexts, progressValues )
|
||||
);
|
||||
.fail( deferred.reject );
|
||||
} else {
|
||||
--remaining;
|
||||
}
|
||||
@ -349,10 +144,10 @@ jQuery.extend( {
|
||||
|
||||
// if we're not waiting on anything, resolve the master
|
||||
if ( !remaining ) {
|
||||
master.resolveWith( resolveContexts, resolveValues );
|
||||
deferred.resolveWith( resolveContexts, resolveValues );
|
||||
}
|
||||
|
||||
return master.promise();
|
||||
return deferred.promise();
|
||||
}
|
||||
} );
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
<script src="../external/qunit-assert-step/qunit-assert-step.js"></script>
|
||||
<script src="../external/sinon/sinon-1.14.1.js"></script>
|
||||
<script src="../external/sinon/timers_ie.js"></script>
|
||||
<script src="../external/npo/npo.js"></script>
|
||||
<script src="../external/requirejs/require.js"></script>
|
||||
<!-- See testinit for the list of tests -->
|
||||
<script src="data/testinit.js"></script>
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user