NodeFilter constructor in Traversal: NS_ERROR_DOM_NOT_SUPPORTED_ERR

P

Patient Guy

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);
}
 
M

Martin Honnen

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
)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top