Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
prohibit use of both define() and module.setExports() at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Jan 19, 2011
1 parent 86bd17a commit 54872dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/api-utils/lib/securable-module.js
Expand Up @@ -291,6 +291,12 @@
careful to leave self.modules[path] alone, as it will have
been modified in the asyncMain() callback-handling code,
fired during sandbox.evaluate(). */
if (self.defineUsed[path]) {
// you can do one or the other, not both
throw new Error("define() was used, so module.exports= and "
+ "module.setExports() may not be used: "
+ path);
}
self.modules[path] = posteval_exports;
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/api-utils/tests/modules/dupeSetExports.js
@@ -0,0 +1,4 @@
define({name: "dupeSetExports"});

// so this should cause a failure
module.setExports("no no no");
10 changes: 10 additions & 0 deletions packages/api-utils/tests/test-set-exports.js
Expand Up @@ -8,6 +8,16 @@ exports.testSetExports = function(test) {
test.assertEqual(five, 5);
}

exports.testDupeSetExports = function(test) {
var passed = false;
try {
var dupe = require('modules/dupeSetExports');
} catch(e) {
passed = /define\(\) was used, so module\.exports= and module\.setExports\(\) may not be used/.test(e.toString());
}
test.assertEqual(passed, true, 'define() or setExports(), not both');
}

exports.testModule = function(test) {
// module.id is not cast in stone yet. For now, it's just the module name.
// In the future, it may include the package name too, or may possibly be a
Expand Down

0 comments on commit 54872dd

Please sign in to comment.