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 4927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4938 Isolate* isolate = arguments->thread()->isolate(); | 4938 Isolate* isolate = arguments->thread()->isolate(); |
4939 ASSERT(isolate == Isolate::Current()); | 4939 ASSERT(isolate == Isolate::Current()); |
4940 ASSERT(isolate->api_state() != NULL && | 4940 ASSERT(isolate->api_state() != NULL && |
4941 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); | 4941 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); |
4942 #endif | 4942 #endif |
4943 Api::SetWeakHandleReturnValue(arguments, rval); | 4943 Api::SetWeakHandleReturnValue(arguments, rval); |
4944 } | 4944 } |
4945 | 4945 |
4946 | 4946 |
4947 // --- Environment --- | 4947 // --- Environment --- |
4948 RawString* Api::GetEnvironmentValue(Thread* thread, const String& name) { | |
4949 String& result = String::Handle(CallEnvironmentCallback(thread, name)); | |
4950 if (result.IsNull()) { | |
4951 // Every 'dart:X' library introduces an environment variable | |
rmacnak
2016/02/05 00:38:46
Presumably we want these to answer false.
dart.l
Ivan Posva
2016/02/05 01:10:53
That is a very good point. Any private dart: libra
floitsch
2016/02/08 16:49:12
Done.
| |
4952 // 'dart.library.X' that is set to 'true'. | |
4953 const String& prefix = Symbols::DartLibrary(); | |
rmacnak
2016/02/05 00:38:46
if (!FLAG_enable_mirrors && name == "dart.library.
floitsch
2016/02/08 16:49:13
Done.
| |
4954 if (name.StartsWith(prefix)) { | |
4955 const String& library_name = | |
4956 String::Handle(String::SubString(name, prefix.Length())); | |
4957 if (!library_name.IsNull()) { | |
4958 const String& dart_library_name = | |
4959 String::Handle(String::Concat(Symbols::DartScheme(), library_name)); | |
4960 const Library& library = | |
4961 Library::Handle(Library::LookupLibrary(dart_library_name)); | |
4962 if (!library.IsNull()) { | |
4963 return Symbols::True().raw(); | |
4964 } | |
4965 } | |
4966 } | |
4967 // Check for default VM provided values. If it was not overriden on the | |
4968 // command line. | |
4969 if (Symbols::DartIsVM().Equals(name)) { | |
4970 return Symbols::True().raw(); | |
4971 } | |
4972 } | |
4973 return result.raw(); | |
4974 } | |
4975 | |
4976 | |
4948 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { | 4977 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { |
4949 Isolate* isolate = thread->isolate(); | 4978 Isolate* isolate = thread->isolate(); |
4950 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 4979 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
4951 String& result = String::Handle(thread->zone()); | 4980 String& result = String::Handle(thread->zone()); |
4952 if (callback != NULL) { | 4981 if (callback != NULL) { |
4953 TransitionVMToNative transition(thread); | 4982 TransitionVMToNative transition(thread); |
4954 Scope api_scope(thread); | 4983 Scope api_scope(thread); |
4955 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); | 4984 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); |
4956 if (::Dart_IsString(response)) { | 4985 if (::Dart_IsString(response)) { |
4957 result ^= Api::UnwrapHandle(response); | 4986 result ^= Api::UnwrapHandle(response); |
4958 } else if (::Dart_IsError(response)) { | 4987 } else if (::Dart_IsError(response)) { |
4959 const Object& error = Object::Handle( | 4988 const Object& error = Object::Handle( |
4960 thread->zone(), Api::UnwrapHandle(response)); | 4989 thread->zone(), Api::UnwrapHandle(response)); |
4961 Exceptions::ThrowArgumentError( | 4990 Exceptions::ThrowArgumentError( |
4962 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); | 4991 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); |
4963 } else if (!::Dart_IsNull(response)) { | 4992 } else if (!::Dart_IsNull(response)) { |
4964 // At this point everything except null are invalid environment values. | 4993 // At this point everything except null are invalid environment values. |
4965 Exceptions::ThrowArgumentError( | 4994 Exceptions::ThrowArgumentError( |
4966 String::Handle(String::New("Illegal environment value"))); | 4995 String::Handle(String::New("Illegal environment value"))); |
4967 } | 4996 } |
4968 } | 4997 } |
4969 if (result.IsNull()) { | |
4970 // TODO(iposva): Determine whether builtin values can be overriden by the | |
4971 // embedder. | |
4972 // Check for default VM provided values. If it was not overriden on the | |
4973 // command line. | |
4974 if (Symbols::DartIsVM().Equals(name)) { | |
4975 return Symbols::True().raw(); | |
4976 } | |
4977 } | |
4978 return result.raw(); | 4998 return result.raw(); |
4979 } | 4999 } |
4980 | 5000 |
4981 | 5001 |
4982 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( | 5002 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( |
4983 Dart_EnvironmentCallback callback) { | 5003 Dart_EnvironmentCallback callback) { |
4984 Isolate* isolate = Isolate::Current(); | 5004 Isolate* isolate = Isolate::Current(); |
4985 CHECK_ISOLATE(isolate); | 5005 CHECK_ISOLATE(isolate); |
4986 isolate->set_environment_callback(callback); | 5006 isolate->set_environment_callback(callback); |
4987 return Api::Success(); | 5007 return Api::Success(); |
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6100 return Api::Success(); | 6120 return Api::Success(); |
6101 } | 6121 } |
6102 #endif // DART_PRECOMPILER | 6122 #endif // DART_PRECOMPILER |
6103 | 6123 |
6104 | 6124 |
6105 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { | 6125 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { |
6106 return Dart::IsRunningPrecompiledCode(); | 6126 return Dart::IsRunningPrecompiledCode(); |
6107 } | 6127 } |
6108 | 6128 |
6109 } // namespace dart | 6129 } // namespace dart |
OLD | NEW |