open-parameters-toString.htm (1008B)
1 <!doctype html> 2 <title>XMLHttpRequest: open() attempts to toString its string parameters</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <div id="log"></div> 6 <script> 7 test(() => { 8 let log = []; 9 let expected = [ 10 'method', 11 'url', 12 // NOTE: 'async' intentionally missing 13 'username', 14 'password', 15 ]; 16 17 let xhr = new XMLHttpRequest; 18 xhr.open( 19 { 20 toString() { 21 log.push('method'); 22 return 'get'; 23 }, 24 }, 25 { 26 toString() { 27 log.push('url'); 28 return location.href; 29 }, 30 }, 31 // NOTE: ToBoolean should not invoke valueOf 32 { 33 valueOf() { 34 log.push('async'); 35 return true; 36 }, 37 }, 38 { 39 toString() { 40 log.push('username'); 41 return 'username'; 42 }, 43 }, 44 { 45 toString() { 46 log.push('password'); 47 return 'password'; 48 }, 49 } 50 ); 51 52 assert_array_equals(log, expected); 53 }); 54 </script>