OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "bin/isolate_data.h" | 6 #include "bin/isolate_data.h" |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 void FUNCTION_NAME(Common_IsBuiltinList)(Dart_NativeArguments args) { | 9 void FUNCTION_NAME(Common_IsBuiltinList)(Dart_NativeArguments args) { |
10 Dart_EnterScope(); | 10 Dart_EnterScope(); |
11 Dart_Handle list = Dart_GetNativeArgument(args, 0); | 11 Dart_Handle list = Dart_GetNativeArgument(args, 0); |
12 Dart_Handle list_class = Dart_InstanceGetClass(list); | 12 Dart_Handle list_class = Dart_InstanceGetClass(list); |
13 ASSERT(!Dart_IsError(list_class)); | 13 ASSERT(!Dart_IsError(list_class)); |
14 | 14 |
15 // Fetch the cached builtin array types for this isolate. | 15 // Fetch the cached builtin array types for this isolate. |
16 IsolateData* isolate_data = | 16 IsolateData* isolate_data = |
17 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 17 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
18 Dart_Handle object_array_class = isolate_data->object_array_class; | 18 Dart_Handle object_array_class = isolate_data->object_array_class; |
19 Dart_Handle growable_object_array_class = | 19 Dart_Handle growable_object_array_class = |
20 isolate_data->growable_object_array_class; | 20 isolate_data->growable_object_array_class; |
21 Dart_Handle immutable_array_class = isolate_data->immutable_array_class; | 21 Dart_Handle immutable_array_class = isolate_data->immutable_array_class; |
22 | 22 |
23 // If we have not cached the class pointers in the isolate data, | 23 // If we have not cached the class pointers in the isolate data, |
24 // look them up and cache them now. | 24 // look them up and cache them now. |
25 if (object_array_class == NULL) { | 25 if (object_array_class == NULL) { |
26 Dart_Handle core_lib = | 26 Dart_Handle core_lib = |
27 Dart_LookupLibrary(Dart_NewString("dart:core")); | 27 Dart_LookupLibrary(Dart_NewStringFromCString("dart:core")); |
28 ASSERT(!Dart_IsError(core_lib)); | 28 ASSERT(!Dart_IsError(core_lib)); |
29 object_array_class = | 29 object_array_class = |
30 Dart_GetClass(core_lib, Dart_NewString("_ObjectArray")); | 30 Dart_GetClass(core_lib, Dart_NewStringFromCString("_ObjectArray")); |
31 ASSERT(!Dart_IsError(object_array_class)); | 31 ASSERT(!Dart_IsError(object_array_class)); |
32 immutable_array_class = | 32 immutable_array_class = |
33 Dart_GetClass(core_lib, Dart_NewString("_ImmutableArray")); | 33 Dart_GetClass(core_lib, Dart_NewStringFromCString("_ImmutableArray")); |
34 ASSERT(!Dart_IsError(immutable_array_class)); | 34 ASSERT(!Dart_IsError(immutable_array_class)); |
35 growable_object_array_class = | 35 growable_object_array_class = Dart_GetClass( |
36 Dart_GetClass(core_lib, Dart_NewString("_GrowableObjectArray")); | 36 core_lib, Dart_NewStringFromCString("_GrowableObjectArray")); |
37 ASSERT(!Dart_IsError(growable_object_array_class)); | 37 ASSERT(!Dart_IsError(growable_object_array_class)); |
38 // Update the cache. | 38 // Update the cache. |
39 isolate_data->object_array_class = | 39 isolate_data->object_array_class = |
40 Dart_NewPersistentHandle(object_array_class); | 40 Dart_NewPersistentHandle(object_array_class); |
41 ASSERT(!Dart_IsError(isolate_data->object_array_class)); | 41 ASSERT(!Dart_IsError(isolate_data->object_array_class)); |
42 isolate_data->growable_object_array_class = | 42 isolate_data->growable_object_array_class = |
43 Dart_NewPersistentHandle(growable_object_array_class); | 43 Dart_NewPersistentHandle(growable_object_array_class); |
44 ASSERT(!Dart_IsError(isolate_data->growable_object_array_class)); | 44 ASSERT(!Dart_IsError(isolate_data->growable_object_array_class)); |
45 isolate_data->immutable_array_class = | 45 isolate_data->immutable_array_class = |
46 Dart_NewPersistentHandle(immutable_array_class); | 46 Dart_NewPersistentHandle(immutable_array_class); |
47 ASSERT(!Dart_IsError(isolate_data->immutable_array_class)); | 47 ASSERT(!Dart_IsError(isolate_data->immutable_array_class)); |
48 } | 48 } |
49 | 49 |
50 bool builtin_array = | 50 bool builtin_array = |
51 (Dart_IdentityEquals(list_class, growable_object_array_class) || | 51 (Dart_IdentityEquals(list_class, growable_object_array_class) || |
52 Dart_IdentityEquals(list_class, object_array_class) || | 52 Dart_IdentityEquals(list_class, object_array_class) || |
53 Dart_IdentityEquals(list_class, immutable_array_class)); | 53 Dart_IdentityEquals(list_class, immutable_array_class)); |
54 Dart_SetReturnValue(args, Dart_NewBoolean(builtin_array)); | 54 Dart_SetReturnValue(args, Dart_NewBoolean(builtin_array)); |
55 Dart_ExitScope(); | 55 Dart_ExitScope(); |
56 } | 56 } |
OLD | NEW |