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