| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/allocation.h" | 6 #include "vm/allocation.h" |
| 7 #include "vm/longjump.h" | 7 #include "vm/longjump.h" |
| 8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 UNIT_TEST_CASE(StackAllocatedDestruction) { | 80 UNIT_TEST_CASE(StackAllocatedDestruction) { |
| 81 int data = 1; | 81 int data = 1; |
| 82 StackAllocatedDestructionHelper(&data); | 82 StackAllocatedDestructionHelper(&data); |
| 83 EXPECT_EQ(4, data); | 83 EXPECT_EQ(4, data); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 static void StackAllocatedLongJumpHelper(int* ptr, LongJump* jump) { | 87 static void StackAllocatedLongJumpHelper(int* ptr, LongJumpScope* jump) { |
| 88 TestValueObject stacked(ptr); | 88 TestValueObject stacked(ptr); |
| 89 EXPECT_EQ(2, *ptr); | 89 EXPECT_EQ(2, *ptr); |
| 90 *ptr = 3; | 90 *ptr = 3; |
| 91 const Error& error = | 91 const Error& error = |
| 92 Error::Handle(LanguageError::New( | 92 Error::Handle(LanguageError::New( |
| 93 String::Handle(String::New("StackAllocatedLongJump")))); | 93 String::Handle(String::New("StackAllocatedLongJump")))); |
| 94 jump->Jump(1, error); | 94 jump->Jump(1, error); |
| 95 UNREACHABLE(); | 95 UNREACHABLE(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 TEST_CASE(StackAllocatedLongJump) { | 99 TEST_CASE(StackAllocatedLongJump) { |
| 100 LongJump jump; | 100 LongJumpScope jump; |
| 101 int data = 1; | 101 int data = 1; |
| 102 if (setjmp(*jump.Set()) == 0) { | 102 if (setjmp(*jump.Set()) == 0) { |
| 103 StackAllocatedLongJumpHelper(&data, &jump); | 103 StackAllocatedLongJumpHelper(&data, &jump); |
| 104 UNREACHABLE(); | 104 UNREACHABLE(); |
| 105 } | 105 } |
| 106 EXPECT_EQ(3, data); | 106 EXPECT_EQ(3, data); |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 static void StackedStackResourceDestructionHelper(int* ptr) { | 110 static void StackedStackResourceDestructionHelper(int* ptr) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 | 126 |
| 127 TEST_CASE(StackResourceDestruction) { | 127 TEST_CASE(StackResourceDestruction) { |
| 128 int data = 1; | 128 int data = 1; |
| 129 StackResourceDestructionHelper(&data); | 129 StackResourceDestructionHelper(&data); |
| 130 EXPECT_EQ(7, data); | 130 EXPECT_EQ(7, data); |
| 131 } | 131 } |
| 132 | 132 |
| 133 | 133 |
| 134 static void StackedStackResourceLongJumpHelper(int* ptr, LongJump* jump) { | 134 static void StackedStackResourceLongJumpHelper(int* ptr, LongJumpScope* jump) { |
| 135 TestStackedStackResource stacked(ptr); | 135 TestStackedStackResource stacked(ptr); |
| 136 EXPECT_EQ(4, *ptr); | 136 EXPECT_EQ(4, *ptr); |
| 137 *ptr = 5; | 137 *ptr = 5; |
| 138 const Error& error = | 138 const Error& error = |
| 139 Error::Handle(LanguageError::New( | 139 Error::Handle(LanguageError::New( |
| 140 String::Handle(String::New("StackedStackResourceLongJump")))); | 140 String::Handle(String::New("StackedStackResourceLongJump")))); |
| 141 jump->Jump(1, error); | 141 jump->Jump(1, error); |
| 142 UNREACHABLE(); | 142 UNREACHABLE(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 static void StackResourceLongJumpHelper(int* ptr, LongJump* jump) { | 146 static void StackResourceLongJumpHelper(int* ptr, LongJumpScope* jump) { |
| 147 TestStackResource stacked(ptr); | 147 TestStackResource stacked(ptr); |
| 148 EXPECT_EQ(2, *ptr); | 148 EXPECT_EQ(2, *ptr); |
| 149 *ptr = 3; | 149 *ptr = 3; |
| 150 StackedStackResourceLongJumpHelper(ptr, jump); | 150 StackedStackResourceLongJumpHelper(ptr, jump); |
| 151 UNREACHABLE(); | 151 UNREACHABLE(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 TEST_CASE(StackResourceLongJump) { | 155 TEST_CASE(StackResourceLongJump) { |
| 156 LongJump jump; | 156 LongJumpScope* base = Isolate::Current()->long_jump_base(); |
| 157 int data = 1; | 157 { |
| 158 if (setjmp(*jump.Set()) == 0) { | 158 LongJumpScope jump; |
| 159 StackResourceLongJumpHelper(&data, &jump); | 159 int data = 1; |
| 160 UNREACHABLE(); | 160 if (setjmp(*jump.Set()) == 0) { |
| 161 StackResourceLongJumpHelper(&data, &jump); |
| 162 UNREACHABLE(); |
| 163 } |
| 164 EXPECT_EQ(7, data); |
| 161 } | 165 } |
| 162 EXPECT_EQ(7, data); | 166 ASSERT(base == Isolate::Current()->long_jump_base()); |
| 163 } | 167 } |
| 164 | 168 |
| 165 } // namespace dart | 169 } // namespace dart |
| OLD | NEW |