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

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

Issue 10878037: - GET_NATIVE_ARGUMENT uses the isolate which is passed in to allocate the handle. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | « no previous file | runtime/lib/string.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 "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { 14 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
15 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); 15 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0));
16 // TODO(srdjan): Check that parameterized type is an int. 16 // TODO(srdjan): Check that parameterized type is an int.
17 Zone* zone = Isolate::Current()->current_zone(); 17 Zone* zone = isolate->current_zone();
18 intptr_t len = a.Length(); 18 intptr_t len = a.Length();
19 19
20 // Unbox the array and determine the maximum element width. 20 // Unbox the array and determine the maximum element width.
21 bool is_one_byte_string = true; 21 bool is_one_byte_string = true;
22 bool is_two_byte_string = true; 22 bool is_two_byte_string = true;
23 uint32_t* temp = zone->Alloc<uint32_t>(len); 23 uint32_t* temp = zone->Alloc<uint32_t>(len);
24 Smi& element = Smi::Handle(); 24 Object& index_object = Object::Handle(isolate);
25 for (intptr_t i = 0; i < len; i++) { 25 for (intptr_t i = 0; i < len; i++) {
26 const Object& index_object = Object::Handle(a.At(i)); 26 index_object = a.At(i);
27 if (!index_object.IsSmi()) { 27 if (!index_object.IsSmi()) {
28 GrowableArray<const Object*> args; 28 GrowableArray<const Object*> args;
29 args.Add(&index_object); 29 args.Add(&index_object);
30 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 30 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
31 } 31 }
32 element ^= index_object.raw(); 32 intptr_t value = Smi::Cast(index_object).Value();
33 intptr_t value = element.Value();
34 if (value < 0) { 33 if (value < 0) {
35 GrowableArray<const Object*> args; 34 GrowableArray<const Object*> args;
36 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 35 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
37 } else if (value > 0xFFFF) { 36 } else if (value > 0xFFFF) {
38 is_one_byte_string = false; 37 is_one_byte_string = false;
39 is_two_byte_string = false; 38 is_two_byte_string = false;
40 } else if (value > 0xFF) { 39 } else if (value > 0xFF) {
41 is_one_byte_string = false; 40 is_one_byte_string = false;
42 } 41 }
43 temp[i] = value; 42 temp[i] = value;
44 } 43 }
45 String& result = String::Handle(); 44 String& result = String::Handle(isolate);
46 if (is_one_byte_string) { 45 if (is_one_byte_string) {
47 result ^= OneByteString::New(temp, len, Heap::kNew); 46 result ^= OneByteString::New(temp, len, Heap::kNew);
48 } else if (is_two_byte_string) { 47 } else if (is_two_byte_string) {
49 result ^= TwoByteString::New(temp, len, Heap::kNew); 48 result ^= TwoByteString::New(temp, len, Heap::kNew);
50 } else { 49 } else {
51 result ^= FourByteString::New(temp, len, Heap::kNew); 50 result ^= FourByteString::New(temp, len, Heap::kNew);
52 } 51 }
53 arguments->SetReturn(result); 52 arguments->SetReturn(result);
54 } 53 }
55 54
56 55
57 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) { 56 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) {
58 GET_NATIVE_ARGUMENT(String, receiver, arguments->At(0)); 57 GET_NATIVE_ARGUMENT(String, receiver, arguments->At(0));
59 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->At(1)); 58 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->At(1));
60 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->At(2)); 59 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->At(2));
61 60
62 intptr_t start = start_obj.Value(); 61 intptr_t start = start_obj.Value();
63 intptr_t end = end_obj.Value(); 62 intptr_t end = end_obj.Value();
64 63
65 const String& result = String::Handle( 64 const String& result = String::Handle(
66 String::SubString(receiver, start, (end - start))); 65 isolate, String::SubString(receiver, start, (end - start)));
67 arguments->SetReturn(result); 66 arguments->SetReturn(result);
68 } 67 }
69 68
70 69
71 DEFINE_NATIVE_ENTRY(String_hashCode, 1) { 70 DEFINE_NATIVE_ENTRY(String_hashCode, 1) {
72 const String& receiver = String::CheckedHandle(arguments->At(0)); 71 const String& receiver = String::CheckedHandle(arguments->At(0));
73 intptr_t hash_val = receiver.Hash(); 72 intptr_t hash_val = receiver.Hash();
74 ASSERT(hash_val > 0); 73 ASSERT(hash_val > 0);
75 ASSERT(Smi::IsValid(hash_val)); 74 ASSERT(Smi::IsValid(hash_val));
76 const Smi& hash_smi = Smi::Handle(Smi::New(hash_val)); 75 const Smi& hash_smi = Smi::Handle(Smi::New(hash_val));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 GrowableArray<const Object*> args; 161 GrowableArray<const Object*> args;
163 args.Add(&elem); 162 args.Add(&elem);
164 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 163 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
165 } 164 }
166 } 165 }
167 const String& result = String::Handle(String::ConcatAll(strings)); 166 const String& result = String::Handle(String::ConcatAll(strings));
168 arguments->SetReturn(result); 167 arguments->SetReturn(result);
169 } 168 }
170 169
171 } // namespace dart 170 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698