| 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 functions. | 29 // Test the mirror object for functions. |
| 30 | 30 |
| 31 function MirrorRefCache(json_refs) { |
| 32 var tmp = eval('(' + json_refs + ')'); |
| 33 this.refs_ = []; |
| 34 for (var i = 0; i < tmp.length; i++) { |
| 35 this.refs_[tmp[i].handle] = tmp[i]; |
| 36 } |
| 37 } |
| 38 |
| 39 MirrorRefCache.prototype.lookup = function(handle) { |
| 40 return this.refs_[handle]; |
| 41 } |
| 42 |
| 31 function testFunctionMirror(f) { | 43 function testFunctionMirror(f) { |
| 32 // Create mirror and JSON representation. | 44 // Create mirror and JSON representation. |
| 33 var mirror = debug.MakeMirror(f); | 45 var mirror = debug.MakeMirror(f); |
| 34 var json = mirror.toJSONProtocol(true); | 46 var serializer = debug.MakeMirrorSerializer(); |
| 47 var json = serializer.serializeValue(mirror); |
| 48 var refs = new MirrorRefCache(serializer.serializeReferencedObjects()); |
| 35 | 49 |
| 36 // Check the mirror hierachy. | 50 // Check the mirror hierachy. |
| 37 assertTrue(mirror instanceof debug.Mirror); | 51 assertTrue(mirror instanceof debug.Mirror); |
| 38 assertTrue(mirror instanceof debug.ValueMirror); | 52 assertTrue(mirror instanceof debug.ValueMirror); |
| 39 assertTrue(mirror instanceof debug.ObjectMirror); | 53 assertTrue(mirror instanceof debug.ObjectMirror); |
| 40 assertTrue(mirror instanceof debug.FunctionMirror); | 54 assertTrue(mirror instanceof debug.FunctionMirror); |
| 41 | 55 |
| 42 // Check the mirror properties. | 56 // Check the mirror properties. |
| 43 assertTrue(mirror.isFunction()); | 57 assertTrue(mirror.isFunction()); |
| 44 assertEquals('function', mirror.type()); | 58 assertEquals('function', mirror.type()); |
| 45 assertFalse(mirror.isPrimitive()); | 59 assertFalse(mirror.isPrimitive()); |
| 46 assertEquals("Function", mirror.className()); | 60 assertEquals("Function", mirror.className()); |
| 47 assertEquals(f.name, mirror.name()); | 61 assertEquals(f.name, mirror.name()); |
| 48 assertTrue(mirror.resolved()); | 62 assertTrue(mirror.resolved()); |
| 49 assertEquals(f.toString(), mirror.source()); | 63 assertEquals(f.toString(), mirror.source()); |
| 50 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); | 64 assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); |
| 51 assertTrue(mirror.protoObject() instanceof debug.Mirror); | 65 assertTrue(mirror.protoObject() instanceof debug.Mirror); |
| 52 assertTrue(mirror.prototypeObject() instanceof debug.Mirror); | 66 assertTrue(mirror.prototypeObject() instanceof debug.Mirror); |
| 53 | 67 |
| 54 // Test text representation | 68 // Test text representation |
| 55 assertEquals(f.toString(), mirror.toText()); | 69 assertEquals(f.toString(), mirror.toText()); |
| 56 | 70 |
| 57 // Parse JSON representation and check. | 71 // Parse JSON representation and check. |
| 58 var fromJSON = eval('(' + json + ')'); | 72 var fromJSON = eval('(' + json + ')'); |
| 59 assertEquals('function', fromJSON.type); | 73 assertEquals('function', fromJSON.type); |
| 60 assertEquals('Function', fromJSON.className); | 74 assertEquals('Function', fromJSON.className); |
| 61 assertEquals('function', fromJSON.constructorFunction.type); | 75 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); |
| 62 assertEquals('Function', fromJSON.constructorFunction.name); | 76 assertEquals('Function', refs.lookup(fromJSON.constructorFunction.ref).name); |
| 63 assertTrue(fromJSON.resolved); | 77 assertTrue(fromJSON.resolved); |
| 64 assertEquals(f.name, fromJSON.name); | 78 assertEquals(f.name, fromJSON.name); |
| 65 assertEquals(f.toString(), fromJSON.source); | 79 assertEquals(f.toString(), fromJSON.source); |
| 66 | 80 |
| 67 // Check the formatted text (regress 1142074). | 81 // Check the formatted text (regress 1142074). |
| 68 assertEquals(f.toString(), fromJSON.text); | 82 assertEquals(f.toString(), fromJSON.text); |
| 69 } | 83 } |
| 70 | 84 |
| 71 | 85 |
| 72 // Test a number of different functions. | 86 // Test a number of different functions. |
| 73 testFunctionMirror(function(){}); | 87 testFunctionMirror(function(){}); |
| 74 testFunctionMirror(function a(){return 1;}); | 88 testFunctionMirror(function a(){return 1;}); |
| 75 testFunctionMirror(Math.sin); | 89 testFunctionMirror(Math.sin); |
| OLD | NEW |