OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
11 #include "vm/resolver.h" | 11 #include "vm/resolver.h" |
12 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
13 #include "vm/unit_test.h" | 13 #include "vm/unit_test.h" |
14 #include "vm/verifier.h" | 14 #include "vm/verifier.h" |
15 #include "vm/zone.h" | 15 #include "vm/zone.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 | 18 |
| 19 DECLARE_FLAG(bool, lazy_dispatchers); |
| 20 |
19 // Unit test for empty stack frame iteration. | 21 // Unit test for empty stack frame iteration. |
20 TEST_CASE(EmptyStackFrameIteration) { | 22 TEST_CASE(EmptyStackFrameIteration) { |
21 StackFrameIterator iterator(StackFrameIterator::kValidateFrames); | 23 StackFrameIterator iterator(StackFrameIterator::kValidateFrames); |
22 EXPECT(!iterator.HasNextFrame()); | 24 EXPECT(!iterator.HasNextFrame()); |
23 EXPECT(iterator.NextFrame() == NULL); | 25 EXPECT(iterator.NextFrame() == NULL); |
24 VerifyPointersVisitor::VerifyPointers(); | 26 VerifyPointersVisitor::VerifyPointers(); |
25 } | 27 } |
26 | 28 |
27 | 29 |
28 // Unit test for empty dart stack frame iteration. | 30 // Unit test for empty dart stack frame iteration. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 Dart_Handle lib = TestCase::LoadTestScript( | 241 Dart_Handle lib = TestCase::LoadTestScript( |
240 kScriptChars, | 242 kScriptChars, |
241 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | 243 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
242 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest")); | 244 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest")); |
243 EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL)); | 245 EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL)); |
244 } | 246 } |
245 | 247 |
246 | 248 |
247 // Unit test case to verify stack frame iteration. | 249 // Unit test case to verify stack frame iteration. |
248 TEST_CASE(ValidateNoSuchMethodStackFrameIteration) { | 250 TEST_CASE(ValidateNoSuchMethodStackFrameIteration) { |
249 const char* kScriptChars = | 251 const char* kScriptChars; |
| 252 // The true stack depends on which strategy we are using for noSuchMethod. The |
| 253 // stacktrace as seen by Dart is the same either way because dispatcher |
| 254 // methods are marked invisible. |
| 255 if (FLAG_lazy_dispatchers) { |
| 256 kScriptChars = |
250 "class StackFrame {" | 257 "class StackFrame {" |
251 " static equals(var obj1, var obj2) native \"StackFrame_equals\";" | 258 " static equals(var obj1, var obj2) native \"StackFrame_equals\";" |
252 " static int frameCount() native \"StackFrame_frameCount\";" | 259 " static int frameCount() native \"StackFrame_frameCount\";" |
253 " static int dartFrameCount() native \"StackFrame_dartFrameCount\";" | 260 " static int dartFrameCount() native \"StackFrame_dartFrameCount\";" |
254 " static validateFrame(int index," | 261 " static validateFrame(int index," |
255 " String name) native \"StackFrame_validateFrame\";" | 262 " String name) native \"StackFrame_validateFrame\";" |
256 "} " | 263 "} " |
257 "class StackFrame2Test {" | 264 "class StackFrame2Test {" |
258 " StackFrame2Test() {}" | 265 " StackFrame2Test() {}" |
259 " noSuchMethod(Invocation im) {" | 266 " noSuchMethod(Invocation im) {" |
(...skipping 11 matching lines...) Expand all Loading... |
271 " StackFrame.validateFrame(1, \"StackFrame2Test_noSuchMethod\");" | 278 " StackFrame.validateFrame(1, \"StackFrame2Test_noSuchMethod\");" |
272 " StackFrame.validateFrame(2, \"StackFrame2Test_foo\");" | 279 " StackFrame.validateFrame(2, \"StackFrame2Test_foo\");" |
273 " StackFrame.validateFrame(3, \"StackFrame2Test_testMain\");" | 280 " StackFrame.validateFrame(3, \"StackFrame2Test_testMain\");" |
274 " return 5;" | 281 " return 5;" |
275 " }" | 282 " }" |
276 " static testMain() {" | 283 " static testMain() {" |
277 " var obj = new StackFrame2Test();" | 284 " var obj = new StackFrame2Test();" |
278 " StackFrame.equals(5, obj.foo(101, 202));" | 285 " StackFrame.equals(5, obj.foo(101, 202));" |
279 " }" | 286 " }" |
280 "}"; | 287 "}"; |
| 288 } else { |
| 289 kScriptChars = |
| 290 "class StackFrame {" |
| 291 " static equals(var obj1, var obj2) native \"StackFrame_equals\";" |
| 292 " static int frameCount() native \"StackFrame_frameCount\";" |
| 293 " static int dartFrameCount() native \"StackFrame_dartFrameCount\";" |
| 294 " static validateFrame(int index," |
| 295 " String name) native \"StackFrame_validateFrame\";" |
| 296 "} " |
| 297 "class StackFrame2Test {" |
| 298 " StackFrame2Test() {}" |
| 299 " noSuchMethod(Invocation im) {" |
| 300 " /* We should have 8 general frames and 3 dart frames as follows:" |
| 301 " * exit frame" |
| 302 " * dart frame corresponding to StackFrame.frameCount" |
| 303 " * dart frame corresponding to StackFrame2Test.noSuchMethod" |
| 304 " * entry frame" |
| 305 " * exit frame (call to runtime InvokeNoSuchMethodDispatcher)" |
| 306 " * IC stub" |
| 307 " * dart frame corresponding to StackFrame2Test.testMain" |
| 308 " * entry frame" |
| 309 " */" |
| 310 " StackFrame.equals(8, StackFrame.frameCount());" |
| 311 " StackFrame.equals(3, StackFrame.dartFrameCount());" |
| 312 " StackFrame.validateFrame(0, \"StackFrame_validateFrame\");" |
| 313 " StackFrame.validateFrame(1, \"StackFrame2Test_noSuchMethod\");" |
| 314 " StackFrame.validateFrame(2, \"StackFrame2Test_testMain\");" |
| 315 " return 5;" |
| 316 " }" |
| 317 " static testMain() {" |
| 318 " var obj = new StackFrame2Test();" |
| 319 " StackFrame.equals(5, obj.foo(101, 202));" |
| 320 " }" |
| 321 "}"; |
| 322 } |
281 Dart_Handle lib = TestCase::LoadTestScript( | 323 Dart_Handle lib = TestCase::LoadTestScript( |
282 kScriptChars, | 324 kScriptChars, |
283 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | 325 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
284 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrame2Test")); | 326 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrame2Test")); |
285 EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL)); | 327 EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL)); |
286 } | 328 } |
287 | 329 |
288 } // namespace dart | 330 } // namespace dart |
OLD | NEW |