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 "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
(...skipping 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2834 const String& dotted_name, | 2834 const String& dotted_name, |
2835 int num_args); | 2835 int num_args); |
2836 | 2836 |
2837 | 2837 |
2838 static RawObject* ThrowArgumentError(const char* exception_message) { | 2838 static RawObject* ThrowArgumentError(const char* exception_message) { |
2839 Thread* thread = Thread::Current(); | 2839 Thread* thread = Thread::Current(); |
2840 Zone* zone = thread->zone(); | 2840 Zone* zone = thread->zone(); |
2841 // Lookup the class ArgumentError in dart:core. | 2841 // Lookup the class ArgumentError in dart:core. |
2842 const String& lib_url = String::Handle(String::New("dart:core")); | 2842 const String& lib_url = String::Handle(String::New("dart:core")); |
2843 const String& class_name = String::Handle(String::New("ArgumentError")); | 2843 const String& class_name = String::Handle(String::New("ArgumentError")); |
2844 const Library& lib = | 2844 const Library& lib = Library::Handle(zone, |
2845 Library::Handle(zone, Library::LookupLibrary(lib_url)); | 2845 Library::LookupLibrary(thread, lib_url)); |
2846 if (lib.IsNull()) { | 2846 if (lib.IsNull()) { |
2847 const String& message = String::Handle( | 2847 const String& message = String::Handle( |
2848 String::NewFormatted("%s: library '%s' not found.", | 2848 String::NewFormatted("%s: library '%s' not found.", |
2849 CURRENT_FUNC, lib_url.ToCString())); | 2849 CURRENT_FUNC, lib_url.ToCString())); |
2850 return ApiError::New(message); | 2850 return ApiError::New(message); |
2851 } | 2851 } |
2852 const Class& cls = Class::Handle( | 2852 const Class& cls = Class::Handle( |
2853 zone, lib.LookupClassAllowPrivate(class_name)); | 2853 zone, lib.LookupClassAllowPrivate(class_name)); |
2854 ASSERT(!cls.IsNull()); | 2854 ASSERT(!cls.IsNull()); |
2855 Object& result = Object::Handle(zone); | 2855 Object& result = Object::Handle(zone); |
(...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4987 const String& prefix = Symbols::DartLibrary(); | 4987 const String& prefix = Symbols::DartLibrary(); |
4988 if (name.StartsWith(prefix)) { | 4988 if (name.StartsWith(prefix)) { |
4989 const String& library_name = | 4989 const String& library_name = |
4990 String::Handle(String::SubString(name, prefix.Length())); | 4990 String::Handle(String::SubString(name, prefix.Length())); |
4991 | 4991 |
4992 // Private libraries (starting with "_") are not exposed to the user. | 4992 // Private libraries (starting with "_") are not exposed to the user. |
4993 if (!library_name.IsNull() && library_name.CharAt(0) != '_') { | 4993 if (!library_name.IsNull() && library_name.CharAt(0) != '_') { |
4994 const String& dart_library_name = | 4994 const String& dart_library_name = |
4995 String::Handle(String::Concat(Symbols::DartScheme(), library_name)); | 4995 String::Handle(String::Concat(Symbols::DartScheme(), library_name)); |
4996 const Library& library = | 4996 const Library& library = |
4997 Library::Handle(Library::LookupLibrary(dart_library_name)); | 4997 Library::Handle(Library::LookupLibrary(thread, dart_library_name)); |
4998 if (!library.IsNull()) { | 4998 if (!library.IsNull()) { |
4999 return Symbols::True().raw(); | 4999 return Symbols::True().raw(); |
5000 } | 5000 } |
5001 } | 5001 } |
5002 } | 5002 } |
5003 // Check for default VM provided values. If it was not overriden on the | 5003 // Check for default VM provided values. If it was not overriden on the |
5004 // command line. | 5004 // command line. |
5005 if (Symbols::DartIsVM().Equals(name)) { | 5005 if (Symbols::DartIsVM().Equals(name)) { |
5006 return Symbols::True().raw(); | 5006 return Symbols::True().raw(); |
5007 } | 5007 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5140 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5140 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5141 CURRENT_FUNC); | 5141 CURRENT_FUNC); |
5142 } | 5142 } |
5143 CHECK_CALLBACK_STATE(T); | 5143 CHECK_CALLBACK_STATE(T); |
5144 CHECK_COMPILATION_ALLOWED(I); | 5144 CHECK_COMPILATION_ALLOWED(I); |
5145 | 5145 |
5146 NoHeapGrowthControlScope no_growth_control; | 5146 NoHeapGrowthControlScope no_growth_control; |
5147 | 5147 |
5148 library = Library::New(url_str); | 5148 library = Library::New(url_str); |
5149 library.set_debuggable(true); | 5149 library.set_debuggable(true); |
5150 library.Register(); | 5150 library.Register(T); |
5151 I->object_store()->set_root_library(library); | 5151 I->object_store()->set_root_library(library); |
5152 | 5152 |
5153 const Script& script = Script::Handle(Z, | 5153 const Script& script = Script::Handle(Z, |
5154 Script::New(url_str, source_str, RawScript::kScriptTag)); | 5154 Script::New(url_str, source_str, RawScript::kScriptTag)); |
5155 script.SetLocationOffset(line_offset, column_offset); | 5155 script.SetLocationOffset(line_offset, column_offset); |
5156 Dart_Handle result; | 5156 Dart_Handle result; |
5157 CompileSource(T, library, script, &result); | 5157 CompileSource(T, library, script, &result); |
5158 return result; | 5158 return result; |
5159 } | 5159 } |
5160 | 5160 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5341 return Api::NewHandle(T, url.raw()); | 5341 return Api::NewHandle(T, url.raw()); |
5342 } | 5342 } |
5343 | 5343 |
5344 | 5344 |
5345 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 5345 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
5346 DARTSCOPE(Thread::Current()); | 5346 DARTSCOPE(Thread::Current()); |
5347 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5347 const String& url_str = Api::UnwrapStringHandle(Z, url); |
5348 if (url_str.IsNull()) { | 5348 if (url_str.IsNull()) { |
5349 RETURN_TYPE_ERROR(Z, url, String); | 5349 RETURN_TYPE_ERROR(Z, url, String); |
5350 } | 5350 } |
5351 const Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); | 5351 const Library& library = Library::Handle(Z, |
| 5352 Library::LookupLibrary(T, url_str)); |
5352 if (library.IsNull()) { | 5353 if (library.IsNull()) { |
5353 return Api::NewError("%s: library '%s' not found.", | 5354 return Api::NewError("%s: library '%s' not found.", |
5354 CURRENT_FUNC, url_str.ToCString()); | 5355 CURRENT_FUNC, url_str.ToCString()); |
5355 } else { | 5356 } else { |
5356 return Api::NewHandle(T, library.raw()); | 5357 return Api::NewHandle(T, library.raw()); |
5357 } | 5358 } |
5358 } | 5359 } |
5359 | 5360 |
5360 | 5361 |
5361 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, | 5362 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5407 } | 5408 } |
5408 if (column_offset < 0) { | 5409 if (column_offset < 0) { |
5409 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5410 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5410 CURRENT_FUNC); | 5411 CURRENT_FUNC); |
5411 } | 5412 } |
5412 CHECK_CALLBACK_STATE(T); | 5413 CHECK_CALLBACK_STATE(T); |
5413 CHECK_COMPILATION_ALLOWED(I); | 5414 CHECK_COMPILATION_ALLOWED(I); |
5414 | 5415 |
5415 NoHeapGrowthControlScope no_growth_control; | 5416 NoHeapGrowthControlScope no_growth_control; |
5416 | 5417 |
5417 Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); | 5418 Library& library = Library::Handle(Z, Library::LookupLibrary(T, url_str)); |
5418 if (library.IsNull()) { | 5419 if (library.IsNull()) { |
5419 library = Library::New(url_str); | 5420 library = Library::New(url_str); |
5420 library.Register(); | 5421 library.Register(T); |
5421 } else if (library.LoadInProgress() || | 5422 } else if (library.LoadInProgress() || |
5422 library.Loaded() || | 5423 library.Loaded() || |
5423 library.LoadFailed()) { | 5424 library.LoadFailed()) { |
5424 // The source for this library has either been loaded or is in the | 5425 // The source for this library has either been loaded or is in the |
5425 // process of loading. Return an error. | 5426 // process of loading. Return an error. |
5426 return Api::NewError("%s: library '%s' has already been loaded.", | 5427 return Api::NewError("%s: library '%s' has already been loaded.", |
5427 CURRENT_FUNC, url_str.ToCString()); | 5428 CURRENT_FUNC, url_str.ToCString()); |
5428 } | 5429 } |
5429 const Script& script = Script::Handle(Z, | 5430 const Script& script = Script::Handle(Z, |
5430 Script::New(url_str, source_str, RawScript::kLibraryTag)); | 5431 Script::New(url_str, source_str, RawScript::kLibraryTag)); |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6193 return Api::Success(); | 6194 return Api::Success(); |
6194 } | 6195 } |
6195 #endif // DART_PRECOMPILER | 6196 #endif // DART_PRECOMPILER |
6196 | 6197 |
6197 | 6198 |
6198 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { | 6199 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { |
6199 return Dart::IsRunningPrecompiledCode(); | 6200 return Dart::IsRunningPrecompiledCode(); |
6200 } | 6201 } |
6201 | 6202 |
6202 } // namespace dart | 6203 } // namespace dart |
OLD | NEW |