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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 2184
2185 RawFunction* Class::LookupDynamicFunction(const String& name) const { 2185 RawFunction* Class::LookupDynamicFunction(const String& name) const {
2186 Function& function = Function::Handle(LookupFunction(name)); 2186 Function& function = Function::Handle(LookupFunction(name));
2187 if (function.IsNull() || !function.IsDynamicFunction()) { 2187 if (function.IsNull() || !function.IsDynamicFunction()) {
2188 return Function::null(); 2188 return Function::null();
2189 } 2189 }
2190 return function.raw(); 2190 return function.raw();
2191 } 2191 }
2192 2192
2193 2193
2194 RawFunction* Class::LookupDynamicFunctionAllowPrivate(
2195 const String& name) const {
2196 Function& function = Function::Handle(LookupFunctionAllowPrivate(name));
2197 if (function.IsNull() || !function.IsDynamicFunction()) {
2198 return Function::null();
2199 }
2200 return function.raw();
2201 }
2202
2203
2194 RawFunction* Class::LookupStaticFunction(const String& name) const { 2204 RawFunction* Class::LookupStaticFunction(const String& name) const {
2195 Function& function = Function::Handle(LookupFunction(name)); 2205 Function& function = Function::Handle(LookupFunction(name));
2196 if (function.IsNull() || !function.IsStaticFunction()) { 2206 if (function.IsNull() || !function.IsStaticFunction()) {
2197 return Function::null(); 2207 return Function::null();
2198 } 2208 }
2199 return function.raw(); 2209 return function.raw();
2200 } 2210 }
2201 2211
2202 2212
2213 RawFunction* Class::LookupStaticFunctionAllowPrivate(const String& name) const {
2214 Function& function = Function::Handle(LookupFunctionAllowPrivate(name));
2215 if (function.IsNull() || !function.IsStaticFunction()) {
2216 return Function::null();
2217 }
2218 return function.raw();
2219 }
2220
2221
2203 RawFunction* Class::LookupConstructor(const String& name) const { 2222 RawFunction* Class::LookupConstructor(const String& name) const {
2204 Function& function = Function::Handle(LookupFunction(name)); 2223 Function& function = Function::Handle(LookupFunction(name));
2205 if (function.IsNull() || !function.IsConstructor()) { 2224 if (function.IsNull() || !function.IsConstructor()) {
2206 return Function::null(); 2225 return Function::null();
2207 } 2226 }
2208 ASSERT(!function.is_static()); 2227 ASSERT(!function.is_static());
2209 return function.raw(); 2228 return function.raw();
2210 } 2229 }
2211 2230
2212 2231
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 2265
2247 RawFunction* Class::LookupFunction(const String& name) const { 2266 RawFunction* Class::LookupFunction(const String& name) const {
2248 Isolate* isolate = Isolate::Current(); 2267 Isolate* isolate = Isolate::Current();
2249 ASSERT(name.IsOneByteString()); 2268 ASSERT(name.IsOneByteString());
2250 Array& funcs = Array::Handle(isolate, functions()); 2269 Array& funcs = Array::Handle(isolate, functions());
2251 if (funcs.IsNull()) { 2270 if (funcs.IsNull()) {
2252 // This can occur, e.g., for Null classes. 2271 // This can occur, e.g., for Null classes.
2253 return Function::null(); 2272 return Function::null();
2254 } 2273 }
2255 Function& function = Function::Handle(isolate, Function::null()); 2274 Function& function = Function::Handle(isolate, Function::null());
2275 if (name.IsSymbol()) {
2276 // Quick Symbol compare.
2277 intptr_t len = funcs.Length();
2278 for (intptr_t i = 0; i < len; i++) {
2279 function ^= funcs.At(i);
2280 if (function.name() == name.raw()) {
2281 return function.raw();
2282 }
2283 }
2284 } else {
2285 String& function_name = String::Handle(isolate, String::null());
2286 intptr_t len = funcs.Length();
2287 for (intptr_t i = 0; i < len; i++) {
2288 function ^= funcs.At(i);
2289 function_name ^= function.name();
2290 if (function_name.Equals(name)) {
2291 return function.raw();
2292 }
2293 }
2294 }
2295 // No function found.
2296 return Function::null();
2297 }
2298
2299
2300 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const {
2301 Isolate* isolate = Isolate::Current();
2302 ASSERT(name.IsOneByteString());
2303 Array& funcs = Array::Handle(isolate, functions());
2304 if (funcs.IsNull()) {
2305 // This can occur, e.g., for Null classes.
2306 return Function::null();
2307 }
2308 Function& function = Function::Handle(isolate, Function::null());
2256 String& function_name = String::Handle(isolate, String::null()); 2309 String& function_name = String::Handle(isolate, String::null());
2257 intptr_t len = funcs.Length(); 2310 intptr_t len = funcs.Length();
2258 for (intptr_t i = 0; i < len; i++) { 2311 for (intptr_t i = 0; i < len; i++) {
2259 function ^= funcs.At(i); 2312 function ^= funcs.At(i);
2260 function_name ^= function.name(); 2313 function_name ^= function.name();
2261 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) { 2314 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) {
2262 return function.raw(); 2315 return function.raw();
2263 } 2316 }
2264 } 2317 }
2265
2266 // No function found. 2318 // No function found.
2267 return Function::null(); 2319 return Function::null();
2268 } 2320 }
2269 2321
2270 2322
2271 RawFunction* Class::LookupGetterFunction(const String& name) const { 2323 RawFunction* Class::LookupGetterFunction(const String& name) const {
2272 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); 2324 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name);
2273 } 2325 }
2274 2326
2275 2327
(...skipping 3906 matching lines...) Expand 10 before | Expand all | Expand 10 after
6182 lib_url ^= lib.url(); 6234 lib_url ^= lib.url();
6183 lib_key = lib_url.Hash(); 6235 lib_key = lib_url.Hash();
6184 if (lib_key == key) { 6236 if (lib_key == key) {
6185 return true; 6237 return true;
6186 } 6238 }
6187 } 6239 }
6188 return false; 6240 return false;
6189 } 6241 }
6190 6242
6191 6243
6244 static bool IsPrivate(const String& name) {
6245 if (ShouldBePrivate(name)) return true;
6246 // Factory names: List._fromLiteral.
6247 for (intptr_t i = 1; i < name.Length() - 1; i++) {
6248 if (name.CharAt(i) == '.') {
6249 if (name.CharAt(i + 1) == '_') {
6250 return true;
6251 }
6252 }
6253 }
6254 return false;
6255 }
6256
6257
6258 // Cannot handle qualified names properly as it only appends private key to
6259 // the end (e.g. _Alfa.foo -> _Alfa.foo@...).
6192 RawString* Library::PrivateName(const String& name) const { 6260 RawString* Library::PrivateName(const String& name) const {
6193 ASSERT(ShouldBePrivate(name)); 6261 ASSERT(IsPrivate(name));
6194 // ASSERT(strchr(name, '@') == NULL); 6262 // ASSERT(strchr(name, '@') == NULL);
6195 String& str = String::Handle(); 6263 String& str = String::Handle();
6196 str ^= name.raw(); 6264 str ^= name.raw();
6197 str = String::Concat(str, String::Handle(this->private_key())); 6265 str = String::Concat(str, String::Handle(this->private_key()));
6198 str = Symbols::New(str); 6266 str = Symbols::New(str);
6199 return str.raw(); 6267 return str.raw();
6200 } 6268 }
6201 6269
6202 6270
6203 RawLibrary* Library::GetLibrary(intptr_t index) { 6271 RawLibrary* Library::GetLibrary(intptr_t index) {
(...skipping 6332 matching lines...) Expand 10 before | Expand all | Expand 10 after
12536 } 12604 }
12537 return result.raw(); 12605 return result.raw();
12538 } 12606 }
12539 12607
12540 12608
12541 const char* WeakProperty::ToCString() const { 12609 const char* WeakProperty::ToCString() const {
12542 return "_WeakProperty"; 12610 return "_WeakProperty";
12543 } 12611 }
12544 12612
12545 } // namespace dart 12613 } // namespace dart
OLDNEW
« 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