Skip to content

Commit

Permalink
Thanks to a great test case from Gilles Ruppert, tracked down an issu…
Browse files Browse the repository at this point in the history
…e with a priority module loaded that did not have all its dependencies in the priority layer.
  • Loading branch information
jrburke committed Oct 14, 2010
1 parent 1d50f68 commit 79188c7
Show file tree
Hide file tree
Showing 11 changed files with 1,546 additions and 97 deletions.
40 changes: 26 additions & 14 deletions require.js
Expand Up @@ -13,7 +13,7 @@ setInterval: false, importScripts: false */
var require;
(function () {
//Change this version number for each release.
var version = "0.14.2",
var version = "0.14.2+",
empty = {}, s,
i, defContextName = "_", contextLoads = [],
scripts, script, rePkg, src, m, dataMain, cfg = {}, setReadyState,
Expand Down Expand Up @@ -107,6 +107,27 @@ var require;
}
}

/**
* Determine if priority loading is done. If so clear the priorityWait
*/
function isPriorityDone(context) {
var priorityDone = true,
priorityWait = context.config.priorityWait,
priorityName, i;
if (priorityWait) {
for (i = 0; (priorityName = priorityWait[i]); i++) {
if (!context.loaded[priorityName]) {
priorityDone = false;
break;
}
}
if (priorityDone) {
delete context.config.priorityWait;
}
}
return priorityDone;
}

/**
* Resumes tracing of dependencies and then checks if everything is loaded.
*/
Expand All @@ -130,7 +151,7 @@ var require;
}

//Skip the resume if current context is in priority wait.
if (s.contexts[s.ctxName].config.priorityWait) {
if (context.config.priorityWait && !isPriorityDone(context)) {
return;
}

Expand Down Expand Up @@ -1040,8 +1061,7 @@ var require;
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
loaded, defined = context.defined,
modifiers = context.modifiers, waiting, noLoads = "",
hasLoadedProp = false, stillLoading = false, prop, priorityDone,
priorityName,
hasLoadedProp = false, stillLoading = false, prop,

//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
pIsWaiting = s.plugins.isWaiting, pOrderDeps = s.plugins.orderDeps,
Expand All @@ -1058,17 +1078,9 @@ var require;
//Determine if priority loading is done. If so clear the priority. If
//not, then do not check
if (context.config.priorityWait) {
priorityDone = true;
for (i = 0; (priorityName = context.config.priorityWait[i]); i++) {
if (!context.loaded[priorityName]) {
priorityDone = false;
break;
}
}
if (priorityDone) {
//Clean up priority and call resume, since it could have
if (isPriorityDone(context)) {
//Call resume, since it could have
//some waiting dependencies to trace.
delete context.config.priorityWait;
resume(context);
} else {
return;
Expand Down
1 change: 1 addition & 0 deletions tests/all.js
Expand Up @@ -30,6 +30,7 @@ doh.registerUrl("relative", "../relative/relative.html");
doh.registerUrl("exports", "../exports/exports.html");
doh.registerUrl("transportD", "../transportD/transportD.html");
doh.registerUrl("priority", "../priority/priority.html");
doh.registerUrl("priorityWithDeps", "../priority/priorityWithDeps/priorityWithDeps.html");
doh.registerUrl("prioritySingleCall", "../priority/prioritySingleCall.html");

if (typeof Worker !== "undefined") {
Expand Down
83 changes: 0 additions & 83 deletions tests/priority/priorityCallback/priorityCallback.html

This file was deleted.

65 changes: 65 additions & 0 deletions tests/priority/priorityWithDeps/priorityWithDeps.html
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Priority With Deps Test</title>
<link rel="stylesheet" href="style/qunit.css" type="text/css" media="screen">
<script src="script/lib/qunit.js"></script>

<script type="text/javascript" src="../../doh/runner.js"></script>
<script type="text/javascript" src="../../doh/_browserRunner.js"></script>

<script>
var master = new doh.Deferred();

doh.register(
"priorityWithDeps",
[
{
name: "priorityWithDeps",
timeout: 3000,
runTest: function () {
return master;
}
}
]
);
doh.run();

require = {
baseUrl: 'script',
// should also work
//deps: ['req/begin', 'req/config', 'req/utils/utils'],
deps: ['req/bootstrap'],
priority: ['req/bootstrap'],
callback: function() {

doh.is(ip.begin, 'begin');
doh.is(ip.config.state, 'alpha');
doh.is(ip.utils.test(), 'utils Hello require');

master.callback(true);
}
};
</script>

<script src="../../../require.js"></script>
<script>
</script>

</head>
<body>
<h1>require.js: Priority With Deps Test</h1>
<p>Tests a priority with a callback, and with the priority item needing
to still load some modules, not all of the modules are included in the
priority build layer.</p>
<p>Check console for messages</p>

<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>

</body>
</html>

0 comments on commit 79188c7

Please sign in to comment.