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

Unified Diff: runtime/vm/object.cc

Issue 11968022: Lookup functions by name that contains the private key, except for dart_api which allows ignoring t… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 17175)
+++ runtime/vm/object.cc (working copy)
@@ -2191,6 +2191,16 @@
}
+RawFunction* Class::LookupDynamicFunctionAllowPrivate(
+ const String& name) const {
+ Function& function = Function::Handle(LookupFunctionAllowPrivate(name));
+ if (function.IsNull() || !function.IsDynamicFunction()) {
+ return Function::null();
+ }
+ return function.raw();
+}
+
+
RawFunction* Class::LookupStaticFunction(const String& name) const {
Function& function = Function::Handle(LookupFunction(name));
if (function.IsNull() || !function.IsStaticFunction()) {
@@ -2200,6 +2210,15 @@
}
+RawFunction* Class::LookupStaticFunctionAllowPrivate(const String& name) const {
+ Function& function = Function::Handle(LookupFunctionAllowPrivate(name));
+ if (function.IsNull() || !function.IsStaticFunction()) {
+ return Function::null();
+ }
+ return function.raw();
+}
+
+
RawFunction* Class::LookupConstructor(const String& name) const {
Function& function = Function::Handle(LookupFunction(name));
if (function.IsNull() || !function.IsConstructor()) {
@@ -2253,6 +2272,40 @@
return Function::null();
}
Function& function = Function::Handle(isolate, Function::null());
+ if (name.IsSymbol()) {
+ // Quick Symbol compare.
+ intptr_t len = funcs.Length();
+ for (intptr_t i = 0; i < len; i++) {
+ function ^= funcs.At(i);
+ if (function.name() == name.raw()) {
+ return function.raw();
+ }
+ }
+ } else {
+ String& function_name = String::Handle(isolate, String::null());
+ intptr_t len = funcs.Length();
+ for (intptr_t i = 0; i < len; i++) {
+ function ^= funcs.At(i);
+ function_name ^= function.name();
+ if (function_name.Equals(name)) {
+ return function.raw();
+ }
+ }
+ }
+ // No function found.
+ return Function::null();
+}
+
+
+RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const {
+ Isolate* isolate = Isolate::Current();
+ ASSERT(name.IsOneByteString());
+ Array& funcs = Array::Handle(isolate, functions());
+ if (funcs.IsNull()) {
+ // This can occur, e.g., for Null classes.
+ return Function::null();
+ }
+ Function& function = Function::Handle(isolate, Function::null());
String& function_name = String::Handle(isolate, String::null());
intptr_t len = funcs.Length();
for (intptr_t i = 0; i < len; i++) {
@@ -2262,7 +2315,6 @@
return function.raw();
}
}
-
// No function found.
return Function::null();
}
@@ -6189,8 +6241,24 @@
}
+static bool IsPrivate(const String& name) {
+ if (ShouldBePrivate(name)) return true;
+ // Factory names: List._fromLiteral.
+ for (intptr_t i = 1; i < name.Length() - 1; i++) {
+ if (name.CharAt(i) == '.') {
+ if (name.CharAt(i + 1) == '_') {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+// Cannot handle qualified names properly as it only appends private key to
+// the end (e.g. _Alfa.foo -> _Alfa.foo@...).
RawString* Library::PrivateName(const String& name) const {
- ASSERT(ShouldBePrivate(name));
+ ASSERT(IsPrivate(name));
// ASSERT(strchr(name, '@') == NULL);
String& str = String::Handle();
str ^= name.raw();
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698