Skip to content

Commit

Permalink
Merge pull request knockout#1756 from knockout/1756-hasOwnProperty-in…
Browse files Browse the repository at this point in the history
…-component-register-check

Component named "watch" will give an error in Firefox
  • Loading branch information
SteveSanderson committed Apr 9, 2015
2 parents 1768108 + e14b7d5 commit b1063ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions spec/components/defaultLoaderBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ describe('Components: Default loader', function() {
expect(ko.components.isRegistered(testComponentName)).toBe(false);
});

it('Allows registering component names that may conflict with properties on Object.prototype', function() {
var prototypeProperty = 'toString';

expect(ko.components.isRegistered(prototypeProperty)).toBe(false);
ko.components.register(prototypeProperty, {});
expect(ko.components.isRegistered(prototypeProperty)).toBe(true);

ko.components.unregister(prototypeProperty);
expect(ko.components.isRegistered(prototypeProperty)).toBe(false);
});

it('Throws if you try to register a component that is already registered', function() {
ko.components.register(testComponentName, {});

Expand Down
8 changes: 4 additions & 4 deletions src/components/defaultLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
}

defaultConfigRegistry[componentName] = config;
}
};

ko.components.isRegistered = function(componentName) {
return componentName in defaultConfigRegistry;
}
return defaultConfigRegistry.hasOwnProperty(componentName);
};

ko.components.unregister = function(componentName) {
delete defaultConfigRegistry[componentName];
ko.components.clearCachedDefinition(componentName);
}
};

ko.components.defaultLoader = {
'getConfig': function(componentName, callback) {
Expand Down

0 comments on commit b1063ed

Please sign in to comment.