🌐 AI搜索 & 代理 主页
Skip to content

Commit f2a09c7

Browse files
committed
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`. Ref jquerygh-4541 Ref d0ce00c
1 parent 3dedc3f commit f2a09c7

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/ajax.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ jQuery.extend( {
610610
// Add or update anti-cache param if needed
611611
if ( s.cache === false ) {
612612
cacheURL = cacheURL.replace( rantiCache, "$1" );
613-
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
613+
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce.guid++ ) +
614+
uncached;
614615
}
615616

616617
// Put hash and anti-cache on the URL that will be requested (gh-1732)

src/ajax/jsonp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var oldCallbacks = [],
1515
jQuery.ajaxSetup( {
1616
jsonp: "callback",
1717
jsonpCallback: function() {
18-
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
18+
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce.guid++ ) );
1919
this[ callback ] = true;
2020
return callback;
2121
}

src/ajax/var/nonce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
define( function() {
22
"use strict";
33

4-
return Date.now();
4+
return { guid: Date.now() };
55
} );

src/exports/global.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define( [
22
"../core"
3-
], function( jQuery, noGlobal ) {
3+
], function( jQuery ) {
44

55
"use strict";
66

@@ -27,7 +27,7 @@ jQuery.noConflict = function( deep ) {
2727
// Expose jQuery and $ identifiers, even in AMD
2828
// (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
2929
// and CommonJS for browser emulators (#13566)
30-
if ( !noGlobal ) {
30+
if ( typeof noGlobal === "undefined" ) {
3131
window.jQuery = window.$ = jQuery;
3232
}
3333

0 commit comments

Comments
 (0)