1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<p>This page tests whether primitive conversions during equality tests properly
throw exceptions. If the test passes, you'll see a series of PASS messages below.
</p>
<hr>
<pre id="console"></pre>
<script>
function log(s)
{
document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
}
function shouldThrow(expression, exception, didCorrectlyThrow)
{
if (didCorrectlyThrow)
log("PASS: " + expression + " should throw a " + exception + ", and did.");
else
log("FAIL: " + expression + " should throw a " + exception + ", but didn't.");
}
if (window.testRunner)
testRunner.dumpAsText();
var o = {
valueOf: function() {
return { }; // should throw, because this is not a primitive value
},
toString: function() {
return { }; // should throw, because this is not a primitive value
}
};
shouldThrow("o == 'a'", "type error", (function() { try { o == 'a'; return false; } catch(e) { return e instanceof TypeError; } })());
shouldThrow("o != 'a'", "type error", (function() { try { o != 'a'; return false; } catch(e) { return e instanceof TypeError; } })());
shouldThrow("o == 0", "type error", (function() { try { o == 'a'; return false; } catch(e) { return e instanceof TypeError; } })());
shouldThrow("o != 0", "type error", (function() { try { o != 'a'; return false; } catch(e) { return e instanceof TypeError; } })());
</script>
|