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

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

Issue 24975002: - Implement a first cut for const String.env in the VM to allow (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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
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 "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/dart_api_impl.h"
10 #include "vm/isolate.h"
8 #include "vm/native_entry.h" 11 #include "vm/native_entry.h"
9 #include "vm/object.h" 12 #include "vm/object.h"
10 #include "vm/symbols.h" 13 #include "vm/symbols.h"
11 #include "vm/unicode.h" 14 #include "vm/unicode.h"
12 15
13 namespace dart { 16 namespace dart {
14 17
18 DEFINE_NATIVE_ENTRY(String_env, 3) {
19 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1));
20 GET_NATIVE_ARGUMENT(String, default_value, arguments->NativeArgAt(2));
21 // Call the embedder to supply us with the environment.
22 Dart_ConfigCallback callback = isolate->config_callback();
23 if (callback != NULL) {
24 Dart_Handle result = callback(kStringConfig,
25 Api::NewHandle(isolate, name.raw()));
26 if (!Dart_IsError(result)) {
27 const Object& value = Object::Handle(isolate, Api::UnwrapHandle(result));
28 if (value.IsString()) {
29 return Symbols::New(String::Cast(value));
30 }
31 }
32 }
33 return default_value.raw();
34 }
35
36
15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { 37 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
16 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); 38 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0));
17 if (!list.IsGrowableObjectArray() && !list.IsArray()) { 39 if (!list.IsGrowableObjectArray() && !list.IsArray()) {
18 const Array& args = Array::Handle(Array::New(1)); 40 const Array& args = Array::Handle(Array::New(1));
19 args.SetAt(0, list); 41 args.SetAt(0, list);
20 Exceptions::ThrowByType(Exceptions::kArgument, args); 42 Exceptions::ThrowByType(Exceptions::kArgument, args);
21 } 43 }
22 44
23 Array& a = Array::Handle(); 45 Array& a = Array::Handle();
24 intptr_t array_len; 46 intptr_t array_len;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) 268 ? String::Handle(OneByteString::New(length_value, Heap::kNew))
247 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); 269 : String::Handle(TwoByteString::New(length_value, Heap::kNew));
248 NoGCScope no_gc; 270 NoGCScope no_gc;
249 271
250 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); 272 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0));
251 String::Copy(result, 0, data_position, length_value); 273 String::Copy(result, 0, data_position, length_value);
252 return result.raw(); 274 return result.raw();
253 } 275 }
254 276
255 } // namespace dart 277 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698