Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / toString-and-valueOf-override.html
blob9e7e4778c56641579f9965deffe8b92baf8efed5
1 <html>
2 <head>
3 <script>
4 function testToStringAndValueOf(title, type, object)
6 var results = [ title ];
7 try { addResult(type + ' : ' + object); } catch(e) { addResult(e); }
8 try { addResult('[' + type + '] : ' + [object]); } catch(e) { addResult(e); }
9 try { addResult('String(' + type + ') : ' + String(object)); } catch(e) { addResult(e); }
10 try { addResult('String([' + type + ']) : ' + String([object])); } catch(e) { addResult(e); }
11 try { addResult(type + '.toString : ' + object.toString); } catch(e) { addResult(e); }
12 try { var toString = object.toString; addResult(type + '.toString() (cached in variable) : ' + toString()); } catch(e) { addResult(e); }
13 try { addResult(type + '.toString() : ' + object.toString()); } catch(e) { addResult(e); }
14 try { addResult('[' + type + '].toString() : ' + [object].toString()); } catch(e) { addResult(e); }
15 try { addResult(type + '.valueOf() : ' + object.valueOf()); } catch(e) { addResult(e); }
16 try { addResult('[' + type + '].valueOf() : ' + [object].valueOf()); } catch(e) { addResult(e); }
17 return results.join('<br>') + '<br><br>';
19 function addResult(result)
21 results.push(result);
25 function test(resultsElement, type, object)
27 var results = '';
28 results += testToStringAndValueOf('Unmodified ' + type, type, object);
30 object.toString = function() { return "toString" }
31 object.valueOf = function() { return "valueOf" }
32 results += testToStringAndValueOf(type + ' with modified toString and valueOf', type, object);
34 object.toString = function() { return new Object(); }
35 results += testToStringAndValueOf(type + ' with modified toString that returns an Object', type, object);
37 object.toString = function() { return 'toString'; }
38 object.valueOf = function() { return new Object(); }
39 results += testToStringAndValueOf(type + ' with modified valueOf that returns an Object', type, object);
41 object.toString = function() { return new Object(); }
42 results += testToStringAndValueOf(type + ' with modified toString and valueOf that returns an Object', type, object);
44 object.toString = function() { throw "Exception"; }
45 object.valueOf = function() { return "valueOf"; }
46 results += testToStringAndValueOf(type + ' with modified toString that throws an exception', type, object);
48 object.toString = function() { return 'toString'; }
49 object.valueOf = function() { throw "Exception"; }
50 results += testToStringAndValueOf(type + ' with modified valueOf that throws an exception', type, object);
52 object.toString = function() { throw "Exception"; }
53 object.valueOf = function() { throw "Exception"; }
54 results += testToStringAndValueOf(type + ' with modified toString an valueOf that throw exceptions', type, object);
56 resultsElement.innerHTML += results + '<br>';
59 function runTests()
61 if (window.testRunner)
62 testRunner.dumpAsText();
64 var resultsElement = document.getElementById('results');
65 test(resultsElement, 'span', document.createElement('span'));
66 test(resultsElement, 'window', window);
67 test(resultsElement, 'Navigator', window.navigator);
68 test(resultsElement, 'History', window.history);
69 test(resultsElement, 'Selection', window.getSelection());
71 </script>
72 </head>
73 <body onload="runTests();">
74 <div id="results">
75 </div>
76 </body>
77 </html>