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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 { | 902 { |
903 StackZone zone(isolate); | 903 StackZone zone(isolate); |
904 HANDLESCOPE(isolate); | 904 HANDLESCOPE(isolate); |
905 const Error& error_obj = | 905 const Error& error_obj = |
906 Error::Handle(isolate, | 906 Error::Handle(isolate, |
907 Dart::InitializeIsolate(snapshot, callback_data)); | 907 Dart::InitializeIsolate(snapshot, callback_data)); |
908 if (error_obj.IsNull()) { | 908 if (error_obj.IsNull()) { |
909 if (FLAG_check_function_fingerprints) { | 909 if (FLAG_check_function_fingerprints) { |
910 Library::CheckFunctionFingerprints(); | 910 Library::CheckFunctionFingerprints(); |
911 } | 911 } |
912 START_TIMER(time_total_runtime); | 912 START_TIMER(isolate, time_total_runtime); |
913 return reinterpret_cast<Dart_Isolate>(isolate); | 913 return reinterpret_cast<Dart_Isolate>(isolate); |
914 } | 914 } |
915 *error = strdup(error_obj.ToErrorCString()); | 915 *error = strdup(error_obj.ToErrorCString()); |
916 } | 916 } |
917 Dart::ShutdownIsolate(); | 917 Dart::ShutdownIsolate(); |
918 return reinterpret_cast<Dart_Isolate>(NULL); | 918 return reinterpret_cast<Dart_Isolate>(NULL); |
919 } | 919 } |
920 | 920 |
921 | 921 |
922 DART_EXPORT void Dart_ShutdownIsolate() { | 922 DART_EXPORT void Dart_ShutdownIsolate() { |
923 Isolate* isolate = Isolate::Current(); | 923 Isolate* isolate = Isolate::Current(); |
924 CHECK_ISOLATE(isolate); | 924 CHECK_ISOLATE(isolate); |
925 { | 925 { |
926 StackZone zone(isolate); | 926 StackZone zone(isolate); |
927 HandleScope handle_scope(isolate); | 927 HandleScope handle_scope(isolate); |
928 Dart::RunShutdownCallback(); | 928 Dart::RunShutdownCallback(); |
929 } | 929 } |
930 STOP_TIMER(time_total_runtime); | 930 STOP_TIMER(isolate, time_total_runtime); |
931 Dart::ShutdownIsolate(); | 931 Dart::ShutdownIsolate(); |
932 } | 932 } |
933 | 933 |
934 | 934 |
935 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { | 935 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { |
936 return Api::CastIsolate(Isolate::Current()); | 936 return Api::CastIsolate(Isolate::Current()); |
937 } | 937 } |
938 | 938 |
939 | 939 |
940 DART_EXPORT void* Dart_CurrentIsolateData() { | 940 DART_EXPORT void* Dart_CurrentIsolateData() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 intptr_t new_size) { | 982 intptr_t new_size) { |
983 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( | 983 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
984 ptr, old_size, new_size); | 984 ptr, old_size, new_size); |
985 } | 985 } |
986 | 986 |
987 | 987 |
988 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, | 988 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
989 intptr_t* size) { | 989 intptr_t* size) { |
990 Isolate* isolate = Isolate::Current(); | 990 Isolate* isolate = Isolate::Current(); |
991 DARTSCOPE(isolate); | 991 DARTSCOPE(isolate); |
992 TIMERSCOPE(time_creating_snapshot); | 992 TIMERSCOPE(isolate, time_creating_snapshot); |
993 if (buffer == NULL) { | 993 if (buffer == NULL) { |
994 RETURN_NULL_ERROR(buffer); | 994 RETURN_NULL_ERROR(buffer); |
995 } | 995 } |
996 if (size == NULL) { | 996 if (size == NULL) { |
997 RETURN_NULL_ERROR(size); | 997 RETURN_NULL_ERROR(size); |
998 } | 998 } |
999 Dart_Handle state = Api::CheckIsolateState(isolate); | 999 Dart_Handle state = Api::CheckIsolateState(isolate); |
1000 if (::Dart_IsError(state)) { | 1000 if (::Dart_IsError(state)) { |
1001 return state; | 1001 return state; |
1002 } | 1002 } |
1003 // Since this is only a snapshot the root library should not be set. | 1003 // Since this is only a snapshot the root library should not be set. |
1004 isolate->object_store()->set_root_library(Library::Handle(isolate)); | 1004 isolate->object_store()->set_root_library(Library::Handle(isolate)); |
1005 FullSnapshotWriter writer(buffer, ApiReallocate); | 1005 FullSnapshotWriter writer(buffer, ApiReallocate); |
1006 writer.WriteFullSnapshot(); | 1006 writer.WriteFullSnapshot(); |
1007 *size = writer.BytesWritten(); | 1007 *size = writer.BytesWritten(); |
1008 return Api::Success(); | 1008 return Api::Success(); |
1009 } | 1009 } |
1010 | 1010 |
1011 | 1011 |
1012 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1012 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
1013 intptr_t* size) { | 1013 intptr_t* size) { |
1014 Isolate* isolate = Isolate::Current(); | 1014 Isolate* isolate = Isolate::Current(); |
1015 DARTSCOPE(isolate); | 1015 DARTSCOPE(isolate); |
1016 TIMERSCOPE(time_creating_snapshot); | 1016 TIMERSCOPE(isolate, time_creating_snapshot); |
1017 if (buffer == NULL) { | 1017 if (buffer == NULL) { |
1018 RETURN_NULL_ERROR(buffer); | 1018 RETURN_NULL_ERROR(buffer); |
1019 } | 1019 } |
1020 if (size == NULL) { | 1020 if (size == NULL) { |
1021 RETURN_NULL_ERROR(size); | 1021 RETURN_NULL_ERROR(size); |
1022 } | 1022 } |
1023 Dart_Handle state = Api::CheckIsolateState(isolate); | 1023 Dart_Handle state = Api::CheckIsolateState(isolate); |
1024 if (::Dart_IsError(state)) { | 1024 if (::Dart_IsError(state)) { |
1025 return state; | 1025 return state; |
1026 } | 1026 } |
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3262 | 3262 |
3263 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 3263 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
3264 Dart_Handle name, | 3264 Dart_Handle name, |
3265 int number_of_arguments, | 3265 int number_of_arguments, |
3266 Dart_Handle* arguments) { | 3266 Dart_Handle* arguments) { |
3267 Isolate* isolate = Isolate::Current(); | 3267 Isolate* isolate = Isolate::Current(); |
3268 DARTSCOPE(isolate); | 3268 DARTSCOPE(isolate); |
3269 CHECK_CALLBACK_STATE(isolate); | 3269 CHECK_CALLBACK_STATE(isolate); |
3270 // TODO(turnidge): This is a bit simplistic. It overcounts when | 3270 // TODO(turnidge): This is a bit simplistic. It overcounts when |
3271 // other operations (gc, compilation) are active. | 3271 // other operations (gc, compilation) are active. |
3272 TIMERSCOPE(time_dart_execution); | 3272 TIMERSCOPE(isolate, time_dart_execution); |
3273 | 3273 |
3274 const String& function_name = Api::UnwrapStringHandle(isolate, name); | 3274 const String& function_name = Api::UnwrapStringHandle(isolate, name); |
3275 if (function_name.IsNull()) { | 3275 if (function_name.IsNull()) { |
3276 RETURN_TYPE_ERROR(isolate, name, String); | 3276 RETURN_TYPE_ERROR(isolate, name, String); |
3277 } | 3277 } |
3278 if (number_of_arguments < 0) { | 3278 if (number_of_arguments < 0) { |
3279 return Api::NewError( | 3279 return Api::NewError( |
3280 "%s expects argument 'number_of_arguments' to be non-negative.", | 3280 "%s expects argument 'number_of_arguments' to be non-negative.", |
3281 CURRENT_FUNC); | 3281 CURRENT_FUNC); |
3282 } | 3282 } |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4168 lib.SetLoadError(); | 4168 lib.SetLoadError(); |
4169 } | 4169 } |
4170 } | 4170 } |
4171 } | 4171 } |
4172 | 4172 |
4173 | 4173 |
4174 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 4174 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
4175 Dart_Handle source, | 4175 Dart_Handle source, |
4176 intptr_t line_offset, | 4176 intptr_t line_offset, |
4177 intptr_t col_offset) { | 4177 intptr_t col_offset) { |
4178 TIMERSCOPE(time_script_loading); | |
4179 Isolate* isolate = Isolate::Current(); | 4178 Isolate* isolate = Isolate::Current(); |
4180 DARTSCOPE(isolate); | 4179 DARTSCOPE(isolate); |
| 4180 TIMERSCOPE(isolate, time_script_loading); |
4181 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4181 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
4182 if (url_str.IsNull()) { | 4182 if (url_str.IsNull()) { |
4183 RETURN_TYPE_ERROR(isolate, url, String); | 4183 RETURN_TYPE_ERROR(isolate, url, String); |
4184 } | 4184 } |
4185 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4185 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
4186 if (source_str.IsNull()) { | 4186 if (source_str.IsNull()) { |
4187 RETURN_TYPE_ERROR(isolate, source, String); | 4187 RETURN_TYPE_ERROR(isolate, source, String); |
4188 } | 4188 } |
4189 Library& library = | 4189 Library& library = |
4190 Library::Handle(isolate, isolate->object_store()->root_library()); | 4190 Library::Handle(isolate, isolate->object_store()->root_library()); |
(...skipping 25 matching lines...) Expand all Loading... |
4216 Dart_Handle result; | 4216 Dart_Handle result; |
4217 CompileSource(isolate, library, script, &result); | 4217 CompileSource(isolate, library, script, &result); |
4218 return result; | 4218 return result; |
4219 } | 4219 } |
4220 | 4220 |
4221 | 4221 |
4222 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 4222 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
4223 intptr_t buffer_len) { | 4223 intptr_t buffer_len) { |
4224 Isolate* isolate = Isolate::Current(); | 4224 Isolate* isolate = Isolate::Current(); |
4225 DARTSCOPE(isolate); | 4225 DARTSCOPE(isolate); |
4226 TIMERSCOPE(time_script_loading); | 4226 TIMERSCOPE(isolate, time_script_loading); |
4227 if (buffer == NULL) { | 4227 if (buffer == NULL) { |
4228 RETURN_NULL_ERROR(buffer); | 4228 RETURN_NULL_ERROR(buffer); |
4229 } | 4229 } |
4230 NoHeapGrowthControlScope no_growth_control; | 4230 NoHeapGrowthControlScope no_growth_control; |
4231 | 4231 |
4232 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 4232 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
4233 if (!snapshot->IsScriptSnapshot()) { | 4233 if (!snapshot->IsScriptSnapshot()) { |
4234 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4234 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
4235 " snapshot.", CURRENT_FUNC); | 4235 " snapshot.", CURRENT_FUNC); |
4236 } | 4236 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4396 return Api::NewError("%s: library '%s' not found.", | 4396 return Api::NewError("%s: library '%s' not found.", |
4397 CURRENT_FUNC, url_str.ToCString()); | 4397 CURRENT_FUNC, url_str.ToCString()); |
4398 } else { | 4398 } else { |
4399 return Api::NewHandle(isolate, library.raw()); | 4399 return Api::NewHandle(isolate, library.raw()); |
4400 } | 4400 } |
4401 } | 4401 } |
4402 | 4402 |
4403 | 4403 |
4404 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 4404 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
4405 Dart_Handle source) { | 4405 Dart_Handle source) { |
4406 TIMERSCOPE(time_script_loading); | |
4407 Isolate* isolate = Isolate::Current(); | 4406 Isolate* isolate = Isolate::Current(); |
4408 DARTSCOPE(isolate); | 4407 DARTSCOPE(isolate); |
| 4408 TIMERSCOPE(isolate, time_script_loading); |
4409 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4409 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
4410 if (url_str.IsNull()) { | 4410 if (url_str.IsNull()) { |
4411 RETURN_TYPE_ERROR(isolate, url, String); | 4411 RETURN_TYPE_ERROR(isolate, url, String); |
4412 } | 4412 } |
4413 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4413 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
4414 if (source_str.IsNull()) { | 4414 if (source_str.IsNull()) { |
4415 RETURN_TYPE_ERROR(isolate, source, String); | 4415 RETURN_TYPE_ERROR(isolate, source, String); |
4416 } | 4416 } |
4417 CHECK_CALLBACK_STATE(isolate); | 4417 CHECK_CALLBACK_STATE(isolate); |
4418 | 4418 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4488 library_vm.AddObject(library_prefix, prefix_symbol); | 4488 library_vm.AddObject(library_prefix, prefix_symbol); |
4489 } | 4489 } |
4490 } | 4490 } |
4491 return Api::Success(); | 4491 return Api::Success(); |
4492 } | 4492 } |
4493 | 4493 |
4494 | 4494 |
4495 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 4495 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
4496 Dart_Handle url, | 4496 Dart_Handle url, |
4497 Dart_Handle source) { | 4497 Dart_Handle source) { |
4498 TIMERSCOPE(time_script_loading); | |
4499 Isolate* isolate = Isolate::Current(); | 4498 Isolate* isolate = Isolate::Current(); |
4500 DARTSCOPE(isolate); | 4499 DARTSCOPE(isolate); |
| 4500 TIMERSCOPE(isolate, time_script_loading); |
4501 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4501 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
4502 if (lib.IsNull()) { | 4502 if (lib.IsNull()) { |
4503 RETURN_TYPE_ERROR(isolate, library, Library); | 4503 RETURN_TYPE_ERROR(isolate, library, Library); |
4504 } | 4504 } |
4505 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4505 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
4506 if (url_str.IsNull()) { | 4506 if (url_str.IsNull()) { |
4507 RETURN_TYPE_ERROR(isolate, url, String); | 4507 RETURN_TYPE_ERROR(isolate, url, String); |
4508 } | 4508 } |
4509 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4509 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
4510 if (source_str.IsNull()) { | 4510 if (source_str.IsNull()) { |
4511 RETURN_TYPE_ERROR(isolate, source, String); | 4511 RETURN_TYPE_ERROR(isolate, source, String); |
4512 } | 4512 } |
4513 CHECK_CALLBACK_STATE(isolate); | 4513 CHECK_CALLBACK_STATE(isolate); |
4514 | 4514 |
4515 NoHeapGrowthControlScope no_growth_control; | 4515 NoHeapGrowthControlScope no_growth_control; |
4516 | 4516 |
4517 const Script& script = Script::Handle( | 4517 const Script& script = Script::Handle( |
4518 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); | 4518 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); |
4519 Dart_Handle result; | 4519 Dart_Handle result; |
4520 CompileSource(isolate, lib, script, &result); | 4520 CompileSource(isolate, lib, script, &result); |
4521 return result; | 4521 return result; |
4522 } | 4522 } |
4523 | 4523 |
4524 | 4524 |
4525 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 4525 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
4526 Dart_Handle url, | 4526 Dart_Handle url, |
4527 Dart_Handle patch_source) { | 4527 Dart_Handle patch_source) { |
4528 TIMERSCOPE(time_script_loading); | |
4529 Isolate* isolate = Isolate::Current(); | 4528 Isolate* isolate = Isolate::Current(); |
4530 DARTSCOPE(isolate); | 4529 DARTSCOPE(isolate); |
| 4530 TIMERSCOPE(isolate, time_script_loading); |
4531 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4531 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
4532 if (lib.IsNull()) { | 4532 if (lib.IsNull()) { |
4533 RETURN_TYPE_ERROR(isolate, library, Library); | 4533 RETURN_TYPE_ERROR(isolate, library, Library); |
4534 } | 4534 } |
4535 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4535 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
4536 if (url_str.IsNull()) { | 4536 if (url_str.IsNull()) { |
4537 RETURN_TYPE_ERROR(isolate, url, String); | 4537 RETURN_TYPE_ERROR(isolate, url, String); |
4538 } | 4538 } |
4539 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 4539 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
4540 if (source_str.IsNull()) { | 4540 if (source_str.IsNull()) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4632 | 4632 |
4633 | 4633 |
4634 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4634 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
4635 const char* name, | 4635 const char* name, |
4636 Dart_ServiceRequestCallback callback, | 4636 Dart_ServiceRequestCallback callback, |
4637 void* user_data) { | 4637 void* user_data) { |
4638 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4638 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
4639 } | 4639 } |
4640 | 4640 |
4641 } // namespace dart | 4641 } // namespace dart |
OLD | NEW |