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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; | 35 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
36 | 36 |
37 const char* CanonicalFunction(const char* func) { | 37 const char* CanonicalFunction(const char* func) { |
38 if (strncmp(func, "dart::", 6) == 0) { | 38 if (strncmp(func, "dart::", 6) == 0) { |
39 return func + 6; | 39 return func + 6; |
40 } else { | 40 } else { |
41 return func; | 41 return func; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 #define RETURN_TYPE_ERROR(isolate, dart_handle, Type) \ | 45 #define RETURN_TYPE_ERROR(isolate, dart_handle, type) \ |
46 do { \ | 46 do { \ |
47 const Object& tmp = \ | 47 const Object& tmp = \ |
48 Object::Handle(isolate, Api::UnwrapHandle((dart_handle))); \ | 48 Object::Handle(isolate, Api::UnwrapHandle((dart_handle))); \ |
49 if (tmp.IsNull()) { \ | 49 if (tmp.IsNull()) { \ |
50 return Api::NewError("%s expects argument '%s' to be non-null.", \ | 50 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
51 CURRENT_FUNC, #dart_handle); \ | 51 CURRENT_FUNC, #dart_handle); \ |
52 } else if (tmp.IsError()) { \ | 52 } else if (tmp.IsError()) { \ |
53 return dart_handle; \ | 53 return dart_handle; \ |
54 } else { \ | 54 } else { \ |
55 return Api::NewError("%s expects argument '%s' to be of type %s.", \ | 55 return Api::NewError("%s expects argument '%s' to be of type %s.", \ |
56 CURRENT_FUNC, #dart_handle, #Type); \ | 56 CURRENT_FUNC, #dart_handle, #type); \ |
57 } \ | 57 } \ |
58 } while (0) | 58 } while (0) |
59 | 59 |
60 | 60 |
61 // Return error if isolate is in an inconsistent state. | 61 // Return error if isolate is in an inconsistent state. |
62 // Return NULL when no error condition exists. | 62 // Return NULL when no error condition exists. |
63 // | 63 // |
64 // TODO(turnidge): Make this function return an error handle directly | 64 // TODO(turnidge): Make this function return an error handle directly |
65 // rather than returning an error string. The current behavior can | 65 // rather than returning an error string. The current behavior can |
66 // cause compilation errors to appear to be api errors. | 66 // cause compilation errors to appear to be api errors. |
67 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { | 67 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 state->IsValidWeakPersistentHandle(object) || | 117 state->IsValidWeakPersistentHandle(object) || |
118 state->IsValidPersistentHandle(object) || | 118 state->IsValidPersistentHandle(object) || |
119 state->IsValidLocalHandle(object)); | 119 state->IsValidLocalHandle(object)); |
120 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 120 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
121 PersistentHandle::raw_offset() == 0 && | 121 PersistentHandle::raw_offset() == 0 && |
122 LocalHandle::raw_offset() == 0); | 122 LocalHandle::raw_offset() == 0); |
123 #endif | 123 #endif |
124 return *(reinterpret_cast<RawObject**>(object)); | 124 return *(reinterpret_cast<RawObject**>(object)); |
125 } | 125 } |
126 | 126 |
127 #define DEFINE_UNWRAP(Type) \ | 127 #define DEFINE_UNWRAP(type) \ |
128 const Type& Api::Unwrap##Type##Handle(Isolate* iso, \ | 128 const type& Api::Unwrap##type##Handle(Isolate* iso, \ |
129 Dart_Handle dart_handle) { \ | 129 Dart_Handle dart_handle) { \ |
130 const Object& tmp = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ | 130 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ |
131 Type& typed_handle = Type::Handle(iso); \ | 131 if (obj.Is##type()) { \ |
132 if (tmp.Is##Type()) { \ | 132 return type::Cast(obj); \ |
133 typed_handle ^= tmp.raw(); \ | 133 } \ |
134 } \ | 134 return type::Handle(iso); \ |
135 return typed_handle; \ | |
136 } | 135 } |
137 CLASS_LIST_NO_OBJECT(DEFINE_UNWRAP) | 136 CLASS_LIST_NO_OBJECT(DEFINE_UNWRAP) |
138 #undef DEFINE_UNWRAP | 137 #undef DEFINE_UNWRAP |
139 | 138 |
140 | 139 |
141 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state, | 140 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state, |
142 Dart_Handle object) { | 141 Dart_Handle object) { |
143 ASSERT(state.IsValidLocalHandle(object)); | 142 ASSERT(state.IsValidLocalHandle(object)); |
144 return reinterpret_cast<LocalHandle*>(object); | 143 return reinterpret_cast<LocalHandle*>(object); |
145 } | 144 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { | 284 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { |
286 return Api::ClassId(object) == kUnwindError; | 285 return Api::ClassId(object) == kUnwindError; |
287 } | 286 } |
288 | 287 |
289 | 288 |
290 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 289 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
291 Isolate* isolate = Isolate::Current(); | 290 Isolate* isolate = Isolate::Current(); |
292 DARTSCOPE(isolate); | 291 DARTSCOPE(isolate); |
293 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 292 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
294 if (obj.IsError()) { | 293 if (obj.IsError()) { |
295 Error& error = Error::Handle(isolate); | 294 const Error& error = Error::Cast(obj); |
296 error ^= obj.raw(); | |
297 const char* str = error.ToErrorCString(); | 295 const char* str = error.ToErrorCString(); |
298 intptr_t len = strlen(str) + 1; | 296 intptr_t len = strlen(str) + 1; |
299 char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len)); | 297 char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len)); |
300 strncpy(str_copy, str, len); | 298 strncpy(str_copy, str, len); |
301 // Strip a possible trailing '\n'. | 299 // Strip a possible trailing '\n'. |
302 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 300 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
303 str_copy[len - 2] = '\0'; | 301 str_copy[len - 2] = '\0'; |
304 } | 302 } |
305 return str_copy; | 303 return str_copy; |
306 } else { | 304 } else { |
307 return ""; | 305 return ""; |
308 } | 306 } |
309 } | 307 } |
310 | 308 |
311 | 309 |
312 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { | 310 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
313 Isolate* isolate = Isolate::Current(); | 311 Isolate* isolate = Isolate::Current(); |
314 DARTSCOPE(isolate); | 312 DARTSCOPE(isolate); |
315 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 313 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
316 return obj.IsUnhandledException(); | 314 return obj.IsUnhandledException(); |
317 } | 315 } |
318 | 316 |
319 | 317 |
320 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { | 318 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
321 Isolate* isolate = Isolate::Current(); | 319 Isolate* isolate = Isolate::Current(); |
322 DARTSCOPE(isolate); | 320 DARTSCOPE(isolate); |
323 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 321 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
324 if (obj.IsUnhandledException()) { | 322 if (obj.IsUnhandledException()) { |
325 UnhandledException& error = UnhandledException::Handle(isolate); | 323 const UnhandledException& error = UnhandledException::Cast(obj); |
326 error ^= obj.raw(); | |
327 return Api::NewHandle(isolate, error.exception()); | 324 return Api::NewHandle(isolate, error.exception()); |
328 } else if (obj.IsError()) { | 325 } else if (obj.IsError()) { |
329 return Api::NewError("This error is not an unhandled exception error."); | 326 return Api::NewError("This error is not an unhandled exception error."); |
330 } else { | 327 } else { |
331 return Api::NewError("Can only get exceptions from error handles."); | 328 return Api::NewError("Can only get exceptions from error handles."); |
332 } | 329 } |
333 } | 330 } |
334 | 331 |
335 | 332 |
336 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { | 333 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |
337 Isolate* isolate = Isolate::Current(); | 334 Isolate* isolate = Isolate::Current(); |
338 DARTSCOPE(isolate); | 335 DARTSCOPE(isolate); |
339 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 336 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
340 if (obj.IsUnhandledException()) { | 337 if (obj.IsUnhandledException()) { |
341 UnhandledException& error = UnhandledException::Handle(isolate); | 338 const UnhandledException& error = UnhandledException::Cast(obj); |
342 error ^= obj.raw(); | |
343 return Api::NewHandle(isolate, error.stacktrace()); | 339 return Api::NewHandle(isolate, error.stacktrace()); |
344 } else if (obj.IsError()) { | 340 } else if (obj.IsError()) { |
345 return Api::NewError("This error is not an unhandled exception error."); | 341 return Api::NewError("This error is not an unhandled exception error."); |
346 } else { | 342 } else { |
347 return Api::NewError("Can only get stacktraces from error handles."); | 343 return Api::NewError("Can only get stacktraces from error handles."); |
348 } | 344 } |
349 } | 345 } |
350 | 346 |
351 | 347 |
352 // Deprecated. | 348 // Deprecated. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 RETURN_TYPE_ERROR(isolate, exception, Instance); | 397 RETURN_TYPE_ERROR(isolate, exception, Instance); |
402 } | 398 } |
403 const Instance& stacktrace = Instance::Handle(isolate); | 399 const Instance& stacktrace = Instance::Handle(isolate); |
404 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); | 400 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); |
405 } | 401 } |
406 | 402 |
407 | 403 |
408 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 404 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
409 Isolate* isolate = Isolate::Current(); | 405 Isolate* isolate = Isolate::Current(); |
410 CHECK_ISOLATE(isolate); | 406 CHECK_ISOLATE(isolate); |
411 const Object& error = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 407 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
412 if (!error.IsError()) { | 408 if (!obj.IsError()) { |
413 return Api::NewError( | 409 return Api::NewError( |
414 "%s expects argument 'handle' to be an error handle. " | 410 "%s expects argument 'handle' to be an error handle. " |
415 "Did you forget to check Dart_IsError first?", | 411 "Did you forget to check Dart_IsError first?", |
416 CURRENT_FUNC); | 412 CURRENT_FUNC); |
417 } | 413 } |
418 if (isolate->top_exit_frame_info() == 0) { | 414 if (isolate->top_exit_frame_info() == 0) { |
419 // There are no dart frames on the stack so it would be illegal to | 415 // There are no dart frames on the stack so it would be illegal to |
420 // propagate an error here. | 416 // propagate an error here. |
421 return Api::NewError("No Dart frames on stack, cannot propagate error."); | 417 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
422 } | 418 } |
423 | 419 |
424 // Unwind all the API scopes till the exit frame before propagating. | 420 // Unwind all the API scopes till the exit frame before propagating. |
425 ApiState* state = isolate->api_state(); | 421 ApiState* state = isolate->api_state(); |
426 ASSERT(state != NULL); | 422 ASSERT(state != NULL); |
427 state->UnwindScopes(isolate->top_exit_frame_info()); | 423 state->UnwindScopes(isolate->top_exit_frame_info()); |
428 Exceptions::PropagateError(error); | 424 Exceptions::PropagateError(Error::Cast(obj)); |
429 UNREACHABLE(); | 425 UNREACHABLE(); |
430 | 426 |
431 return Api::NewError("Cannot reach here. Internal error."); | 427 return Api::NewError("Cannot reach here. Internal error."); |
432 } | 428 } |
433 | 429 |
434 | 430 |
435 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 431 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
436 int line, | 432 int line, |
437 const char* handle, | 433 const char* handle, |
438 const char* message) { | 434 const char* message) { |
439 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 435 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
440 file, line, handle, message); | 436 file, line, handle, message); |
441 OS::Abort(); | 437 OS::Abort(); |
442 } | 438 } |
443 | 439 |
444 | 440 |
445 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 441 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
446 Isolate* isolate = Isolate::Current(); | 442 Isolate* isolate = Isolate::Current(); |
447 DARTSCOPE(isolate); | 443 DARTSCOPE(isolate); |
448 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 444 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
449 if (obj.IsString()) { | 445 if (obj.IsString()) { |
450 return Api::NewHandle(isolate, obj.raw()); | 446 return Api::NewHandle(isolate, obj.raw()); |
451 } else if (obj.IsInstance()) { | 447 } else if (obj.IsInstance()) { |
452 Instance& receiver = Instance::Handle(isolate); | 448 const Instance& receiver = Instance::Cast(obj); |
453 receiver ^= obj.raw(); | |
454 return Api::NewHandle(isolate, DartLibraryCalls::ToString(receiver)); | 449 return Api::NewHandle(isolate, DartLibraryCalls::ToString(receiver)); |
455 } else { | 450 } else { |
456 // This is a VM internal object. Call the C++ method of printing. | 451 // This is a VM internal object. Call the C++ method of printing. |
457 return Api::NewHandle(isolate, String::New(obj.ToCString())); | 452 return Api::NewHandle(isolate, String::New(obj.ToCString())); |
458 } | 453 } |
459 } | 454 } |
460 | 455 |
461 | 456 |
462 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 457 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
463 Isolate* isolate = Isolate::Current(); | 458 Isolate* isolate = Isolate::Current(); |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 bool* value) { | 1132 bool* value) { |
1138 Isolate* isolate = Isolate::Current(); | 1133 Isolate* isolate = Isolate::Current(); |
1139 DARTSCOPE(isolate); | 1134 DARTSCOPE(isolate); |
1140 const Instance& expected = | 1135 const Instance& expected = |
1141 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); | 1136 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); |
1142 const Instance& actual = | 1137 const Instance& actual = |
1143 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj2)); | 1138 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj2)); |
1144 const Object& result = | 1139 const Object& result = |
1145 Object::Handle(isolate, DartLibraryCalls::Equals(expected, actual)); | 1140 Object::Handle(isolate, DartLibraryCalls::Equals(expected, actual)); |
1146 if (result.IsBool()) { | 1141 if (result.IsBool()) { |
1147 Bool& b = Bool::Handle(isolate); | 1142 *value = Bool::Cast(result).value(); |
1148 b ^= result.raw(); | |
1149 *value = b.value(); | |
1150 return Api::Success(isolate); | 1143 return Api::Success(isolate); |
1151 } else if (result.IsError()) { | 1144 } else if (result.IsError()) { |
1152 return Api::NewHandle(isolate, result.raw()); | 1145 return Api::NewHandle(isolate, result.raw()); |
1153 } else { | 1146 } else { |
1154 return Api::NewError("Expected boolean result from =="); | 1147 return Api::NewError("Expected boolean result from =="); |
1155 } | 1148 } |
1156 } | 1149 } |
1157 | 1150 |
1158 | 1151 |
1159 // TODO(iposva): This call actually implements IsInstanceOfClass. | 1152 // TODO(iposva): This call actually implements IsInstanceOfClass. |
(...skipping 10 matching lines...) Expand all Loading... |
1170 RETURN_TYPE_ERROR(isolate, clazz, Class); | 1163 RETURN_TYPE_ERROR(isolate, clazz, Class); |
1171 } | 1164 } |
1172 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1165 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
1173 if (obj.IsError()) { | 1166 if (obj.IsError()) { |
1174 return object; | 1167 return object; |
1175 } else if (!obj.IsNull() && !obj.IsInstance()) { | 1168 } else if (!obj.IsNull() && !obj.IsInstance()) { |
1176 return Api::NewError( | 1169 return Api::NewError( |
1177 "%s expects argument 'object' to be an instance of Object.", | 1170 "%s expects argument 'object' to be an instance of Object.", |
1178 CURRENT_FUNC); | 1171 CURRENT_FUNC); |
1179 } | 1172 } |
1180 | |
1181 Instance& instance = Instance::Handle(isolate); | |
1182 instance ^= obj.raw(); | |
1183 // Finalize all classes. | 1173 // Finalize all classes. |
1184 const char* msg = CheckIsolateState(isolate); | 1174 const char* msg = CheckIsolateState(isolate); |
1185 if (msg != NULL) { | 1175 if (msg != NULL) { |
1186 return Api::NewError(msg); | 1176 return Api::NewError(msg); |
1187 } | 1177 } |
1188 const Type& type = Type::Handle(isolate, Type::NewNonParameterizedType(cls)); | 1178 if (obj.IsInstance()) { |
1189 Error& malformed_type_error = Error::Handle(isolate); | 1179 const Type& type = Type::Handle(isolate, |
1190 *value = instance.IsInstanceOf( | 1180 Type::NewNonParameterizedType(cls)); |
1191 type, TypeArguments::Handle(isolate), &malformed_type_error); | 1181 Error& malformed_type_error = Error::Handle(isolate); |
1192 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. | 1182 *value = Instance::Cast(obj).IsInstanceOf(type, |
| 1183 TypeArguments::Handle(isolate), |
| 1184 &malformed_type_error); |
| 1185 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
| 1186 } else { |
| 1187 *value = false; |
| 1188 } |
1193 return Api::Success(isolate); | 1189 return Api::Success(isolate); |
1194 } | 1190 } |
1195 | 1191 |
1196 | 1192 |
1197 // --- Instances ---- | 1193 // --- Instances ---- |
1198 | 1194 |
1199 | 1195 |
1200 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1196 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
1201 Isolate* isolate = Isolate::Current(); | 1197 Isolate* isolate = Isolate::Current(); |
1202 DARTSCOPE(isolate); | 1198 DARTSCOPE(isolate); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 if (class_id == kSmi || class_id == kMint) { | 1238 if (class_id == kSmi || class_id == kMint) { |
1243 *fits = true; | 1239 *fits = true; |
1244 return Api::Success(isolate); | 1240 return Api::Success(isolate); |
1245 } | 1241 } |
1246 | 1242 |
1247 DARTSCOPE_NOCHECKS(isolate); | 1243 DARTSCOPE_NOCHECKS(isolate); |
1248 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1244 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1249 if (int_obj.IsNull()) { | 1245 if (int_obj.IsNull()) { |
1250 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1246 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1251 } | 1247 } |
1252 ASSERT(int_obj.IsBigint()); | 1248 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(int_obj))); |
1253 #if defined(DEBUG) | |
1254 Bigint& bigint = Bigint::Handle(isolate); | |
1255 bigint ^= int_obj.raw(); | |
1256 ASSERT(!BigintOperations::FitsIntoMint(bigint)); | |
1257 #endif | |
1258 *fits = false; | 1249 *fits = false; |
1259 return Api::Success(isolate); | 1250 return Api::Success(isolate); |
1260 } | 1251 } |
1261 | 1252 |
1262 | 1253 |
1263 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 1254 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
1264 bool* fits) { | 1255 bool* fits) { |
1265 // Fast path for Smis. | 1256 // Fast path for Smis. |
1266 Isolate* isolate = Isolate::Current(); | 1257 Isolate* isolate = Isolate::Current(); |
1267 CHECK_ISOLATE(isolate); | 1258 CHECK_ISOLATE(isolate); |
1268 if (Api::IsSmi(integer)) { | 1259 if (Api::IsSmi(integer)) { |
1269 *fits = (Api::SmiValue(integer) >= 0); | 1260 *fits = (Api::SmiValue(integer) >= 0); |
1270 return Api::Success(isolate); | 1261 return Api::Success(isolate); |
1271 } | 1262 } |
1272 | 1263 |
1273 DARTSCOPE_NOCHECKS(isolate); | 1264 DARTSCOPE_NOCHECKS(isolate); |
1274 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1265 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1275 if (int_obj.IsNull()) { | 1266 if (int_obj.IsNull()) { |
1276 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1267 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1277 } | 1268 } |
1278 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1269 if (int_obj.IsSmi() || int_obj.IsMint()) { |
1279 *fits = !int_obj.IsNegative(); | 1270 *fits = !int_obj.IsNegative(); |
1280 } else { | 1271 } else { |
1281 ASSERT(int_obj.IsBigint()); | 1272 *fits = BigintOperations::FitsIntoUint64(Bigint::Cast(int_obj)); |
1282 Bigint& bigint = Bigint::Handle(isolate); | |
1283 bigint ^= int_obj.raw(); | |
1284 *fits = BigintOperations::FitsIntoUint64(bigint); | |
1285 } | 1273 } |
1286 return Api::Success(isolate); | 1274 return Api::Success(isolate); |
1287 } | 1275 } |
1288 | 1276 |
1289 | 1277 |
1290 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 1278 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
1291 // Fast path for Smis. | 1279 // Fast path for Smis. |
1292 Isolate* isolate = Isolate::Current(); | 1280 Isolate* isolate = Isolate::Current(); |
1293 CHECK_ISOLATE(isolate); | 1281 CHECK_ISOLATE(isolate); |
1294 if (Smi::IsValid64(value)) { | 1282 if (Smi::IsValid64(value)) { |
(...skipping 26 matching lines...) Expand all Loading... |
1321 | 1309 |
1322 DARTSCOPE_NOCHECKS(isolate); | 1310 DARTSCOPE_NOCHECKS(isolate); |
1323 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1311 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1324 if (int_obj.IsNull()) { | 1312 if (int_obj.IsNull()) { |
1325 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1313 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1326 } | 1314 } |
1327 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1315 if (int_obj.IsSmi() || int_obj.IsMint()) { |
1328 *value = int_obj.AsInt64Value(); | 1316 *value = int_obj.AsInt64Value(); |
1329 return Api::Success(isolate); | 1317 return Api::Success(isolate); |
1330 } else { | 1318 } else { |
1331 ASSERT(int_obj.IsBigint()); | 1319 const Bigint& bigint = Bigint::Cast(int_obj); |
1332 Bigint& bigint = Bigint::Handle(isolate); | |
1333 bigint ^= int_obj.raw(); | |
1334 if (BigintOperations::FitsIntoMint(bigint)) { | 1320 if (BigintOperations::FitsIntoMint(bigint)) { |
1335 *value = BigintOperations::ToMint(bigint); | 1321 *value = BigintOperations::ToMint(bigint); |
1336 return Api::Success(isolate); | 1322 return Api::Success(isolate); |
1337 } | 1323 } |
1338 } | 1324 } |
1339 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", | 1325 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
1340 CURRENT_FUNC, int_obj.ToCString()); | 1326 CURRENT_FUNC, int_obj.ToCString()); |
1341 } | 1327 } |
1342 | 1328 |
1343 | 1329 |
(...skipping 14 matching lines...) Expand all Loading... |
1358 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1344 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1359 if (int_obj.IsNull()) { | 1345 if (int_obj.IsNull()) { |
1360 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1346 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1361 } | 1347 } |
1362 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1348 if (int_obj.IsSmi() || int_obj.IsMint()) { |
1363 if (!int_obj.IsNegative()) { | 1349 if (!int_obj.IsNegative()) { |
1364 *value = int_obj.AsInt64Value(); | 1350 *value = int_obj.AsInt64Value(); |
1365 return Api::Success(isolate); | 1351 return Api::Success(isolate); |
1366 } | 1352 } |
1367 } else { | 1353 } else { |
1368 ASSERT(int_obj.IsBigint()); | 1354 const Bigint& bigint = Bigint::Cast(int_obj); |
1369 Bigint& bigint = Bigint::Handle(isolate); | |
1370 bigint ^= int_obj.raw(); | |
1371 if (BigintOperations::FitsIntoUint64(bigint)) { | 1355 if (BigintOperations::FitsIntoUint64(bigint)) { |
1372 *value = BigintOperations::ToUint64(bigint); | 1356 *value = BigintOperations::ToUint64(bigint); |
1373 return Api::Success(isolate); | 1357 return Api::Success(isolate); |
1374 } | 1358 } |
1375 } | 1359 } |
1376 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 1360 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
1377 CURRENT_FUNC, int_obj.ToCString()); | 1361 CURRENT_FUNC, int_obj.ToCString()); |
1378 } | 1362 } |
1379 | 1363 |
1380 | 1364 |
1381 static uword ApiAllocate(intptr_t size) { | 1365 static uword ApiAllocate(intptr_t size) { |
1382 return Api::Allocate(Isolate::Current(), size); | 1366 return Api::Allocate(Isolate::Current(), size); |
1383 } | 1367 } |
1384 | 1368 |
1385 | 1369 |
1386 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 1370 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
1387 const char** value) { | 1371 const char** value) { |
1388 Isolate* isolate = Isolate::Current(); | 1372 Isolate* isolate = Isolate::Current(); |
1389 DARTSCOPE(isolate); | 1373 DARTSCOPE(isolate); |
1390 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1374 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1391 if (int_obj.IsNull()) { | 1375 if (int_obj.IsNull()) { |
1392 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1376 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1393 } | 1377 } |
1394 Bigint& bigint = Bigint::Handle(isolate); | |
1395 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1378 if (int_obj.IsSmi() || int_obj.IsMint()) { |
1396 bigint ^= BigintOperations::NewFromInt64(int_obj.AsInt64Value()); | 1379 const Bigint& bigint = Bigint::Handle(isolate, |
| 1380 BigintOperations::NewFromInt64(int_obj.AsInt64Value())); |
1397 *value = BigintOperations::ToHexCString(bigint, ApiAllocate); | 1381 *value = BigintOperations::ToHexCString(bigint, ApiAllocate); |
1398 } else { | 1382 } else { |
1399 ASSERT(int_obj.IsBigint()); | 1383 *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj), ApiAllocate); |
1400 bigint ^= int_obj.raw(); | |
1401 *value = BigintOperations::ToHexCString(bigint, ApiAllocate); | |
1402 } | 1384 } |
1403 return Api::Success(isolate); | 1385 return Api::Success(isolate); |
1404 } | 1386 } |
1405 | 1387 |
1406 | 1388 |
1407 // --- Booleans ---- | 1389 // --- Booleans ---- |
1408 | 1390 |
1409 | 1391 |
1410 DART_EXPORT Dart_Handle Dart_True() { | 1392 DART_EXPORT Dart_Handle Dart_True() { |
1411 Isolate* isolate = Isolate::Current(); | 1393 Isolate* isolate = Isolate::Current(); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 *bytes = result; | 1718 *bytes = result; |
1737 return Api::Success(isolate); | 1719 return Api::Success(isolate); |
1738 } | 1720 } |
1739 | 1721 |
1740 | 1722 |
1741 // --- Lists --- | 1723 // --- Lists --- |
1742 | 1724 |
1743 | 1725 |
1744 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { | 1726 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { |
1745 if (obj.IsInstance()) { | 1727 if (obj.IsInstance()) { |
1746 Instance& instance = Instance::Handle(isolate); | 1728 const Instance& instance = Instance::Cast(obj); |
1747 instance ^= obj.raw(); | |
1748 const Type& type = | 1729 const Type& type = |
1749 Type::Handle(isolate, isolate->object_store()->list_interface()); | 1730 Type::Handle(isolate, isolate->object_store()->list_interface()); |
1750 Error& malformed_type_error = Error::Handle(isolate); | 1731 Error& malformed_type_error = Error::Handle(isolate); |
1751 if (instance.IsInstanceOf(type, | 1732 if (instance.IsInstanceOf(type, |
1752 TypeArguments::Handle(isolate), | 1733 TypeArguments::Handle(isolate), |
1753 &malformed_type_error)) { | 1734 &malformed_type_error)) { |
1754 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 1735 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
1755 return instance.raw(); | 1736 return instance.raw(); |
1756 } | 1737 } |
1757 } | 1738 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 if (function.IsNull()) { | 1796 if (function.IsNull()) { |
1816 return Api::NewError("List object does not have a 'length' field."); | 1797 return Api::NewError("List object does not have a 'length' field."); |
1817 } | 1798 } |
1818 | 1799 |
1819 GrowableArray<const Object*> args(0); | 1800 GrowableArray<const Object*> args(0); |
1820 const Array& kNoArgumentNames = Array::Handle(isolate); | 1801 const Array& kNoArgumentNames = Array::Handle(isolate); |
1821 const Object& retval = Object::Handle( | 1802 const Object& retval = Object::Handle( |
1822 isolate, | 1803 isolate, |
1823 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1804 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1824 if (retval.IsSmi() || retval.IsMint()) { | 1805 if (retval.IsSmi() || retval.IsMint()) { |
1825 Integer& integer = Integer::Handle(isolate); | 1806 *len = Integer::Cast(retval).AsInt64Value(); |
1826 integer ^= retval.raw(); | |
1827 *len = integer.AsInt64Value(); | |
1828 return Api::Success(isolate); | 1807 return Api::Success(isolate); |
1829 } else if (retval.IsBigint()) { | 1808 } else if (retval.IsBigint()) { |
1830 Bigint& bigint = Bigint::Handle(isolate); | 1809 const Bigint& bigint = Bigint::Cast(retval); |
1831 bigint ^= retval.raw(); | |
1832 if (BigintOperations::FitsIntoMint(bigint)) { | 1810 if (BigintOperations::FitsIntoMint(bigint)) { |
1833 *len = BigintOperations::ToMint(bigint); | 1811 *len = BigintOperations::ToMint(bigint); |
1834 return Api::Success(isolate); | 1812 return Api::Success(isolate); |
1835 } else { | 1813 } else { |
1836 return Api::NewError("Length of List object is greater than the " | 1814 return Api::NewError("Length of List object is greater than the " |
1837 "maximum value that 'len' parameter can hold"); | 1815 "maximum value that 'len' parameter can hold"); |
1838 } | 1816 } |
1839 } else if (retval.IsError()) { | 1817 } else if (retval.IsError()) { |
1840 return Api::NewHandle(isolate, retval.raw()); | 1818 return Api::NewHandle(isolate, retval.raw()); |
1841 } else { | 1819 } else { |
1842 return Api::NewError("Length of List object is not an integer"); | 1820 return Api::NewError("Length of List object is not an integer"); |
1843 } | 1821 } |
1844 } | 1822 } |
1845 | 1823 |
1846 | 1824 |
1847 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ | 1825 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ |
1848 type& array_obj = type::Handle(isolate); \ | 1826 const type& array_obj = type::Cast(obj); \ |
1849 array_obj ^= obj.raw(); \ | |
1850 if ((index >= 0) && (index < array_obj.Length())) { \ | 1827 if ((index >= 0) && (index < array_obj.Length())) { \ |
1851 return Api::NewHandle(isolate, array_obj.At(index)); \ | 1828 return Api::NewHandle(isolate, array_obj.At(index)); \ |
1852 } \ | 1829 } \ |
1853 return Api::NewError("Invalid index passed in to access list element"); \ | 1830 return Api::NewError("Invalid index passed in to access list element"); \ |
1854 | 1831 |
1855 | 1832 |
1856 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1833 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
1857 Isolate* isolate = Isolate::Current(); | 1834 Isolate* isolate = Isolate::Current(); |
1858 DARTSCOPE(isolate); | 1835 DARTSCOPE(isolate); |
1859 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1836 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
(...skipping 20 matching lines...) Expand all Loading... |
1880 return Api::NewHandle( | 1857 return Api::NewHandle( |
1881 isolate, | 1858 isolate, |
1882 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1859 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1883 } | 1860 } |
1884 } | 1861 } |
1885 return Api::NewError("Object does not implement the 'List' interface"); | 1862 return Api::NewError("Object does not implement the 'List' interface"); |
1886 } | 1863 } |
1887 | 1864 |
1888 | 1865 |
1889 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ | 1866 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ |
1890 type& array = type::Handle(isolate); \ | 1867 const type& array = type::Cast(obj); \ |
1891 array ^= obj.raw(); \ | |
1892 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ | 1868 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ |
1893 if ((index >= 0) && (index < array.Length())) { \ | 1869 if ((index >= 0) && (index < array.Length())) { \ |
1894 array.SetAt(index, value_obj); \ | 1870 array.SetAt(index, value_obj); \ |
1895 return Api::Success(isolate); \ | 1871 return Api::Success(isolate); \ |
1896 } \ | 1872 } \ |
1897 return Api::NewError("Invalid index passed in to set list element"); \ | 1873 return Api::NewError("Invalid index passed in to set list element"); \ |
1898 | 1874 |
1899 | 1875 |
1900 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1876 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
1901 intptr_t index, | 1877 intptr_t index, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1909 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1934 } | 1910 } |
1935 } | 1911 } |
1936 return Api::NewError("Object does not implement the 'List' interface"); | 1912 return Api::NewError("Object does not implement the 'List' interface"); |
1937 } | 1913 } |
1938 | 1914 |
1939 | 1915 |
1940 // TODO(hpayer): value should always be smaller then 0xff. Add error handling. | 1916 // TODO(hpayer): value should always be smaller then 0xff. Add error handling. |
1941 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 1917 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ |
1942 length) \ | 1918 length) \ |
1943 type& array = type::Handle(isolate); \ | 1919 const type& array = type::Cast(obj); \ |
1944 array ^= obj.raw(); \ | |
1945 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 1920 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
1946 Object& element = Object::Handle(isolate); \ | 1921 Object& element = Object::Handle(isolate); \ |
1947 Integer& integer = Integer::Handle(isolate); \ | |
1948 for (int i = 0; i < length; i++) { \ | 1922 for (int i = 0; i < length; i++) { \ |
1949 element = array.At(offset + i); \ | 1923 element = array.At(offset + i); \ |
1950 if (!element.IsInteger()) { \ | 1924 if (!element.IsInteger()) { \ |
1951 return Api::NewError("%s expects the argument 'list' to be " \ | 1925 return Api::NewError("%s expects the argument 'list' to be " \ |
1952 "a List of int", CURRENT_FUNC); \ | 1926 "a List of int", CURRENT_FUNC); \ |
1953 } \ | 1927 } \ |
1954 integer ^= element.raw(); \ | 1928 const Integer& integer = Integer::Cast(element); \ |
1955 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 1929 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ |
1956 ASSERT(integer.AsInt64Value() <= 0xff); \ | 1930 ASSERT(integer.AsInt64Value() <= 0xff); \ |
1957 } \ | 1931 } \ |
1958 return Api::Success(isolate); \ | 1932 return Api::Success(isolate); \ |
1959 } \ | 1933 } \ |
1960 return Api::NewError("Invalid length passed in to access array elements"); \ | 1934 return Api::NewError("Invalid length passed in to access array elements"); \ |
1961 | 1935 |
1962 | 1936 |
1963 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1937 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
1964 intptr_t offset, | 1938 intptr_t offset, |
1965 uint8_t* native_array, | 1939 uint8_t* native_array, |
1966 intptr_t length) { | 1940 intptr_t length) { |
1967 Isolate* isolate = Isolate::Current(); | 1941 Isolate* isolate = Isolate::Current(); |
1968 DARTSCOPE(isolate); | 1942 DARTSCOPE(isolate); |
1969 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1943 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
1970 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { | 1944 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { |
1971 ByteArray& byte_array = ByteArray::Handle(isolate); | 1945 const ByteArray& byte_array = ByteArray::Cast(obj); |
1972 byte_array ^= obj.raw(); | |
1973 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 1946 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
1974 ByteArray::Copy(native_array, byte_array, offset, length); | 1947 ByteArray::Copy(native_array, byte_array, offset, length); |
1975 return Api::Success(isolate); | 1948 return Api::Success(isolate); |
1976 } | 1949 } |
1977 return Api::NewError("Invalid length passed in to access list elements"); | 1950 return Api::NewError("Invalid length passed in to access list elements"); |
1978 } | 1951 } |
1979 if (obj.IsArray()) { | 1952 if (obj.IsArray()) { |
1980 GET_LIST_ELEMENT_AS_BYTES(isolate, | 1953 GET_LIST_ELEMENT_AS_BYTES(isolate, |
1981 Array, | 1954 Array, |
1982 obj, | 1955 obj, |
(...skipping 26 matching lines...) Expand all Loading... |
2009 const Array& kNoArgumentNames = Array::Handle(isolate); | 1982 const Array& kNoArgumentNames = Array::Handle(isolate); |
2010 result = DartEntry::InvokeDynamic( | 1983 result = DartEntry::InvokeDynamic( |
2011 instance, function, args, kNoArgumentNames); | 1984 instance, function, args, kNoArgumentNames); |
2012 if (result.IsError()) { | 1985 if (result.IsError()) { |
2013 return Api::NewHandle(isolate, result.raw()); | 1986 return Api::NewHandle(isolate, result.raw()); |
2014 } | 1987 } |
2015 if (!result.IsInteger()) { | 1988 if (!result.IsInteger()) { |
2016 return Api::NewError("%s expects the argument 'list' to be " | 1989 return Api::NewError("%s expects the argument 'list' to be " |
2017 "a List of int", CURRENT_FUNC); | 1990 "a List of int", CURRENT_FUNC); |
2018 } | 1991 } |
2019 intobj ^= result.raw(); | 1992 const Integer& integer_result = Integer::Cast(result); |
2020 ASSERT(intobj.AsInt64Value() <= 0xff); | 1993 ASSERT(integer_result.AsInt64Value() <= 0xff); |
2021 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1994 // TODO(hpayer): value should always be smaller then 0xff. Add error |
2022 // handling. | 1995 // handling. |
2023 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1996 native_array[i] = |
| 1997 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); |
2024 } | 1998 } |
2025 return Api::Success(isolate); | 1999 return Api::Success(isolate); |
2026 } | 2000 } |
2027 } | 2001 } |
2028 return Api::NewError("Object does not implement the 'List' interface"); | 2002 return Api::NewError("Object does not implement the 'List' interface"); |
2029 } | 2003 } |
2030 | 2004 |
2031 | 2005 |
2032 #define SET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 2006 #define SET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ |
2033 length) \ | 2007 length) \ |
2034 type& array = type::Handle(isolate); \ | 2008 const type& array = type::Cast(obj); \ |
2035 array ^= obj.raw(); \ | |
2036 Integer& integer = Integer::Handle(isolate); \ | 2009 Integer& integer = Integer::Handle(isolate); \ |
2037 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2010 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
2038 for (int i = 0; i < length; i++) { \ | 2011 for (int i = 0; i < length; i++) { \ |
2039 integer = Integer::New(native_array[i]); \ | 2012 integer = Integer::New(native_array[i]); \ |
2040 array.SetAt(offset + i, integer); \ | 2013 array.SetAt(offset + i, integer); \ |
2041 } \ | 2014 } \ |
2042 return Api::Success(isolate); \ | 2015 return Api::Success(isolate); \ |
2043 } \ | 2016 } \ |
2044 return Api::NewError("Invalid length passed in to set array elements"); \ | 2017 return Api::NewError("Invalid length passed in to set array elements"); \ |
2045 | 2018 |
2046 | 2019 |
2047 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 2020 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
2048 intptr_t offset, | 2021 intptr_t offset, |
2049 uint8_t* native_array, | 2022 uint8_t* native_array, |
2050 intptr_t length) { | 2023 intptr_t length) { |
2051 Isolate* isolate = Isolate::Current(); | 2024 Isolate* isolate = Isolate::Current(); |
2052 DARTSCOPE(isolate); | 2025 DARTSCOPE(isolate); |
2053 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2026 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
2054 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { | 2027 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { |
2055 ByteArray& byte_array = ByteArray::Handle(isolate); | 2028 const ByteArray& byte_array = ByteArray::Cast(obj); |
2056 byte_array ^= obj.raw(); | |
2057 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 2029 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
2058 ByteArray::Copy(byte_array, offset, native_array, length); | 2030 ByteArray::Copy(byte_array, offset, native_array, length); |
2059 return Api::Success(isolate); | 2031 return Api::Success(isolate); |
2060 } | 2032 } |
2061 return Api::NewError("Invalid length passed in to set list elements"); | 2033 return Api::NewError("Invalid length passed in to set list elements"); |
2062 } | 2034 } |
2063 if (obj.IsArray()) { | 2035 if (obj.IsArray()) { |
2064 if (obj.IsImmutableArray()) { | 2036 if (obj.IsImmutableArray()) { |
2065 return Api::NewError("Cannot modify immutable array"); | 2037 return Api::NewError("Cannot modify immutable array"); |
2066 } | 2038 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); | 2333 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); |
2362 if (obj.IsNull()) { | 2334 if (obj.IsNull()) { |
2363 return Api::NewError("Null object passed in to invoke closure"); | 2335 return Api::NewError("Null object passed in to invoke closure"); |
2364 } | 2336 } |
2365 if (!obj.IsClosure()) { | 2337 if (!obj.IsClosure()) { |
2366 return Api::NewError("Invalid closure passed to invoke closure"); | 2338 return Api::NewError("Invalid closure passed to invoke closure"); |
2367 } | 2339 } |
2368 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2340 ASSERT(ClassFinalizer::AllClassesFinalized()); |
2369 | 2341 |
2370 // Now try to invoke the closure. | 2342 // Now try to invoke the closure. |
2371 Closure& closure_obj = Closure::Handle(isolate); | 2343 const Closure& closure_obj = Closure::Cast(obj); |
2372 closure_obj ^= obj.raw(); | |
2373 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 2344 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
2374 for (int i = 0; i < number_of_arguments; i++) { | 2345 for (int i = 0; i < number_of_arguments; i++) { |
2375 const Object& arg = | 2346 const Object& arg = |
2376 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2347 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
2377 dart_arguments.Add(&arg); | 2348 dart_arguments.Add(&arg); |
2378 } | 2349 } |
2379 const Array& kNoArgumentNames = Array::Handle(isolate); | 2350 const Array& kNoArgumentNames = Array::Handle(isolate); |
2380 return Api::NewHandle( | 2351 return Api::NewHandle( |
2381 isolate, | 2352 isolate, |
2382 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); | 2353 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); |
(...skipping 21 matching lines...) Expand all Loading... |
2404 | 2375 |
2405 | 2376 |
2406 // --- Classes and Interfaces --- | 2377 // --- Classes and Interfaces --- |
2407 | 2378 |
2408 | 2379 |
2409 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { | 2380 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { |
2410 Isolate* isolate = Isolate::Current(); | 2381 Isolate* isolate = Isolate::Current(); |
2411 DARTSCOPE(isolate); | 2382 DARTSCOPE(isolate); |
2412 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 2383 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
2413 if (obj.IsClass()) { | 2384 if (obj.IsClass()) { |
2414 Class& cls = Class::Handle(isolate); | 2385 return !Class::Cast(obj).is_interface(); |
2415 cls ^= obj.raw(); | |
2416 return !cls.is_interface(); | |
2417 } | 2386 } |
2418 return false; | 2387 return false; |
2419 } | 2388 } |
2420 | 2389 |
2421 | 2390 |
2422 DART_EXPORT bool Dart_IsInterface(Dart_Handle handle) { | 2391 DART_EXPORT bool Dart_IsInterface(Dart_Handle handle) { |
2423 Isolate* isolate = Isolate::Current(); | 2392 Isolate* isolate = Isolate::Current(); |
2424 DARTSCOPE(isolate); | 2393 DARTSCOPE(isolate); |
2425 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 2394 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
2426 if (obj.IsClass()) { | 2395 if (obj.IsClass()) { |
2427 Class& cls = Class::Handle(isolate); | 2396 return Class::Cast(obj).is_interface(); |
2428 cls ^= obj.raw(); | |
2429 return cls.is_interface(); | |
2430 } | 2397 } |
2431 return false; | 2398 return false; |
2432 } | 2399 } |
2433 | 2400 |
2434 | 2401 |
2435 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { | 2402 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { |
2436 Isolate* isolate = Isolate::Current(); | 2403 Isolate* isolate = Isolate::Current(); |
2437 DARTSCOPE(isolate); | 2404 DARTSCOPE(isolate); |
2438 Class& cls = Class::Handle(isolate); | 2405 const Class& cls = Class::Handle( |
2439 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); | 2406 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
2440 if (cls.IsNull()) { | 2407 if (cls.IsNull()) { |
2441 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2408 RETURN_TYPE_ERROR(isolate, clazz, Class); |
2442 } | 2409 } |
2443 return Api::NewHandle(isolate, cls.Name()); | 2410 return Api::NewHandle(isolate, cls.Name()); |
2444 } | 2411 } |
2445 | 2412 |
2446 | 2413 |
2447 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { | 2414 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { |
2448 Isolate* isolate = Isolate::Current(); | 2415 Isolate* isolate = Isolate::Current(); |
2449 DARTSCOPE(isolate); | 2416 DARTSCOPE(isolate); |
2450 Class& cls = Class::Handle(isolate); | 2417 const Class& cls = Class::Handle( |
2451 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); | 2418 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
2452 if (cls.IsNull()) { | 2419 if (cls.IsNull()) { |
2453 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2420 RETURN_TYPE_ERROR(isolate, clazz, Class); |
2454 } | 2421 } |
2455 return Api::NewHandle(isolate, cls.library()); | 2422 return Api::NewHandle(isolate, cls.library()); |
2456 } | 2423 } |
2457 | 2424 |
2458 | 2425 |
2459 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) { | 2426 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) { |
2460 Isolate* isolate = Isolate::Current(); | 2427 Isolate* isolate = Isolate::Current(); |
2461 DARTSCOPE(isolate); | 2428 DARTSCOPE(isolate); |
2462 Class& cls = Class::Handle(isolate); | 2429 const Class& cls = Class::Handle( |
2463 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); | 2430 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
2464 if (cls.IsNull()) { | 2431 if (cls.IsNull()) { |
2465 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2432 RETURN_TYPE_ERROR(isolate, clazz, Class); |
2466 } | 2433 } |
2467 | 2434 |
2468 // Finalize all classes. | 2435 // Finalize all classes. |
2469 const char* msg = CheckIsolateState(isolate); | 2436 const char* msg = CheckIsolateState(isolate); |
2470 if (msg != NULL) { | 2437 if (msg != NULL) { |
2471 return Api::NewError(msg); | 2438 return Api::NewError(msg); |
2472 } | 2439 } |
2473 | 2440 |
2474 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { | 2441 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { |
2475 return Api::NewHandle(isolate, cls.FactoryClass()); | 2442 return Api::NewHandle(isolate, cls.FactoryClass()); |
2476 } | 2443 } |
2477 return Api::Null(isolate); | 2444 return Api::Null(isolate); |
2478 } | 2445 } |
2479 | 2446 |
2480 | 2447 |
2481 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, | 2448 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, |
2482 intptr_t* count) { | 2449 intptr_t* count) { |
2483 Isolate* isolate = Isolate::Current(); | 2450 Isolate* isolate = Isolate::Current(); |
2484 DARTSCOPE(isolate); | 2451 DARTSCOPE(isolate); |
2485 Class& cls = Class::Handle(isolate); | 2452 const Class& cls = Class::Handle( |
2486 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); | 2453 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
2487 if (cls.IsNull()) { | 2454 if (cls.IsNull()) { |
2488 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2455 RETURN_TYPE_ERROR(isolate, clazz, Class); |
2489 } | 2456 } |
2490 | 2457 |
2491 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); | 2458 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); |
2492 if (interface_types.IsNull()) { | 2459 if (interface_types.IsNull()) { |
2493 *count = 0; | 2460 *count = 0; |
2494 } else { | 2461 } else { |
2495 *count = interface_types.Length(); | 2462 *count = interface_types.Length(); |
2496 } | 2463 } |
2497 return Api::Success(isolate); | 2464 return Api::Success(isolate); |
2498 } | 2465 } |
2499 | 2466 |
2500 | 2467 |
2501 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, | 2468 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, |
2502 intptr_t index) { | 2469 intptr_t index) { |
2503 Isolate* isolate = Isolate::Current(); | 2470 Isolate* isolate = Isolate::Current(); |
2504 DARTSCOPE(isolate); | 2471 DARTSCOPE(isolate); |
2505 Class& cls = Class::Handle(isolate); | 2472 const Class& cls = Class::Handle( |
2506 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); | 2473 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
2507 if (cls.IsNull()) { | 2474 if (cls.IsNull()) { |
2508 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2475 RETURN_TYPE_ERROR(isolate, clazz, Class); |
2509 } | 2476 } |
2510 | 2477 |
2511 // Finalize all classes. | 2478 // Finalize all classes. |
2512 const char* msg = CheckIsolateState(isolate); | 2479 const char* msg = CheckIsolateState(isolate); |
2513 if (msg != NULL) { | 2480 if (msg != NULL) { |
2514 return Api::NewError(msg); | 2481 return Api::NewError(msg); |
2515 } | 2482 } |
2516 | 2483 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2588 DARTSCOPE(isolate); | 2555 DARTSCOPE(isolate); |
2589 Object& result = Object::Handle(isolate); | 2556 Object& result = Object::Handle(isolate); |
2590 | 2557 |
2591 if (number_of_arguments < 0) { | 2558 if (number_of_arguments < 0) { |
2592 return Api::NewError( | 2559 return Api::NewError( |
2593 "%s expects argument 'number_of_arguments' to be non-negative.", | 2560 "%s expects argument 'number_of_arguments' to be non-negative.", |
2594 CURRENT_FUNC); | 2561 CURRENT_FUNC); |
2595 } | 2562 } |
2596 | 2563 |
2597 // Get the class to instantiate. | 2564 // Get the class to instantiate. |
2598 Class& cls = Class::Handle(isolate); | 2565 Class& cls = Class::Handle( |
2599 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); | 2566 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
2600 if (cls.IsNull()) { | 2567 if (cls.IsNull()) { |
2601 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2568 RETURN_TYPE_ERROR(isolate, clazz, Class); |
2602 } | 2569 } |
2603 String& base_constructor_name = String::Handle(); | 2570 String& base_constructor_name = String::Handle(); |
2604 base_constructor_name = cls.Name(); | 2571 base_constructor_name = cls.Name(); |
2605 | 2572 |
2606 // And get the name of the constructor to invoke. | 2573 // And get the name of the constructor to invoke. |
2607 String& dot_name = String::Handle(isolate); | 2574 String& dot_name = String::Handle(isolate); |
2608 const Object& name_obj = | 2575 const Object& name_obj = |
2609 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); | 2576 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); |
2610 if (name_obj.IsNull()) { | 2577 if (name_obj.IsNull()) { |
2611 dot_name = String::NewSymbol("."); | 2578 dot_name = String::NewSymbol("."); |
2612 } else if (name_obj.IsString()) { | 2579 } else if (name_obj.IsString()) { |
2613 const String& dot = String::Handle(isolate, String::NewSymbol(".")); | 2580 const String& dot = String::Handle(isolate, String::NewSymbol(".")); |
2614 String& name_str = String::Handle(isolate); | 2581 dot_name = String::Concat(dot, String::Cast(name_obj)); |
2615 name_str ^= name_obj.raw(); | |
2616 dot_name ^= String::Concat(dot, name_str); | |
2617 } else { | 2582 } else { |
2618 return Api::NewError( | 2583 return Api::NewError( |
2619 "%s expects argument 'constructor_name' to be of type String.", | 2584 "%s expects argument 'constructor_name' to be of type String.", |
2620 CURRENT_FUNC); | 2585 CURRENT_FUNC); |
2621 } | 2586 } |
2622 | 2587 |
2623 const char* msg = CheckIsolateState(isolate); | 2588 const char* msg = CheckIsolateState(isolate); |
2624 if (msg != NULL) { | 2589 if (msg != NULL) { |
2625 return Api::NewError(msg); | 2590 return Api::NewError(msg); |
2626 } | 2591 } |
(...skipping 16 matching lines...) Expand all Loading... |
2643 // looking up the constructor. | 2608 // looking up the constructor. |
2644 const TypeArguments& no_type_args = TypeArguments::Handle(isolate); | 2609 const TypeArguments& no_type_args = TypeArguments::Handle(isolate); |
2645 Error& error = Error::Handle(); | 2610 Error& error = Error::Handle(); |
2646 if (factory_class.IsSubtypeOf(no_type_args, cls, no_type_args, &error)) { | 2611 if (factory_class.IsSubtypeOf(no_type_args, cls, no_type_args, &error)) { |
2647 base_constructor_name = factory_class.Name(); | 2612 base_constructor_name = factory_class.Name(); |
2648 } | 2613 } |
2649 if (!error.IsNull()) { | 2614 if (!error.IsNull()) { |
2650 return Api::NewHandle(isolate, error.raw()); | 2615 return Api::NewHandle(isolate, error.raw()); |
2651 } | 2616 } |
2652 | 2617 |
2653 cls ^= cls.FactoryClass(); | 2618 cls = cls.FactoryClass(); |
2654 } | 2619 } |
2655 | 2620 |
2656 // Resolve the constructor. | 2621 // Resolve the constructor. |
2657 result = ResolveConstructor( | 2622 result = ResolveConstructor( |
2658 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); | 2623 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); |
2659 if (result.IsError()) { | 2624 if (result.IsError()) { |
2660 return Api::NewHandle(isolate, result.raw()); | 2625 return Api::NewHandle(isolate, result.raw()); |
2661 } | 2626 } |
2662 ASSERT(result.IsFunction()); | 2627 ASSERT(result.IsFunction()); |
2663 Function& constructor = Function::Handle(isolate); | 2628 Function& constructor = Function::Handle(isolate); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2773 isolate, | 2738 isolate, |
2774 DartEntry::InvokeDynamic(instance, function, args, kNoArgNames)); | 2739 DartEntry::InvokeDynamic(instance, function, args, kNoArgNames)); |
2775 | 2740 |
2776 } else if (obj.IsClass()) { | 2741 } else if (obj.IsClass()) { |
2777 // Finalize all classes. | 2742 // Finalize all classes. |
2778 const char* msg = CheckIsolateState(isolate); | 2743 const char* msg = CheckIsolateState(isolate); |
2779 if (msg != NULL) { | 2744 if (msg != NULL) { |
2780 return Api::NewError(msg); | 2745 return Api::NewError(msg); |
2781 } | 2746 } |
2782 | 2747 |
2783 Class& cls = Class::Handle(isolate); | 2748 const Class& cls = Class::Cast(obj); |
2784 cls ^= obj.raw(); | |
2785 const Function& function = Function::Handle( | 2749 const Function& function = Function::Handle( |
2786 isolate, | 2750 isolate, |
2787 Resolver::ResolveStatic(cls, | 2751 Resolver::ResolveStatic(cls, |
2788 function_name, | 2752 function_name, |
2789 number_of_arguments, | 2753 number_of_arguments, |
2790 Array::Handle(isolate), | 2754 Array::Handle(isolate), |
2791 Resolver::kIsQualified)); | 2755 Resolver::kIsQualified)); |
2792 if (function.IsNull()) { | 2756 if (function.IsNull()) { |
2793 const String& cls_name = String::Handle(isolate, cls.Name()); | 2757 const String& cls_name = String::Handle(isolate, cls.Name()); |
2794 return Api::NewError("%s: did not find static method '%s.%s'.", | 2758 return Api::NewError("%s: did not find static method '%s.%s'.", |
2795 CURRENT_FUNC, | 2759 CURRENT_FUNC, |
2796 cls_name.ToCString(), | 2760 cls_name.ToCString(), |
2797 function_name.ToCString()); | 2761 function_name.ToCString()); |
2798 } | 2762 } |
2799 return Api::NewHandle( | 2763 return Api::NewHandle( |
2800 isolate, | 2764 isolate, |
2801 DartEntry::InvokeStatic(function, args, kNoArgNames)); | 2765 DartEntry::InvokeStatic(function, args, kNoArgNames)); |
2802 | 2766 |
2803 } else if (obj.IsLibrary()) { | 2767 } else if (obj.IsLibrary()) { |
2804 // Check whether class finalization is needed. | 2768 // Check whether class finalization is needed. |
2805 bool finalize_classes = true; | 2769 bool finalize_classes = true; |
2806 Library& lib = Library::Handle(isolate); | 2770 const Library& lib = Library::Cast(obj); |
2807 lib ^= obj.raw(); | |
2808 | 2771 |
2809 // When calling functions in the dart:builtin library do not finalize as it | 2772 // When calling functions in the dart:builtin library do not finalize as it |
2810 // should have been prefinalized. | 2773 // should have been prefinalized. |
2811 Library& builtin = | 2774 Library& builtin = |
2812 Library::Handle(isolate, isolate->object_store()->builtin_library()); | 2775 Library::Handle(isolate, isolate->object_store()->builtin_library()); |
2813 if (builtin.raw() == lib.raw()) { | 2776 if (builtin.raw() == lib.raw()) { |
2814 finalize_classes = false; | 2777 finalize_classes = false; |
2815 } | 2778 } |
2816 | 2779 |
2817 // Finalize all classes if needed. | 2780 // Finalize all classes if needed. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2871 | 2834 |
2872 Field& field = Field::Handle(isolate); | 2835 Field& field = Field::Handle(isolate); |
2873 Function& getter = Function::Handle(isolate); | 2836 Function& getter = Function::Handle(isolate); |
2874 if (obj.IsNull()) { | 2837 if (obj.IsNull()) { |
2875 return Api::NewError("%s expects argument 'container' to be non-null.", | 2838 return Api::NewError("%s expects argument 'container' to be non-null.", |
2876 CURRENT_FUNC); | 2839 CURRENT_FUNC); |
2877 } else if (obj.IsInstance()) { | 2840 } else if (obj.IsInstance()) { |
2878 // Every instance field has a getter Function. Try to find the | 2841 // Every instance field has a getter Function. Try to find the |
2879 // getter in any superclass and use that function to access the | 2842 // getter in any superclass and use that function to access the |
2880 // field. | 2843 // field. |
2881 Instance& instance = Instance::Handle(isolate); | 2844 const Instance& instance = Instance::Cast(obj); |
2882 instance ^= obj.raw(); | |
2883 Class& cls = Class::Handle(isolate, instance.clazz()); | 2845 Class& cls = Class::Handle(isolate, instance.clazz()); |
2884 while (!cls.IsNull()) { | 2846 while (!cls.IsNull()) { |
2885 String& getter_name = | 2847 String& getter_name = |
2886 String::Handle(isolate, Field::GetterName(field_name)); | 2848 String::Handle(isolate, Field::GetterName(field_name)); |
2887 getter = cls.LookupDynamicFunction(getter_name); | 2849 getter = cls.LookupDynamicFunction(getter_name); |
2888 if (!getter.IsNull()) { | 2850 if (!getter.IsNull()) { |
2889 break; | 2851 break; |
2890 } | 2852 } |
2891 cls = cls.SuperClass(); | 2853 cls = cls.SuperClass(); |
2892 } | 2854 } |
(...skipping 11 matching lines...) Expand all Loading... |
2904 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames)); | 2866 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames)); |
2905 | 2867 |
2906 } else if (obj.IsClass()) { | 2868 } else if (obj.IsClass()) { |
2907 // Finalize all classes. | 2869 // Finalize all classes. |
2908 const char* msg = CheckIsolateState(isolate); | 2870 const char* msg = CheckIsolateState(isolate); |
2909 if (msg != NULL) { | 2871 if (msg != NULL) { |
2910 return Api::NewError(msg); | 2872 return Api::NewError(msg); |
2911 } | 2873 } |
2912 // To access a static field we may need to use the Field or the | 2874 // To access a static field we may need to use the Field or the |
2913 // getter Function. | 2875 // getter Function. |
2914 Class& cls = Class::Handle(isolate); | 2876 const Class& cls = Class::Cast(obj); |
2915 cls ^= obj.raw(); | |
2916 field = cls.LookupStaticField(field_name); | 2877 field = cls.LookupStaticField(field_name); |
2917 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { | 2878 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { |
2918 const String& getter_name = | 2879 const String& getter_name = |
2919 String::Handle(isolate, Field::GetterName(field_name)); | 2880 String::Handle(isolate, Field::GetterName(field_name)); |
2920 getter = cls.LookupStaticFunction(getter_name); | 2881 getter = cls.LookupStaticFunction(getter_name); |
2921 } | 2882 } |
2922 | 2883 |
2923 if (!getter.IsNull()) { | 2884 if (!getter.IsNull()) { |
2924 // Invoke the getter and return the result. | 2885 // Invoke the getter and return the result. |
2925 GrowableArray<const Object*> args; | 2886 GrowableArray<const Object*> args; |
2926 const Array& kNoArgNames = Array::Handle(isolate); | 2887 const Array& kNoArgNames = Array::Handle(isolate); |
2927 return Api::NewHandle( | 2888 return Api::NewHandle( |
2928 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); | 2889 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); |
2929 } else if (!field.IsNull()) { | 2890 } else if (!field.IsNull()) { |
2930 return Api::NewHandle(isolate, field.value()); | 2891 return Api::NewHandle(isolate, field.value()); |
2931 } else { | 2892 } else { |
2932 return Api::NewError("%s: did not find static field '%s'.", | 2893 return Api::NewError("%s: did not find static field '%s'.", |
2933 CURRENT_FUNC, field_name.ToCString()); | 2894 CURRENT_FUNC, field_name.ToCString()); |
2934 } | 2895 } |
2935 | 2896 |
2936 } else if (obj.IsLibrary()) { | 2897 } else if (obj.IsLibrary()) { |
2937 // TODO(turnidge): Do we need to call CheckIsolateState here? | 2898 // TODO(turnidge): Do we need to call CheckIsolateState here? |
2938 | 2899 |
2939 // To access a top-level we may need to use the Field or the | 2900 // To access a top-level we may need to use the Field or the |
2940 // getter Function. The getter function may either be in the | 2901 // getter Function. The getter function may either be in the |
2941 // library or in the field's owner class, depending. | 2902 // library or in the field's owner class, depending. |
2942 Library& lib = Library::Handle(isolate); | 2903 const Library& lib = Library::Cast(obj); |
2943 lib ^= obj.raw(); | |
2944 field = lib.LookupFieldAllowPrivate(field_name); | 2904 field = lib.LookupFieldAllowPrivate(field_name); |
2945 if (field.IsNull()) { | 2905 if (field.IsNull()) { |
2946 // No field found. Check for a getter in the lib. | 2906 // No field found. Check for a getter in the lib. |
2947 const String& getter_name = | 2907 const String& getter_name = |
2948 String::Handle(isolate, Field::GetterName(field_name)); | 2908 String::Handle(isolate, Field::GetterName(field_name)); |
2949 getter = lib.LookupFunctionAllowPrivate(getter_name); | 2909 getter = lib.LookupFunctionAllowPrivate(getter_name); |
2950 } else if (FieldIsUninitialized(isolate, field)) { | 2910 } else if (FieldIsUninitialized(isolate, field)) { |
2951 // A field was found. Check for a getter in the field's owner classs. | 2911 // A field was found. Check for a getter in the field's owner classs. |
2952 const Class& cls = Class::Handle(isolate, field.owner()); | 2912 const Class& cls = Class::Handle(isolate, field.owner()); |
2953 const String& getter_name = | 2913 const String& getter_name = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2998 Field& field = Field::Handle(isolate); | 2958 Field& field = Field::Handle(isolate); |
2999 Function& setter = Function::Handle(isolate); | 2959 Function& setter = Function::Handle(isolate); |
3000 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 2960 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
3001 if (obj.IsNull()) { | 2961 if (obj.IsNull()) { |
3002 return Api::NewError("%s expects argument 'container' to be non-null.", | 2962 return Api::NewError("%s expects argument 'container' to be non-null.", |
3003 CURRENT_FUNC); | 2963 CURRENT_FUNC); |
3004 } else if (obj.IsInstance()) { | 2964 } else if (obj.IsInstance()) { |
3005 // Every instance field has a setter Function. Try to find the | 2965 // Every instance field has a setter Function. Try to find the |
3006 // setter in any superclass and use that function to access the | 2966 // setter in any superclass and use that function to access the |
3007 // field. | 2967 // field. |
3008 Instance& instance = Instance::Handle(isolate); | 2968 const Instance& instance = Instance::Cast(obj); |
3009 instance ^= obj.raw(); | |
3010 Class& cls = Class::Handle(isolate, instance.clazz()); | 2969 Class& cls = Class::Handle(isolate, instance.clazz()); |
3011 while (!cls.IsNull()) { | 2970 while (!cls.IsNull()) { |
3012 field = cls.LookupInstanceField(field_name); | 2971 field = cls.LookupInstanceField(field_name); |
3013 if (!field.IsNull() && field.is_final()) { | 2972 if (!field.IsNull() && field.is_final()) { |
3014 return Api::NewError("%s: cannot set final field '%s'.", | 2973 return Api::NewError("%s: cannot set final field '%s'.", |
3015 CURRENT_FUNC, field_name.ToCString()); | 2974 CURRENT_FUNC, field_name.ToCString()); |
3016 } | 2975 } |
3017 String& setter_name = | 2976 String& setter_name = |
3018 String::Handle(isolate, Field::SetterName(field_name)); | 2977 String::Handle(isolate, Field::SetterName(field_name)); |
3019 setter = cls.LookupDynamicFunction(setter_name); | 2978 setter = cls.LookupDynamicFunction(setter_name); |
(...skipping 12 matching lines...) Expand all Loading... |
3032 GrowableArray<const Object*> args(1); | 2991 GrowableArray<const Object*> args(1); |
3033 args.Add(&value_instance); | 2992 args.Add(&value_instance); |
3034 const Array& kNoArgNames = Array::Handle(isolate); | 2993 const Array& kNoArgNames = Array::Handle(isolate); |
3035 return Api::NewHandle( | 2994 return Api::NewHandle( |
3036 isolate, | 2995 isolate, |
3037 DartEntry::InvokeDynamic(instance, setter, args, kNoArgNames)); | 2996 DartEntry::InvokeDynamic(instance, setter, args, kNoArgNames)); |
3038 | 2997 |
3039 } else if (obj.IsClass()) { | 2998 } else if (obj.IsClass()) { |
3040 // To access a static field we may need to use the Field or the | 2999 // To access a static field we may need to use the Field or the |
3041 // setter Function. | 3000 // setter Function. |
3042 Class& cls = Class::Handle(isolate); | 3001 const Class& cls = Class::Cast(obj); |
3043 cls ^= obj.raw(); | |
3044 field = cls.LookupStaticField(field_name); | 3002 field = cls.LookupStaticField(field_name); |
3045 if (field.IsNull()) { | 3003 if (field.IsNull()) { |
3046 String& setter_name = | 3004 String& setter_name = |
3047 String::Handle(isolate, Field::SetterName(field_name)); | 3005 String::Handle(isolate, Field::SetterName(field_name)); |
3048 setter = cls.LookupStaticFunction(setter_name); | 3006 setter = cls.LookupStaticFunction(setter_name); |
3049 } | 3007 } |
3050 | 3008 |
3051 if (!setter.IsNull()) { | 3009 if (!setter.IsNull()) { |
3052 // Invoke the setter and return the result. | 3010 // Invoke the setter and return the result. |
3053 GrowableArray<const Object*> args(1); | 3011 GrowableArray<const Object*> args(1); |
(...skipping 17 matching lines...) Expand all Loading... |
3071 } | 3029 } |
3072 } else { | 3030 } else { |
3073 return Api::NewError("%s: did not find static field '%s'.", | 3031 return Api::NewError("%s: did not find static field '%s'.", |
3074 CURRENT_FUNC, field_name.ToCString()); | 3032 CURRENT_FUNC, field_name.ToCString()); |
3075 } | 3033 } |
3076 | 3034 |
3077 } else if (obj.IsLibrary()) { | 3035 } else if (obj.IsLibrary()) { |
3078 // To access a top-level we may need to use the Field or the | 3036 // To access a top-level we may need to use the Field or the |
3079 // setter Function. The setter function may either be in the | 3037 // setter Function. The setter function may either be in the |
3080 // library or in the field's owner class, depending. | 3038 // library or in the field's owner class, depending. |
3081 Library& lib = Library::Handle(isolate); | 3039 const Library& lib = Library::Cast(obj); |
3082 lib ^= obj.raw(); | |
3083 field = lib.LookupFieldAllowPrivate(field_name); | 3040 field = lib.LookupFieldAllowPrivate(field_name); |
3084 if (field.IsNull()) { | 3041 if (field.IsNull()) { |
3085 const String& setter_name = | 3042 const String& setter_name = |
3086 String::Handle(isolate, Field::SetterName(field_name)); | 3043 String::Handle(isolate, Field::SetterName(field_name)); |
3087 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 3044 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
3088 } | 3045 } |
3089 | 3046 |
3090 if (!setter.IsNull()) { | 3047 if (!setter.IsNull()) { |
3091 // Invoke the setter and return the result. | 3048 // Invoke the setter and return the result. |
3092 GrowableArray<const Object*> args(1); | 3049 GrowableArray<const Object*> args(1); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3664 *buffer_size = 0; | 3621 *buffer_size = 0; |
3665 } | 3622 } |
3666 } | 3623 } |
3667 | 3624 |
3668 | 3625 |
3669 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { | 3626 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { |
3670 Dart::set_flow_graph_writer(function); | 3627 Dart::set_flow_graph_writer(function); |
3671 } | 3628 } |
3672 | 3629 |
3673 } // namespace dart | 3630 } // namespace dart |
OLD | NEW |