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 2713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2724 } else { | 2724 } else { |
2725 return Api::NewError( | 2725 return Api::NewError( |
2726 "%s expects argument 'target' to be a class or library.", | 2726 "%s expects argument 'target' to be a class or library.", |
2727 CURRENT_FUNC); | 2727 CURRENT_FUNC); |
2728 } | 2728 } |
2729 | 2729 |
2730 #if defined(DEBUG) | 2730 #if defined(DEBUG) |
2731 if (!func.IsNull()) { | 2731 if (!func.IsNull()) { |
2732 // We only provide access to a subset of function kinds. | 2732 // We only provide access to a subset of function kinds. |
2733 RawFunction::Kind func_kind = func.kind(); | 2733 RawFunction::Kind func_kind = func.kind(); |
2734 ASSERT(func_kind == RawFunction::kFunction || | 2734 ASSERT(func_kind == RawFunction::kRegularFunction || |
2735 func_kind == RawFunction::kGetterFunction || | 2735 func_kind == RawFunction::kGetterFunction || |
2736 func_kind == RawFunction::kSetterFunction || | 2736 func_kind == RawFunction::kSetterFunction || |
2737 func_kind == RawFunction::kConstructor || | 2737 func_kind == RawFunction::kConstructor || |
2738 func_kind == RawFunction::kAbstract); | 2738 func_kind == RawFunction::kAbstract); |
2739 } | 2739 } |
2740 #endif | 2740 #endif |
2741 return Api::NewHandle(isolate, func.raw()); | 2741 return Api::NewHandle(isolate, func.raw()); |
2742 } | 2742 } |
2743 | 2743 |
2744 | 2744 |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3784 | 3784 |
3785 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 3785 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
3786 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 3786 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
3787 // which shows up because of the use of setjmp. | 3787 // which shows up because of the use of setjmp. |
3788 static void CompileSource(Isolate* isolate, | 3788 static void CompileSource(Isolate* isolate, |
3789 const Library& lib, | 3789 const Library& lib, |
3790 const String& url, | 3790 const String& url, |
3791 const String& source, | 3791 const String& source, |
3792 RawScript::Kind kind, | 3792 RawScript::Kind kind, |
3793 Dart_Handle* result) { | 3793 Dart_Handle* result) { |
3794 bool update_lib_status = (kind == RawScript::kScript || | 3794 bool update_lib_status = (kind == RawScript::kScriptTag || |
3795 kind == RawScript::kLibrary); | 3795 kind == RawScript::kLibraryTag); |
3796 if (update_lib_status) { | 3796 if (update_lib_status) { |
3797 lib.SetLoadInProgress(); | 3797 lib.SetLoadInProgress(); |
3798 } | 3798 } |
3799 const Script& script = | 3799 const Script& script = |
3800 Script::Handle(isolate, Script::New(url, source, kind)); | 3800 Script::Handle(isolate, Script::New(url, source, kind)); |
3801 ASSERT(isolate != NULL); | 3801 ASSERT(isolate != NULL); |
3802 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); | 3802 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); |
3803 if (error.IsNull()) { | 3803 if (error.IsNull()) { |
3804 *result = Api::NewHandle(isolate, lib.raw()); | 3804 *result = Api::NewHandle(isolate, lib.raw()); |
3805 if (update_lib_status) { | 3805 if (update_lib_status) { |
(...skipping 30 matching lines...) Expand all Loading... |
3836 } | 3836 } |
3837 library = Library::New(url_str); | 3837 library = Library::New(url_str); |
3838 library.set_debuggable(true); | 3838 library.set_debuggable(true); |
3839 library.Register(); | 3839 library.Register(); |
3840 isolate->object_store()->set_root_library(library); | 3840 isolate->object_store()->set_root_library(library); |
3841 Dart_Handle result; | 3841 Dart_Handle result; |
3842 CompileSource(isolate, | 3842 CompileSource(isolate, |
3843 library, | 3843 library, |
3844 url_str, | 3844 url_str, |
3845 source_str, | 3845 source_str, |
3846 RawScript::kScript, | 3846 RawScript::kScriptTag, |
3847 &result); | 3847 &result); |
3848 return result; | 3848 return result; |
3849 } | 3849 } |
3850 | 3850 |
3851 | 3851 |
3852 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 3852 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { |
3853 Isolate* isolate = Isolate::Current(); | 3853 Isolate* isolate = Isolate::Current(); |
3854 DARTSCOPE(isolate); | 3854 DARTSCOPE(isolate); |
3855 TIMERSCOPE(time_script_loading); | 3855 TIMERSCOPE(time_script_loading); |
3856 if (buffer == NULL) { | 3856 if (buffer == NULL) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4037 // The source for this library has either been loaded or is in the | 4037 // The source for this library has either been loaded or is in the |
4038 // process of loading. Return an error. | 4038 // process of loading. Return an error. |
4039 return Api::NewError("%s: library '%s' has already been loaded.", | 4039 return Api::NewError("%s: library '%s' has already been loaded.", |
4040 CURRENT_FUNC, url_str.ToCString()); | 4040 CURRENT_FUNC, url_str.ToCString()); |
4041 } | 4041 } |
4042 Dart_Handle result; | 4042 Dart_Handle result; |
4043 CompileSource(isolate, | 4043 CompileSource(isolate, |
4044 library, | 4044 library, |
4045 url_str, | 4045 url_str, |
4046 source_str, | 4046 source_str, |
4047 RawScript::kLibrary, | 4047 RawScript::kLibraryTag, |
4048 &result); | 4048 &result); |
4049 // Propagate the error out right now. | 4049 // Propagate the error out right now. |
4050 if (::Dart_IsError(result)) { | 4050 if (::Dart_IsError(result)) { |
4051 return result; | 4051 return result; |
4052 } | 4052 } |
4053 | 4053 |
4054 // If this is the dart:builtin library, register it with the VM. | 4054 // If this is the dart:builtin library, register it with the VM. |
4055 if (url_str.Equals("dart:builtin")) { | 4055 if (url_str.Equals("dart:builtin")) { |
4056 isolate->object_store()->set_builtin_library(library); | 4056 isolate->object_store()->set_builtin_library(library); |
4057 const char* msg = CheckIsolateState(isolate); | 4057 const char* msg = CheckIsolateState(isolate); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4092 } | 4092 } |
4093 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4093 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
4094 if (url_str.IsNull()) { | 4094 if (url_str.IsNull()) { |
4095 RETURN_TYPE_ERROR(isolate, url, String); | 4095 RETURN_TYPE_ERROR(isolate, url, String); |
4096 } | 4096 } |
4097 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4097 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
4098 if (source_str.IsNull()) { | 4098 if (source_str.IsNull()) { |
4099 RETURN_TYPE_ERROR(isolate, source, String); | 4099 RETURN_TYPE_ERROR(isolate, source, String); |
4100 } | 4100 } |
4101 Dart_Handle result; | 4101 Dart_Handle result; |
4102 CompileSource(isolate, lib, url_str, source_str, RawScript::kSource, &result); | 4102 CompileSource(isolate, lib, url_str, source_str, |
| 4103 RawScript::kSourceTag, &result); |
4103 return result; | 4104 return result; |
4104 } | 4105 } |
4105 | 4106 |
4106 | 4107 |
4107 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 4108 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
4108 Dart_Handle library, | 4109 Dart_Handle library, |
4109 Dart_NativeEntryResolver resolver) { | 4110 Dart_NativeEntryResolver resolver) { |
4110 Isolate* isolate = Isolate::Current(); | 4111 Isolate* isolate = Isolate::Current(); |
4111 DARTSCOPE(isolate); | 4112 DARTSCOPE(isolate); |
4112 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4113 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4148 *buffer_size = 0; | 4149 *buffer_size = 0; |
4149 } | 4150 } |
4150 } | 4151 } |
4151 | 4152 |
4152 | 4153 |
4153 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { | 4154 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { |
4154 Dart::set_flow_graph_writer(function); | 4155 Dart::set_flow_graph_writer(function); |
4155 } | 4156 } |
4156 | 4157 |
4157 } // namespace dart | 4158 } // namespace dart |
OLD | NEW |