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 21 matching lines...) Expand all Loading... |
32 debug.PropertyAttribute.DontEnum | | 32 debug.PropertyAttribute.DontEnum | |
33 debug.PropertyAttribute.DontDelete; | 33 debug.PropertyAttribute.DontDelete; |
34 var expected_attributes = { | 34 var expected_attributes = { |
35 'source': all_attributes, | 35 'source': all_attributes, |
36 'global': all_attributes, | 36 'global': all_attributes, |
37 'ignoreCase': all_attributes, | 37 'ignoreCase': all_attributes, |
38 'multiline': all_attributes, | 38 'multiline': all_attributes, |
39 'lastIndex': debug.PropertyAttribute.DontEnum | debug.PropertyAttribute.DontDe
lete | 39 'lastIndex': debug.PropertyAttribute.DontEnum | debug.PropertyAttribute.DontDe
lete |
40 }; | 40 }; |
41 | 41 |
| 42 function MirrorRefCache(json_refs) { |
| 43 var tmp = eval('(' + json_refs + ')'); |
| 44 this.refs_ = []; |
| 45 for (var i = 0; i < tmp.length; i++) { |
| 46 this.refs_[tmp[i].handle] = tmp[i]; |
| 47 } |
| 48 } |
| 49 |
| 50 MirrorRefCache.prototype.lookup = function(handle) { |
| 51 return this.refs_[handle]; |
| 52 } |
| 53 |
42 function testRegExpMirror(r) { | 54 function testRegExpMirror(r) { |
43 // Create mirror and JSON representation. | 55 // Create mirror and JSON representation. |
44 var mirror = debug.MakeMirror(r); | 56 var mirror = debug.MakeMirror(r); |
45 var json = mirror.toJSONProtocol(true); | 57 var serializer = debug.MakeMirrorSerializer(); |
| 58 var json = serializer.serializeValue(mirror); |
| 59 var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); |
46 | 60 |
47 // Check the mirror hierachy. | 61 // Check the mirror hierachy. |
48 assertTrue(mirror instanceof debug.Mirror); | 62 assertTrue(mirror instanceof debug.Mirror); |
49 assertTrue(mirror instanceof debug.ValueMirror); | 63 assertTrue(mirror instanceof debug.ValueMirror); |
50 assertTrue(mirror instanceof debug.ObjectMirror); | 64 assertTrue(mirror instanceof debug.ObjectMirror); |
51 assertTrue(mirror instanceof debug.RegExpMirror); | 65 assertTrue(mirror instanceof debug.RegExpMirror); |
52 | 66 |
53 // Check the mirror properties. | 67 // Check the mirror properties. |
54 assertTrue(mirror.isRegExp()); | 68 assertTrue(mirror.isRegExp()); |
55 assertEquals('regexp', mirror.type()); | 69 assertEquals('regexp', mirror.type()); |
56 assertFalse(mirror.isPrimitive()); | 70 assertFalse(mirror.isPrimitive()); |
57 assertEquals(mirror.source(), r.source, 'source'); | |
58 assertEquals(mirror.global(), r.global, 'global'); | |
59 assertEquals(mirror.ignoreCase(), r.ignoreCase, 'ignoreCase'); | |
60 assertEquals(mirror.multiline(), r.multiline, 'multiline'); | |
61 for (var p in expected_attributes) { | 71 for (var p in expected_attributes) { |
62 assertEquals(mirror.property(p).attributes(), | 72 assertEquals(mirror.property(p).attributes(), |
63 expected_attributes[p], | 73 expected_attributes[p], |
64 p + ' attributes'); | 74 p + ' attributes'); |
65 } | 75 } |
66 | 76 |
67 // Test text representation | 77 // Test text representation |
68 assertEquals('/' + r.source + '/', mirror.toText()); | 78 assertEquals('/' + r.source + '/', mirror.toText()); |
69 | 79 |
70 // Parse JSON representation and check. | 80 // Parse JSON representation and check. |
71 var fromJSON = eval('(' + json + ')'); | 81 var fromJSON = eval('(' + json + ')'); |
72 assertEquals('regexp', fromJSON.type); | 82 assertEquals('regexp', fromJSON.type); |
73 assertEquals('RegExp', fromJSON.className); | 83 assertEquals('RegExp', fromJSON.className); |
74 assertEquals(fromJSON.source, r.source, 'source'); | |
75 assertEquals(fromJSON.global, r.global, 'global'); | |
76 assertEquals(fromJSON.ignoreCase, r.ignoreCase, 'ignoreCase'); | |
77 assertEquals(fromJSON.multiline, r.multiline, 'multiline'); | |
78 for (var p in expected_attributes) { | 84 for (var p in expected_attributes) { |
79 for (var i = 0; i < fromJSON.properties.length; i++) { | 85 for (var i = 0; i < fromJSON.properties.length; i++) { |
80 if (fromJSON.properties[i].name == p) { | 86 if (fromJSON.properties[i].name == p) { |
81 assertEquals(fromJSON.properties[i].attributes, | 87 assertEquals(expected_attributes[p], |
82 expected_attributes[p], | 88 fromJSON.properties[i].attributes, |
83 p + ' attributes'); | 89 'Unexpected value for ' + p + ' attributes'); |
| 90 assertEquals(mirror.property(p).propertyType(), |
| 91 fromJSON.properties[i].propertyType, |
| 92 'Unexpected value for ' + p + ' propertyType'); |
| 93 assertEquals(mirror.property(p).value().handle(), |
| 94 fromJSON.properties[i].ref, |
| 95 'Unexpected handle for ' + p); |
| 96 assertEquals(mirror.property(p).value().value(), |
| 97 refs.lookup(fromJSON.properties[i].ref).value, |
| 98 'Unexpected value for ' + p); |
84 } | 99 } |
85 } | 100 } |
86 } | 101 } |
87 } | 102 } |
88 | 103 |
89 | 104 |
90 // Test Date values. | 105 // Test Date values. |
91 testRegExpMirror(/x/); | 106 testRegExpMirror(/x/); |
92 testRegExpMirror(/[abc]/); | 107 testRegExpMirror(/[abc]/); |
93 testRegExpMirror(/[\r\n]/g); | 108 testRegExpMirror(/[\r\n]/g); |
94 testRegExpMirror(/a*b/gmi); | 109 testRegExpMirror(/a*b/gmi); |
OLD | NEW |