[Pkg-javascript-commits] [dojo] 108/149: fixes #18123, require.undef with loader plugins

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:53 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository dojo.

commit ba2d73d1ea5d99e91b1754b5291472a3c84f88a6
Author: chuckd <chuckd at us.ibm.com>
Date:   Sat Dec 26 05:59:43 2015 -0700

    fixes #18123, require.undef with loader plugins
---
 dojo.js                                |  4 ++--
 tests/unit/all.js                      |  1 +
 tests/unit/loader_tests/all.js         |  4 ++++
 tests/unit/loader_tests/undefPlugin.js | 44 ++++++++++++++++++++++++++++++++++
 tests/unit/support/foobarPlugin.js     |  9 +++++++
 5 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/dojo.js b/dojo.js
index 587b7a8..fc9bf5d 100644
--- a/dojo.js
+++ b/dojo.js
@@ -1161,7 +1161,7 @@
 				var prid = resolvePluginResourceId(plugin, pseudoPluginResource.prid, pseudoPluginResource.req.module),
 					mid = plugin.dynamic ? pseudoPluginResource.mid.replace(/waitingForPlugin$/, prid) : (plugin.mid + "!" + prid),
 					pluginResource = mix(mix({}, pseudoPluginResource), {mid:mid, prid:prid, injected:0});
-				if(!modules[mid]){
+				if(!modules[mid] || !modules[mid].injected /*for require.undef*/){
 					// create a new (the real) plugin resource and inject it normally now that the plugin is on board
 					injectPlugin(modules[mid] = pluginResource);
 				} // else this was a duplicate request for the same (plugin, rid) for a nondynamic plugin
@@ -1315,7 +1315,7 @@
 			// This is useful for testing frameworks (at least).
 			var module = getModule(moduleId, referenceModule);
 			setArrived(module);
-			mix(module, {def:0, executed:0, injected:0, node:0});
+			mix(module, {def:0, executed:0, injected:0, node:0, load:0});
 		};
 	}
 
diff --git a/tests/unit/all.js b/tests/unit/all.js
index 7be118b..d51c14a 100644
--- a/tests/unit/all.js
+++ b/tests/unit/all.js
@@ -21,6 +21,7 @@ define([
 	'./json',
 	'./keys',
 	'./loadInit',
+	'./loader_tests/all',
 	'./number',
 	'./on',
 	'./on/debounce',
diff --git a/tests/unit/loader_tests/all.js b/tests/unit/loader_tests/all.js
new file mode 100644
index 0000000..ed35ea2
--- /dev/null
+++ b/tests/unit/loader_tests/all.js
@@ -0,0 +1,4 @@
+define([
+	'./undefPlugin'
+], function () {
+});
diff --git a/tests/unit/loader_tests/undefPlugin.js b/tests/unit/loader_tests/undefPlugin.js
new file mode 100644
index 0000000..323fbbd
--- /dev/null
+++ b/tests/unit/loader_tests/undefPlugin.js
@@ -0,0 +1,44 @@
+define([ 
+    'require',
+    'intern!object', 
+    'intern/chai!assert', 
+    '../../../Deferred',
+    '../../../has' 
+], function(require, registerSuite, assert, Deferred, has) {
+
+    function testIt(expected, fooValue, barValue) {
+        has.add("foo", fooValue, true, true);
+        has.add("bar", barValue, true, true);
+        var dfd = new Deferred();
+        require([ "../support/foobarPlugin!" ], function(data) {
+            assert.strictEqual(data, expected);
+            dfd.resolve();
+        });
+        return dfd;
+    }
+
+    registerSuite({
+        name : 'dojo/loader_tests/undefPlugin',
+        setup : function() {
+            require({async:true});  // only fails in async mode
+        },
+        beforeEach : function() {
+            require.undef('../support/foobarPlugin!');
+            require.undef('../support/foobarPlugin');
+        },
+        teardown : function() {
+            require.undef('../../support/foobarPlugin!');
+            require.undef('../../support/foobarPlugin');
+        },
+        expectFoo : function() {
+            return testIt("foo", true, false);
+        },
+        expectBar : function() {
+            return testIt("bar", false, true);
+        },
+        expectUndefined : function() {
+            return testIt("undefined", false, false);
+        }
+    });
+
+});
diff --git a/tests/unit/support/foobarPlugin.js b/tests/unit/support/foobarPlugin.js
new file mode 100644
index 0000000..bb1b272
--- /dev/null
+++ b/tests/unit/support/foobarPlugin.js
@@ -0,0 +1,9 @@
+define(["dojo/has"], function(has) {
+	/* Loads a string based on the value of defined features */
+	var data = has("foo") ? "foo" : has("bar") ? "bar" : "undefined";
+	return {
+		load: function(id, parentRequire, loaded) {
+			loaded(data);
+		}
+	}
+});
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list