NodeFilter constructor in Traversal: NS_ERROR_DOM_NOT_SUPPORTED_ERR

Discussion in 'Javascript' started by Patient Guy, Jul 25, 2006.

  1. Patient Guy

    Patient Guy Guest

    I am trying to write functions that manipulate objects representing
    dynamic tables in HTML documents in a more friendly way (to me).

    I do this by creating a table object (tableObject) through a constructor
    (code below) whose properties include .rows and .columns and arrays
    corresponding to cells, and I can just set/get values (probably through
    methods) to change the tables, with other functions adding and pruning
    DOM-related nodes to the table as the case may be.

    Within the constructor, I am trying to call a function described in the
    DOM Traversal specification for walking the nodes of the table tree, but I
    am getting an error:
    Error: Object cannot be created in this context =
    NS_ERROR_DOM_NOT_SUPPORTED_ERR

    The function being called is a NodeFilter constructor related to the
    Traversal spec. The system/browser being used is Firefox 1.5.0.4, which
    apparently implements this constructor, since I have included code which
    attempts to define the constructor IF it is not implemented/defined by
    other systems/browsers, and FF is returning the error (not my code).


    Anyone have an idea what the error is and what may be causing it?

    Google has a scarcity of results and none I can find that actually
    describe under what conditions the error code is/might be returned. I
    can't even find anything on the Mozilla site.


    ============= code fragment start ===============


    /*
    the tableObject constructor for an existing table document object
    --- argument 'documentID' is the value of the 'id' attribute of the
    table element in the HTML document which is to be characterized and
    manipulated
    */

    function tableObject(documentID)
    {
    var i, node, collection;
    if ((this.docObject = node = document.getElementById(documentID)) ==
    null)
    return (null);
    if (node.nodeName.toLowerCase() != "table")
    return (null);
    this.type = "tableObject";
    this.documentID = documentID;
    this.getDocumentId = function () {
    return (this.documentID);
    };
    this.getNode = function () {
    return (this.docObject);
    };
    // store the THEAD, TBODY, TFOOT and their TR and TH/TH nodes for
    // dynamic table

    /* The line immediately below calling a NodeFilter constructor
    is the one producing the error
    Error: Object cannot be created in this context =
    NS_ERROR_DOM_NOT_SUPPORTED_ERR
    */

    var nodeFilter = new NodeFilter(collectionsFilter);


    var twalk = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT,
    nodeFilter, false);
    if (typeof(childNodeType) != "string")
    {
    var i;
    if (typeof(childNodeType) != "object" ||
    typeof(childNodeType.length) == "undefined")
    return (null);
    }
    return (this);
    }


    function collectionsFilter(node, whatToFilter)
    {
    if (typeof(node) == "undefined" ||
    typeof(whatToFilter) == "undefined")
    return (NodeFilter.FILTER_REJECT);
    if (node.getNodeType() == Node.ELEMENT_NODE)
    for (i = 0; i < whatToFilter.length; i++)
    if (node.getNodeName().toLowerCase() ==
    whatToFilter.toLowerCase())
    return (NodeFilter.FILTER_ACCEPT);
    return (NodeFilter.FILTER_SKIP);
    }
    Patient Guy, Jul 25, 2006
    #1
    1. Advertising

  2. Patient Guy wrote:


    > /* The line immediately below calling a NodeFilter constructor
    > is the one producing the error
    > Error: Object cannot be created in this context =
    > NS_ERROR_DOM_NOT_SUPPORTED_ERR
    > */
    >
    > var nodeFilter = new NodeFilter(collectionsFilter);


    That is not supposed to work, NodeFilter as an object is only there so
    that you can access the constants (e.g. NodeFilter.SHOW_ELEMENT as you
    do below). You don't need any constructor function call, in the
    ECMAScript binding
    <http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ecma-script-binding.html>
    you simply pass in a function that takes a node as an argument and
    retuns a number so all you need is

    > var twalk = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT,
    > nodeFilter, false);


    e.g.
    document.createTreeWalker(
    node,
    NodeFilter.SHOW_ELEMENT,
    function (node) {
    // check node as needed and return one of
    // FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP
    },
    false
    )



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 26, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wynan James
    Replies:
    1
    Views:
    1,576
    Miguel De Anda
    Oct 6, 2003
  2. Big Jim

    Fous Traversal Policy

    Big Jim, Jan 27, 2006, in forum: Java
    Replies:
    0
    Views:
    395
    Big Jim
    Jan 27, 2006
  3. Replies:
    0
    Views:
    402
  4. Generic Usenet Account
    Replies:
    10
    Views:
    2,197
  5. Replies:
    0
    Views:
    87
Loading...

Share This Page