From 906f663b04c4de74a8c4950fb1fcd34df73d420b Mon Sep 17 00:00:00 2001 From: jrburke Date: Mon, 21 Jan 2013 15:16:17 -0800 Subject: [PATCH] Refs #553, experiment to avoid anon mismatch error --- require.js | 43 +++++++++++++++------------- tests/anonScript/anonScript.html | 44 +++++++++++++++++++++++++++++ tests/anonScript/anonScript2.html | 47 +++++++++++++++++++++++++++++++ tests/anonScript/badUse.js | 11 ++++++++ tests/anonScript/build1.js | 18 ++++++++++++ tests/anonScript/build2.js | 18 ++++++++++++ tests/anonScript/dropDefine.js | 6 ++++ 7 files changed, 167 insertions(+), 20 deletions(-) create mode 100644 tests/anonScript/anonScript.html create mode 100644 tests/anonScript/anonScript2.html create mode 100644 tests/anonScript/badUse.js create mode 100644 tests/anonScript/build1.js create mode 100644 tests/anonScript/build2.js create mode 100644 tests/anonScript/dropDefine.js diff --git a/require.js b/require.js index 67f7be280..5fadfc280 100644 --- a/require.js +++ b/require.js @@ -1181,17 +1181,19 @@ var requirejs, require, define; } function intakeDefines() { - var args; + var args, i; //Any defined modules in the global queue, intake them now. takeGlobalQueue(); //Make sure any remaining defQueue items get properly processed. - while (defQueue.length) { - args = defQueue.shift(); - if (args[0] === null) { - return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1])); - } else { + for(i = 0; i < defQueue.length; i++) { + args = defQueue[i]; + //If anon module (arg[0] is null), leave it be, + //may be picked up via completeLoad. + if (args[0] !== null) { + args = defQueue.splice(i, 1); + i -= 1; //args are id, deps, factory. Should be normalized by the //define() function. callGetModule(args); @@ -1474,23 +1476,24 @@ var requirejs, require, define; takeGlobalQueue(); + if (!useInteractive) { + eachReverse(defQueue, function (args) { + if (args[0] === null) { +console.log('DEFQUEUE ', defQueue); +console.log('ASSIGNING ' + moduleName + ' to: ', args[2].toString()); + args[0] = moduleName; + + return (found = true); + + } + }); + } + while (defQueue.length) { args = defQueue.shift(); - if (args[0] === null) { - args[0] = moduleName; - //If already found an anonymous module and bound it - //to this name, then this is some other anon module - //waiting for its completeLoad to fire. - if (found) { - break; - } - found = true; - } else if (args[0] === moduleName) { - //Found matching define call for this script! - found = true; + if (args[0] !== null) { + callGetModule(args); } - - callGetModule(args); } //Do this after the cycle of callGetModule in case the result diff --git a/tests/anonScript/anonScript.html b/tests/anonScript/anonScript.html new file mode 100644 index 000000000..54ccb7612 --- /dev/null +++ b/tests/anonScript/anonScript.html @@ -0,0 +1,44 @@ + + + + require.js: Anon Script Test + + + + + + + + +

require.js: Anon Script Test

+

Make sure a script that does an anon define does not mess up + other module loading.

+

Check console for messages

+ + diff --git a/tests/anonScript/anonScript2.html b/tests/anonScript/anonScript2.html new file mode 100644 index 000000000..bdc67573c --- /dev/null +++ b/tests/anonScript/anonScript2.html @@ -0,0 +1,47 @@ + + + + require.js: Anon Script Test + + + + + + + + +

require.js: Anon Script Test

+

Make sure a script that does an anon define does not mess up + other module loading.

+

Check console for messages

+ + diff --git a/tests/anonScript/badUse.js b/tests/anonScript/badUse.js new file mode 100644 index 000000000..eb28076e8 --- /dev/null +++ b/tests/anonScript/badUse.js @@ -0,0 +1,11 @@ +(function () { + var n = 'badUse' + (globalCounter += 1); + console.log(n); + + define(function () { + return { + name: n + }; + }); + +}()); \ No newline at end of file diff --git a/tests/anonScript/build1.js b/tests/anonScript/build1.js new file mode 100644 index 000000000..9015d1181 --- /dev/null +++ b/tests/anonScript/build1.js @@ -0,0 +1,18 @@ +define('c1', { + name: 'c1' +}); +define('c2', { + name: 'c2' +}); +define('c3', { + name: 'c3' +}); + +define(['c1', 'c2', 'c3'], function (c1, c2, c3) { + return { + name: 'build1', + c1: c1, + c2: c2, + c3: c3 + }; +}); diff --git a/tests/anonScript/build2.js b/tests/anonScript/build2.js new file mode 100644 index 000000000..8bcb0c6c4 --- /dev/null +++ b/tests/anonScript/build2.js @@ -0,0 +1,18 @@ +define('d1', { + name: 'd1' +}); +define('d2', { + name: 'd2' +}); +define('d3', { + name: 'd3' +}); + +define(['d1', 'd2', 'd3'], function (d1, d2, d3) { + return { + name: 'build2', + d1: d1, + d2: d2, + d3: d3 + }; +}); diff --git a/tests/anonScript/dropDefine.js b/tests/anonScript/dropDefine.js new file mode 100644 index 000000000..75583f671 --- /dev/null +++ b/tests/anonScript/dropDefine.js @@ -0,0 +1,6 @@ +define({ + name: 'dropDefine' +}); + +//This require call collects outstanding define calls. +require(['build1'], function (build1) {}); \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy