OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 } | 1065 } |
1066 | 1066 |
1067 | 1067 |
1068 // --- Scopes ---- | 1068 // --- Scopes ---- |
1069 | 1069 |
1070 DART_EXPORT void Dart_EnterScope() { | 1070 DART_EXPORT void Dart_EnterScope() { |
1071 Isolate* isolate = Isolate::Current(); | 1071 Isolate* isolate = Isolate::Current(); |
1072 CHECK_ISOLATE(isolate); | 1072 CHECK_ISOLATE(isolate); |
1073 ApiState* state = isolate->api_state(); | 1073 ApiState* state = isolate->api_state(); |
1074 ASSERT(state != NULL); | 1074 ASSERT(state != NULL); |
1075 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(), | 1075 ApiLocalScope* new_scope = state->reusable_scope(); |
1076 isolate->top_exit_frame_info()); | 1076 if (new_scope == NULL) { |
1077 ASSERT(new_scope != NULL); | 1077 new_scope = new ApiLocalScope(state->top_scope(), |
| 1078 isolate->top_exit_frame_info()); |
| 1079 ASSERT(new_scope != NULL); |
| 1080 } else { |
| 1081 new_scope->Reinit(isolate, |
| 1082 state->top_scope(), |
| 1083 isolate->top_exit_frame_info()); |
| 1084 state->set_reusable_scope(NULL); |
| 1085 } |
1078 state->set_top_scope(new_scope); // New scope is now the top scope. | 1086 state->set_top_scope(new_scope); // New scope is now the top scope. |
1079 } | 1087 } |
1080 | 1088 |
1081 | 1089 |
1082 DART_EXPORT void Dart_ExitScope() { | 1090 DART_EXPORT void Dart_ExitScope() { |
1083 Isolate* isolate = Isolate::Current(); | 1091 Isolate* isolate = Isolate::Current(); |
1084 CHECK_ISOLATE_SCOPE(isolate); | 1092 CHECK_ISOLATE_SCOPE(isolate); |
1085 ApiState* state = isolate->api_state(); | 1093 ApiState* state = isolate->api_state(); |
1086 ApiLocalScope* scope = state->top_scope(); | 1094 ApiLocalScope* scope = state->top_scope(); |
1087 | 1095 ApiLocalScope* reusable_scope = state->reusable_scope(); |
1088 state->set_top_scope(scope->previous()); // Reset top scope to previous. | 1096 state->set_top_scope(scope->previous()); // Reset top scope to previous. |
1089 delete scope; // Free up the old scope which we have just exited. | 1097 if (reusable_scope == NULL) { |
| 1098 scope->Reset(isolate); // Reset the old scope which we just exited. |
| 1099 state->set_reusable_scope(scope); |
| 1100 } else { |
| 1101 ASSERT(reusable_scope != scope); |
| 1102 delete scope; |
| 1103 } |
1090 } | 1104 } |
1091 | 1105 |
1092 | 1106 |
1093 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { | 1107 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { |
1094 Zone* zone; | 1108 Zone* zone; |
1095 Isolate* isolate = Isolate::Current(); | 1109 Isolate* isolate = Isolate::Current(); |
1096 if (isolate != NULL) { | 1110 if (isolate != NULL) { |
1097 ApiState* state = isolate->api_state(); | 1111 ApiState* state = isolate->api_state(); |
1098 if (state == NULL) return NULL; | 1112 if (state == NULL) return NULL; |
1099 ApiLocalScope* scope = state->top_scope(); | 1113 ApiLocalScope* scope = state->top_scope(); |
(...skipping 2904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4004 } | 4018 } |
4005 { | 4019 { |
4006 NoGCScope no_gc; | 4020 NoGCScope no_gc; |
4007 RawObject* raw_obj = obj.raw(); | 4021 RawObject* raw_obj = obj.raw(); |
4008 isolate->heap()->SetPeer(raw_obj, peer); | 4022 isolate->heap()->SetPeer(raw_obj, peer); |
4009 } | 4023 } |
4010 return Api::Success(); | 4024 return Api::Success(); |
4011 } | 4025 } |
4012 | 4026 |
4013 } // namespace dart | 4027 } // namespace dart |
OLD | NEW |