OLD | NEW |
| (Empty) |
1 // Copyright 2008 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
27 | |
28 // Flags: --expose-debug-as debug | |
29 // Test the mirror object for regular expression values | |
30 | |
31 var dont_enum = debug.PropertyAttribute.DontEnum; | |
32 var dont_delete = debug.PropertyAttribute.DontDelete; | |
33 var expected_prototype_attributes = { | |
34 'source': dont_enum, | |
35 'global': dont_enum, | |
36 'ignoreCase': dont_enum, | |
37 'multiline': dont_enum, | |
38 'unicode' : dont_enum, | |
39 }; | |
40 | |
41 function MirrorRefCache(json_refs) { | |
42 var tmp = eval('(' + json_refs + ')'); | |
43 this.refs_ = []; | |
44 for (var i = 0; i < tmp.length; i++) { | |
45 this.refs_[tmp[i].handle] = tmp[i]; | |
46 } | |
47 } | |
48 | |
49 MirrorRefCache.prototype.lookup = function(handle) { | |
50 return this.refs_[handle]; | |
51 } | |
52 | |
53 function testRegExpMirror(r) { | |
54 // Create mirror and JSON representation. | |
55 var mirror = debug.MakeMirror(r); | |
56 var serializer = debug.MakeMirrorSerializer(); | |
57 var json = JSON.stringify(serializer.serializeValue(mirror)); | |
58 var refs = new MirrorRefCache( | |
59 JSON.stringify(serializer.serializeReferencedObjects())); | |
60 | |
61 // Check the mirror hierachy. | |
62 assertTrue(mirror instanceof debug.Mirror); | |
63 assertTrue(mirror instanceof debug.ValueMirror); | |
64 assertTrue(mirror instanceof debug.ObjectMirror); | |
65 assertTrue(mirror instanceof debug.RegExpMirror); | |
66 | |
67 // Check the mirror properties. | |
68 assertTrue(mirror.isRegExp()); | |
69 assertEquals('regexp', mirror.type()); | |
70 assertFalse(mirror.isPrimitive()); | |
71 assertEquals(dont_enum | dont_delete, | |
72 mirror.property('lastIndex').attributes()); | |
73 var proto_mirror = mirror.protoObject(); | |
74 for (var p in expected_prototype_attributes) { | |
75 assertEquals(expected_prototype_attributes[p], | |
76 proto_mirror.property(p).attributes(), | |
77 p + ' attributes'); | |
78 } | |
79 | |
80 // Test text representation | |
81 assertEquals('/' + r.source + '/', mirror.toText()); | |
82 | |
83 // Parse JSON representation and check. | |
84 var fromJSON = eval('(' + json + ')'); | |
85 assertEquals('regexp', fromJSON.type); | |
86 assertEquals('RegExp', fromJSON.className); | |
87 assertEquals('lastIndex', fromJSON.properties[0].name); | |
88 assertEquals(dont_enum | dont_delete, fromJSON.properties[0].attributes); | |
89 assertEquals(mirror.property('lastIndex').propertyType(), | |
90 fromJSON.properties[0].propertyType); | |
91 assertEquals(mirror.property('lastIndex').value().value(), | |
92 refs.lookup(fromJSON.properties[0].ref).value); | |
93 } | |
94 | |
95 | |
96 // Test Date values. | |
97 testRegExpMirror(/x/); | |
98 testRegExpMirror(/[abc]/); | |
99 testRegExpMirror(/[\r\n]/g); | |
100 testRegExpMirror(/a*b/gmi); | |
101 testRegExpMirror(/(\u{0066}|\u{0062})oo/u); | |
OLD | NEW |