Re: [whatwg] WebIDL and HTML5

On Tue, Aug 26, 2008 at 8:04 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Garrett Smith wrote:
>>
>> Null is not the empty string.
>
> No one claimed that it was. A number of DOM methods are specified as
> treating them equivalently, however.
>

Well, I'm not so sure. I corresponded with Jonas who indicated that he
though null should convert to "". Now Maciej seems to be confused
about textContent = null. The result should be no effect.

And we can see that the implementation of textContent = null "feature"
was not per spec in Firefox or Webkit, so it is apparently quite
confusing.

I have created a demo which expects that setting textContent to null
will have no effect, as per DOM Core 3. The deom does not take into my
opinion that setting textContent to null should result in the
textContent being "null"

<!DOCTYPE HTML>
<html lang="en">
<head>
	<title>Setting textContent to null</title>
<link rel="help"
href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent"/>
<link rel="author" title="Garrett Smith" href="mailto:dhtmlkitchen@gmail.com"/>
<style type="text/css">
    #pass {
        display: none;
        background: #0F0;
    }
    #fail {
        display: none;
        background: #F00;
    }
</style>
</head>
<body>
<div id="el">this is the test node.</div>
<script>
var el = document.getElementById('el');
var orig = el.textContent;

function fail() {
  var f = document.getElementById('fail');
  var found = el.textContent;
  f.style.display = "inline-block";
  f.textContent += ": expected '" + orig + "'" +
  ", found '" + found + "' (" + (typeof found) + ")";
}
function reset() {
	el.textContent = orig;
}
clicks = [];
function checkPass(i) {
  clicks[i] = 1;
  if(clicks[1] && clicks[2])
    document.getElementById('pass').style.display = "inline-block";
}
</script>

<button onclick="reset();el.textContent;el.textContent = null;
	if(el.textContent!=orig)fail();else checkPass(1);">el.textContent =
null</button>
<button onclick="reset();el.textContent =
'';checkPass(1);">el.textContent = ''</button>
<button onclick="reset();el.textContent = undefined;">el.textContent =
undefined</button>

<div id="fail">FAIL</div>
</body>
</html>

Results:
 Firefox 3.1, Webkit
  FAIL: expected 'this is the test node.', found '' (string)
 Opera:
  FAIL: expected 'this is the test node.', found 'null' (string)

I feel that Opera's behavior is ideal, even though it is non-standard.
I would like to ask that the DOM 3 recommendation to be changed so
that setting textContent = null sets the textContent to have the
string value "null". Reasons:
1) Widespread inconsistencies.
2) A feature not relied on (likely to break few, if any existing sites)
3) Would make debugging easier

Garrett

> -Boris
>
>

Received on Wednesday, 27 August 2008 03:13:30 UTC