Closed Bug 964212 Opened 12 years ago Closed 12 years ago

Node.insertBefore() method should allow the second parameter being omitted

Categories

(Core :: DOM: Core & HTML, defect)

27 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: duanyao.ustc, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0 (Beta/Release) Build ID: 20140115144847 Steps to reproduce: Omit the second parameter of Node.insertBefore() method, e.g.: document.documentElement.insertBefore(document.createElement('div')); Actual results: An exception is thrown: TypeError: Not enough arguments to Node.insertBefore. Expected results: No exception, child node is appended to the parant node.
I known that the spec (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html) does not say that insertBefore(newChild, refChild)'s param refChild is optional, only say that null is allowed. However, chrome and IE do allow refChild being omitted or being `undefined`; firefox allow refChild being `undefined` but not omitted. Chrome and IE's behavior looks more natural to me; while firefox's behavior is a little confusing: if a param can be undefined/null, why it can't be omitted? So I suggest that firefox should follow chrome and IE's behavior. It even better if the spec could be revised to make parameter refChild optinal.
You're looking at an ancient spec. However, the current specification matches Firefox: <http://dom.spec.whatwg.org/#node>. If you want to append a child, use appendChild instead. If you think the spec should be changed, there's a "Participate" section at the top that explains where you can make that argument. (It's not here.)
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
Sorry, but I can't find a statement in the current spec says what insertBefore should do if the second param is omited. Do you think chrome and IE are incorrect here and I should report bugs to them instead? Regards.
If an argument is not explicitly marked as optional, it is required, and a TypeError is thrown when it is not passed. This is specified in IDL: http://heycam.github.io/webidl/#es-operations http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm Filing bugs on other browsers f they get this wrong is probably a good idea.
I'll think about it. Thank you!
You need to log in before you can comment on or make changes to this bug.