blob: 0711ff95aecf657e4070f88f069c4f6a1f7c09bf [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// 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
Ben Murdoch61f157c2016-09-16 13:49:30 +010028// Flags: --expose-debug-as debug
Steve Blocka7e24c12009-10-30 11:49:00 +000029// Test the mirror object for regular expression values
30
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000031var dont_enum = debug.PropertyAttribute.DontEnum;
32var dont_delete = debug.PropertyAttribute.DontDelete;
33var expected_prototype_attributes = {
34 'source': dont_enum,
35 'global': dont_enum,
36 'ignoreCase': dont_enum,
37 'multiline': dont_enum,
38 'unicode' : dont_enum,
Steve Blocka7e24c12009-10-30 11:49:00 +000039};
40
41function 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
49MirrorRefCache.prototype.lookup = function(handle) {
50 return this.refs_[handle];
51}
52
53function 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());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 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(),
Steve Blocka7e24c12009-10-30 11:49:00 +000077 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);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000087 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);
Steve Blocka7e24c12009-10-30 11:49:00 +000093}
94
95
96// Test Date values.
97testRegExpMirror(/x/);
98testRegExpMirror(/[abc]/);
99testRegExpMirror(/[\r\n]/g);
100testRegExpMirror(/a*b/gmi);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101testRegExpMirror(/(\u{0066}|\u{0062})oo/u);