| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
| 29 // Test the mirror object for string values | 29 // Test the mirror object for string values |
| 30 | 30 |
| 31 const kMaxProtocolStringLength = 80; // Constant from mirror-delay.js |
| 32 |
| 31 function testStringMirror(s) { | 33 function testStringMirror(s) { |
| 32 // Create mirror and JSON representation. | 34 // Create mirror and JSON representation. |
| 33 var mirror = debug.MakeMirror(s); | 35 var mirror = debug.MakeMirror(s); |
| 34 var json = mirror.toJSONProtocol(true); | 36 var json = mirror.toJSONProtocol(true); |
| 35 | 37 |
| 36 // Check the mirror hierachy. | 38 // Check the mirror hierachy. |
| 37 assertTrue(mirror instanceof debug.Mirror); | 39 assertTrue(mirror instanceof debug.Mirror); |
| 38 assertTrue(mirror instanceof debug.ValueMirror); | 40 assertTrue(mirror instanceof debug.ValueMirror); |
| 39 assertTrue(mirror instanceof debug.StringMirror); | 41 assertTrue(mirror instanceof debug.StringMirror); |
| 40 | 42 |
| 41 // Check the mirror properties. | 43 // Check the mirror properties. |
| 42 assertTrue(mirror.isString()); | 44 assertTrue(mirror.isString()); |
| 43 assertEquals('string', mirror.type()); | 45 assertEquals('string', mirror.type()); |
| 44 assertTrue(mirror.isPrimitive()); | 46 assertTrue(mirror.isPrimitive()); |
| 45 | 47 |
| 46 // Test text representation | 48 // Test text representation |
| 47 assertEquals(s, mirror.toText()); | 49 if (s.length <= kMaxProtocolStringLength) { |
| 50 assertEquals(s, mirror.toText()); |
| 51 } else { |
| 52 assertEquals(s.substring(0, kMaxProtocolStringLength), |
| 53 mirror.toText().substring(0, kMaxProtocolStringLength)); |
| 54 } |
| 48 | 55 |
| 49 // Parse JSON representation and check. | 56 // Parse JSON representation and check. |
| 50 var fromJSON = eval('(' + json + ')'); | 57 var fromJSON = eval('(' + json + ')'); |
| 51 assertEquals('string', fromJSON.type); | 58 assertEquals('string', fromJSON.type); |
| 52 assertEquals(s, fromJSON.value); | 59 if (s.length <= kMaxProtocolStringLength) { |
| 60 assertEquals(s, fromJSON.value); |
| 61 } else { |
| 62 assertEquals(s.substring(0, kMaxProtocolStringLength), |
| 63 fromJSON.value.substring(0, kMaxProtocolStringLength)); |
| 64 assertEquals(fromJSON.fromIndex, 0); |
| 65 assertEquals(fromJSON.toIndex, kMaxProtocolStringLength); |
| 66 } |
| 53 } | 67 } |
| 54 | 68 |
| 55 Number =2; | |
| 56 | |
| 57 // Test a number of different strings. | 69 // Test a number of different strings. |
| 58 testStringMirror(''); | 70 testStringMirror(''); |
| 59 testStringMirror('abcdABCD'); | 71 testStringMirror('abcdABCD'); |
| 60 testStringMirror('1234'); | 72 testStringMirror('1234'); |
| 61 testStringMirror('"'); | 73 testStringMirror('"'); |
| 62 testStringMirror('"""'); | 74 testStringMirror('"""'); |
| 63 testStringMirror("'"); | 75 testStringMirror("'"); |
| 64 testStringMirror("'''"); | 76 testStringMirror("'''"); |
| 65 testStringMirror("'\"'"); | 77 testStringMirror("'\"'"); |
| 66 testStringMirror('\\'); | 78 testStringMirror('\\'); |
| 67 testStringMirror('\b\t\n\f\r'); | 79 testStringMirror('\b\t\n\f\r'); |
| 68 testStringMirror('\u0001\u0002\u001E\u001F'); | 80 testStringMirror('\u0001\u0002\u001E\u001F'); |
| 69 testStringMirror('"a":1,"b":2'); | 81 testStringMirror('"a":1,"b":2'); |
| 82 |
| 83 var s = "1234567890" |
| 84 s = s + s + s + s + s + s + s + s; |
| 85 assertEquals(kMaxProtocolStringLength, s.length); |
| 86 testStringMirror(s); |
| 87 s = s + 'X'; |
| 88 testStringMirror(s); |
| OLD | NEW |