39 lines
1.4 KiB
HTML
39 lines
1.4 KiB
HTML
<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>
|