diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2016-04-15 17:13:59 -0400 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2016-04-23 00:30:48 -0400 |
commit | 76084372c29a59b3fa790ea4d2687f0767514999 (patch) | |
tree | d4597330a1373fb0ad65ac866f7ae4fe7ff995ec /src | |
parent | 84427591ccffe686f158ce81e5c6ba6694f7da50 (diff) | |
download | jquery-76084372c29a59b3fa790ea4d2687f0767514999.tar.gz jquery-76084372c29a59b3fa790ea4d2687f0767514999.zip |
Deferred: Remove default callback context
Employs strict mode to simplify Deferred callback context handling.
Fixes gh-3060
Closes gh-3061
Diffstat (limited to 'src')
-rw-r--r-- | src/deferred.js | 14 | ||||
-rw-r--r-- | src/wrapper.js | 10 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/deferred.js b/src/deferred.js index bc2ea8637..91c55a64e 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -4,6 +4,8 @@ define( [ "./callbacks" ], function( jQuery, slice ) { +"use strict"; + function Identity( v ) { return v; } @@ -60,7 +62,7 @@ jQuery.extend( { .fail( newDefer.reject ); } else { newDefer[ tuple[ 0 ] + "With" ]( - this === promise ? newDefer.promise() : this, + this, fn ? [ returned ] : arguments ); } @@ -73,7 +75,7 @@ jQuery.extend( { var maxDepth = 0; function resolve( depth, deferred, handler, special ) { return function() { - var that = this === promise ? undefined : this, + var that = this, args = arguments, mightThrow = function() { var returned, then; @@ -144,8 +146,7 @@ jQuery.extend( { // Process the value(s) // Default process is resolve - ( special || deferred.resolveWith )( - that || deferred.promise(), args ); + ( special || deferred.resolveWith )( that, args ); } }, @@ -174,8 +175,7 @@ jQuery.extend( { args = [ e ]; } - deferred.rejectWith( that || deferred.promise(), - args ); + deferred.rejectWith( that, args ); } } }; @@ -282,7 +282,7 @@ jQuery.extend( { // deferred.resolve = function() { deferred.resolveWith(...) } // deferred.reject = function() { deferred.rejectWith(...) } deferred[ tuple[ 0 ] ] = function() { - deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments ); + deferred[ tuple[ 0 ] + "With" ]( this === deferred ? undefined : this, arguments ); return this; }; diff --git a/src/wrapper.js b/src/wrapper.js index 4ad7776d1..8866d6bcd 100644 --- a/src/wrapper.js +++ b/src/wrapper.js @@ -38,11 +38,11 @@ // Pass this if window is not defined yet }( typeof window !== "undefined" ? window : this, function( window, noGlobal ) { -// Support: Firefox 18+ -// Can't be in strict mode, several libs including ASP.NET trace -// the stack via arguments.caller.callee and Firefox dies if -// you try to trace through "use strict" call chains. (#13335) -//"use strict"; +// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1 +// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode +// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common +// enough that all such attempts are guarded in a try block. +"use strict"; // @CODE // build.js inserts compiled jQuery here |