Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: test/mjsunit/debug-receiver.js

Issue 7388011: Fix the debugger for strict-mode functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 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 // Get the Debug object exposed from the debug context global object.
30 Debug = debug.Debug;
31
32 var test_name;
33 var listener_delegate;
34 var listener_called;
35 var exception;
36 var expected_receiver;
37 var begin_test_count = 0;
38 var end_test_count = 0;
39 var break_count = 0;
40
41 // Debug event listener which delegates. Exceptions have to be
42 // explictly caught here and checked later because exception in the
43 // listener are not propagated to the surrounding JavaScript code.
44 function listener(event, exec_state, event_data, data) {
45 try {
46 if (event == Debug.DebugEvent.Break) {
47 break_count++;
48 listener_called = true;
49 listener_delegate(exec_state);
50 }
51 } catch (e) {
52 exception = e;
53 }
54 }
55
56 // Add the debug event listener.
57 Debug.setListener(listener);
58
59
60 // Initialize for a new test.
61 function BeginTest(name) {
62 test_name = name;
63 listener_called = false;
64 exception = null;
65 begin_test_count++;
66 }
67
68
69 // Check result of a test.
70 function EndTest() {
71 assertTrue(listener_called, "listerner not called for " + test_name);
72 assertNull(exception, test_name);
73 end_test_count++;
74 }
75
76
77 // Check that the debugger correctly reflects that the receiver is not
78 // converted to object for strict mode functions.
79 function Strict() { "use strict"; debugger; }
80 function TestStrict(receiver) {
81 expected_receiver = receiver;
82 Strict.call(receiver);
83 }
84
85 listener_delegate = function(exec_state) {
86 var receiver = exec_state.frame().receiver();
87 assertTrue(!receiver.isObject());
88 assertEquals(expected_receiver, receiver.value())
89 }
90
91 BeginTest("strict: undefined"); TestStrict(undefined); EndTest();
92 BeginTest("strict: null"); TestStrict(null); EndTest();
93 BeginTest("strict: 1"); TestStrict(1); EndTest();
94 BeginTest("strict: 1.2"); TestStrict(1.2); EndTest();
95 BeginTest("strict: 'asdf'"); TestStrict('asdf'); EndTest();
96 BeginTest("strict: true"); TestStrict(true); EndTest();
97
98
99 // Check that the debugger correctly reflects the object conversion of
100 // the receiver for non-strict mode functions.
101 function NonStrict() { debugger; }
102 function TestNonStrict(receiver) {
103 // null and undefined should be transformed to the global object and
104 // primitives should be wrapped.
105 expected_receiver = (receiver == null) ? this : Object(receiver);
106 NonStrict.call(receiver);
107 }
108
109 listener_delegate = function(exec_state) {
110 var receiver = exec_state.frame().receiver();
111 assertTrue(receiver.isObject());
112 assertEquals(expected_receiver, receiver.value());
113 }
114
115 BeginTest("non-strict: undefined"); TestNonStrict(undefined); EndTest();
116 BeginTest("non-strict: null"); TestNonStrict(null); EndTest();
117 BeginTest("non-strict: 1"); TestNonStrict(1); EndTest();
118 BeginTest("non-strict: 1.2"); TestNonStrict(1.2); EndTest();
119 BeginTest("non-strict: 'asdf'"); TestNonStrict('asdf'); EndTest();
120 BeginTest("non-strict: true"); TestNonStrict(true); EndTest();
121
122
123 assertEquals(begin_test_count, break_count,
124 'one or more tests did not enter the debugger');
125 assertEquals(begin_test_count, end_test_count,
126 'one or more tests did not have its result checked');
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698