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