| 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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 4948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4959 ASSERT(isolate == Isolate::Current()); | 4959 ASSERT(isolate == Isolate::Current()); |
| 4960 ASSERT(isolate->api_state() != NULL && | 4960 ASSERT(isolate->api_state() != NULL && |
| 4961 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || | 4961 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || |
| 4962 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); | 4962 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); |
| 4963 #endif | 4963 #endif |
| 4964 Api::SetWeakHandleReturnValue(arguments, rval); | 4964 Api::SetWeakHandleReturnValue(arguments, rval); |
| 4965 } | 4965 } |
| 4966 | 4966 |
| 4967 | 4967 |
| 4968 // --- Environment --- | 4968 // --- Environment --- |
| 4969 RawString* Api::CallEnvironmentCallback(Isolate* isolate, const String& name) { | 4969 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { |
| 4970 Isolate* isolate = thread->isolate(); |
| 4970 Scope api_scope(isolate); | 4971 Scope api_scope(isolate); |
| 4971 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 4972 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
| 4972 String& result = String::Handle(isolate->current_zone()); | 4973 String& result = String::Handle(thread->zone()); |
| 4973 if (callback != NULL) { | 4974 if (callback != NULL) { |
| 4974 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); | 4975 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); |
| 4975 if (::Dart_IsString(response)) { | 4976 if (::Dart_IsString(response)) { |
| 4976 result ^= Api::UnwrapHandle(response); | 4977 result ^= Api::UnwrapHandle(response); |
| 4977 } else if (::Dart_IsError(response)) { | 4978 } else if (::Dart_IsError(response)) { |
| 4978 const Object& error = | 4979 const Object& error = Object::Handle( |
| 4979 Object::Handle(isolate->current_zone(), Api::UnwrapHandle(response)); | 4980 thread->zone(), Api::UnwrapHandle(response)); |
| 4980 Exceptions::ThrowArgumentError( | 4981 Exceptions::ThrowArgumentError( |
| 4981 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); | 4982 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); |
| 4982 } else if (!::Dart_IsNull(response)) { | 4983 } else if (!::Dart_IsNull(response)) { |
| 4983 // At this point everything except null are invalid environment values. | 4984 // At this point everything except null are invalid environment values. |
| 4984 Exceptions::ThrowArgumentError( | 4985 Exceptions::ThrowArgumentError( |
| 4985 String::Handle(String::New("Illegal environment value"))); | 4986 String::Handle(String::New("Illegal environment value"))); |
| 4986 } | 4987 } |
| 4987 } | 4988 } |
| 4988 if (result.IsNull()) { | 4989 if (result.IsNull()) { |
| 4989 // TODO(iposva): Determine whether builtin values can be overriden by the | 4990 // TODO(iposva): Determine whether builtin values can be overriden by the |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5045 Isolate* isolate = Isolate::Current(); | 5046 Isolate* isolate = Isolate::Current(); |
| 5046 CHECK_ISOLATE(isolate); | 5047 CHECK_ISOLATE(isolate); |
| 5047 isolate->set_library_tag_handler(handler); | 5048 isolate->set_library_tag_handler(handler); |
| 5048 return Api::Success(); | 5049 return Api::Success(); |
| 5049 } | 5050 } |
| 5050 | 5051 |
| 5051 | 5052 |
| 5052 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 5053 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 5053 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 5054 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 5054 // which shows up because of the use of setjmp. | 5055 // which shows up because of the use of setjmp. |
| 5055 static void CompileSource(Isolate* isolate, | 5056 static void CompileSource(Thread* thread, |
| 5056 const Library& lib, | 5057 const Library& lib, |
| 5057 const Script& script, | 5058 const Script& script, |
| 5058 Dart_Handle* result) { | 5059 Dart_Handle* result) { |
| 5059 bool update_lib_status = (script.kind() == RawScript::kScriptTag || | 5060 bool update_lib_status = (script.kind() == RawScript::kScriptTag || |
| 5060 script.kind() == RawScript::kLibraryTag); | 5061 script.kind() == RawScript::kLibraryTag); |
| 5061 if (update_lib_status) { | 5062 if (update_lib_status) { |
| 5062 lib.SetLoadInProgress(); | 5063 lib.SetLoadInProgress(); |
| 5063 } | 5064 } |
| 5064 ASSERT(isolate != NULL); | 5065 ASSERT(thread != NULL); |
| 5065 const Error& error = | 5066 const Error& error = |
| 5066 Error::Handle(isolate->current_zone(), Compiler::Compile(lib, script)); | 5067 Error::Handle(thread->zone(), Compiler::Compile(lib, script)); |
| 5067 if (error.IsNull()) { | 5068 if (error.IsNull()) { |
| 5068 *result = Api::NewHandle(isolate, lib.raw()); | 5069 *result = Api::NewHandle(thread->isolate(), lib.raw()); |
| 5069 } else { | 5070 } else { |
| 5070 *result = Api::NewHandle(isolate, error.raw()); | 5071 *result = Api::NewHandle(thread->isolate(), error.raw()); |
| 5071 // Compilation errors are not Dart instances, so just mark the library | 5072 // Compilation errors are not Dart instances, so just mark the library |
| 5072 // as having failed to load without providing an error instance. | 5073 // as having failed to load without providing an error instance. |
| 5073 lib.SetLoadError(Object::null_instance()); | 5074 lib.SetLoadError(Object::null_instance()); |
| 5074 } | 5075 } |
| 5075 } | 5076 } |
| 5076 | 5077 |
| 5077 | 5078 |
| 5078 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 5079 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 5079 Dart_Handle source, | 5080 Dart_Handle source, |
| 5080 intptr_t line_offset, | 5081 intptr_t line_offset, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5109 | 5110 |
| 5110 library = Library::New(url_str); | 5111 library = Library::New(url_str); |
| 5111 library.set_debuggable(true); | 5112 library.set_debuggable(true); |
| 5112 library.Register(); | 5113 library.Register(); |
| 5113 I->object_store()->set_root_library(library); | 5114 I->object_store()->set_root_library(library); |
| 5114 | 5115 |
| 5115 const Script& script = Script::Handle(Z, | 5116 const Script& script = Script::Handle(Z, |
| 5116 Script::New(url_str, source_str, RawScript::kScriptTag)); | 5117 Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 5117 script.SetLocationOffset(line_offset, column_offset); | 5118 script.SetLocationOffset(line_offset, column_offset); |
| 5118 Dart_Handle result; | 5119 Dart_Handle result; |
| 5119 CompileSource(I, library, script, &result); | 5120 CompileSource(T, library, script, &result); |
| 5120 return result; | 5121 return result; |
| 5121 } | 5122 } |
| 5122 | 5123 |
| 5123 | 5124 |
| 5124 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 5125 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
| 5125 intptr_t buffer_len) { | 5126 intptr_t buffer_len) { |
| 5126 DARTSCOPE(Thread::Current()); | 5127 DARTSCOPE(Thread::Current()); |
| 5127 StackZone zone(T); | 5128 StackZone zone(T); |
| 5128 if (buffer == NULL) { | 5129 if (buffer == NULL) { |
| 5129 RETURN_NULL_ERROR(buffer); | 5130 RETURN_NULL_ERROR(buffer); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5354 library.LoadFailed()) { | 5355 library.LoadFailed()) { |
| 5355 // The source for this library has either been loaded or is in the | 5356 // The source for this library has either been loaded or is in the |
| 5356 // process of loading. Return an error. | 5357 // process of loading. Return an error. |
| 5357 return Api::NewError("%s: library '%s' has already been loaded.", | 5358 return Api::NewError("%s: library '%s' has already been loaded.", |
| 5358 CURRENT_FUNC, url_str.ToCString()); | 5359 CURRENT_FUNC, url_str.ToCString()); |
| 5359 } | 5360 } |
| 5360 const Script& script = Script::Handle(Z, | 5361 const Script& script = Script::Handle(Z, |
| 5361 Script::New(url_str, source_str, RawScript::kLibraryTag)); | 5362 Script::New(url_str, source_str, RawScript::kLibraryTag)); |
| 5362 script.SetLocationOffset(line_offset, column_offset); | 5363 script.SetLocationOffset(line_offset, column_offset); |
| 5363 Dart_Handle result; | 5364 Dart_Handle result; |
| 5364 CompileSource(I, library, script, &result); | 5365 CompileSource(T, library, script, &result); |
| 5365 // Propagate the error out right now. | 5366 // Propagate the error out right now. |
| 5366 if (::Dart_IsError(result)) { | 5367 if (::Dart_IsError(result)) { |
| 5367 return result; | 5368 return result; |
| 5368 } | 5369 } |
| 5369 | 5370 |
| 5370 // If this is the dart:_builtin library, register it with the VM. | 5371 // If this is the dart:_builtin library, register it with the VM. |
| 5371 if (url_str.Equals("dart:_builtin")) { | 5372 if (url_str.Equals("dart:_builtin")) { |
| 5372 I->object_store()->set_builtin_library(library); | 5373 I->object_store()->set_builtin_library(library); |
| 5373 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 5374 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
| 5374 if (::Dart_IsError(state)) { | 5375 if (::Dart_IsError(state)) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5449 } | 5450 } |
| 5450 CHECK_CALLBACK_STATE(T); | 5451 CHECK_CALLBACK_STATE(T); |
| 5451 CHECK_COMPILATION_ALLOWED(I); | 5452 CHECK_COMPILATION_ALLOWED(I); |
| 5452 | 5453 |
| 5453 NoHeapGrowthControlScope no_growth_control; | 5454 NoHeapGrowthControlScope no_growth_control; |
| 5454 | 5455 |
| 5455 const Script& script = Script::Handle(Z, | 5456 const Script& script = Script::Handle(Z, |
| 5456 Script::New(url_str, source_str, RawScript::kSourceTag)); | 5457 Script::New(url_str, source_str, RawScript::kSourceTag)); |
| 5457 script.SetLocationOffset(line_offset, column_offset); | 5458 script.SetLocationOffset(line_offset, column_offset); |
| 5458 Dart_Handle result; | 5459 Dart_Handle result; |
| 5459 CompileSource(I, lib, script, &result); | 5460 CompileSource(T, lib, script, &result); |
| 5460 return result; | 5461 return result; |
| 5461 } | 5462 } |
| 5462 | 5463 |
| 5463 | 5464 |
| 5464 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5465 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
| 5465 Dart_Handle url, | 5466 Dart_Handle url, |
| 5466 Dart_Handle patch_source) { | 5467 Dart_Handle patch_source) { |
| 5467 DARTSCOPE(Thread::Current()); | 5468 DARTSCOPE(Thread::Current()); |
| 5468 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5469 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5469 if (lib.IsNull()) { | 5470 if (lib.IsNull()) { |
| 5470 RETURN_TYPE_ERROR(Z, library, Library); | 5471 RETURN_TYPE_ERROR(Z, library, Library); |
| 5471 } | 5472 } |
| 5472 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5473 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5473 if (url_str.IsNull()) { | 5474 if (url_str.IsNull()) { |
| 5474 RETURN_TYPE_ERROR(Z, url, String); | 5475 RETURN_TYPE_ERROR(Z, url, String); |
| 5475 } | 5476 } |
| 5476 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); | 5477 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); |
| 5477 if (source_str.IsNull()) { | 5478 if (source_str.IsNull()) { |
| 5478 RETURN_TYPE_ERROR(Z, patch_source, String); | 5479 RETURN_TYPE_ERROR(Z, patch_source, String); |
| 5479 } | 5480 } |
| 5480 CHECK_CALLBACK_STATE(T); | 5481 CHECK_CALLBACK_STATE(T); |
| 5481 CHECK_COMPILATION_ALLOWED(I); | 5482 CHECK_COMPILATION_ALLOWED(I); |
| 5482 | 5483 |
| 5483 NoHeapGrowthControlScope no_growth_control; | 5484 NoHeapGrowthControlScope no_growth_control; |
| 5484 | 5485 |
| 5485 const Script& script = Script::Handle(Z, | 5486 const Script& script = Script::Handle(Z, |
| 5486 Script::New(url_str, source_str, RawScript::kPatchTag)); | 5487 Script::New(url_str, source_str, RawScript::kPatchTag)); |
| 5487 Dart_Handle result; | 5488 Dart_Handle result; |
| 5488 CompileSource(I, lib, script, &result); | 5489 CompileSource(T, lib, script, &result); |
| 5489 return result; | 5490 return result; |
| 5490 } | 5491 } |
| 5491 | 5492 |
| 5492 | 5493 |
| 5493 // Finalizes classes and invokes Dart core library function that completes | 5494 // Finalizes classes and invokes Dart core library function that completes |
| 5494 // futures of loadLibrary calls (deferred library loading). | 5495 // futures of loadLibrary calls (deferred library loading). |
| 5495 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5496 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
| 5496 DARTSCOPE(Thread::Current()); | 5497 DARTSCOPE(Thread::Current()); |
| 5497 CHECK_CALLBACK_STATE(T); | 5498 CHECK_CALLBACK_STATE(T); |
| 5498 | 5499 |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6089 ApiReallocate); | 6090 ApiReallocate); |
| 6090 writer.WriteFullSnapshot(); | 6091 writer.WriteFullSnapshot(); |
| 6091 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6092 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 6092 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6093 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 6093 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 6094 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 6094 | 6095 |
| 6095 return Api::Success(); | 6096 return Api::Success(); |
| 6096 } | 6097 } |
| 6097 | 6098 |
| 6098 } // namespace dart | 6099 } // namespace dart |
| OLD | NEW |