Core:Ajax: Align nonce & global with master, fix an AMD issue

This commit aligns the `3.x-stable` branch with `master` in two aspects:
1. It migrates the nonce module to return an object instead of a primitive
variable. This had to be changed on `master` as in ES modules you export
live read-only bindings to variables, meaning you can't increment the nonce
directly. Also, the way it was done so far was working differently in AMD & the
single built file - in the built file one nonce variable was declared, accessed
and incremented. In AMD mode separate instances were create for each module
that depend on the nonce module, creating unintended nonce clashes.
2. Whether the `noGlobal` parameter was set to `true` is now checked using the
typeof operator to align with `master`.

Closes gh-4612
Ref gh-4541
Ref d0ce00cdfa
This commit is contained in:
Michał Gołębiowski-Owczarek 2020-02-24 19:10:03 +01:00 committed by GitHub
parent 3dedc3f2d4
commit 22bf701fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 5 deletions

View File

@ -610,7 +610,8 @@ jQuery.extend( {
// Add or update anti-cache param if needed
if ( s.cache === false ) {
cacheURL = cacheURL.replace( rantiCache, "$1" );
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce.guid++ ) +
uncached;
}
// Put hash and anti-cache on the URL that will be requested (gh-1732)

View File

@ -15,7 +15,7 @@ var oldCallbacks = [],
jQuery.ajaxSetup( {
jsonp: "callback",
jsonpCallback: function() {
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce.guid++ ) );
this[ callback ] = true;
return callback;
}

View File

@ -1,5 +1,5 @@
define( function() {
"use strict";
return Date.now();
return { guid: Date.now() };
} );

View File

@ -1,6 +1,6 @@
define( [
"../core"
], function( jQuery, noGlobal ) {
], function( jQuery ) {
"use strict";
@ -27,7 +27,7 @@ jQuery.noConflict = function( deep ) {
// Expose jQuery and $ identifiers, even in AMD
// (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
// and CommonJS for browser emulators (#13566)
if ( !noGlobal ) {
if ( typeof noGlobal === "undefined" ) {
window.jQuery = window.$ = jQuery;
}