Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / debug-stepin-property-function-call.js
1 // Copyright 2014 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 --nocrankshaft
29 // Get the Debug object exposed from the debug context global object.
30 Debug = debug.Debug
31
32 var exception = null;
33 var state = 1;
34
35 // Simple debug event handler which first time will cause 'step in' action
36 // to get into g.call and than check that execution is stopped inside
37 // function 'g'.
38 function listener(event, exec_state, event_data, data) {
39   try {
40     if (event == Debug.DebugEvent.Break) {
41       if (state == 1) {
42         exec_state.prepareStep(Debug.StepAction.StepIn, 3);
43         state = 2;
44       } else if (state == 2) {
45         assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0,
46           "source line: \"" + event_data.sourceLineText() + "\"");
47         state = 3;
48       }
49     }
50   } catch(e) {
51     print("Exception: " + e);
52     exception = e;
53   }
54 };
55
56 // Add the debug event listener.
57 Debug.setListener(listener);
58
59 var count = 0;
60 var obj = {
61   fun: function() {
62     ++count;
63     return count; // Expected to step
64   }
65 };
66 obj.fun2 = obj.fun;
67
68 function testCall_Dots() {
69   debugger;
70   obj.fun();
71 }
72
73 function testCall_Quotes() {
74   debugger;
75   obj["fun"]();
76 }
77
78 function testCall_Call() {
79   debugger;
80   obj.fun.call(obj);
81 }
82
83 function testCall_Apply() {
84   debugger;
85   obj.fun.apply(obj);
86 }
87
88 function testCall_Variable() {
89   var functionName = "fun";
90   debugger;
91   obj[functionName]();
92 }
93
94 function testCall_Fun2() {
95   debugger;
96   obj.fun2();
97 }
98
99 function testCall_InternStrings() {
100   var cache = { "fun": "fun" };
101   var functionName = "fu" + "n";
102   debugger;
103   obj[cache[functionName]]();
104 }
105
106 function testCall_ViaFunRef() {
107   var functionName = "fu" + "n";
108   var funRef = obj[functionName];
109   debugger;
110   funRef();
111 }
112
113 // bug 2888
114 function testCall_RuntimeVariable1() {
115   var functionName = "fu" + "n";
116   debugger;
117   obj[functionName]();
118 }
119
120 // bug 2888
121 function testCall_RuntimeVariable2() {
122   var functionName = "un".replace(/u/, "fu");
123   debugger;
124   obj[functionName]();
125 }
126
127 // bug 2888
128 function testCall_RuntimeVariable3() {
129   var expr = "fu" + "n";
130   const functionName = expr;
131   assertEquals("fun", functionName);
132   debugger;
133   obj[functionName]();
134 }
135
136 var functionsCalled = 0;
137 for (var n in this) {
138   if (n.substr(0, 4) != 'test' || typeof this[n] !== "function") {
139     continue;
140   }
141   state = 1;
142   print("Running " + n + "...");
143   this[n]();
144   ++functionsCalled;
145   assertNull(exception, n);
146   assertEquals(3, state, n);
147   assertEquals(functionsCalled, count, n);
148 }
149
150 assertEquals(11, functionsCalled);
151
152 // Get rid of the debug event listener.
153 Debug.setListener(null);