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

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
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 17169)
+++ 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();
}
@@ -5688,15 +5740,22 @@
static bool ShouldBePrivate(const String& name) {
siva 2013/01/16 23:57:24 I find the name ShouldBePrivate pretty weird. It s
srdjan 2013/01/17 00:31:11 Reverting this code to original, adding an IsPriva
- return
- (name.Length() >= 1 &&
- name.CharAt(0) == '_') ||
- (name.Length() >= 5 &&
- (name.CharAt(4) == '_' &&
- (name.CharAt(0) == 'g' || name.CharAt(0) == 's') &&
- name.CharAt(1) == 'e' &&
- name.CharAt(2) == 't' &&
- name.CharAt(3) == ':'));
+ if (name.Length() <= 1) return false;
+ if (name.CharAt(0) == '_') return true;
+ if (name.StartsWith(Symbols::PrivateGetterPrefix()) ||
+ name.StartsWith(Symbols::PrivateSetterPrefix())) {
+ return true;
+ }
+ // Factory names: List._fromLiteral.
+ // TODO(srdjan): Improve speed by assuming OnebyteStrings.
siva 2013/01/16 23:57:24 assuming OneByteStrings or ExternalOneByteStrings
srdjan 2013/01/17 00:31:11 Done.
+ for (intptr_t i = 1; i < name.Length() - 1; i++) {
+ if (name.CharAt(i) == '.') {
+ if (name.CharAt(i + 1) == '_') {
+ return true;
+ }
+ }
+ }
siva 2013/01/16 23:57:24 As discussed offline, this additional check here p
srdjan 2013/01/17 00:31:11 Done.
+ return false;
}
« runtime/vm/dart_entry.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698