Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: runtime/lib/string.cc

Issue 186573002: Revert "Fix fromEnvironment when called from isolates." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/integers.cc ('k') | tests/corelib/bool_from_environment_default_value_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
11 #include "vm/native_entry.h" 11 #include "vm/native_entry.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/symbols.h" 13 #include "vm/symbols.h"
14 #include "vm/unicode.h" 14 #include "vm/unicode.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) { 18 DEFINE_NATIVE_ENTRY(String_fromEnvironment, 3) {
19 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); 19 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1));
20 GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2)); 20 GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2));
21 // Call the embedder to supply us with the environment. 21 // Call the embedder to supply us with the environment.
22 Dart_EnterScope();
23 Dart_EnvironmentCallback callback = isolate->environment_callback(); 22 Dart_EnvironmentCallback callback = isolate->environment_callback();
24 if (callback != NULL) { 23 if (callback != NULL) {
25 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw())); 24 Dart_Handle result = callback(Api::NewHandle(isolate, name.raw()));
26 if (Dart_IsString(result)) { 25 if (Dart_IsString(result)) {
27 const Object& value = 26 const Object& value =
28 Object::Handle(isolate, Api::UnwrapHandle(result)); 27 Object::Handle(isolate, Api::UnwrapHandle(result));
29 return Symbols::New(String::Cast(value)); 28 return Symbols::New(String::Cast(value));
30 } else if (Dart_IsError(result)) { 29 } else if (Dart_IsError(result)) {
31 const Object& error = 30 const Object& error =
32 Object::Handle(isolate, Api::UnwrapHandle(result)); 31 Object::Handle(isolate, Api::UnwrapHandle(result));
33 Exceptions::ThrowArgumentError( 32 Exceptions::ThrowArgumentError(
34 String::Handle( 33 String::Handle(
35 String::New(Error::Cast(error).ToErrorCString()))); 34 String::New(Error::Cast(error).ToErrorCString())));
36 } else if (!Dart_IsNull(result)) { 35 } else if (!Dart_IsNull(result)) {
37 Exceptions::ThrowArgumentError( 36 Exceptions::ThrowArgumentError(
38 String::Handle(String::New("Illegal environment value"))); 37 String::Handle(String::New("Illegal environment value")));
39 } 38 }
40 } 39 }
41 Dart_ExitScope();
42 return default_value.raw(); 40 return default_value.raw();
43 } 41 }
44 42
45 43
46 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { 44 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
47 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); 45 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0));
48 if (!list.IsGrowableObjectArray() && !list.IsArray()) { 46 if (!list.IsGrowableObjectArray() && !list.IsArray()) {
49 Exceptions::ThrowArgumentError(list); 47 Exceptions::ThrowArgumentError(list);
50 } 48 }
51 49
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) 348 ? String::Handle(OneByteString::New(length_value, Heap::kNew))
351 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); 349 : String::Handle(TwoByteString::New(length_value, Heap::kNew));
352 NoGCScope no_gc; 350 NoGCScope no_gc;
353 351
354 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); 352 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0));
355 String::Copy(result, 0, data_position, length_value); 353 String::Copy(result, 0, data_position, length_value);
356 return result.raw(); 354 return result.raw();
357 } 355 }
358 356
359 } // namespace dart 357 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/integers.cc ('k') | tests/corelib/bool_from_environment_default_value_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698