[whatwg] Fake Code

Kristof Zelechovski giecrilj at stegny.2a.pl
Wed Jul 30 00:27:10 PDT 2008

And this particular example should be recursive.  Unfolding inherently
recursive procedures with an explicit stack, perhaps to construct an
enumerator or to simulate a coroutine, is a technical detail that does not
belong here.

-----Original Message-----
From: whatwg-bounces at lists.whatwg.org
[mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Garrett Smith
Sent: Wednesday, July 30, 2008 8:46 AM
Subject: [whatwg] Fake Code

Examples should work.

Citation from:

The following JavaScript function shows how the tree walk could be
implemented. The root argument is the root of the tree to walk, and
the enter and exit arguments are callbacks that are called with the
nodes as they are entered and exited. [ECMA262]

function (root, enter, exit) {
  var node = root;
  start: do while (node) {
    if (node.firstChild) {
      node = node.firstChild;
      continue start;
    while (node) {
      if (node.nextSibling) {
        node = node.nextSibling;
        continue start;
      if (node == root)
        node = null;
        node = node.parentNode;

This code cannot be interpreted in a compliant implementation of
EcmaScript. It has more syntax errors than I can count. It is unclear
what the author thinks this code will do. If its intent were clearer,
and the syntax errors fewer, it might be possible for me to help out
by fixing them. The above code is not even close to ECMA262.

Examples should not contain errors.


More information about the whatwg mailing list