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 "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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 RETURN_NULL_ERROR(size); | 816 RETURN_NULL_ERROR(size); |
817 } | 817 } |
818 const char* msg = CheckIsolateState(isolate, | 818 const char* msg = CheckIsolateState(isolate, |
819 ClassFinalizer::kGeneratingSnapshot); | 819 ClassFinalizer::kGeneratingSnapshot); |
820 if (msg != NULL) { | 820 if (msg != NULL) { |
821 return Api::NewError(msg); | 821 return Api::NewError(msg); |
822 } | 822 } |
823 // Since this is only a snapshot the root library should not be set. | 823 // Since this is only a snapshot the root library should not be set. |
824 isolate->object_store()->set_root_library(Library::Handle(isolate)); | 824 isolate->object_store()->set_root_library(Library::Handle(isolate)); |
825 SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate); | 825 SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate); |
826 writer.WriteFullSnapshot(); | 826 *size = writer.WriteFullSnapshot(); |
siva
2012/08/22 23:30:39
I would prefer not returning the size as a return
turnidge
2012/08/23 18:37:57
Done.
| |
827 *size = writer.BytesWritten(); | |
828 return Api::Success(isolate); | 827 return Api::Success(isolate); |
829 } | 828 } |
830 | 829 |
831 | 830 |
832 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 831 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
833 intptr_t* size) { | 832 intptr_t* size) { |
834 Isolate* isolate = Isolate::Current(); | 833 Isolate* isolate = Isolate::Current(); |
835 DARTSCOPE(isolate); | 834 DARTSCOPE(isolate); |
836 TIMERSCOPE(time_creating_snapshot); | 835 TIMERSCOPE(time_creating_snapshot); |
837 if (buffer == NULL) { | 836 if (buffer == NULL) { |
838 RETURN_NULL_ERROR(buffer); | 837 RETURN_NULL_ERROR(buffer); |
839 } | 838 } |
840 if (size == NULL) { | 839 if (size == NULL) { |
841 RETURN_NULL_ERROR(size); | 840 RETURN_NULL_ERROR(size); |
842 } | 841 } |
843 const char* msg = CheckIsolateState(isolate); | 842 const char* msg = CheckIsolateState(isolate); |
844 if (msg != NULL) { | 843 if (msg != NULL) { |
845 return Api::NewError(msg); | 844 return Api::NewError(msg); |
846 } | 845 } |
847 Library& library = | 846 Library& library = |
848 Library::Handle(isolate, isolate->object_store()->root_library()); | 847 Library::Handle(isolate, isolate->object_store()->root_library()); |
849 if (library.IsNull()) { | 848 if (library.IsNull()) { |
850 return | 849 return |
851 Api::NewError("%s expects the isolate to have a script loaded in it.", | 850 Api::NewError("%s expects the isolate to have a script loaded in it.", |
852 CURRENT_FUNC); | 851 CURRENT_FUNC); |
853 } | 852 } |
854 ScriptSnapshotWriter writer(buffer, ApiReallocate); | 853 ScriptSnapshotWriter writer(buffer, ApiReallocate); |
855 writer.WriteScriptSnapshot(library); | 854 *size = writer.WriteScriptSnapshot(library); |
856 *size = writer.BytesWritten(); | |
857 return Api::Success(isolate); | 855 return Api::Success(isolate); |
858 } | 856 } |
859 | 857 |
860 | 858 |
861 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 859 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
862 if (isolate == NULL) { | 860 if (isolate == NULL) { |
863 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 861 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
864 } | 862 } |
865 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 863 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
866 iso->ScheduleInterrupts(Isolate::kApiInterrupt); | 864 iso->ScheduleInterrupts(Isolate::kApiInterrupt); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 return reinterpret_cast<uint8_t*>(new_ptr); | 945 return reinterpret_cast<uint8_t*>(new_ptr); |
948 } | 946 } |
949 | 947 |
950 | 948 |
951 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, | 949 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, |
952 intptr_t len, | 950 intptr_t len, |
953 intptr_t* data) { | 951 intptr_t* data) { |
954 uint8_t* buffer = NULL; | 952 uint8_t* buffer = NULL; |
955 ApiMessageWriter writer(&buffer, &allocator); | 953 ApiMessageWriter writer(&buffer, &allocator); |
956 | 954 |
957 writer.WriteMessage(len, data); | 955 intptr_t buffer_len = writer.WriteMessage(len, data); |
958 | 956 |
959 // Post the message at the given port. | 957 // Post the message at the given port. |
960 return PortMap::PostMessage(new Message( | 958 return PortMap::PostMessage(new Message( |
961 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); | 959 port_id, Message::kIllegalPort, buffer, buffer_len, |
960 Message::kNormalPriority)); | |
962 } | 961 } |
963 | 962 |
964 | 963 |
965 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { | 964 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { |
966 uint8_t* buffer = NULL; | 965 uint8_t* buffer = NULL; |
967 ApiMessageWriter writer(&buffer, allocator); | 966 ApiMessageWriter writer(&buffer, allocator); |
968 | 967 |
969 writer.WriteCMessage(message); | 968 intptr_t buffer_len = writer.WriteCMessage(message); |
970 | 969 |
971 // Post the message at the given port. | 970 // Post the message at the given port. |
972 return PortMap::PostMessage(new Message( | 971 return PortMap::PostMessage(new Message( |
973 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); | 972 port_id, Message::kIllegalPort, buffer, buffer_len, |
973 Message::kNormalPriority)); | |
974 } | 974 } |
975 | 975 |
976 | 976 |
977 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 977 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
978 Isolate* isolate = Isolate::Current(); | 978 Isolate* isolate = Isolate::Current(); |
979 CHECK_ISOLATE(isolate); | 979 CHECK_ISOLATE(isolate); |
980 DARTSCOPE_NOCHECKS(isolate); | 980 DARTSCOPE_NOCHECKS(isolate); |
981 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 981 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
982 uint8_t* data = NULL; | 982 uint8_t* data = NULL; |
983 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); | 983 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); |
984 writer.WriteObject(object.raw()); | 984 writer.WriteObject(object.raw()); |
985 writer.FinalizeBuffer(); | 985 intptr_t len = writer.FinalizeBuffer(); |
986 return PortMap::PostMessage(new Message( | 986 return PortMap::PostMessage(new Message( |
987 port_id, Message::kIllegalPort, data, Message::kNormalPriority)); | 987 port_id, Message::kIllegalPort, data, len, Message::kNormalPriority)); |
988 } | 988 } |
989 | 989 |
990 | 990 |
991 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, | 991 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, |
992 Dart_NativeMessageHandler handler, | 992 Dart_NativeMessageHandler handler, |
993 bool handle_concurrently) { | 993 bool handle_concurrently) { |
994 if (name == NULL) { | 994 if (name == NULL) { |
995 name = "<UnnamedNativePort>"; | 995 name = "<UnnamedNativePort>"; |
996 } | 996 } |
997 if (handler == NULL) { | 997 if (handler == NULL) { |
(...skipping 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3776 } | 3776 } |
3777 | 3777 |
3778 | 3778 |
3779 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 3779 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { |
3780 Isolate* isolate = Isolate::Current(); | 3780 Isolate* isolate = Isolate::Current(); |
3781 DARTSCOPE(isolate); | 3781 DARTSCOPE(isolate); |
3782 TIMERSCOPE(time_script_loading); | 3782 TIMERSCOPE(time_script_loading); |
3783 if (buffer == NULL) { | 3783 if (buffer == NULL) { |
3784 RETURN_NULL_ERROR(buffer); | 3784 RETURN_NULL_ERROR(buffer); |
3785 } | 3785 } |
3786 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 3786 const Snapshot* snapshot = |
3787 Snapshot::SetupFromBuffer(buffer, Snapshot::kTrustedLength); | |
3788 if (snapshot == NULL) { | |
3789 return Api::NewError("%s: unexpected error during snapshot parsing." | |
3790 " snapshot", CURRENT_FUNC); | |
3791 } | |
3787 if (!snapshot->IsScriptSnapshot()) { | 3792 if (!snapshot->IsScriptSnapshot()) { |
3788 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 3793 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
3789 " snapshot", CURRENT_FUNC); | 3794 " snapshot.", CURRENT_FUNC); |
3790 } | 3795 } |
3791 Library& library = | 3796 Library& library = |
3792 Library::Handle(isolate, isolate->object_store()->root_library()); | 3797 Library::Handle(isolate, isolate->object_store()->root_library()); |
3793 if (!library.IsNull()) { | 3798 if (!library.IsNull()) { |
3794 const String& library_url = String::Handle(isolate, library.url()); | 3799 const String& library_url = String::Handle(isolate, library.url()); |
3795 return Api::NewError("%s: A script has already been loaded from '%s'.", | 3800 return Api::NewError("%s: A script has already been loaded from '%s'.", |
3796 CURRENT_FUNC, library_url.ToCString()); | 3801 CURRENT_FUNC, library_url.ToCString()); |
3797 } | 3802 } |
3798 SnapshotReader reader(snapshot, isolate); | 3803 SnapshotReader reader(snapshot, isolate); |
3799 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); | 3804 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4081 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4086 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
4082 Dart::set_perf_events_writer(function); | 4087 Dart::set_perf_events_writer(function); |
4083 } | 4088 } |
4084 | 4089 |
4085 | 4090 |
4086 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4091 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
4087 Dart::set_flow_graph_writer(function); | 4092 Dart::set_flow_graph_writer(function); |
4088 } | 4093 } |
4089 | 4094 |
4090 } // namespace dart | 4095 } // namespace dart |
OLD | NEW |