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

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

Issue 16968006: Add Dart_Allocate to the C++ API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allow Type objects as well Created 7 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 2807 matching lines...) Expand 10 before | Expand all | Expand 10 after
2818 if (constructor.IsConstructor()) { 2818 if (constructor.IsConstructor()) {
2819 ASSERT(result.IsNull()); 2819 ASSERT(result.IsNull());
2820 } else { 2820 } else {
2821 ASSERT(result.IsNull() || result.IsInstance()); 2821 ASSERT(result.IsNull() || result.IsInstance());
2822 new_object ^= result.raw(); 2822 new_object ^= result.raw();
2823 } 2823 }
2824 return Api::NewHandle(isolate, new_object.raw()); 2824 return Api::NewHandle(isolate, new_object.raw());
2825 } 2825 }
2826 2826
2827 2827
2828 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) {
2829 Isolate* isolate = Isolate::Current();
2830 DARTSCOPE(isolate);
2831 CHECK_CALLBACK_STATE(isolate);
2832 const Object& result = Object::Handle(isolate, Api::UnwrapHandle(type));
2833
2834 // Get the class to instantiate.
2835 if (result.IsNull()) {
2836 RETURN_TYPE_ERROR(isolate, type, Type);
2837 }
2838 Class& cls = Class::Handle(isolate);
2839 if (result.IsType()) {
2840 cls = Type::Cast(result).type_class();
2841 } else if (result.IsClass()) {
2842 // For backwards compatibility we allow class objects to be passed in
2843 // for now. This needs to be removed once all code that uses class
2844 // objects to invoke Dart_New is removed.
siva 2013/06/19 15:36:24 invoke Dart_Allocate
2845 cls ^= result.raw();
2846 } else {
2847 RETURN_TYPE_ERROR(isolate, type, Type);
2848 }
2849
2850 // Allocate an object for the given class.
2851 return Api::NewHandle(isolate, Instance::New(cls));
2852 }
2853
2854
2828 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, 2855 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target,
2829 Dart_Handle name, 2856 Dart_Handle name,
2830 int number_of_arguments, 2857 int number_of_arguments,
2831 Dart_Handle* arguments) { 2858 Dart_Handle* arguments) {
2832 Isolate* isolate = Isolate::Current(); 2859 Isolate* isolate = Isolate::Current();
2833 DARTSCOPE(isolate); 2860 DARTSCOPE(isolate);
2834 CHECK_CALLBACK_STATE(isolate); 2861 CHECK_CALLBACK_STATE(isolate);
2835 2862
2836 const String& function_name = Api::UnwrapStringHandle(isolate, name); 2863 const String& function_name = Api::UnwrapStringHandle(isolate, name);
2837 if (function_name.IsNull()) { 2864 if (function_name.IsNull()) {
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 } 3950 }
3924 { 3951 {
3925 NoGCScope no_gc; 3952 NoGCScope no_gc;
3926 RawObject* raw_obj = obj.raw(); 3953 RawObject* raw_obj = obj.raw();
3927 isolate->heap()->SetPeer(raw_obj, peer); 3954 isolate->heap()->SetPeer(raw_obj, peer);
3928 } 3955 }
3929 return Api::Success(); 3956 return Api::Success();
3930 } 3957 }
3931 3958
3932 } // namespace dart 3959 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698