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

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

Issue 349643003: Add a function Dart_AllocateWithNativeFields which allocates an object and sets the native fields i… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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
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 3578 matching lines...) Expand 10 before | Expand all | Expand 10 after
3589 if (constructor.IsConstructor()) { 3589 if (constructor.IsConstructor()) {
3590 ASSERT(result.IsNull()); 3590 ASSERT(result.IsNull());
3591 } else { 3591 } else {
3592 ASSERT(result.IsNull() || result.IsInstance()); 3592 ASSERT(result.IsNull() || result.IsInstance());
3593 new_object ^= result.raw(); 3593 new_object ^= result.raw();
3594 } 3594 }
3595 return Api::NewHandle(isolate, new_object.raw()); 3595 return Api::NewHandle(isolate, new_object.raw());
3596 } 3596 }
3597 3597
3598 3598
3599 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { 3599 static RawInstance* AllocateObject(Isolate* isolate, const Class& cls) {
3600 Isolate* isolate = Isolate::Current();
3601 DARTSCOPE(isolate);
3602 CHECK_CALLBACK_STATE(isolate);
3603
3604 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type);
3605 // Get the class to instantiate.
3606 if (type_obj.IsNull()) {
3607 RETURN_TYPE_ERROR(isolate, type, Type);
3608 }
3609 const Class& cls = Class::Handle(isolate, type_obj.type_class());
3610 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
3611 if (!error.IsNull()) {
3612 // An error occurred, return error object.
3613 return Api::NewHandle(isolate, error.raw());
3614 }
3615
3616 if (!cls.is_fields_marked_nullable()) { 3600 if (!cls.is_fields_marked_nullable()) {
3617 // Mark all fields as nullable. 3601 // Mark all fields as nullable.
3618 Class& iterate_cls = Class::Handle(isolate, cls.raw()); 3602 Class& iterate_cls = Class::Handle(isolate, cls.raw());
3619 Field& field = Field::Handle(isolate); 3603 Field& field = Field::Handle(isolate);
3620 Array& fields = Array::Handle(isolate); 3604 Array& fields = Array::Handle(isolate);
3621 while (!iterate_cls.IsNull()) { 3605 while (!iterate_cls.IsNull()) {
3622 ASSERT(iterate_cls.is_finalized()); 3606 ASSERT(iterate_cls.is_finalized());
3623 iterate_cls.set_is_fields_marked_nullable(); 3607 iterate_cls.set_is_fields_marked_nullable();
3624 fields = iterate_cls.fields(); 3608 fields = iterate_cls.fields();
3625 iterate_cls = iterate_cls.SuperClass(); 3609 iterate_cls = iterate_cls.SuperClass();
3626 for (int field_num = 0; field_num < fields.Length(); field_num++) { 3610 for (int field_num = 0; field_num < fields.Length(); field_num++) {
3627 field ^= fields.At(field_num); 3611 field ^= fields.At(field_num);
3628 if (field.is_static()) { 3612 if (field.is_static()) {
3629 continue; 3613 continue;
3630 } 3614 }
3631 field.RecordStore(Object::null_object()); 3615 field.RecordStore(Object::null_object());
3632 } 3616 }
3633 } 3617 }
3634 } 3618 }
3635 3619
3636 // Allocate an object for the given class. 3620 // Allocate an object for the given class.
3637 return Api::NewHandle(isolate, Instance::New(cls)); 3621 return Instance::New(cls);
3622 }
3623
3624
3625 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) {
3626 Isolate* isolate = Isolate::Current();
3627 DARTSCOPE(isolate);
3628 CHECK_CALLBACK_STATE(isolate);
3629
3630 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type);
3631 // Get the class to instantiate.
3632 if (type_obj.IsNull()) {
3633 RETURN_TYPE_ERROR(isolate, type, Type);
3634 }
3635 const Class& cls = Class::Handle(isolate, type_obj.type_class());
3636 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
3637 if (!error.IsNull()) {
3638 // An error occurred, return error object.
3639 return Api::NewHandle(isolate, error.raw());
3640 }
3641 return Api::NewHandle(isolate, AllocateObject(isolate, cls));
3642 }
3643
3644
3645 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields(
3646 Dart_Handle type,
3647 intptr_t num_native_fields,
3648 const intptr_t* native_fields) {
3649 Isolate* isolate = Isolate::Current();
3650 DARTSCOPE(isolate);
3651 CHECK_CALLBACK_STATE(isolate);
3652
3653 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type);
3654 // Get the class to instantiate.
3655 if (type_obj.IsNull()) {
3656 RETURN_TYPE_ERROR(isolate, type, Type);
3657 }
3658 if (native_fields == NULL) {
3659 RETURN_NULL_ERROR(native_fields);
3660 }
3661 const Class& cls = Class::Handle(isolate, type_obj.type_class());
3662 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
3663 if (!error.IsNull()) {
3664 // An error occurred, return error object.
3665 return Api::NewHandle(isolate, error.raw());
3666 }
3667 if (num_native_fields != cls.num_native_fields()) {
3668 return Api::NewError(
3669 "%s: invalid number of native fields %d passed in, expected %d",
3670 CURRENT_FUNC, num_native_fields, cls.num_native_fields());
3671 }
3672 const Instance& instance = Instance::Handle(isolate,
3673 AllocateObject(isolate, cls));
3674 instance.SetNativeFields(num_native_fields, native_fields);
3675 return Api::NewHandle(isolate, instance.raw());
3638 } 3676 }
3639 3677
3640 3678
3641 static Dart_Handle SetupArguments(Isolate* isolate, 3679 static Dart_Handle SetupArguments(Isolate* isolate,
3642 int num_args, 3680 int num_args,
3643 Dart_Handle* arguments, 3681 Dart_Handle* arguments,
3644 int extra_args, 3682 int extra_args,
3645 Array* args) { 3683 Array* args) {
3646 // Check for malformed arguments in the arguments list. 3684 // Check for malformed arguments in the arguments list.
3647 *args = Array::New(num_args + extra_args); 3685 *args = Array::New(num_args + extra_args);
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
5219 5257
5220 5258
5221 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5259 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5222 const char* name, 5260 const char* name,
5223 Dart_ServiceRequestCallback callback, 5261 Dart_ServiceRequestCallback callback,
5224 void* user_data) { 5262 void* user_data) {
5225 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5263 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5226 } 5264 }
5227 5265
5228 } // namespace dart 5266 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698