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

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

Issue 392043003: The dart version of typeddata library has changed to be compatible with the dart2js implementation (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_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 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 // different signature classes for closures. 1848 // different signature classes for closures.
1849 Isolate* isolate = Isolate::Current(); 1849 Isolate* isolate = Isolate::Current();
1850 CHECK_ISOLATE(isolate); 1850 CHECK_ISOLATE(isolate);
1851 ReusableObjectHandleScope reused_obj_handle(isolate); 1851 ReusableObjectHandleScope reused_obj_handle(isolate);
1852 const Instance& closure_obj = 1852 const Instance& closure_obj =
1853 Api::UnwrapInstanceHandle(reused_obj_handle, object); 1853 Api::UnwrapInstanceHandle(reused_obj_handle, object);
1854 return (!closure_obj.IsNull() && closure_obj.IsClosure()); 1854 return (!closure_obj.IsNull() && closure_obj.IsClosure());
1855 } 1855 }
1856 1856
1857 1857
1858 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) {
1859 TRACE_API_CALL(CURRENT_FUNC);
1860 intptr_t cid = Api::ClassId(handle);
1861 return RawObject::IsTypedDataClassId(cid) ||
1862 RawObject::IsExternalTypedDataClassId(cid);
1863 }
1864
1865
1866 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) {
1867 TRACE_API_CALL(CURRENT_FUNC);
1868 return Api::ClassId(handle) == kByteBufferCid;
1869 }
1870
1871
1858 // --- Instances ---- 1872 // --- Instances ----
1859 1873
1860 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { 1874 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) {
1861 Isolate* isolate = Isolate::Current(); 1875 Isolate* isolate = Isolate::Current();
1862 DARTSCOPE(isolate); 1876 DARTSCOPE(isolate);
1863 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance)); 1877 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance));
1864 if (obj.IsNull()) { 1878 if (obj.IsNull()) {
1865 return Api::NewHandle(isolate, isolate->object_store()->null_type()); 1879 return Api::NewHandle(isolate, isolate->object_store()->null_type());
1866 } 1880 }
1867 if (!obj.IsInstance()) { 1881 if (!obj.IsInstance()) {
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3079 Object& result = Object::Handle(isolate); 3093 Object& result = Object::Handle(isolate);
3080 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot(), 1); 3094 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot(), 1);
3081 ASSERT(!result.IsNull()); 3095 ASSERT(!result.IsNull());
3082 ASSERT(result.IsFunction()); 3096 ASSERT(result.IsFunction());
3083 const Function& factory = Function::Cast(result); 3097 const Function& factory = Function::Cast(result);
3084 ASSERT(!factory.IsConstructor()); 3098 ASSERT(!factory.IsConstructor());
3085 3099
3086 // Create the argument list. 3100 // Create the argument list.
3087 const Array& args = Array::Handle(isolate, Array::New(2)); 3101 const Array& args = Array::Handle(isolate, Array::New(2));
3088 // Factories get type arguments. 3102 // Factories get type arguments.
3089 args.SetAt(0, TypeArguments::Handle(isolate)); 3103 args.SetAt(0, Object::null_type_arguments());
3090 args.SetAt(1, Smi::Handle(isolate, Smi::New(length))); 3104 args.SetAt(1, Smi::Handle(isolate, Smi::New(length)));
3091 3105
3092 // Invoke the constructor and return the new object. 3106 // Invoke the constructor and return the new object.
3093 result = DartEntry::InvokeFunction(factory, args); 3107 result = DartEntry::InvokeFunction(factory, args);
3094 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); 3108 ASSERT(result.IsInstance() || result.IsNull() || result.IsError());
3095 return Api::NewHandle(isolate, result.raw()); 3109 return Api::NewHandle(isolate, result.raw());
3096 } 3110 }
3097 3111
3098 3112
3099 static Dart_Handle NewTypedData(Isolate* isolate, 3113 static Dart_Handle NewTypedData(Isolate* isolate,
(...skipping 29 matching lines...) Expand all
3129 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot_view(), 3); 3143 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot_view(), 3);
3130 ASSERT(!result.IsNull()); 3144 ASSERT(!result.IsNull());
3131 ASSERT(result.IsFunction()); 3145 ASSERT(result.IsFunction());
3132 const Function& factory = Function::Cast(result); 3146 const Function& factory = Function::Cast(result);
3133 ASSERT(!factory.IsConstructor()); 3147 ASSERT(!factory.IsConstructor());
3134 3148
3135 // Create the argument list. 3149 // Create the argument list.
3136 const intptr_t num_args = 3; 3150 const intptr_t num_args = 3;
3137 const Array& args = Array::Handle(isolate, Array::New(num_args + 1)); 3151 const Array& args = Array::Handle(isolate, Array::New(num_args + 1));
3138 // Factories get type arguments. 3152 // Factories get type arguments.
3139 args.SetAt(0, TypeArguments::Handle(isolate)); 3153 args.SetAt(0, Object::null_type_arguments());
3140 const ExternalTypedData& array = 3154 const ExternalTypedData& array =
3141 Api::UnwrapExternalTypedDataHandle(isolate, ext_data); 3155 Api::UnwrapExternalTypedDataHandle(isolate, ext_data);
3142 args.SetAt(1, array); 3156 args.SetAt(1, array);
3143 Smi& smi = Smi::Handle(isolate); 3157 Smi& smi = Smi::Handle(isolate);
3144 smi = Smi::New(0); 3158 smi = Smi::New(0);
3145 args.SetAt(2, smi); 3159 args.SetAt(2, smi);
3146 smi = Smi::New(length); 3160 smi = Smi::New(length);
3147 args.SetAt(3, smi); 3161 args.SetAt(3, smi);
3148 3162
3149 // Invoke the constructor and return the new object. 3163 // Invoke the constructor and return the new object.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3269 length); 3283 length);
3270 default: 3284 default:
3271 return Api::NewError("%s expects argument 'type' to be of" 3285 return Api::NewError("%s expects argument 'type' to be of"
3272 " 'external TypedData'", CURRENT_FUNC); 3286 " 'external TypedData'", CURRENT_FUNC);
3273 } 3287 }
3274 UNREACHABLE(); 3288 UNREACHABLE();
3275 return Api::Null(); 3289 return Api::Null();
3276 } 3290 }
3277 3291
3278 3292
3293 static RawObject* GetByteBufferConstructor(Isolate* isolate,
3294 const String& class_name,
3295 const String& constructor_name,
3296 intptr_t num_args) {
3297 const Library& lib =
3298 Library::Handle(isolate->object_store()->typed_data_library());
3299 ASSERT(!lib.IsNull());
3300 const Class& cls = Class::Handle(
3301 isolate, lib.LookupClassAllowPrivate(class_name));
3302 ASSERT(!cls.IsNull());
3303 return ResolveConstructor(CURRENT_FUNC,
3304 cls,
3305 class_name,
3306 constructor_name,
3307 num_args);
3308 }
3309
3310
3311 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) {
3312 Isolate* isolate = Isolate::Current();
3313 DARTSCOPE(isolate);
3314 intptr_t class_id = Api::ClassId(typed_data);
3315 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3316 !RawObject::IsTypedDataViewClassId(class_id) &&
3317 !RawObject::IsTypedDataClassId(class_id)) {
3318 RETURN_TYPE_ERROR(isolate, typed_data, 'TypedData');
3319 }
3320 Object& result = Object::Handle(isolate);
3321 result = GetByteBufferConstructor(isolate,
3322 Symbols::_ByteBuffer(),
3323 Symbols::_ByteBufferDot_New(),
3324 1);
3325 ASSERT(!result.IsNull());
3326 ASSERT(result.IsFunction());
3327 const Function& factory = Function::Cast(result);
3328 ASSERT(!factory.IsConstructor());
3329
3330 // Create the argument list.
3331 const Array& args = Array::Handle(isolate, Array::New(2));
3332 // Factories get type arguments.
3333 args.SetAt(0, Object::null_type_arguments());
3334 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(typed_data));
3335 args.SetAt(1, obj);
3336
3337 // Invoke the factory constructor and return the new object.
3338 result = DartEntry::InvokeFunction(factory, args);
3339 ASSERT(result.IsInstance() || result.IsNull() || result.IsError());
3340 return Api::NewHandle(isolate, result.raw());
3341 }
3342
3343
3279 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, 3344 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object,
3280 Dart_TypedData_Type* type, 3345 Dart_TypedData_Type* type,
3281 void** data, 3346 void** data,
3282 intptr_t* len) { 3347 intptr_t* len) {
3283 Isolate* isolate = Isolate::Current(); 3348 Isolate* isolate = Isolate::Current();
3284 DARTSCOPE(isolate); 3349 DARTSCOPE(isolate);
3285 intptr_t class_id = Api::ClassId(object); 3350 intptr_t class_id = Api::ClassId(object);
3286 if (!RawObject::IsExternalTypedDataClassId(class_id) && 3351 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3287 !RawObject::IsTypedDataViewClassId(class_id) && 3352 !RawObject::IsTypedDataViewClassId(class_id) &&
3288 !RawObject::IsTypedDataClassId(class_id)) { 3353 !RawObject::IsTypedDataClassId(class_id)) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); 3414 RETURN_TYPE_ERROR(isolate, object, 'TypedData');
3350 } 3415 }
3351 if (!RawObject::IsExternalTypedDataClassId(class_id)) { 3416 if (!RawObject::IsExternalTypedDataClassId(class_id)) {
3352 isolate->DecrementNoGCScopeDepth(); 3417 isolate->DecrementNoGCScopeDepth();
3353 END_NO_CALLBACK_SCOPE(isolate); 3418 END_NO_CALLBACK_SCOPE(isolate);
3354 } 3419 }
3355 return Api::Success(); 3420 return Api::Success();
3356 } 3421 }
3357 3422
3358 3423
3424 DART_EXPORT Dart_Handle Dart_GetDataFromByteBuffer(Dart_Handle object) {
3425 Isolate* isolate = Isolate::Current();
3426 CHECK_ISOLATE(isolate);
3427 intptr_t class_id = Api::ClassId(object);
3428 if (class_id != kByteBufferCid) {
3429 RETURN_TYPE_ERROR(isolate, object, 'ByteBuffer');
3430 }
3431 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object);
3432 ASSERT(!instance.IsNull());
3433 return Api::NewHandle(isolate, ByteBuffer::Data(instance));
3434 }
3435
3436
3359 // --- Invoking Constructors, Methods, and Field accessors --- 3437 // --- Invoking Constructors, Methods, and Field accessors ---
3360 3438
3361 static RawObject* ResolveConstructor(const char* current_func, 3439 static RawObject* ResolveConstructor(const char* current_func,
3362 const Class& cls, 3440 const Class& cls,
3363 const String& class_name, 3441 const String& class_name,
3364 const String& constr_name, 3442 const String& constr_name,
3365 int num_args) { 3443 int num_args) {
3366 // The constructor must be present in the interface. 3444 // The constructor must be present in the interface.
3367 const Function& constructor = 3445 const Function& constructor =
3368 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); 3446 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name));
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after
5208 5286
5209 5287
5210 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5288 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5211 const char* name, 5289 const char* name,
5212 Dart_ServiceRequestCallback callback, 5290 Dart_ServiceRequestCallback callback,
5213 void* user_data) { 5291 void* user_data) {
5214 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5292 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5215 } 5293 }
5216 5294
5217 } // namespace dart 5295 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698