Skip to content

Commit

Permalink
Fix for exception thrown when documenting symbols with special names …
Browse files Browse the repository at this point in the history
…like "hasOwnProperty". Closes jsdoc#125.
  • Loading branch information
micmath committed Jun 7, 2012
1 parent 810dd7f commit ef37251
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 26 deletions.
5 changes: 3 additions & 2 deletions jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,11 @@ function main() {
docs.push(packageDocs);

function indexAll(docs) {
var lookupTable = {};
var lookupTable = {},
hasOwnProperty = Object.prototype.hasOwnProperty;

docs.forEach(function(doc) {
if ( !lookupTable.hasOwnProperty(doc.longname) ) {
if ( !hasOwnProperty.call(lookupTable, doc.longname) ) {
lookupTable[doc.longname] = [];
}
lookupTable[doc.longname].push(doc);
Expand Down
7 changes: 4 additions & 3 deletions node_modules/common/args.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion node_modules/common/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions rhino_modules/jsdoc/augment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

(function() {
var hasOwnProperty = Object.prototype.hasOwnProperty;

exports.addInherited = function(docs) {
var dependencies = mapDependencies(docs.index);
Expand All @@ -9,7 +10,7 @@
var additions = getAdditions(doclets, docs);
additions.forEach(function(doc) {
var name = doc.longname;
if (!(docs.index.hasOwnProperty(name))) {
if ( !hasOwnProperty.call(docs.index, name) ) {
docs.index[name] = [];
}
docs.index[name].push(doc);
Expand Down Expand Up @@ -78,7 +79,7 @@
var clone = o instanceof Array ? [] : {}, prop;

for (prop in o){
if ( o.hasOwnProperty(prop) ) {
if ( hasOwnProperty.call(o, prop) ) {
clone[prop] = (o[prop] instanceof Object)? doop(o[prop]) : o[prop];
}
}
Expand Down
3 changes: 2 additions & 1 deletion rhino_modules/jsdoc/borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exports.resolveBorrows = function(docs) {
});
}

var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
Deep clone a simple object.
@private
Expand All @@ -57,7 +58,7 @@ function doop(o) {
var clone = o instanceof Array ? [] : {}, prop;

for (prop in o){
if ( o.hasOwnProperty(prop) ) {
if ( hasOwnProperty.call(o, prop) ) {
clone[prop] = (o[prop] instanceof Object)? doop(o[prop]) : o[prop];
}
}
Expand Down
7 changes: 4 additions & 3 deletions rhino_modules/jsdoc/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

var Token = Packages.org.mozilla.javascript.Token,
currentParser = null,
currentSourceName = '';
currentSourceName = '',
hasOwnProperty = Object.prototype.hasOwnProperty;

/**
* @class
Expand Down Expand Up @@ -185,7 +186,7 @@ exports.Parser.prototype.astnodeToMemberof = function(node) {
id = 'astnode'+scope.enclosingFunction.hashCode();
doclet = this.refs[id];
if (doclet && doclet.meta.vars && basename in doclet.meta.vars) {
var alias = doclet.meta.vars.hasOwnProperty(basename)? doclet.meta.vars[basename] : false;
var alias = hasOwnProperty.call(doclet.meta.vars, basename)? doclet.meta.vars[basename] : false;
if (alias !== false) {
return [alias, basename];
}
Expand All @@ -195,7 +196,7 @@ exports.Parser.prototype.astnodeToMemberof = function(node) {
}
//First check to see if we have a global scope alias
doclet = this.refs["__global__"];
if (doclet && doclet.meta.vars && doclet.meta.vars.hasOwnProperty(basename)) {
if (doclet && doclet.meta.vars && hasOwnProperty.call(doclet.meta.vars, basename)) {
var alias = doclet.meta.vars[basename];
if (alias !== false) {
return [alias, basename];
Expand Down
11 changes: 6 additions & 5 deletions rhino_modules/jsdoc/tag/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

var _synonyms = {},
_definitions = {},
_namespaces = [];
_namespaces = [],
hasOwnProperty = Object.prototype.hasOwnProperty;

function _TagDefinition(title, etc) {
etc = etc || {};

this.title = dictionary.normalise(title);

for (var p in etc) {
if (etc.hasOwnProperty(p)) {
if ( hasOwnProperty.call(etc, p) ) {
this[p] = etc[p];
}
}
Expand Down Expand Up @@ -42,7 +43,7 @@ var dictionary = {
lookUp: function(title) {
title = dictionary.normalise(title);

if ( _definitions.hasOwnProperty(title) ) {
if ( hasOwnProperty.call(_definitions, title) ) {
return _definitions[title];
}

Expand All @@ -58,7 +59,7 @@ var dictionary = {
normalise: function(title) {
canonicalName = title.toLowerCase();

if ( _synonyms.hasOwnProperty(canonicalName) ) {
if ( hasOwnProperty.call(_synonyms, canonicalName) ) {
return _synonyms[canonicalName];
}

Expand All @@ -69,7 +70,7 @@ var dictionary = {
require('jsdoc/tag/dictionary/definitions').defineTags(dictionary);

for (var prop in dictionary) {
if (dictionary.hasOwnProperty(prop)) {
if ( hasOwnProperty.call(dictionary, prop) ) {
exports[prop] = dictionary[prop];
}
}
Expand Down
17 changes: 9 additions & 8 deletions templates/default/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var template = require('jsdoc/template'),
fs = require('fs'),
helper = require('jsdoc/util/templateHelper'),
scopeToPunc = { 'static': '.', 'inner': '~', 'instance': '#' };
scopeToPunc = { 'static': '.', 'inner': '~', 'instance': '#' },
hasOwnProperty = Object.prototype.hasOwnProperty;

/**
@global
Expand Down Expand Up @@ -245,7 +246,7 @@
if (moduleNames.length) {
nav += '<h3>Modules</h3><ul>';
moduleNames.forEach(function(m) {
if ( !seen.hasOwnProperty(m.longname) ) nav += '<li>'+linkto(m.longname, m.name)+'</li>';
if ( !hasOwnProperty.call(seen, m.longname) ) nav += '<li>'+linkto(m.longname, m.name)+'</li>';
seen[m.longname] = true;
});

Expand All @@ -259,7 +260,7 @@
if (externalNames.length) {
nav += '<h3>Externals</h3><ul>';
externalNames.forEach(function(e) {
if ( !seen.hasOwnProperty(e.longname) ) nav += '<li>'+linkto( e.longname, e.name.replace(/(^"|"$)/g, '') )+'</li>';
if ( !hasOwnProperty.call(seen, e.longname) ) nav += '<li>'+linkto( e.longname, e.name.replace(/(^"|"$)/g, '') )+'</li>';
seen[e.longname] = true;
});

Expand All @@ -279,7 +280,7 @@
moduleSameName[0].module = c;
}

if (!seen.hasOwnProperty(c.longname) ) nav += '<li>'+linkto(c.longname, c.name)+'</li>';
if ( !hasOwnProperty.call(seen, c.longname) ) nav += '<li>'+linkto(c.longname, c.name)+'</li>';
seen[c.longname] = true;
});

Expand All @@ -293,7 +294,7 @@
if (namespaceNames.length) {
nav += '<h3>Namespaces</h3><ul>';
namespaceNames.forEach(function(n) {
if ( !seen.hasOwnProperty(n.longname) ) nav += '<li>'+linkto(n.longname, n.name)+'</li>';
if ( !hasOwnProperty.call(seen, n.longname) ) nav += '<li>'+linkto(n.longname, n.name)+'</li>';
seen[n.longname] = true;
});

Expand All @@ -304,7 +305,7 @@
// if (constantNames.length) {
// nav += '<h3>Constants</h3><ul>';
// constantNames.forEach(function(c) {
// if ( !seen.hasOwnProperty(c.longname) ) nav += '<li>'+linkto(c.longname, c.name)+'</li>';
// if ( !hasOwnProperty.call(seen, c.longname) ) nav += '<li>'+linkto(c.longname, c.name)+'</li>';
// seen[c.longname] = true;
// });
//
Expand All @@ -318,7 +319,7 @@
if (mixinNames.length) {
nav += '<h3>Mixins</h3><ul>';
mixinNames.forEach(function(m) {
if ( !seen.hasOwnProperty(m.longname) ) nav += '<li>'+linkto(m.longname, m.name)+'</li>';
if ( !hasOwnProperty.call(seen, m.longname) ) nav += '<li>'+linkto(m.longname, m.name)+'</li>';
seen[m.longname] = true;
});

Expand All @@ -342,7 +343,7 @@
nav += '<h3>Global</h3><ul>';

globalNames.forEach(function(g) {
if ( g.kind !== 'typedef' && !seen.hasOwnProperty(g.longname) ) nav += '<li>'+linkto(g.longname, g.name)+'</li>';
if ( g.kind !== 'typedef' && !hasOwnProperty.call(seen, g.longname) ) nav += '<li>'+linkto(g.longname, g.name)+'</li>';
seen[g.longname] = true;
});

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/specialnames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** document me */
var hasOwnProperty = Object.prototype.hasOwnProperty;
10 changes: 10 additions & 0 deletions test/specs/documentation/specialnames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe("documenting symbols with special names", function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/specialnames.js'),
name = docSet.getByLongname('hasOwnProperty').filter(function($) {
return ! $.undocumented;
});

it('When a symbol has the documented name of "hasOwnProperty," JSDoc should correctly include it in the docs.', function() {
expect(name.length).toEqual(1);
});
});
4 changes: 3 additions & 1 deletion test/specs/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var hasOwnProperty = Object.prototype.hasOwnProperty;

exports.getDocSetFromFile = function(filename, parser) {
var sourceCode = readFile(__dirname + '/' + filename),
testParser = parser || new (require('jsdoc/src/parser')).Parser(),
Expand Down Expand Up @@ -26,7 +28,7 @@ exports.getDocSetFromFile = function(filename, parser) {
exports.indexAll = function(docs) {
var index = {};
docs.forEach(function(doc) {
if (!index.hasOwnProperty(doc.longname)){index[doc.longname] = [];}
if (!hasOwnProperty.call(index, doc.longname)){index[doc.longname] = [];}
index[doc.longname].push(doc);
});
docs.index = index;
Expand Down

0 comments on commit ef37251

Please sign in to comment.