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 // Unit test for empty stack frame iteration. | 19 // Unit test for empty stack frame iteration. |
20 ISOLATE_UNIT_TEST_CASE(EmptyStackFrameIteration) { | 20 ISOLATE_UNIT_TEST_CASE(EmptyStackFrameIteration) { |
21 StackFrameIterator iterator(StackFrameIterator::kValidateFrames); | 21 StackFrameIterator iterator(StackFrameIterator::kValidateFrames, |
| 22 Thread::Current(), false); |
22 EXPECT(!iterator.HasNextFrame()); | 23 EXPECT(!iterator.HasNextFrame()); |
23 EXPECT(iterator.NextFrame() == NULL); | 24 EXPECT(iterator.NextFrame() == NULL); |
24 VerifyPointersVisitor::VerifyPointers(); | 25 VerifyPointersVisitor::VerifyPointers(); |
25 } | 26 } |
26 | 27 |
27 | 28 |
28 // Unit test for empty dart stack frame iteration. | 29 // Unit test for empty dart stack frame iteration. |
29 ISOLATE_UNIT_TEST_CASE(EmptyDartStackFrameIteration) { | 30 ISOLATE_UNIT_TEST_CASE(EmptyDartStackFrameIteration) { |
30 DartFrameIterator iterator; | 31 DartFrameIterator iterator(Thread::Current(), false); |
31 EXPECT(iterator.NextFrame() == NULL); | 32 EXPECT(iterator.NextFrame() == NULL); |
32 VerifyPointersVisitor::VerifyPointers(); | 33 VerifyPointersVisitor::VerifyPointers(); |
33 } | 34 } |
34 | 35 |
35 | 36 |
36 #define FUNCTION_NAME(name) StackFrame_##name | 37 #define FUNCTION_NAME(name) StackFrame_##name |
37 #define REGISTER_FUNCTION(name, count) {"" #name, FUNCTION_NAME(name), count}, | 38 #define REGISTER_FUNCTION(name, count) {"" #name, FUNCTION_NAME(name), count}, |
38 | 39 |
39 | 40 |
40 void FUNCTION_NAME(StackFrame_equals)(Dart_NativeArguments args) { | 41 void FUNCTION_NAME(StackFrame_equals)(Dart_NativeArguments args) { |
41 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 42 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
42 const Instance& expected = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 43 const Instance& expected = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
43 const Instance& actual = Instance::CheckedHandle(arguments->NativeArgAt(1)); | 44 const Instance& actual = Instance::CheckedHandle(arguments->NativeArgAt(1)); |
44 if (!expected.OperatorEquals(actual)) { | 45 if (!expected.OperatorEquals(actual)) { |
45 OS::Print("expected: '%s' actual: '%s'\n", expected.ToCString(), | 46 OS::Print("expected: '%s' actual: '%s'\n", expected.ToCString(), |
46 actual.ToCString()); | 47 actual.ToCString()); |
47 FATAL("Expect_equals fails.\n"); | 48 FATAL("Expect_equals fails.\n"); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 | 52 |
52 void FUNCTION_NAME(StackFrame_frameCount)(Dart_NativeArguments args) { | 53 void FUNCTION_NAME(StackFrame_frameCount)(Dart_NativeArguments args) { |
53 int count = 0; | 54 int count = 0; |
54 StackFrameIterator frames(StackFrameIterator::kValidateFrames); | 55 StackFrameIterator frames(StackFrameIterator::kValidateFrames, |
| 56 Thread::Current(), false); |
55 while (frames.NextFrame() != NULL) { | 57 while (frames.NextFrame() != NULL) { |
56 count += 1; // Count the frame. | 58 count += 1; // Count the frame. |
57 } | 59 } |
58 VerifyPointersVisitor::VerifyPointers(); | 60 VerifyPointersVisitor::VerifyPointers(); |
59 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 61 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
60 arguments->SetReturn(Object::Handle(Smi::New(count))); | 62 arguments->SetReturn(Object::Handle(Smi::New(count))); |
61 } | 63 } |
62 | 64 |
63 | 65 |
64 void FUNCTION_NAME(StackFrame_dartFrameCount)(Dart_NativeArguments args) { | 66 void FUNCTION_NAME(StackFrame_dartFrameCount)(Dart_NativeArguments args) { |
65 int count = 0; | 67 int count = 0; |
66 DartFrameIterator frames; | 68 DartFrameIterator frames(Thread::Current(), false); |
67 while (frames.NextFrame() != NULL) { | 69 while (frames.NextFrame() != NULL) { |
68 count += 1; // Count the dart frame. | 70 count += 1; // Count the dart frame. |
69 } | 71 } |
70 VerifyPointersVisitor::VerifyPointers(); | 72 VerifyPointersVisitor::VerifyPointers(); |
71 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 73 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
72 arguments->SetReturn(Object::Handle(Smi::New(count))); | 74 arguments->SetReturn(Object::Handle(Smi::New(count))); |
73 } | 75 } |
74 | 76 |
75 | 77 |
76 void FUNCTION_NAME(StackFrame_validateFrame)(Dart_NativeArguments args) { | 78 void FUNCTION_NAME(StackFrame_validateFrame)(Dart_NativeArguments args) { |
77 Thread* thread = Thread::Current(); | 79 Thread* thread = Thread::Current(); |
78 Zone* zone = thread->zone(); | 80 Zone* zone = thread->zone(); |
79 | 81 |
80 Dart_Handle index = Dart_GetNativeArgument(args, 0); | 82 Dart_Handle index = Dart_GetNativeArgument(args, 0); |
81 Dart_Handle name = Dart_GetNativeArgument(args, 1); | 83 Dart_Handle name = Dart_GetNativeArgument(args, 1); |
82 const Smi& frame_index_smi = Smi::CheckedHandle(Api::UnwrapHandle(index)); | 84 const Smi& frame_index_smi = Smi::CheckedHandle(Api::UnwrapHandle(index)); |
83 const char* expected_name = | 85 const char* expected_name = |
84 String::CheckedHandle(Api::UnwrapHandle(name)).ToCString(); | 86 String::CheckedHandle(Api::UnwrapHandle(name)).ToCString(); |
85 int frame_index = frame_index_smi.Value(); | 87 int frame_index = frame_index_smi.Value(); |
86 int count = 0; | 88 int count = 0; |
87 DartFrameIterator frames; | 89 DartFrameIterator frames(Thread::Current(), false); |
88 StackFrame* frame = frames.NextFrame(); | 90 StackFrame* frame = frames.NextFrame(); |
89 while (frame != NULL) { | 91 while (frame != NULL) { |
90 if (count == frame_index) { | 92 if (count == frame_index) { |
91 // Find the function corresponding to this frame and check if it | 93 // Find the function corresponding to this frame and check if it |
92 // matches the function name passed in. | 94 // matches the function name passed in. |
93 const Function& function = | 95 const Function& function = |
94 Function::Handle(zone, frame->LookupDartFunction()); | 96 Function::Handle(zone, frame->LookupDartFunction()); |
95 if (function.IsNull()) { | 97 if (function.IsNull()) { |
96 FATAL("StackFrame_validateFrame fails, invalid dart frame.\n"); | 98 FATAL("StackFrame_validateFrame fails, invalid dart frame.\n"); |
97 } | 99 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 " }" | 319 " }" |
318 "}"; | 320 "}"; |
319 } | 321 } |
320 Dart_Handle lib = TestCase::LoadTestScript( | 322 Dart_Handle lib = TestCase::LoadTestScript( |
321 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); | 323 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); |
322 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrame2Test")); | 324 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrame2Test")); |
323 EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL)); | 325 EXPECT_VALID(Dart_Invoke(cls, NewString("testMain"), 0, NULL)); |
324 } | 326 } |
325 | 327 |
326 } // namespace dart | 328 } // namespace dart |
OLD | NEW |