blob: 0490b17f0262857ffd9da556e65f6991e13640e2 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2008 the V8 project authors. All rights reserved.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002// 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
31var all_attributes = debug.PropertyAttribute.ReadOnly |
32 debug.PropertyAttribute.DontEnum |
33 debug.PropertyAttribute.DontDelete;
34var expected_attributes = {
35 'source': all_attributes,
36 'global': all_attributes,
37 'ignoreCase': all_attributes,
38 'multiline': all_attributes,
39 'lastIndex': debug.PropertyAttribute.DontEnum | debug.PropertyAttribute.DontDelete
40};
41
ager@chromium.org32912102009-01-16 10:38:43 +000042function 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
50MirrorRefCache.prototype.lookup = function(handle) {
51 return this.refs_[handle];
52}
53
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000054function testRegExpMirror(r) {
55 // Create mirror and JSON representation.
56 var mirror = debug.MakeMirror(r);
ager@chromium.org32912102009-01-16 10:38:43 +000057 var serializer = debug.MakeMirrorSerializer();
58 var json = serializer.serializeValue(mirror);
59 var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000060
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());
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000071 for (var p in expected_attributes) {
72 assertEquals(mirror.property(p).attributes(),
73 expected_attributes[p],
74 p + ' attributes');
75 }
76
77 // Test text representation
78 assertEquals('/' + r.source + '/', mirror.toText());
79
80 // Parse JSON representation and check.
81 var fromJSON = eval('(' + json + ')');
82 assertEquals('regexp', fromJSON.type);
83 assertEquals('RegExp', fromJSON.className);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000084 for (var p in expected_attributes) {
85 for (var i = 0; i < fromJSON.properties.length; i++) {
86 if (fromJSON.properties[i].name == p) {
ager@chromium.org32912102009-01-16 10:38:43 +000087 assertEquals(expected_attributes[p],
88 fromJSON.properties[i].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);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000099 }
100 }
101 }
102}
103
104
105// Test Date values.
106testRegExpMirror(/x/);
107testRegExpMirror(/[abc]/);
108testRegExpMirror(/[\r\n]/g);
109testRegExpMirror(/a*b/gmi);