| 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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 { | 964 { |
| 965 StackZone zone(isolate); | 965 StackZone zone(isolate); |
| 966 HANDLESCOPE(isolate); | 966 HANDLESCOPE(isolate); |
| 967 const Error& error_obj = | 967 const Error& error_obj = |
| 968 Error::Handle(isolate, | 968 Error::Handle(isolate, |
| 969 Dart::InitializeIsolate(snapshot, callback_data)); | 969 Dart::InitializeIsolate(snapshot, callback_data)); |
| 970 if (error_obj.IsNull()) { | 970 if (error_obj.IsNull()) { |
| 971 if (FLAG_check_function_fingerprints) { | 971 if (FLAG_check_function_fingerprints) { |
| 972 Library::CheckFunctionFingerprints(); | 972 Library::CheckFunctionFingerprints(); |
| 973 } | 973 } |
| 974 START_TIMER(time_total_runtime); | 974 START_TIMER(isolate, time_total_runtime); |
| 975 return reinterpret_cast<Dart_Isolate>(isolate); | 975 return reinterpret_cast<Dart_Isolate>(isolate); |
| 976 } | 976 } |
| 977 *error = strdup(error_obj.ToErrorCString()); | 977 *error = strdup(error_obj.ToErrorCString()); |
| 978 } | 978 } |
| 979 Dart::ShutdownIsolate(); | 979 Dart::ShutdownIsolate(); |
| 980 return reinterpret_cast<Dart_Isolate>(NULL); | 980 return reinterpret_cast<Dart_Isolate>(NULL); |
| 981 } | 981 } |
| 982 | 982 |
| 983 | 983 |
| 984 DART_EXPORT void Dart_ShutdownIsolate() { | 984 DART_EXPORT void Dart_ShutdownIsolate() { |
| 985 Isolate* isolate = Isolate::Current(); | 985 Isolate* isolate = Isolate::Current(); |
| 986 CHECK_ISOLATE(isolate); | 986 CHECK_ISOLATE(isolate); |
| 987 { | 987 { |
| 988 StackZone zone(isolate); | 988 StackZone zone(isolate); |
| 989 HandleScope handle_scope(isolate); | 989 HandleScope handle_scope(isolate); |
| 990 Dart::RunShutdownCallback(); | 990 Dart::RunShutdownCallback(); |
| 991 } | 991 } |
| 992 STOP_TIMER(time_total_runtime); | 992 STOP_TIMER(isolate, time_total_runtime); |
| 993 Dart::ShutdownIsolate(); | 993 Dart::ShutdownIsolate(); |
| 994 } | 994 } |
| 995 | 995 |
| 996 | 996 |
| 997 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { | 997 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { |
| 998 return Api::CastIsolate(Isolate::Current()); | 998 return Api::CastIsolate(Isolate::Current()); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 | 1001 |
| 1002 DART_EXPORT void* Dart_CurrentIsolateData() { | 1002 DART_EXPORT void* Dart_CurrentIsolateData() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 intptr_t new_size) { | 1044 intptr_t new_size) { |
| 1045 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( | 1045 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
| 1046 ptr, old_size, new_size); | 1046 ptr, old_size, new_size); |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 | 1049 |
| 1050 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, | 1050 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
| 1051 intptr_t* size) { | 1051 intptr_t* size) { |
| 1052 Isolate* isolate = Isolate::Current(); | 1052 Isolate* isolate = Isolate::Current(); |
| 1053 DARTSCOPE(isolate); | 1053 DARTSCOPE(isolate); |
| 1054 TIMERSCOPE(time_creating_snapshot); | 1054 TIMERSCOPE(isolate, time_creating_snapshot); |
| 1055 if (buffer == NULL) { | 1055 if (buffer == NULL) { |
| 1056 RETURN_NULL_ERROR(buffer); | 1056 RETURN_NULL_ERROR(buffer); |
| 1057 } | 1057 } |
| 1058 if (size == NULL) { | 1058 if (size == NULL) { |
| 1059 RETURN_NULL_ERROR(size); | 1059 RETURN_NULL_ERROR(size); |
| 1060 } | 1060 } |
| 1061 Dart_Handle state = Api::CheckIsolateState(isolate); | 1061 Dart_Handle state = Api::CheckIsolateState(isolate); |
| 1062 if (::Dart_IsError(state)) { | 1062 if (::Dart_IsError(state)) { |
| 1063 return state; | 1063 return state; |
| 1064 } | 1064 } |
| 1065 // Since this is only a snapshot the root library should not be set. | 1065 // Since this is only a snapshot the root library should not be set. |
| 1066 isolate->object_store()->set_root_library(Library::Handle(isolate)); | 1066 isolate->object_store()->set_root_library(Library::Handle(isolate)); |
| 1067 FullSnapshotWriter writer(buffer, ApiReallocate); | 1067 FullSnapshotWriter writer(buffer, ApiReallocate); |
| 1068 writer.WriteFullSnapshot(); | 1068 writer.WriteFullSnapshot(); |
| 1069 *size = writer.BytesWritten(); | 1069 *size = writer.BytesWritten(); |
| 1070 return Api::Success(); | 1070 return Api::Success(); |
| 1071 } | 1071 } |
| 1072 | 1072 |
| 1073 | 1073 |
| 1074 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1074 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
| 1075 intptr_t* size) { | 1075 intptr_t* size) { |
| 1076 Isolate* isolate = Isolate::Current(); | 1076 Isolate* isolate = Isolate::Current(); |
| 1077 DARTSCOPE(isolate); | 1077 DARTSCOPE(isolate); |
| 1078 TIMERSCOPE(time_creating_snapshot); | 1078 TIMERSCOPE(isolate, time_creating_snapshot); |
| 1079 if (buffer == NULL) { | 1079 if (buffer == NULL) { |
| 1080 RETURN_NULL_ERROR(buffer); | 1080 RETURN_NULL_ERROR(buffer); |
| 1081 } | 1081 } |
| 1082 if (size == NULL) { | 1082 if (size == NULL) { |
| 1083 RETURN_NULL_ERROR(size); | 1083 RETURN_NULL_ERROR(size); |
| 1084 } | 1084 } |
| 1085 Dart_Handle state = Api::CheckIsolateState(isolate); | 1085 Dart_Handle state = Api::CheckIsolateState(isolate); |
| 1086 if (::Dart_IsError(state)) { | 1086 if (::Dart_IsError(state)) { |
| 1087 return state; | 1087 return state; |
| 1088 } | 1088 } |
| (...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3324 | 3324 |
| 3325 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 3325 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
| 3326 Dart_Handle name, | 3326 Dart_Handle name, |
| 3327 int number_of_arguments, | 3327 int number_of_arguments, |
| 3328 Dart_Handle* arguments) { | 3328 Dart_Handle* arguments) { |
| 3329 Isolate* isolate = Isolate::Current(); | 3329 Isolate* isolate = Isolate::Current(); |
| 3330 DARTSCOPE(isolate); | 3330 DARTSCOPE(isolate); |
| 3331 CHECK_CALLBACK_STATE(isolate); | 3331 CHECK_CALLBACK_STATE(isolate); |
| 3332 // TODO(turnidge): This is a bit simplistic. It overcounts when | 3332 // TODO(turnidge): This is a bit simplistic. It overcounts when |
| 3333 // other operations (gc, compilation) are active. | 3333 // other operations (gc, compilation) are active. |
| 3334 TIMERSCOPE(time_dart_execution); | 3334 TIMERSCOPE(isolate, time_dart_execution); |
| 3335 | 3335 |
| 3336 const String& function_name = Api::UnwrapStringHandle(isolate, name); | 3336 const String& function_name = Api::UnwrapStringHandle(isolate, name); |
| 3337 if (function_name.IsNull()) { | 3337 if (function_name.IsNull()) { |
| 3338 RETURN_TYPE_ERROR(isolate, name, String); | 3338 RETURN_TYPE_ERROR(isolate, name, String); |
| 3339 } | 3339 } |
| 3340 if (number_of_arguments < 0) { | 3340 if (number_of_arguments < 0) { |
| 3341 return Api::NewError( | 3341 return Api::NewError( |
| 3342 "%s expects argument 'number_of_arguments' to be non-negative.", | 3342 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3343 CURRENT_FUNC); | 3343 CURRENT_FUNC); |
| 3344 } | 3344 } |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4230 lib.SetLoadError(); | 4230 lib.SetLoadError(); |
| 4231 } | 4231 } |
| 4232 } | 4232 } |
| 4233 } | 4233 } |
| 4234 | 4234 |
| 4235 | 4235 |
| 4236 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 4236 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 4237 Dart_Handle source, | 4237 Dart_Handle source, |
| 4238 intptr_t line_offset, | 4238 intptr_t line_offset, |
| 4239 intptr_t col_offset) { | 4239 intptr_t col_offset) { |
| 4240 TIMERSCOPE(time_script_loading); | |
| 4241 Isolate* isolate = Isolate::Current(); | 4240 Isolate* isolate = Isolate::Current(); |
| 4242 DARTSCOPE(isolate); | 4241 DARTSCOPE(isolate); |
| 4242 TIMERSCOPE(isolate, time_script_loading); |
| 4243 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4243 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4244 if (url_str.IsNull()) { | 4244 if (url_str.IsNull()) { |
| 4245 RETURN_TYPE_ERROR(isolate, url, String); | 4245 RETURN_TYPE_ERROR(isolate, url, String); |
| 4246 } | 4246 } |
| 4247 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4247 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4248 if (source_str.IsNull()) { | 4248 if (source_str.IsNull()) { |
| 4249 RETURN_TYPE_ERROR(isolate, source, String); | 4249 RETURN_TYPE_ERROR(isolate, source, String); |
| 4250 } | 4250 } |
| 4251 Library& library = | 4251 Library& library = |
| 4252 Library::Handle(isolate, isolate->object_store()->root_library()); | 4252 Library::Handle(isolate, isolate->object_store()->root_library()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4278 Dart_Handle result; | 4278 Dart_Handle result; |
| 4279 CompileSource(isolate, library, script, &result); | 4279 CompileSource(isolate, library, script, &result); |
| 4280 return result; | 4280 return result; |
| 4281 } | 4281 } |
| 4282 | 4282 |
| 4283 | 4283 |
| 4284 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 4284 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
| 4285 intptr_t buffer_len) { | 4285 intptr_t buffer_len) { |
| 4286 Isolate* isolate = Isolate::Current(); | 4286 Isolate* isolate = Isolate::Current(); |
| 4287 DARTSCOPE(isolate); | 4287 DARTSCOPE(isolate); |
| 4288 TIMERSCOPE(time_script_loading); | 4288 TIMERSCOPE(isolate, time_script_loading); |
| 4289 if (buffer == NULL) { | 4289 if (buffer == NULL) { |
| 4290 RETURN_NULL_ERROR(buffer); | 4290 RETURN_NULL_ERROR(buffer); |
| 4291 } | 4291 } |
| 4292 NoHeapGrowthControlScope no_growth_control; | 4292 NoHeapGrowthControlScope no_growth_control; |
| 4293 | 4293 |
| 4294 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 4294 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 4295 if (!snapshot->IsScriptSnapshot()) { | 4295 if (!snapshot->IsScriptSnapshot()) { |
| 4296 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4296 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 4297 " snapshot.", CURRENT_FUNC); | 4297 " snapshot.", CURRENT_FUNC); |
| 4298 } | 4298 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4458 return Api::NewError("%s: library '%s' not found.", | 4458 return Api::NewError("%s: library '%s' not found.", |
| 4459 CURRENT_FUNC, url_str.ToCString()); | 4459 CURRENT_FUNC, url_str.ToCString()); |
| 4460 } else { | 4460 } else { |
| 4461 return Api::NewHandle(isolate, library.raw()); | 4461 return Api::NewHandle(isolate, library.raw()); |
| 4462 } | 4462 } |
| 4463 } | 4463 } |
| 4464 | 4464 |
| 4465 | 4465 |
| 4466 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 4466 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 4467 Dart_Handle source) { | 4467 Dart_Handle source) { |
| 4468 TIMERSCOPE(time_script_loading); | |
| 4469 Isolate* isolate = Isolate::Current(); | 4468 Isolate* isolate = Isolate::Current(); |
| 4470 DARTSCOPE(isolate); | 4469 DARTSCOPE(isolate); |
| 4470 TIMERSCOPE(isolate, time_script_loading); |
| 4471 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4471 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4472 if (url_str.IsNull()) { | 4472 if (url_str.IsNull()) { |
| 4473 RETURN_TYPE_ERROR(isolate, url, String); | 4473 RETURN_TYPE_ERROR(isolate, url, String); |
| 4474 } | 4474 } |
| 4475 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4475 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4476 if (source_str.IsNull()) { | 4476 if (source_str.IsNull()) { |
| 4477 RETURN_TYPE_ERROR(isolate, source, String); | 4477 RETURN_TYPE_ERROR(isolate, source, String); |
| 4478 } | 4478 } |
| 4479 CHECK_CALLBACK_STATE(isolate); | 4479 CHECK_CALLBACK_STATE(isolate); |
| 4480 | 4480 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4550 library_vm.AddObject(library_prefix, prefix_symbol); | 4550 library_vm.AddObject(library_prefix, prefix_symbol); |
| 4551 } | 4551 } |
| 4552 } | 4552 } |
| 4553 return Api::Success(); | 4553 return Api::Success(); |
| 4554 } | 4554 } |
| 4555 | 4555 |
| 4556 | 4556 |
| 4557 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 4557 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
| 4558 Dart_Handle url, | 4558 Dart_Handle url, |
| 4559 Dart_Handle source) { | 4559 Dart_Handle source) { |
| 4560 TIMERSCOPE(time_script_loading); | |
| 4561 Isolate* isolate = Isolate::Current(); | 4560 Isolate* isolate = Isolate::Current(); |
| 4562 DARTSCOPE(isolate); | 4561 DARTSCOPE(isolate); |
| 4562 TIMERSCOPE(isolate, time_script_loading); |
| 4563 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4563 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4564 if (lib.IsNull()) { | 4564 if (lib.IsNull()) { |
| 4565 RETURN_TYPE_ERROR(isolate, library, Library); | 4565 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4566 } | 4566 } |
| 4567 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4567 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4568 if (url_str.IsNull()) { | 4568 if (url_str.IsNull()) { |
| 4569 RETURN_TYPE_ERROR(isolate, url, String); | 4569 RETURN_TYPE_ERROR(isolate, url, String); |
| 4570 } | 4570 } |
| 4571 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4571 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4572 if (source_str.IsNull()) { | 4572 if (source_str.IsNull()) { |
| 4573 RETURN_TYPE_ERROR(isolate, source, String); | 4573 RETURN_TYPE_ERROR(isolate, source, String); |
| 4574 } | 4574 } |
| 4575 CHECK_CALLBACK_STATE(isolate); | 4575 CHECK_CALLBACK_STATE(isolate); |
| 4576 | 4576 |
| 4577 NoHeapGrowthControlScope no_growth_control; | 4577 NoHeapGrowthControlScope no_growth_control; |
| 4578 | 4578 |
| 4579 const Script& script = Script::Handle( | 4579 const Script& script = Script::Handle( |
| 4580 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); | 4580 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); |
| 4581 Dart_Handle result; | 4581 Dart_Handle result; |
| 4582 CompileSource(isolate, lib, script, &result); | 4582 CompileSource(isolate, lib, script, &result); |
| 4583 return result; | 4583 return result; |
| 4584 } | 4584 } |
| 4585 | 4585 |
| 4586 | 4586 |
| 4587 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 4587 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
| 4588 Dart_Handle url, | 4588 Dart_Handle url, |
| 4589 Dart_Handle patch_source) { | 4589 Dart_Handle patch_source) { |
| 4590 TIMERSCOPE(time_script_loading); | |
| 4591 Isolate* isolate = Isolate::Current(); | 4590 Isolate* isolate = Isolate::Current(); |
| 4592 DARTSCOPE(isolate); | 4591 DARTSCOPE(isolate); |
| 4592 TIMERSCOPE(isolate, time_script_loading); |
| 4593 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4593 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4594 if (lib.IsNull()) { | 4594 if (lib.IsNull()) { |
| 4595 RETURN_TYPE_ERROR(isolate, library, Library); | 4595 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4596 } | 4596 } |
| 4597 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4597 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4598 if (url_str.IsNull()) { | 4598 if (url_str.IsNull()) { |
| 4599 RETURN_TYPE_ERROR(isolate, url, String); | 4599 RETURN_TYPE_ERROR(isolate, url, String); |
| 4600 } | 4600 } |
| 4601 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 4601 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
| 4602 if (source_str.IsNull()) { | 4602 if (source_str.IsNull()) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4694 | 4694 |
| 4695 | 4695 |
| 4696 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4696 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4697 const char* name, | 4697 const char* name, |
| 4698 Dart_ServiceRequestCallback callback, | 4698 Dart_ServiceRequestCallback callback, |
| 4699 void* user_data) { | 4699 void* user_data) { |
| 4700 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4700 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4701 } | 4701 } |
| 4702 | 4702 |
| 4703 } // namespace dart | 4703 } // namespace dart |
| OLD | NEW |