Permalink
Browse files

Thanks to a great test case from Gilles Ruppert, tracked down an issu…

…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 79188c726f90aefa34a16435e929a7bb98098358
View
@@ -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,
@@ -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.
*/
@@ -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;
}
@@ -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,
@@ -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;
View
@@ -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") {
@@ -1,83 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>require.js: Priority With Callback Test</title>
- <script type="text/javascript" src="../../doh/runner.js"></script>
- <script type="text/javascript" src="../../doh/_browserRunner.js"></script>
- <script>
- var master = new doh.Deferred(),
- count = 0,
- ranCarousel = false,
-
- require = {
- baseUrl: "./",
- priority: ["bootstrap", "app"],
- deps: ["appConfig"],
- callback: function () {
-
- appConfig.service = 'tv'
- count += 1;
-
- //Make sure callback is only called once.
- doh.is(1, count);
-
- doh.is('alpha', appConfig.state);
- doh.is('bootstrap', appConfig.bootstrap);
- doh.is('begin', begin.name);
- }
- };
- </script>
- <script type="text/javascript" src="../../../require.js"></script>
- <script type="text/javascript">
- doh.register(
- "priorityCallback",
- [
- {
- name: "priorityCallback",
- timeout: 5000,
- runTest: function () {
- return master;
- }
- }
- ]
- );
- doh.run();
-
- function verifyFunc() {
- var regExp = /begin|appConfig|Carousel/,
- i,
- scripts = document.getElementsByTagName("script");
- for (i = scripts.length - 1; i > -1; i--) {
- doh.f(regExp.test(scripts[i].src));
- }
-
- doh.is(true, ranCarousel);
- master.callback(true);
- }
-
- //Account for requiring this test with a version of require.js that
- //does not have require.ready built in.
- if (require.ready) {
- require.ready(verifyFunc);
- } else {
- setTimeout(verifyFunc, 3000);
- }
- </script>
-</head>
-<body>
- <h1>require.js: Priority With Callback Test</h1>
- <p>Check console for messages</p>
- <script>
- require(["Carousel"], function (Carousel) {
- var c = new Carousel(appConfig.service);
-
- doh.is('alpha', appConfig.state);
- doh.is('bootstrap', appConfig.bootstrap);
- doh.is('begin', begin.name);
- doh.is('Carousel', c.someType);
- doh.is('tv', c.service);
- ranCarousel = true;
- });
- </script>
-</body>
-</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>
Oops, something went wrong.

0 comments on commit 79188c7

Please sign in to comment.