Closed Bug 592872 Opened 14 years ago Closed 12 years ago

Web Console cleanup: NodeFactory redeclares the "factory" function

Categories

(DevTools :: Console, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: pcwalton, Assigned: msucan)

References

Details

(Whiteboard: [cleanup] [post-fx-4] [console-1] [fixed by bug 673148])

The NodeFactory function in HUDService.jsm looks like this: function NodeFactory(aFactoryType, aNameSpace, aDocument) { // aDocument is presumed to be a XULDocument if (aFactoryType == "text") { function factory(aText) { return aDocument.createTextNode(aText); } return factory; } else { if (aNameSpace == "xul") { function factory(aTag) { return aDocument.createElement(aTag); } return factory; } } } Redeclaring the "factory" function like this is not actually legal in standard JavaScript. IMHO the functions should have different names.
Whiteboard: [cleanup] [post-fx-4] → [cleanup] [post-fx-4] [console-1]
The code is now: function NodeFactory(aFactoryType, ignored, aDocument) { // aDocument is presumed to be a XULDocument if (aFactoryType == "text") { return function factory(aText) { return aDocument.createTextNode(aText); } } else if (aFactoryType == "xul") { return function factory(aTag) { return aDocument.createElement(aTag); } } else { throw new Error('NodeFactory: Unknown factory type: ' + aFactoryType); } } Which is AFAIK valid.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → INVALID
Component: Developer Tools → Developer Tools: Console
QA Contact: developer.tools → developer.tools.console
Version: unspecified → Trunk
Sonny: there are two functions in the code you pasted, both are named "factory", which is not legal in standard JavaScript. The problem is still valid in the current Web Console code.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
And even if they were named differently, function declarations in blocks should be avoided: https://developer.mozilla.org/en/JavaScript/Guide/Functions
This was most-likely fixed by bug 673148.
Assignee: nobody → mihai.sucan
Status: REOPENED → RESOLVED
Closed: 13 years ago12 years ago
Resolution: --- → FIXED
Whiteboard: [cleanup] [post-fx-4] [console-1] → [cleanup] [post-fx-4] [console-1] [fixed by bug 673148]
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.