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

Unified 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 side-by-side diff with in-line comments
Download patch
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,

Powered by Google App Engine
This is Rietveld 408576698