In JS, when a function that needs 1 argument is called with no arguments the argument gets the value null. This is not the case with the DOM method insertBefore that is a method of the Node. When called like below it works node1.insertBefore(node2, null) ...but when it is called like this node1.insertBefore(node2) it doesn't work
Hmm...I believe ECMA says that unspecified arguments should default to undefined. It turns out that we're not failing silently - we generate an error in the console window. The JS->XPCOM glue code used by the DOM currently enforces that the correct number of arguments be passed to a DOM method. Passing null in place of unspecified arguments wouldn't be techinically correct either. Brendan, any thoughts?
Couple of generic JS points: 1. Omitted trailing arguments in a call expression result in undefined, not null, values being passed for the corresponding formal parameters. 2. In ECMAv2 and our JS implementation, you may use the global predefined property 'undefined' to denote the undefined value. 3. Native methods are free to throw an exception or error if not given the desired number of actual arguments. All that said, I wonder whether we shouldn't allow trailing arguments to be omitted where sensible defaults can be imputed. Vidur, did the DOM working group consider this issue in language bindings? What do you think can be done for methods such as insertBefore? /be
The DOM WG was silent on this matter, of course. It may be possible for us to allow for omitted trailing arguments, but it probably wouldn't be compatible with other implementations (specifically, IE). If we were to allow them, I'm not sure how we'd represent optional (or defaulted) arguments in IDL. We could just pass along null to the native methods for unspecified trailing object arguments - that would address this specific case, but not the general issue.
Adding some JS and XPIDL guys. If we ever subsume DOM IDL by XPIDL, we'll need to handle optional trailing args (document.write, where the number of args is unbounded; document.open, where the second arg is optional). Comments on how to express this in IDL solicited. In JS, you can check how many actuals, or you can check for non-null (and/or not undefined) trailing args, but be careful with non-null checks: in JS, null == undefined while null !== undefined, while when using the JS API, JSVAL_IS_NULL is true only for null, and JSVAL_IS_VOID is true only for the undefined value. /be
Well...since this is an ongoing discussion and there isn't any urgency in dealing with the bug, I'm going to move this bug forward.
I'm still not inclined to address this one immediately (especially considering my current bug count). XPConnect guys, care to comment?
Status: ASSIGNED → RESOLVED
Last Resolved: 19 years ago
Resolution: --- → INVALID
I'm marking this INVALID because it's working as designed and desired, and we want to get stuff like this off vidur's bug-radar.
Mass update of qa contact
QA Contact: phillip → janc
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.