| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } else { | 434 } else { |
| 435 SetupErrorResult(result); | 435 SetupErrorResult(result); |
| 436 } | 436 } |
| 437 isolate->set_long_jump_base(base); | 437 isolate->set_long_jump_base(base); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 | 441 |
| 442 // Return error if isolate is in an inconsistent state. | 442 // Return error if isolate is in an inconsistent state. |
| 443 // Return NULL when no error condition exists. | 443 // Return NULL when no error condition exists. |
| 444 static const char* CheckIsolateState(Isolate* isolate) { | 444 static const char* CheckIsolateState( |
| 445 if (!ClassFinalizer::FinalizePendingClasses()) { | 445 Isolate* isolate, |
| 446 bool generating_snapshot = ClassFinalizer::kNotGeneratingSnapshot) { |
| 447 bool result = (generating_snapshot) ? |
| 448 ClassFinalizer::FinalizePendingClassesForSnapshotCreation() : |
| 449 ClassFinalizer::FinalizePendingClasses(); |
| 450 if (!result) { |
| 446 // Make a copy of the error message as the original message string | 451 // Make a copy of the error message as the original message string |
| 447 // may get deallocated when we return back from the Dart API call. | 452 // may get deallocated when we return back from the Dart API call. |
| 448 const String& err = | 453 const String& err = |
| 449 String::Handle(isolate->object_store()->sticky_error()); | 454 String::Handle(isolate->object_store()->sticky_error()); |
| 450 const char* errmsg = err.ToCString(); | 455 const char* errmsg = err.ToCString(); |
| 451 intptr_t errlen = strlen(errmsg) + 1; | 456 intptr_t errlen = strlen(errmsg) + 1; |
| 452 char* msg = reinterpret_cast<char*>(Api::Allocate(errlen)); | 457 char* msg = reinterpret_cast<char*>(Api::Allocate(errlen)); |
| 453 OS::SNPrint(msg, errlen, "%s", errmsg); | 458 OS::SNPrint(msg, errlen, "%s", errmsg); |
| 454 return msg; | 459 return msg; |
| 455 } | 460 } |
| (...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 } | 2008 } |
| 2004 | 2009 |
| 2005 | 2010 |
| 2006 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer, | 2011 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** snapshot_buffer, |
| 2007 intptr_t* snapshot_size) { | 2012 intptr_t* snapshot_size) { |
| 2008 Isolate* isolate = Isolate::Current(); | 2013 Isolate* isolate = Isolate::Current(); |
| 2009 DARTSCOPE(isolate); | 2014 DARTSCOPE(isolate); |
| 2010 if (snapshot_buffer == NULL || snapshot_size == NULL) { | 2015 if (snapshot_buffer == NULL || snapshot_size == NULL) { |
| 2011 return Api::Error("Invalid input parameters to Dart_CreateSnapshot"); | 2016 return Api::Error("Invalid input parameters to Dart_CreateSnapshot"); |
| 2012 } | 2017 } |
| 2013 const char* msg = CheckIsolateState(isolate); | 2018 const char* msg = CheckIsolateState(isolate, |
| 2019 ClassFinalizer::kGeneratingSnapshot); |
| 2014 if (msg != NULL) { | 2020 if (msg != NULL) { |
| 2015 return Api::Error(msg); | 2021 return Api::Error(msg); |
| 2016 } | 2022 } |
| 2017 // Since this is only a snapshot the root library should not be set. | 2023 // Since this is only a snapshot the root library should not be set. |
| 2018 isolate->object_store()->set_root_library(Library::Handle()); | 2024 isolate->object_store()->set_root_library(Library::Handle()); |
| 2019 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); | 2025 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); |
| 2020 writer.WriteFullSnapshot(); | 2026 writer.WriteFullSnapshot(); |
| 2021 *snapshot_size = writer.Size(); | 2027 *snapshot_size = writer.Size(); |
| 2022 return Api::Success(); | 2028 return Api::Success(); |
| 2023 } | 2029 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 ASSERT(isolate != NULL); | 2241 ASSERT(isolate != NULL); |
| 2236 ApiState* state = isolate->api_state(); | 2242 ApiState* state = isolate->api_state(); |
| 2237 ASSERT(state != NULL); | 2243 ASSERT(state != NULL); |
| 2238 ApiLocalScope* scope = state->top_scope(); | 2244 ApiLocalScope* scope = state->top_scope(); |
| 2239 ASSERT(scope != NULL); | 2245 ASSERT(scope != NULL); |
| 2240 return scope->zone().Reallocate(ptr, old_size, new_size); | 2246 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2241 } | 2247 } |
| 2242 | 2248 |
| 2243 | 2249 |
| 2244 } // namespace dart | 2250 } // namespace dart |
| OLD | NEW |