Allow to define modules whose name appears on `Object.prototype` (#196)
One of the CommonJS tests adopted in #195 exposed a defect in Cordova's module system:
When trying to define a module with a name that also is a property of Object.prototype, an exception would occur.
diff --git a/src/scripts/require.js b/src/scripts/require.js
index 24c6a16..5656bfa 100644
--- a/src/scripts/require.js
+++ b/src/scripts/require.js
@@ -67,7 +67,7 @@
};
define = function (id, factory) {
- if (modules[id]) {
+ if (Object.prototype.hasOwnProperty.call(modules, id)) {
throw 'module ' + id + ' already defined';
}
diff --git a/test/test.require.js b/test/test.require.js
index b66e9ab..ace7616 100644
--- a/test/test.require.js
+++ b/test/test.require.js
@@ -231,7 +231,7 @@
});
// Adapted version of CommonJS test `hasOwnProperty`
- xit('Test#018 : allows properties of Object.prototype as module names', () => {
+ it('Test#018 : allows properties of Object.prototype as module names', () => {
expect(() => {
define('hasOwnProperty', jasmine.createSpy());
}).not.toThrow();