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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10834096: Added Dart_FunctionEnclosingClassOrLibrary. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 10077)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -2784,6 +2784,32 @@
}
+DART_EXPORT Dart_Handle Dart_FunctionEnclosingClassOrLibrary(
+ Dart_Handle function) {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ const Function& func = Api::UnwrapFunctionHandle(isolate, function);
+ if (func.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, function, Function);
+ }
Ivan Posva 2012/07/31 23:38:58 if (func.IsError()) { return function; }
rmacnak 2012/08/01 17:21:55 If I add that test with an ASSERT(false), that pat
turnidge 2012/08/01 17:59:42 Checking for an error handle isn't required here.
Ivan Posva 2012/08/01 20:43:55 Thanks for the clarification. The difference betwe
+ const Class& owner = Class::Handle(func.owner());
+ ASSERT(!owner.IsNull());
+ if (owner.IsTopLevel()) {
+ // Top-level functions are implemented as members of a hidden class. We hide
+ // that class here and instead answer the library.
+#if defined(DEBUG)
+ const Library& lib = Library::Handle(owner.library());
+ if (lib.IsNull()) {
+ ASSERT(owner.IsDynamicClass() || owner.IsVoidClass());
+ }
+#endif
+ return Api::NewHandle(isolate, owner.library());
+ } else {
+ return Api::NewHandle(isolate, owner.raw());
+ }
+}
+
+
DART_EXPORT Dart_Handle Dart_FunctionIsAbstract(Dart_Handle function,
bool* is_abstract) {
Isolate* isolate = Isolate::Current();

Powered by Google App Engine
This is Rietveld 408576698