Index: runtime/vm/dart_api_impl.cc |
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
index 1b83aa4f318cebd9b631704ab98ddeecbad42857..1fbf3a64a8767ce637ad93c3aff9060e38e795b4 100644 |
--- a/runtime/vm/dart_api_impl.cc |
+++ b/runtime/vm/dart_api_impl.cc |
@@ -2825,6 +2825,33 @@ DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz, |
} |
+DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { |
+ Isolate* isolate = Isolate::Current(); |
+ DARTSCOPE(isolate); |
+ CHECK_CALLBACK_STATE(isolate); |
+ const Object& result = Object::Handle(isolate, Api::UnwrapHandle(type)); |
+ |
+ // Get the class to instantiate. |
+ if (result.IsNull()) { |
+ RETURN_TYPE_ERROR(isolate, type, Type); |
+ } |
+ Class& cls = Class::Handle(isolate); |
+ if (result.IsType()) { |
+ cls = Type::Cast(result).type_class(); |
+ } else if (result.IsClass()) { |
+ // For backwards compatibility we allow class objects to be passed in |
+ // for now. This needs to be removed once all code that uses class |
+ // objects to invoke Dart_New is removed. |
siva
2013/06/19 15:36:24
invoke Dart_Allocate
|
+ cls ^= result.raw(); |
+ } else { |
+ RETURN_TYPE_ERROR(isolate, type, Type); |
+ } |
+ |
+ // Allocate an object for the given class. |
+ return Api::NewHandle(isolate, Instance::New(cls)); |
+} |
+ |
+ |
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
Dart_Handle name, |
int number_of_arguments, |