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 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2326 | 2326 |
2327 | 2327 |
2328 // Helper method to get the type of a TypedData object. | 2328 // Helper method to get the type of a TypedData object. |
2329 static Dart_TypedData_Type GetType(intptr_t class_id) { | 2329 static Dart_TypedData_Type GetType(intptr_t class_id) { |
2330 Dart_TypedData_Type type; | 2330 Dart_TypedData_Type type; |
2331 switch (class_id) { | 2331 switch (class_id) { |
2332 case kByteArrayCid : | 2332 case kByteArrayCid : |
2333 type = kByteData; | 2333 type = kByteData; |
2334 break; | 2334 break; |
2335 case kTypedDataInt8ArrayCid : | 2335 case kTypedDataInt8ArrayCid : |
2336 case kTypedDataInt8ArrayViewCid : | |
2336 case kExternalTypedDataInt8ArrayCid : | 2337 case kExternalTypedDataInt8ArrayCid : |
2337 type = kInt8; | 2338 type = kInt8; |
2338 break; | 2339 break; |
2339 case kTypedDataUint8ArrayCid : | 2340 case kTypedDataUint8ArrayCid : |
2341 case kTypedDataUint8ArrayViewCid : | |
2340 case kExternalTypedDataUint8ArrayCid : | 2342 case kExternalTypedDataUint8ArrayCid : |
2341 type = kUint8; | 2343 type = kUint8; |
2342 break; | 2344 break; |
2343 case kTypedDataUint8ClampedArrayCid : | 2345 case kTypedDataUint8ClampedArrayCid : |
2346 case kTypedDataUint8ClampedArrayViewCid : | |
2344 case kExternalTypedDataUint8ClampedArrayCid : | 2347 case kExternalTypedDataUint8ClampedArrayCid : |
2345 type = kUint8Clamped; | 2348 type = kUint8Clamped; |
2346 break; | 2349 break; |
2347 case kTypedDataInt16ArrayCid : | 2350 case kTypedDataInt16ArrayCid : |
2351 case kTypedDataInt16ArrayViewCid : | |
2348 case kExternalTypedDataInt16ArrayCid : | 2352 case kExternalTypedDataInt16ArrayCid : |
2349 type = kInt16; | 2353 type = kInt16; |
2350 break; | 2354 break; |
2351 case kTypedDataUint16ArrayCid : | 2355 case kTypedDataUint16ArrayCid : |
2356 case kTypedDataUint16ArrayViewCid : | |
2352 case kExternalTypedDataUint16ArrayCid : | 2357 case kExternalTypedDataUint16ArrayCid : |
2353 type = kUint16; | 2358 type = kUint16; |
2354 break; | 2359 break; |
2355 case kTypedDataInt32ArrayCid : | 2360 case kTypedDataInt32ArrayCid : |
2361 case kTypedDataInt32ArrayViewCid : | |
2356 case kExternalTypedDataInt32ArrayCid : | 2362 case kExternalTypedDataInt32ArrayCid : |
2357 type = kInt32; | 2363 type = kInt32; |
2358 break; | 2364 break; |
2359 case kTypedDataUint32ArrayCid : | 2365 case kTypedDataUint32ArrayCid : |
2366 case kTypedDataUint32ArrayViewCid : | |
2360 case kExternalTypedDataUint32ArrayCid : | 2367 case kExternalTypedDataUint32ArrayCid : |
2361 type = kUint32; | 2368 type = kUint32; |
2362 break; | 2369 break; |
2363 case kTypedDataInt64ArrayCid : | 2370 case kTypedDataInt64ArrayCid : |
2371 case kTypedDataInt64ArrayViewCid : | |
2364 case kExternalTypedDataInt64ArrayCid : | 2372 case kExternalTypedDataInt64ArrayCid : |
2365 type = kInt64; | 2373 type = kInt64; |
2366 break; | 2374 break; |
2367 case kTypedDataUint64ArrayCid : | 2375 case kTypedDataUint64ArrayCid : |
2376 case kTypedDataUint64ArrayViewCid : | |
2368 case kExternalTypedDataUint64ArrayCid : | 2377 case kExternalTypedDataUint64ArrayCid : |
2369 type = kUint64; | 2378 type = kUint64; |
2370 break; | 2379 break; |
2371 case kTypedDataFloat32ArrayCid : | 2380 case kTypedDataFloat32ArrayCid : |
2381 case kTypedDataFloat32ArrayViewCid : | |
2372 case kExternalTypedDataFloat32ArrayCid : | 2382 case kExternalTypedDataFloat32ArrayCid : |
2373 type = kFloat32; | 2383 type = kFloat32; |
2374 break; | 2384 break; |
2375 case kTypedDataFloat64ArrayCid : | 2385 case kTypedDataFloat64ArrayCid : |
2386 case kTypedDataFloat64ArrayViewCid : | |
2376 case kExternalTypedDataFloat64ArrayCid : | 2387 case kExternalTypedDataFloat64ArrayCid : |
2377 type = kFloat64; | 2388 type = kFloat64; |
2378 break; | 2389 break; |
2379 default: | 2390 default: |
2380 type = kInvalid; | 2391 type = kInvalid; |
2381 break; | 2392 break; |
2382 } | 2393 } |
2383 return type; | 2394 return type; |
2384 } | 2395 } |
2385 | 2396 |
2386 | 2397 |
2387 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { | 2398 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { |
2388 intptr_t class_id = Api::ClassId(object); | 2399 intptr_t class_id = Api::ClassId(object); |
2389 if (!RawObject::IsTypedDataClassId(class_id)) { | 2400 if (!RawObject::IsTypedDataClassId(class_id) && |
2401 !RawObject::IsTypedDataViewClassId(class_id)) { | |
2390 return kInvalid; | 2402 return kInvalid; |
2391 } | 2403 } |
2392 return GetType(class_id); | 2404 return GetType(class_id); |
2393 } | 2405 } |
2394 | 2406 |
2395 | 2407 |
2396 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( | 2408 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( |
2397 Dart_Handle object) { | 2409 Dart_Handle object) { |
2398 intptr_t class_id = Api::ClassId(object); | 2410 intptr_t class_id = Api::ClassId(object); |
2399 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 2411 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2575 | 2587 |
2576 | 2588 |
2577 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, | 2589 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, |
2578 Dart_TypedData_Type* type, | 2590 Dart_TypedData_Type* type, |
2579 void** data, | 2591 void** data, |
2580 intptr_t* len) { | 2592 intptr_t* len) { |
2581 Isolate* isolate = Isolate::Current(); | 2593 Isolate* isolate = Isolate::Current(); |
2582 DARTSCOPE(isolate); | 2594 DARTSCOPE(isolate); |
2583 intptr_t class_id = Api::ClassId(object); | 2595 intptr_t class_id = Api::ClassId(object); |
2584 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 2596 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
2597 !RawObject::IsTypedDataViewClassId(class_id) && | |
2585 !RawObject::IsTypedDataClassId(class_id)) { | 2598 !RawObject::IsTypedDataClassId(class_id)) { |
2586 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); | 2599 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); |
2587 } | 2600 } |
2588 if (type == NULL) { | 2601 if (type == NULL) { |
2589 RETURN_NULL_ERROR(type); | 2602 RETURN_NULL_ERROR(type); |
2590 } | 2603 } |
2591 if (data == NULL) { | 2604 if (data == NULL) { |
2592 RETURN_NULL_ERROR(data); | 2605 RETURN_NULL_ERROR(data); |
2593 } | 2606 } |
2594 if (len == NULL) { | 2607 if (len == NULL) { |
2595 RETURN_NULL_ERROR(len); | 2608 RETURN_NULL_ERROR(len); |
2596 } | 2609 } |
2597 // Get the type of typed data object. | 2610 // Get the type of typed data object. |
2598 *type = GetType(class_id); | 2611 *type = GetType(class_id); |
2599 // If it is an external typed data object just return the data field. | 2612 // If it is an external typed data object just return the data field. |
2600 if (RawObject::IsExternalTypedDataClassId(class_id)) { | 2613 if (RawObject::IsExternalTypedDataClassId(class_id)) { |
2601 const ExternalTypedData& obj = | 2614 const ExternalTypedData& obj = |
2602 Api::UnwrapExternalTypedDataHandle(isolate, object); | 2615 Api::UnwrapExternalTypedDataHandle(isolate, object); |
2603 ASSERT(!obj.IsNull()); | 2616 ASSERT(!obj.IsNull()); |
2604 *len = obj.Length(); | 2617 *len = obj.Length(); |
2605 *data = reinterpret_cast<void*>(obj.DataAddr(0)); | 2618 *data = obj.DataAddr(0); |
2606 } else { | 2619 } else if (RawObject::IsTypedDataClassId(class_id)) { |
2607 // Regular typed data object, set up some GC and API callback guards. | 2620 // Regular typed data object, set up some GC and API callback guards. |
2608 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); | 2621 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); |
2609 ASSERT(!obj.IsNull()); | 2622 ASSERT(!obj.IsNull()); |
2610 *len = obj.Length(); | 2623 *len = obj.Length(); |
2611 isolate->IncrementNoGCScopeDepth(); | 2624 isolate->IncrementNoGCScopeDepth(); |
2612 START_NO_CALLBACK_SCOPE(isolate); | 2625 START_NO_CALLBACK_SCOPE(isolate); |
2613 *data = reinterpret_cast<void*>(obj.DataAddr(0)); | 2626 *data = obj.DataAddr(0); |
2627 } else { | |
2628 // typed data view object, set up some GC and API callback guards. | |
2629 // TODO(asiva): Have to come up with a scheme to directly access | |
2630 // the fields using offsets for a more efficient implementation. | |
Ivan Posva
2013/03/22 04:50:01
How about making class _TypedListView known to the
siva
2013/03/25 17:20:35
I thought about this but for now choose against ad
| |
2631 Dart_Handle field_name = Dart_NewStringFromCString("length"); | |
2632 Dart_Handle field_value = Dart_GetField(object, field_name); | |
2633 ASSERT(Api::IsSmi(field_value)); | |
2634 *len = Api::SmiValue(field_value); | |
2635 field_name = Dart_NewStringFromCString("offsetInBytes"); | |
2636 field_value = Dart_GetField(object, field_name); | |
2637 ASSERT(Api::IsSmi(field_value)); | |
2638 intptr_t offset_in_bytes = Api::SmiValue(field_value); | |
2639 field_name = Dart_NewStringFromCString("_typeddata"); | |
2640 field_value = Dart_GetField(object, field_name); | |
2641 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, field_value); | |
2642 isolate->IncrementNoGCScopeDepth(); | |
2643 START_NO_CALLBACK_SCOPE(isolate); | |
2644 *data = obj.DataAddr(offset_in_bytes); | |
2614 } | 2645 } |
2615 return Api::Success(isolate); | 2646 return Api::Success(isolate); |
2616 } | 2647 } |
2617 | 2648 |
2618 | 2649 |
2619 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 2650 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
2620 Isolate* isolate = Isolate::Current(); | 2651 Isolate* isolate = Isolate::Current(); |
2621 DARTSCOPE(isolate); | 2652 DARTSCOPE(isolate); |
2622 intptr_t class_id = Api::ClassId(object); | 2653 intptr_t class_id = Api::ClassId(object); |
2623 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 2654 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
2655 !RawObject::IsTypedDataViewClassId(class_id) && | |
2624 !RawObject::IsTypedDataClassId(class_id)) { | 2656 !RawObject::IsTypedDataClassId(class_id)) { |
2625 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); | 2657 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); |
2626 } | 2658 } |
2627 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 2659 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
2628 isolate->DecrementNoGCScopeDepth(); | 2660 isolate->DecrementNoGCScopeDepth(); |
2629 END_NO_CALLBACK_SCOPE(isolate); | 2661 END_NO_CALLBACK_SCOPE(isolate); |
2630 } | 2662 } |
2631 return Api::Success(isolate); | 2663 return Api::Success(isolate); |
2632 } | 2664 } |
2633 | 2665 |
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4680 } | 4712 } |
4681 { | 4713 { |
4682 NoGCScope no_gc; | 4714 NoGCScope no_gc; |
4683 RawObject* raw_obj = obj.raw(); | 4715 RawObject* raw_obj = obj.raw(); |
4684 isolate->heap()->SetPeer(raw_obj, peer); | 4716 isolate->heap()->SetPeer(raw_obj, peer); |
4685 } | 4717 } |
4686 return Api::Success(isolate); | 4718 return Api::Success(isolate); |
4687 } | 4719 } |
4688 | 4720 |
4689 } // namespace dart | 4721 } // namespace dart |
OLD | NEW |