| 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 2693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2704 *data = obj.DataAddr(0); | 2704 *data = obj.DataAddr(0); |
| 2705 } else if (RawObject::IsTypedDataClassId(class_id)) { | 2705 } else if (RawObject::IsTypedDataClassId(class_id)) { |
| 2706 // Regular typed data object, set up some GC and API callback guards. | 2706 // Regular typed data object, set up some GC and API callback guards. |
| 2707 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); | 2707 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); |
| 2708 ASSERT(!obj.IsNull()); | 2708 ASSERT(!obj.IsNull()); |
| 2709 *len = obj.Length(); | 2709 *len = obj.Length(); |
| 2710 isolate->IncrementNoGCScopeDepth(); | 2710 isolate->IncrementNoGCScopeDepth(); |
| 2711 START_NO_CALLBACK_SCOPE(isolate); | 2711 START_NO_CALLBACK_SCOPE(isolate); |
| 2712 *data = obj.DataAddr(0); | 2712 *data = obj.DataAddr(0); |
| 2713 } else { | 2713 } else { |
| 2714 // typed data view object, set up some GC and API callback guards. | 2714 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); |
| 2715 // TODO(asiva): Have to come up with a scheme to directly access | 2715 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object); |
| 2716 // the fields using offsets for a more efficient implementation. | 2716 ASSERT(!view_obj.IsNull()); |
| 2717 Dart_Handle field_name = Dart_NewStringFromCString("length"); | 2717 Smi& val = Smi::Handle(); |
| 2718 Dart_Handle field_value = Dart_GetField(object, field_name); | 2718 val ^= TypedDataView::Length(view_obj); |
| 2719 ASSERT(Api::IsSmi(field_value)); | 2719 *len = val.Value(); |
| 2720 *len = Api::SmiValue(field_value); | 2720 val ^= TypedDataView::OffsetInBytes(view_obj); |
| 2721 field_name = Dart_NewStringFromCString("offsetInBytes"); | 2721 intptr_t offset_in_bytes = val.Value(); |
| 2722 field_value = Dart_GetField(object, field_name); | 2722 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); |
| 2723 ASSERT(Api::IsSmi(field_value)); | |
| 2724 intptr_t offset_in_bytes = Api::SmiValue(field_value); | |
| 2725 field_name = Dart_NewStringFromCString("_typeddata"); | |
| 2726 field_value = Dart_GetField(object, field_name); | |
| 2727 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, field_value); | |
| 2728 isolate->IncrementNoGCScopeDepth(); | 2723 isolate->IncrementNoGCScopeDepth(); |
| 2729 START_NO_CALLBACK_SCOPE(isolate); | 2724 START_NO_CALLBACK_SCOPE(isolate); |
| 2730 *data = obj.DataAddr(offset_in_bytes); | 2725 if (TypedData::IsTypedData(obj)) { |
| 2726 const TypedData& data_obj = TypedData::Cast(obj); |
| 2727 *data = data_obj.DataAddr(offset_in_bytes); |
| 2728 } else { |
| 2729 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); |
| 2730 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); |
| 2731 *data = data_obj.DataAddr(offset_in_bytes); |
| 2732 } |
| 2731 } | 2733 } |
| 2732 return Api::Success(isolate); | 2734 return Api::Success(isolate); |
| 2733 } | 2735 } |
| 2734 | 2736 |
| 2735 | 2737 |
| 2736 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 2738 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
| 2737 Isolate* isolate = Isolate::Current(); | 2739 Isolate* isolate = Isolate::Current(); |
| 2738 DARTSCOPE(isolate); | 2740 DARTSCOPE(isolate); |
| 2739 intptr_t class_id = Api::ClassId(object); | 2741 intptr_t class_id = Api::ClassId(object); |
| 2740 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 2742 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| (...skipping 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4808 } | 4810 } |
| 4809 { | 4811 { |
| 4810 NoGCScope no_gc; | 4812 NoGCScope no_gc; |
| 4811 RawObject* raw_obj = obj.raw(); | 4813 RawObject* raw_obj = obj.raw(); |
| 4812 isolate->heap()->SetPeer(raw_obj, peer); | 4814 isolate->heap()->SetPeer(raw_obj, peer); |
| 4813 } | 4815 } |
| 4814 return Api::Success(isolate); | 4816 return Api::Success(isolate); |
| 4815 } | 4817 } |
| 4816 | 4818 |
| 4817 } // namespace dart | 4819 } // namespace dart |
| OLD | NEW |