Closed Bug 308626 Opened 19 years ago Closed 19 years ago

insertNode(document) throws wrong exception

Categories

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

x86
Windows XP
defect
Not set
minor

Tracking

()

RESOLVED INVALID

People

(Reporter: stryker330, Unassigned)

References

()

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4

range.insertNode(document) currently throws a HIERARCHY_REQUEST_ERR (code 3)
DOMException. It should throw a INVALID_NODE_TYPE_ERR (code 2) RangeException
instead.

Actually the current exception is probably correct, but I think
INVALID_NODE_TYPE_ERR is more correct.

In any case, Opera 8.0 has the expected behavior.

Reproducible: Always

Steps to Reproduce:
var range = document.createRange();
range.selectNode(document.body);
range.insertNode(document);
Actual Results:  
throw a HIERARCHY_REQUEST_ERR (code 3) DOMException

Expected Results:  
throw a INVALID_NODE_TYPE_ERR (code 2) RangeException
Attached file testcase
DOM Range spec says:

INVALID_NODE_TYPE_ERR
    If the container of an boundary-point of a Range is being set to either a
    node of an invalid type or a node with an ancestor of an invalid type.

That's not happening here, so it would be wrong to throw this exception.  Also
note that insertBefore() has _two_ descriptions in the range spec.  One
description is
(http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level-2-Range-Inserting):

  void insertNode(in Node n) raises(RangeException);

but the other description, which comes with the Range interface is
(http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level2-Range-method-insertNode)
clearly says:

  HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of
  a type that does not allow children of the type of newNode or if newNode is an
  ancestor of the container.

So sounds like we're doing exactly what the spec says and that you should file a
bug on Opera.

Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
Component: DOM: Traversal-Range → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: