Skip to content

Commit

Permalink
Allow to define modules whose name appears on Object.prototype (#196)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
raphinesse authored Apr 28, 2019
1 parent dd8b78f commit a5dec0a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scripts/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var define;
};

define = function (id, factory) {
if (modules[id]) {
if (Object.prototype.hasOwnProperty.call(modules, id)) {
throw 'module ' + id + ' already defined';
}

Expand Down
2 changes: 1 addition & 1 deletion test/test.require.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('require + define', function () {
});

// 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();
Expand Down

0 comments on commit a5dec0a

Please sign in to comment.