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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 4703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 ASSERT(isolate == Isolate::Current()); | 4714 ASSERT(isolate == Isolate::Current()); |
4715 ASSERT(isolate->api_state() != NULL && | 4715 ASSERT(isolate->api_state() != NULL && |
4716 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || | 4716 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || |
4717 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); | 4717 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); |
4718 #endif | 4718 #endif |
4719 Api::SetWeakHandleReturnValue(arguments, rval); | 4719 Api::SetWeakHandleReturnValue(arguments, rval); |
4720 } | 4720 } |
4721 | 4721 |
4722 | 4722 |
4723 // --- Environment --- | 4723 // --- Environment --- |
| 4724 RawString* Api::CallEnvironmentCallback(Isolate* isolate, const String& name) { |
| 4725 Scope api_scope(isolate); |
| 4726 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
| 4727 String& result = String::Handle(isolate); |
| 4728 if (callback != NULL) { |
| 4729 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); |
| 4730 if (::Dart_IsString(response)) { |
| 4731 result ^= Api::UnwrapHandle(response); |
| 4732 } else if (::Dart_IsError(response)) { |
| 4733 const Object& error = |
| 4734 Object::Handle(isolate, Api::UnwrapHandle(response)); |
| 4735 Exceptions::ThrowArgumentError( |
| 4736 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); |
| 4737 } else if (!::Dart_IsNull(response)) { |
| 4738 // At this point everything except null are invalid environment values. |
| 4739 Exceptions::ThrowArgumentError( |
| 4740 String::Handle(String::New("Illegal environment value"))); |
| 4741 } |
| 4742 } |
| 4743 if (result.IsNull()) { |
| 4744 // TODO(iposva): Determine whether builtin values can be overriden by the |
| 4745 // embedder. |
| 4746 // Check for default VM provided values. If it was not overriden on the |
| 4747 // command line. |
| 4748 if (Symbols::DartIsVM().Equals(name)) { |
| 4749 return Symbols::True().raw(); |
| 4750 } |
| 4751 } |
| 4752 return result.raw(); |
| 4753 } |
| 4754 |
| 4755 |
4724 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( | 4756 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( |
4725 Dart_EnvironmentCallback callback) { | 4757 Dart_EnvironmentCallback callback) { |
4726 Isolate* isolate = Isolate::Current(); | 4758 Isolate* isolate = Isolate::Current(); |
4727 CHECK_ISOLATE(isolate); | 4759 CHECK_ISOLATE(isolate); |
4728 isolate->set_environment_callback(callback); | 4760 isolate->set_environment_callback(callback); |
4729 return Api::Success(); | 4761 return Api::Success(); |
4730 } | 4762 } |
4731 | 4763 |
4732 | 4764 |
4733 // --- Scripts and Libraries --- | 4765 // --- Scripts and Libraries --- |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5355 | 5387 |
5356 | 5388 |
5357 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5389 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5358 const char* name, | 5390 const char* name, |
5359 Dart_ServiceRequestCallback callback, | 5391 Dart_ServiceRequestCallback callback, |
5360 void* user_data) { | 5392 void* user_data) { |
5361 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5393 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5362 } | 5394 } |
5363 | 5395 |
5364 } // namespace dart | 5396 } // namespace dart |
OLD | NEW |