Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "vm/symbols.h" | 31 #include "vm/symbols.h" |
| 32 #include "vm/timer.h" | 32 #include "vm/timer.h" |
| 33 #include "vm/unicode.h" | 33 #include "vm/unicode.h" |
| 34 #include "vm/verifier.h" | 34 #include "vm/verifier.h" |
| 35 #include "vm/version.h" | 35 #include "vm/version.h" |
| 36 | 36 |
| 37 namespace dart { | 37 namespace dart { |
| 38 | 38 |
| 39 DECLARE_FLAG(bool, print_class_table); | 39 DECLARE_FLAG(bool, print_class_table); |
| 40 DECLARE_FLAG(bool, verify_handles); | 40 DECLARE_FLAG(bool, verify_handles); |
| 41 DEFINE_FLAG(bool, trace_api, false, "Trace invocation of API calls"); | |
|
regis
2013/09/04 23:05:15
should you add "(debug mode only)"?
siva
2013/09/04 23:27:42
Done.
| |
| 41 | 42 |
| 42 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; | 43 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
| 43 Dart_Handle Api::true_handle_ = NULL; | 44 Dart_Handle Api::true_handle_ = NULL; |
| 44 Dart_Handle Api::false_handle_ = NULL; | 45 Dart_Handle Api::false_handle_ = NULL; |
| 45 Dart_Handle Api::null_handle_ = NULL; | 46 Dart_Handle Api::null_handle_ = NULL; |
| 46 | 47 |
| 47 | 48 |
| 48 const char* CanonicalFunction(const char* func) { | 49 const char* CanonicalFunction(const char* func) { |
| 49 if (strncmp(func, "dart::", 6) == 0) { | 50 if (strncmp(func, "dart::", 6) == 0) { |
| 50 return func + 6; | 51 return func + 6; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 273 |
| 273 void Api::SetWeakHandleReturnValue(NativeArguments* args, | 274 void Api::SetWeakHandleReturnValue(NativeArguments* args, |
| 274 Dart_WeakPersistentHandle retval) { | 275 Dart_WeakPersistentHandle retval) { |
| 275 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw()); | 276 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw()); |
| 276 } | 277 } |
| 277 | 278 |
| 278 | 279 |
| 279 // --- Handles --- | 280 // --- Handles --- |
| 280 | 281 |
| 281 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 282 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 283 TRACE_API_CALLS(CURRENT_FUNC); | |
| 282 return RawObject::IsErrorClassId(Api::ClassId(handle)); | 284 return RawObject::IsErrorClassId(Api::ClassId(handle)); |
| 283 } | 285 } |
| 284 | 286 |
| 285 | 287 |
| 286 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { | 288 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { |
| 289 TRACE_API_CALLS(CURRENT_FUNC); | |
| 287 return Api::ClassId(object) == kApiErrorCid; | 290 return Api::ClassId(object) == kApiErrorCid; |
| 288 } | 291 } |
| 289 | 292 |
| 290 | 293 |
| 291 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { | 294 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { |
| 295 TRACE_API_CALLS(CURRENT_FUNC); | |
| 292 return Api::ClassId(object) == kUnhandledExceptionCid; | 296 return Api::ClassId(object) == kUnhandledExceptionCid; |
| 293 } | 297 } |
| 294 | 298 |
| 295 | 299 |
| 296 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { | 300 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { |
| 301 TRACE_API_CALLS(CURRENT_FUNC); | |
| 297 return Api::ClassId(object) == kLanguageErrorCid; | 302 return Api::ClassId(object) == kLanguageErrorCid; |
| 298 } | 303 } |
| 299 | 304 |
| 300 | 305 |
| 301 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { | 306 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { |
| 307 TRACE_API_CALLS(CURRENT_FUNC); | |
| 302 return Api::ClassId(object) == kUnwindErrorCid; | 308 return Api::ClassId(object) == kUnwindErrorCid; |
| 303 } | 309 } |
| 304 | 310 |
| 305 | 311 |
| 306 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 312 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
|
regis
2013/09/04 23:05:15
You did not add TRACE_API_CALLS here or to the fun
siva
2013/09/04 23:27:42
Most of these functions have DARTISOLATE or CHECK_
| |
| 307 Isolate* isolate = Isolate::Current(); | 313 Isolate* isolate = Isolate::Current(); |
| 308 DARTSCOPE(isolate); | 314 DARTSCOPE(isolate); |
| 309 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 315 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 310 if (obj.IsError()) { | 316 if (obj.IsError()) { |
| 311 const Error& error = Error::Cast(obj); | 317 const Error& error = Error::Cast(obj); |
| 312 const char* str = error.ToErrorCString(); | 318 const char* str = error.ToErrorCString(); |
| 313 intptr_t len = strlen(str) + 1; | 319 intptr_t len = strlen(str) + 1; |
| 314 char* str_copy = Api::TopScope(isolate)->zone()->Alloc<char>(len); | 320 char* str_copy = Api::TopScope(isolate)->zone()->Alloc<char>(len); |
| 315 strncpy(str_copy, str, len); | 321 strncpy(str_copy, str, len); |
| 316 // Strip a possible trailing '\n'. | 322 // Strip a possible trailing '\n'. |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 OS::SNPrint(chars, len, "%s$%s", script_uri, main); | 792 OS::SNPrint(chars, len, "%s$%s", script_uri, main); |
| 787 return chars; | 793 return chars; |
| 788 } | 794 } |
| 789 | 795 |
| 790 | 796 |
| 791 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, | 797 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
| 792 const char* main, | 798 const char* main, |
| 793 const uint8_t* snapshot, | 799 const uint8_t* snapshot, |
| 794 void* callback_data, | 800 void* callback_data, |
| 795 char** error) { | 801 char** error) { |
| 802 TRACE_API_CALLS(CURRENT_FUNC); | |
| 796 char* isolate_name = BuildIsolateName(script_uri, main); | 803 char* isolate_name = BuildIsolateName(script_uri, main); |
| 797 Isolate* isolate = Dart::CreateIsolate(isolate_name); | 804 Isolate* isolate = Dart::CreateIsolate(isolate_name); |
| 798 free(isolate_name); | 805 free(isolate_name); |
| 799 { | 806 { |
| 800 StackZone zone(isolate); | 807 StackZone zone(isolate); |
| 801 HANDLESCOPE(isolate); | 808 HANDLESCOPE(isolate); |
| 802 const Error& error_obj = | 809 const Error& error_obj = |
| 803 Error::Handle(isolate, | 810 Error::Handle(isolate, |
| 804 Dart::InitializeIsolate(snapshot, callback_data)); | 811 Dart::InitializeIsolate(snapshot, callback_data)); |
| 805 if (error_obj.IsNull()) { | 812 if (error_obj.IsNull()) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 CURRENT_FUNC); | 921 CURRENT_FUNC); |
| 915 } | 922 } |
| 916 ScriptSnapshotWriter writer(buffer, ApiReallocate); | 923 ScriptSnapshotWriter writer(buffer, ApiReallocate); |
| 917 writer.WriteScriptSnapshot(library); | 924 writer.WriteScriptSnapshot(library); |
| 918 *size = writer.BytesWritten(); | 925 *size = writer.BytesWritten(); |
| 919 return Api::Success(); | 926 return Api::Success(); |
| 920 } | 927 } |
| 921 | 928 |
| 922 | 929 |
| 923 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 930 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
| 931 TRACE_API_CALLS(CURRENT_FUNC); | |
| 924 if (isolate == NULL) { | 932 if (isolate == NULL) { |
| 925 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 933 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
| 926 } | 934 } |
| 927 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 935 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 928 iso->ScheduleInterrupts(Isolate::kApiInterrupt); | 936 iso->ScheduleInterrupts(Isolate::kApiInterrupt); |
| 929 } | 937 } |
| 930 | 938 |
| 931 | 939 |
| 932 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { | 940 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
| 933 CHECK_NO_ISOLATE(Isolate::Current()); | 941 CHECK_NO_ISOLATE(Isolate::Current()); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 | 1231 |
| 1224 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1232 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
| 1225 Isolate* isolate = Isolate::Current(); | 1233 Isolate* isolate = Isolate::Current(); |
| 1226 DARTSCOPE(isolate); | 1234 DARTSCOPE(isolate); |
| 1227 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1235 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1228 return obj.IsInstance(); | 1236 return obj.IsInstance(); |
| 1229 } | 1237 } |
| 1230 | 1238 |
| 1231 | 1239 |
| 1232 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1240 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
| 1241 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1233 return RawObject::IsNumberClassId(Api::ClassId(object)); | 1242 return RawObject::IsNumberClassId(Api::ClassId(object)); |
| 1234 } | 1243 } |
| 1235 | 1244 |
| 1236 | 1245 |
| 1237 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1246 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
| 1247 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1238 return RawObject::IsIntegerClassId(Api::ClassId(object)); | 1248 return RawObject::IsIntegerClassId(Api::ClassId(object)); |
| 1239 } | 1249 } |
| 1240 | 1250 |
| 1241 | 1251 |
| 1242 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { | 1252 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { |
| 1253 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1243 return Api::ClassId(object) == kDoubleCid; | 1254 return Api::ClassId(object) == kDoubleCid; |
| 1244 } | 1255 } |
| 1245 | 1256 |
| 1246 | 1257 |
| 1247 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { | 1258 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { |
| 1259 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1248 return Api::ClassId(object) == kBoolCid; | 1260 return Api::ClassId(object) == kBoolCid; |
| 1249 } | 1261 } |
| 1250 | 1262 |
| 1251 | 1263 |
| 1252 DART_EXPORT bool Dart_IsString(Dart_Handle object) { | 1264 DART_EXPORT bool Dart_IsString(Dart_Handle object) { |
| 1265 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1253 return RawObject::IsStringClassId(Api::ClassId(object)); | 1266 return RawObject::IsStringClassId(Api::ClassId(object)); |
| 1254 } | 1267 } |
| 1255 | 1268 |
| 1256 | 1269 |
| 1257 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { | 1270 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { |
| 1271 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1258 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); | 1272 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); |
| 1259 } | 1273 } |
| 1260 | 1274 |
| 1261 | 1275 |
| 1262 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1276 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 1277 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1263 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1278 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
| 1264 } | 1279 } |
| 1265 | 1280 |
| 1266 | 1281 |
| 1267 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1282 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
| 1268 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { | 1283 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { |
| 1284 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1269 return true; | 1285 return true; |
| 1270 } | 1286 } |
| 1271 | 1287 |
| 1272 Isolate* isolate = Isolate::Current(); | 1288 Isolate* isolate = Isolate::Current(); |
| 1273 DARTSCOPE(isolate); | 1289 DARTSCOPE(isolate); |
| 1274 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1290 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1275 return GetListInstance(isolate, obj) != Instance::null(); | 1291 return GetListInstance(isolate, obj) != Instance::null(); |
| 1276 } | 1292 } |
| 1277 | 1293 |
| 1278 | 1294 |
| 1279 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 1295 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 1296 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1280 return Api::ClassId(object) == kLibraryCid; | 1297 return Api::ClassId(object) == kLibraryCid; |
| 1281 } | 1298 } |
| 1282 | 1299 |
| 1283 | 1300 |
| 1284 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { | 1301 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { |
| 1302 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1285 return Api::ClassId(handle) == kTypeCid; | 1303 return Api::ClassId(handle) == kTypeCid; |
| 1286 } | 1304 } |
| 1287 | 1305 |
| 1288 | 1306 |
| 1289 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { | 1307 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { |
| 1290 Isolate* isolate = Isolate::Current(); | 1308 Isolate* isolate = Isolate::Current(); |
| 1291 DARTSCOPE(isolate); | 1309 DARTSCOPE(isolate); |
| 1292 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 1310 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 1293 return obj.IsClass(); | 1311 return obj.IsClass(); |
| 1294 } | 1312 } |
| 1295 | 1313 |
| 1296 | 1314 |
| 1297 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { | 1315 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { |
| 1316 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1298 return Api::ClassId(handle) == kFunctionCid; | 1317 return Api::ClassId(handle) == kFunctionCid; |
| 1299 } | 1318 } |
| 1300 | 1319 |
| 1301 | 1320 |
| 1302 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { | 1321 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { |
| 1322 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1303 return Api::ClassId(handle) == kFieldCid; | 1323 return Api::ClassId(handle) == kFieldCid; |
| 1304 } | 1324 } |
| 1305 | 1325 |
| 1306 | 1326 |
| 1307 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { | 1327 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { |
| 1328 TRACE_API_CALLS(CURRENT_FUNC); | |
| 1308 return Api::ClassId(handle) == kTypeParameterCid; | 1329 return Api::ClassId(handle) == kTypeParameterCid; |
| 1309 } | 1330 } |
| 1310 | 1331 |
| 1311 | 1332 |
| 1312 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1333 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 1313 // We can't use a fast class index check here because there are many | 1334 // We can't use a fast class index check here because there are many |
| 1314 // different signature classes for closures. | 1335 // different signature classes for closures. |
| 1315 Isolate* isolate = Isolate::Current(); | 1336 Isolate* isolate = Isolate::Current(); |
| 1316 DARTSCOPE(isolate); | 1337 DARTSCOPE(isolate); |
| 1317 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); | 1338 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2430 break; | 2451 break; |
| 2431 default: | 2452 default: |
| 2432 type = Dart_TypedData_kInvalid; | 2453 type = Dart_TypedData_kInvalid; |
| 2433 break; | 2454 break; |
| 2434 } | 2455 } |
| 2435 return type; | 2456 return type; |
| 2436 } | 2457 } |
| 2437 | 2458 |
| 2438 | 2459 |
| 2439 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { | 2460 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { |
| 2461 TRACE_API_CALLS(CURRENT_FUNC); | |
| 2440 intptr_t class_id = Api::ClassId(object); | 2462 intptr_t class_id = Api::ClassId(object); |
| 2441 if (RawObject::IsTypedDataClassId(class_id) || | 2463 if (RawObject::IsTypedDataClassId(class_id) || |
| 2442 RawObject::IsTypedDataViewClassId(class_id)) { | 2464 RawObject::IsTypedDataViewClassId(class_id)) { |
| 2443 return GetType(class_id); | 2465 return GetType(class_id); |
| 2444 } | 2466 } |
| 2445 return Dart_TypedData_kInvalid; | 2467 return Dart_TypedData_kInvalid; |
| 2446 } | 2468 } |
| 2447 | 2469 |
| 2448 | 2470 |
| 2449 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( | 2471 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( |
| 2450 Dart_Handle object) { | 2472 Dart_Handle object) { |
| 2473 TRACE_API_CALLS(CURRENT_FUNC); | |
| 2451 intptr_t class_id = Api::ClassId(object); | 2474 intptr_t class_id = Api::ClassId(object); |
| 2452 if (RawObject::IsExternalTypedDataClassId(class_id) || | 2475 if (RawObject::IsExternalTypedDataClassId(class_id) || |
| 2453 RawObject::IsTypedDataViewClassId(class_id)) { | 2476 RawObject::IsTypedDataViewClassId(class_id)) { |
| 2454 return GetType(class_id); | 2477 return GetType(class_id); |
| 2455 } | 2478 } |
| 2456 return Dart_TypedData_kInvalid; | 2479 return Dart_TypedData_kInvalid; |
| 2457 } | 2480 } |
| 2458 | 2481 |
| 2459 | 2482 |
| 2460 static RawObject* GetByteDataConstructor(Isolate* isolate, | 2483 static RawObject* GetByteDataConstructor(Isolate* isolate, |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3582 "%s: invalid index %d passed in to set native instance field", | 3605 "%s: invalid index %d passed in to set native instance field", |
| 3583 CURRENT_FUNC, index); | 3606 CURRENT_FUNC, index); |
| 3584 } | 3607 } |
| 3585 instance.SetNativeField(index, value); | 3608 instance.SetNativeField(index, value); |
| 3586 return Api::Success(); | 3609 return Api::Success(); |
| 3587 } | 3610 } |
| 3588 | 3611 |
| 3589 | 3612 |
| 3590 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 3613 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
| 3591 int index) { | 3614 int index) { |
| 3615 TRACE_API_CALLS(CURRENT_FUNC); | |
| 3592 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3616 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3593 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 3617 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3594 return Api::NewError( | 3618 return Api::NewError( |
| 3595 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3619 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3596 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 3620 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3597 } | 3621 } |
| 3598 return Api::NewHandle(arguments->isolate(), arguments->NativeArgAt(index)); | 3622 return Api::NewHandle(arguments->isolate(), arguments->NativeArgAt(index)); |
| 3599 } | 3623 } |
| 3600 | 3624 |
| 3601 | 3625 |
| 3602 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 3626 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
| 3627 TRACE_API_CALLS(CURRENT_FUNC); | |
| 3603 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3628 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3604 return arguments->NativeArgCount(); | 3629 return arguments->NativeArgCount(); |
| 3605 } | 3630 } |
| 3606 | 3631 |
| 3607 | 3632 |
| 3608 DART_EXPORT Dart_Handle Dart_GetNativeFieldOfArgument(Dart_NativeArguments args, | 3633 DART_EXPORT Dart_Handle Dart_GetNativeFieldOfArgument(Dart_NativeArguments args, |
| 3609 int arg_index, | 3634 int arg_index, |
| 3610 int fld_index, | 3635 int fld_index, |
| 3611 intptr_t* value) { | 3636 intptr_t* value) { |
| 3612 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3637 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3685 return Api::NewHandle(isolate, obj.raw()); | 3710 return Api::NewHandle(isolate, obj.raw()); |
| 3686 } | 3711 } |
| 3687 return Api::NewError("%s expects argument to be of" | 3712 return Api::NewError("%s expects argument to be of" |
| 3688 " type String.", CURRENT_FUNC); | 3713 " type String.", CURRENT_FUNC); |
| 3689 } | 3714 } |
| 3690 | 3715 |
| 3691 | 3716 |
| 3692 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, | 3717 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
| 3693 int index, | 3718 int index, |
| 3694 int64_t* value) { | 3719 int64_t* value) { |
| 3720 TRACE_API_CALLS(CURRENT_FUNC); | |
| 3695 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3721 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3696 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 3722 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3697 return Api::NewError( | 3723 return Api::NewError( |
| 3698 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3724 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3699 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 3725 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3700 } | 3726 } |
| 3701 Isolate* isolate = arguments->isolate(); | 3727 Isolate* isolate = arguments->isolate(); |
| 3702 ReusableObjectHandleScope reused_obj_handle(isolate); | 3728 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3703 Object& obj = reused_obj_handle.Handle(); | 3729 Object& obj = reused_obj_handle.Handle(); |
| 3704 obj = arguments->NativeArgAt(index); | 3730 obj = arguments->NativeArgAt(index); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 3723 } | 3749 } |
| 3724 return Api::NewError( | 3750 return Api::NewError( |
| 3725 "%s: argument %d is not an Integer argument.", | 3751 "%s: argument %d is not an Integer argument.", |
| 3726 CURRENT_FUNC, index); | 3752 CURRENT_FUNC, index); |
| 3727 } | 3753 } |
| 3728 | 3754 |
| 3729 | 3755 |
| 3730 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, | 3756 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, |
| 3731 int index, | 3757 int index, |
| 3732 bool* value) { | 3758 bool* value) { |
| 3759 TRACE_API_CALLS(CURRENT_FUNC); | |
| 3733 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3760 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3734 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 3761 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3735 return Api::NewError( | 3762 return Api::NewError( |
| 3736 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3763 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3737 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 3764 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3738 } | 3765 } |
| 3739 Isolate* isolate = arguments->isolate(); | 3766 Isolate* isolate = arguments->isolate(); |
| 3740 ReusableObjectHandleScope reused_obj_handle(isolate); | 3767 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3741 Object& obj = reused_obj_handle.Handle(); | 3768 Object& obj = reused_obj_handle.Handle(); |
| 3742 obj = arguments->NativeArgAt(index); | 3769 obj = arguments->NativeArgAt(index); |
| 3743 intptr_t cid = obj.GetClassId(); | 3770 intptr_t cid = obj.GetClassId(); |
| 3744 if (cid == kBoolCid) { | 3771 if (cid == kBoolCid) { |
| 3745 *value = Bool::Cast(obj).value(); | 3772 *value = Bool::Cast(obj).value(); |
| 3746 return Api::Success(); | 3773 return Api::Success(); |
| 3747 } | 3774 } |
| 3748 if (obj.IsNull()) { | 3775 if (obj.IsNull()) { |
| 3749 *value = false; | 3776 *value = false; |
| 3750 return Api::Success(); | 3777 return Api::Success(); |
| 3751 } | 3778 } |
| 3752 return Api::NewError( | 3779 return Api::NewError( |
| 3753 "%s: argument %d is not a Boolean argument.", | 3780 "%s: argument %d is not a Boolean argument.", |
| 3754 CURRENT_FUNC, index); | 3781 CURRENT_FUNC, index); |
| 3755 } | 3782 } |
| 3756 | 3783 |
| 3757 | 3784 |
| 3758 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, | 3785 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, |
| 3759 int index, | 3786 int index, |
| 3760 double* value) { | 3787 double* value) { |
| 3788 TRACE_API_CALLS(CURRENT_FUNC); | |
| 3761 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3789 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3762 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 3790 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 3763 return Api::NewError( | 3791 return Api::NewError( |
| 3764 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3792 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3765 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 3793 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 3766 } | 3794 } |
| 3767 Isolate* isolate = arguments->isolate(); | 3795 Isolate* isolate = arguments->isolate(); |
| 3768 ReusableObjectHandleScope reused_obj_handle(isolate); | 3796 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 3769 Object& obj = reused_obj_handle.Handle(); | 3797 Object& obj = reused_obj_handle.Handle(); |
| 3770 obj = arguments->NativeArgAt(index); | 3798 obj = arguments->NativeArgAt(index); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3813 CHECK_ISOLATE(isolate); | 3841 CHECK_ISOLATE(isolate); |
| 3814 ASSERT(isolate->api_state() != NULL && | 3842 ASSERT(isolate->api_state() != NULL && |
| 3815 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || | 3843 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || |
| 3816 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); | 3844 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); |
| 3817 Api::SetWeakHandleReturnValue(arguments, rval); | 3845 Api::SetWeakHandleReturnValue(arguments, rval); |
| 3818 } | 3846 } |
| 3819 | 3847 |
| 3820 | 3848 |
| 3821 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, | 3849 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, |
| 3822 bool retval) { | 3850 bool retval) { |
| 3851 TRACE_API_CALLS(CURRENT_FUNC); | |
| 3823 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3852 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3824 arguments->SetReturn(Bool::Get(retval)); | 3853 arguments->SetReturn(Bool::Get(retval)); |
| 3825 } | 3854 } |
| 3826 | 3855 |
| 3827 | 3856 |
| 3828 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 3857 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
| 3829 int64_t retval) { | 3858 int64_t retval) { |
| 3830 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3859 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3831 Isolate* isolate = arguments->isolate(); | 3860 Isolate* isolate = arguments->isolate(); |
| 3832 CHECK_ISOLATE(isolate); | 3861 CHECK_ISOLATE(isolate); |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4321 } | 4350 } |
| 4322 { | 4351 { |
| 4323 NoGCScope no_gc; | 4352 NoGCScope no_gc; |
| 4324 RawObject* raw_obj = obj.raw(); | 4353 RawObject* raw_obj = obj.raw(); |
| 4325 isolate->heap()->SetPeer(raw_obj, peer); | 4354 isolate->heap()->SetPeer(raw_obj, peer); |
| 4326 } | 4355 } |
| 4327 return Api::Success(); | 4356 return Api::Success(); |
| 4328 } | 4357 } |
| 4329 | 4358 |
| 4330 } // namespace dart | 4359 } // namespace dart |
| OLD | NEW |