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

Side by Side Diff: runtime/vm/mirrors_api_impl.cc

Issue 1401643002: Remove isolate parameter when allocating handles (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Sync Created 5 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
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/object.h » ('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) 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_mirrors_api.h" 5 #include "include/dart_mirrors_api.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
11 #include "vm/dart_api_state.h" 11 #include "vm/dart_api_state.h"
12 #include "vm/dart_entry.h" 12 #include "vm/dart_entry.h"
13 #include "vm/exceptions.h" 13 #include "vm/exceptions.h"
14 #include "vm/growable_array.h" 14 #include "vm/growable_array.h"
15 #include "vm/object.h" 15 #include "vm/object.h"
16 #include "vm/resolver.h" 16 #include "vm/resolver.h"
17 #include "vm/stack_frame.h" 17 #include "vm/stack_frame.h"
18 #include "vm/symbols.h" 18 #include "vm/symbols.h"
19 19
20 namespace dart { 20 namespace dart {
21 21
22 // Facilitate quick access to the current zone once we have the curren thread. 22 // Facilitate quick access to the current zone once we have the curren thread.
23 #define Z (T->zone()) 23 #define Z (T->zone())
24 24
25 25
26 // --- Classes and Interfaces Reflection --- 26 // --- Classes and Interfaces Reflection ---
27 27
28 DART_EXPORT Dart_Handle Dart_TypeName(Dart_Handle object) { 28 DART_EXPORT Dart_Handle Dart_TypeName(Dart_Handle object) {
29 DARTSCOPE(Thread::Current()); 29 DARTSCOPE(Thread::Current());
30 const Object& obj = Object::Handle(I, Api::UnwrapHandle(object)); 30 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object));
31 if (obj.IsType()) { 31 if (obj.IsType()) {
32 const Class& cls = Class::Handle(Type::Cast(obj).type_class()); 32 const Class& cls = Class::Handle(Type::Cast(obj).type_class());
33 return Api::NewHandle(I, cls.UserVisibleName()); 33 return Api::NewHandle(I, cls.UserVisibleName());
34 } else { 34 } else {
35 RETURN_TYPE_ERROR(I, object, Class/Type); 35 RETURN_TYPE_ERROR(Z, object, Class/Type);
36 } 36 }
37 } 37 }
38 38
39 39
40 DART_EXPORT Dart_Handle Dart_QualifiedTypeName(Dart_Handle object) { 40 DART_EXPORT Dart_Handle Dart_QualifiedTypeName(Dart_Handle object) {
41 DARTSCOPE(Thread::Current()); 41 DARTSCOPE(Thread::Current());
42 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); 42 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object));
43 if (obj.IsType() || obj.IsClass()) { 43 if (obj.IsType() || obj.IsClass()) {
44 const Class& cls = (obj.IsType()) ? 44 const Class& cls = (obj.IsType()) ?
45 Class::Handle(Z, Type::Cast(obj).type_class()) : Class::Cast(obj); 45 Class::Handle(Z, Type::Cast(obj).type_class()) : Class::Cast(obj);
46 const char* str = cls.ToCString(); 46 const char* str = cls.ToCString();
47 if (str == NULL) { 47 if (str == NULL) {
48 RETURN_NULL_ERROR(str); 48 RETURN_NULL_ERROR(str);
49 } 49 }
50 CHECK_CALLBACK_STATE(I); 50 CHECK_CALLBACK_STATE(I);
51 return Api::NewHandle(I, String::New(str)); 51 return Api::NewHandle(I, String::New(str));
52 } else { 52 } else {
53 RETURN_TYPE_ERROR(I, object, Class/Type); 53 RETURN_TYPE_ERROR(Z, object, Class/Type);
54 } 54 }
55 } 55 }
56 56
57 57
58 // --- Function and Variable Reflection --- 58 // --- Function and Variable Reflection ---
59 59
60 // Outside of the vm, we expose setter names with a trailing '='. 60 // Outside of the vm, we expose setter names with a trailing '='.
61 static bool HasExternalSetterSuffix(const String& name) { 61 static bool HasExternalSetterSuffix(const String& name) {
62 return name.CharAt(name.Length() - 1) == '='; 62 return name.CharAt(name.Length() - 1) == '=';
63 } 63 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 130
131 DART_EXPORT Dart_Handle Dart_LookupFunction(Dart_Handle target, 131 DART_EXPORT Dart_Handle Dart_LookupFunction(Dart_Handle target,
132 Dart_Handle function_name) { 132 Dart_Handle function_name) {
133 DARTSCOPE(Thread::Current()); 133 DARTSCOPE(Thread::Current());
134 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target)); 134 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target));
135 if (obj.IsError()) { 135 if (obj.IsError()) {
136 return target; 136 return target;
137 } 137 }
138 const String& func_name = Api::UnwrapStringHandle(I, function_name); 138 const String& func_name = Api::UnwrapStringHandle(Z, function_name);
139 if (func_name.IsNull()) { 139 if (func_name.IsNull()) {
140 RETURN_TYPE_ERROR(I, function_name, String); 140 RETURN_TYPE_ERROR(Z, function_name, String);
141 } 141 }
142 142
143 Function& func = Function::Handle(Z); 143 Function& func = Function::Handle(Z);
144 String& tmp_name = String::Handle(Z); 144 String& tmp_name = String::Handle(Z);
145 if (obj.IsType()) { 145 if (obj.IsType()) {
146 const Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); 146 const Class& cls = Class::Handle(Z, Type::Cast(obj).type_class());
147 147
148 // Case 1. Lookup the unmodified function name. 148 // Case 1. Lookup the unmodified function name.
149 func = cls.LookupFunctionAllowPrivate(func_name); 149 func = cls.LookupFunctionAllowPrivate(func_name);
150 150
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 func_kind == RawFunction::kSetterFunction || 204 func_kind == RawFunction::kSetterFunction ||
205 func_kind == RawFunction::kConstructor); 205 func_kind == RawFunction::kConstructor);
206 } 206 }
207 #endif 207 #endif
208 return Api::NewHandle(I, func.raw()); 208 return Api::NewHandle(I, func.raw());
209 } 209 }
210 210
211 211
212 DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function) { 212 DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function) {
213 DARTSCOPE(Thread::Current()); 213 DARTSCOPE(Thread::Current());
214 const Function& func = Api::UnwrapFunctionHandle(I, function); 214 const Function& func = Api::UnwrapFunctionHandle(Z, function);
215 if (func.IsNull()) { 215 if (func.IsNull()) {
216 RETURN_TYPE_ERROR(I, function, Function); 216 RETURN_TYPE_ERROR(Z, function, Function);
217 } 217 }
218 return Api::NewHandle(I, func.UserVisibleName()); 218 return Api::NewHandle(I, func.UserVisibleName());
219 } 219 }
220 220
221 221
222 DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function) { 222 DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function) {
223 DARTSCOPE(Thread::Current()); 223 DARTSCOPE(Thread::Current());
224 const Function& func = Api::UnwrapFunctionHandle(I, function); 224 const Function& func = Api::UnwrapFunctionHandle(Z, function);
225 if (func.IsNull()) { 225 if (func.IsNull()) {
226 RETURN_TYPE_ERROR(I, function, Function); 226 RETURN_TYPE_ERROR(Z, function, Function);
227 } 227 }
228 if (func.IsNonImplicitClosureFunction()) { 228 if (func.IsNonImplicitClosureFunction()) {
229 RawFunction* parent_function = func.parent_function(); 229 RawFunction* parent_function = func.parent_function();
230 return Api::NewHandle(I, parent_function); 230 return Api::NewHandle(I, parent_function);
231 } 231 }
232 const Class& owner = Class::Handle(Z, func.Owner()); 232 const Class& owner = Class::Handle(Z, func.Owner());
233 ASSERT(!owner.IsNull()); 233 ASSERT(!owner.IsNull());
234 if (owner.IsTopLevel()) { 234 if (owner.IsTopLevel()) {
235 // Top-level functions are implemented as members of a hidden class. We hide 235 // Top-level functions are implemented as members of a hidden class. We hide
236 // that class here and instead answer the library. 236 // that class here and instead answer the library.
237 #if defined(DEBUG) 237 #if defined(DEBUG)
238 const Library& lib = Library::Handle(Z, owner.library()); 238 const Library& lib = Library::Handle(Z, owner.library());
239 if (lib.IsNull()) { 239 if (lib.IsNull()) {
240 ASSERT(owner.IsDynamicClass() || owner.IsVoidClass()); 240 ASSERT(owner.IsDynamicClass() || owner.IsVoidClass());
241 } 241 }
242 #endif 242 #endif
243 return Api::NewHandle(I, owner.library()); 243 return Api::NewHandle(I, owner.library());
244 } else { 244 } else {
245 return Api::NewHandle(I, owner.RareType()); 245 return Api::NewHandle(I, owner.RareType());
246 } 246 }
247 } 247 }
248 248
249 249
250 DART_EXPORT Dart_Handle Dart_FunctionIsStatic(Dart_Handle function, 250 DART_EXPORT Dart_Handle Dart_FunctionIsStatic(Dart_Handle function,
251 bool* is_static) { 251 bool* is_static) {
252 DARTSCOPE(Thread::Current()); 252 DARTSCOPE(Thread::Current());
253 if (is_static == NULL) { 253 if (is_static == NULL) {
254 RETURN_NULL_ERROR(is_static); 254 RETURN_NULL_ERROR(is_static);
255 } 255 }
256 const Function& func = Api::UnwrapFunctionHandle(I, function); 256 const Function& func = Api::UnwrapFunctionHandle(Z, function);
257 if (func.IsNull()) { 257 if (func.IsNull()) {
258 RETURN_TYPE_ERROR(I, function, Function); 258 RETURN_TYPE_ERROR(Z, function, Function);
259 } 259 }
260 *is_static = func.is_static(); 260 *is_static = func.is_static();
261 return Api::Success(); 261 return Api::Success();
262 } 262 }
263 263
264 264
265 DART_EXPORT Dart_Handle Dart_FunctionIsConstructor(Dart_Handle function, 265 DART_EXPORT Dart_Handle Dart_FunctionIsConstructor(Dart_Handle function,
266 bool* is_constructor) { 266 bool* is_constructor) {
267 DARTSCOPE(Thread::Current()); 267 DARTSCOPE(Thread::Current());
268 if (is_constructor == NULL) { 268 if (is_constructor == NULL) {
269 RETURN_NULL_ERROR(is_constructor); 269 RETURN_NULL_ERROR(is_constructor);
270 } 270 }
271 const Function& func = Api::UnwrapFunctionHandle(I, function); 271 const Function& func = Api::UnwrapFunctionHandle(Z, function);
272 if (func.IsNull()) { 272 if (func.IsNull()) {
273 RETURN_TYPE_ERROR(I, function, Function); 273 RETURN_TYPE_ERROR(Z, function, Function);
274 } 274 }
275 *is_constructor = func.kind() == RawFunction::kConstructor; 275 *is_constructor = func.kind() == RawFunction::kConstructor;
276 return Api::Success(); 276 return Api::Success();
277 } 277 }
278 278
279 279
280 DART_EXPORT Dart_Handle Dart_FunctionIsGetter(Dart_Handle function, 280 DART_EXPORT Dart_Handle Dart_FunctionIsGetter(Dart_Handle function,
281 bool* is_getter) { 281 bool* is_getter) {
282 DARTSCOPE(Thread::Current()); 282 DARTSCOPE(Thread::Current());
283 if (is_getter == NULL) { 283 if (is_getter == NULL) {
284 RETURN_NULL_ERROR(is_getter); 284 RETURN_NULL_ERROR(is_getter);
285 } 285 }
286 const Function& func = Api::UnwrapFunctionHandle(I, function); 286 const Function& func = Api::UnwrapFunctionHandle(Z, function);
287 if (func.IsNull()) { 287 if (func.IsNull()) {
288 RETURN_TYPE_ERROR(I, function, Function); 288 RETURN_TYPE_ERROR(Z, function, Function);
289 } 289 }
290 *is_getter = func.IsGetterFunction(); 290 *is_getter = func.IsGetterFunction();
291 return Api::Success(); 291 return Api::Success();
292 } 292 }
293 293
294 294
295 DART_EXPORT Dart_Handle Dart_FunctionIsSetter(Dart_Handle function, 295 DART_EXPORT Dart_Handle Dart_FunctionIsSetter(Dart_Handle function,
296 bool* is_setter) { 296 bool* is_setter) {
297 DARTSCOPE(Thread::Current()); 297 DARTSCOPE(Thread::Current());
298 if (is_setter == NULL) { 298 if (is_setter == NULL) {
299 RETURN_NULL_ERROR(is_setter); 299 RETURN_NULL_ERROR(is_setter);
300 } 300 }
301 const Function& func = Api::UnwrapFunctionHandle(I, function); 301 const Function& func = Api::UnwrapFunctionHandle(Z, function);
302 if (func.IsNull()) { 302 if (func.IsNull()) {
303 RETURN_TYPE_ERROR(I, function, Function); 303 RETURN_TYPE_ERROR(Z, function, Function);
304 } 304 }
305 *is_setter = (func.kind() == RawFunction::kSetterFunction); 305 *is_setter = (func.kind() == RawFunction::kSetterFunction);
306 return Api::Success(); 306 return Api::Success();
307 } 307 }
308 308
309 309
310 // --- Libraries Reflection --- 310 // --- Libraries Reflection ---
311 311
312 DART_EXPORT Dart_Handle Dart_LibraryName(Dart_Handle library) { 312 DART_EXPORT Dart_Handle Dart_LibraryName(Dart_Handle library) {
313 DARTSCOPE(Thread::Current()); 313 DARTSCOPE(Thread::Current());
314 const Library& lib = Api::UnwrapLibraryHandle(I, library); 314 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
315 if (lib.IsNull()) { 315 if (lib.IsNull()) {
316 RETURN_TYPE_ERROR(I, library, Library); 316 RETURN_TYPE_ERROR(Z, library, Library);
317 } 317 }
318 const String& name = String::Handle(Z, lib.name()); 318 const String& name = String::Handle(Z, lib.name());
319 ASSERT(!name.IsNull()); 319 ASSERT(!name.IsNull());
320 return Api::NewHandle(I, name.raw()); 320 return Api::NewHandle(I, name.raw());
321 } 321 }
322 322
323 DART_EXPORT Dart_Handle Dart_LibraryGetClassNames(Dart_Handle library) { 323 DART_EXPORT Dart_Handle Dart_LibraryGetClassNames(Dart_Handle library) {
324 DARTSCOPE(Thread::Current()); 324 DARTSCOPE(Thread::Current());
325 const Library& lib = Api::UnwrapLibraryHandle(I, library); 325 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
326 if (lib.IsNull()) { 326 if (lib.IsNull()) {
327 RETURN_TYPE_ERROR(I, library, Library); 327 RETURN_TYPE_ERROR(Z, library, Library);
328 } 328 }
329 329
330 const GrowableObjectArray& names = 330 const GrowableObjectArray& names =
331 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); 331 GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
332 ClassDictionaryIterator it(lib); 332 ClassDictionaryIterator it(lib);
333 Class& cls = Class::Handle(Z); 333 Class& cls = Class::Handle(Z);
334 String& name = String::Handle(Z); 334 String& name = String::Handle(Z);
335 while (it.HasNext()) { 335 while (it.HasNext()) {
336 cls = it.GetNextClass(); 336 cls = it.GetNextClass();
337 if (cls.IsSignatureClass()) { 337 if (cls.IsSignatureClass()) {
(...skipping 10 matching lines...) Expand all
348 } 348 }
349 } 349 }
350 return Api::NewHandle(I, Array::MakeArray(names)); 350 return Api::NewHandle(I, Array::MakeArray(names));
351 } 351 }
352 352
353 353
354 // --- Closures Reflection --- 354 // --- Closures Reflection ---
355 355
356 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { 356 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) {
357 DARTSCOPE(Thread::Current()); 357 DARTSCOPE(Thread::Current());
358 const Instance& closure_obj = Api::UnwrapInstanceHandle(I, closure); 358 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure);
359 if (closure_obj.IsNull() || !closure_obj.IsClosure()) { 359 if (closure_obj.IsNull() || !closure_obj.IsClosure()) {
360 RETURN_TYPE_ERROR(I, closure, Instance); 360 RETURN_TYPE_ERROR(Z, closure, Instance);
361 } 361 }
362 362
363 ASSERT(ClassFinalizer::AllClassesFinalized()); 363 ASSERT(ClassFinalizer::AllClassesFinalized());
364 364
365 RawFunction* rf = Closure::function(closure_obj); 365 RawFunction* rf = Closure::function(closure_obj);
366 return Api::NewHandle(I, rf); 366 return Api::NewHandle(I, rf);
367 } 367 }
368 368
369 } // namespace dart 369 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698