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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 321293002: Censor dart:_blink and dart:builtin from the enumeration of libraries in the isolate and from impor… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/mirrors/mirrors_reader_test.dart » ('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 "lib/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 378 }
379 379
380 380
381 static RawInstance* CreateLibraryMirror(const Library& lib) { 381 static RawInstance* CreateLibraryMirror(const Library& lib) {
382 const Array& args = Array::Handle(Array::New(3)); 382 const Array& args = Array::Handle(Array::New(3));
383 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); 383 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib)));
384 String& str = String::Handle(); 384 String& str = String::Handle();
385 str = lib.name(); 385 str = lib.name();
386 args.SetAt(1, str); 386 args.SetAt(1, str);
387 str = lib.url(); 387 str = lib.url();
388 if (str.Equals("dart:builtin") || str.Equals("dart:_blink")) {
389 // Censored library (grumble).
390 return Instance::null();
391 }
388 args.SetAt(2, str); 392 args.SetAt(2, str);
389 return CreateMirror(Symbols::_LocalLibraryMirror(), args); 393 return CreateMirror(Symbols::_LocalLibraryMirror(), args);
390 } 394 }
391 395
392 396
393 static RawInstance* CreateCombinatorMirror(const Object& identifiers, 397 static RawInstance* CreateCombinatorMirror(const Object& identifiers,
394 bool is_show) { 398 bool is_show) {
395 const Array& args = Array::Handle(Array::New(2)); 399 const Array& args = Array::Handle(Array::New(2));
396 args.SetAt(0, identifiers); 400 args.SetAt(0, identifiers);
397 args.SetAt(1, Bool::Get(is_show)); 401 args.SetAt(1, Bool::Get(is_show));
398 return CreateMirror(Symbols::_LocalCombinatorMirror(), args); 402 return CreateMirror(Symbols::_LocalCombinatorMirror(), args);
399 } 403 }
400 404
401 405
402 static RawInstance* CreateLibraryDependencyMirror(const Instance& importer, 406 static RawInstance* CreateLibraryDependencyMirror(const Instance& importer,
403 const Namespace& ns, 407 const Namespace& ns,
404 const String& prefix, 408 const String& prefix,
405 bool is_import) { 409 bool is_import) {
406 const Library& importee = Library::Handle(ns.library()); 410 const Library& importee = Library::Handle(ns.library());
407 const Instance& importee_mirror = 411 const Instance& importee_mirror =
408 Instance::Handle(CreateLibraryMirror(importee)); 412 Instance::Handle(CreateLibraryMirror(importee));
413 if (importee_mirror.IsNull()) {
414 // Imported library is censored: censor the import.
415 return Instance::null();
416 }
409 417
410 const Array& show_names = Array::Handle(ns.show_names()); 418 const Array& show_names = Array::Handle(ns.show_names());
411 const Array& hide_names = Array::Handle(ns.hide_names()); 419 const Array& hide_names = Array::Handle(ns.hide_names());
412 intptr_t n = show_names.IsNull() ? 0 : show_names.Length(); 420 intptr_t n = show_names.IsNull() ? 0 : show_names.Length();
413 intptr_t m = hide_names.IsNull() ? 0 : hide_names.Length(); 421 intptr_t m = hide_names.IsNull() ? 0 : hide_names.Length();
414 const Array& combinators = Array::Handle(Array::New(n + m)); 422 const Array& combinators = Array::Handle(Array::New(n + m));
415 Object& t = Object::Handle(); 423 Object& t = Object::Handle();
416 intptr_t i = 0; 424 intptr_t i = 0;
417 for (intptr_t j = 0; j < n; j++) { 425 for (intptr_t j = 0; j < n; j++) {
418 t = show_names.At(j); 426 t = show_names.At(j);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 String& prefix = String::Handle(); 462 String& prefix = String::Handle();
455 GrowableObjectArray& deps = 463 GrowableObjectArray& deps =
456 GrowableObjectArray::Handle(GrowableObjectArray::New()); 464 GrowableObjectArray::Handle(GrowableObjectArray::New());
457 465
458 // Unprefixed imports. 466 // Unprefixed imports.
459 ports = lib.imports(); 467 ports = lib.imports();
460 for (intptr_t i = 0; i < ports.Length(); i++) { 468 for (intptr_t i = 0; i < ports.Length(); i++) {
461 ns ^= ports.At(i); 469 ns ^= ports.At(i);
462 if (!ns.IsNull()) { 470 if (!ns.IsNull()) {
463 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true); 471 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true);
464 deps.Add(dep); 472 if (!dep.IsNull()) {
473 deps.Add(dep);
474 }
465 } 475 }
466 } 476 }
467 477
468 // Exports. 478 // Exports.
469 ports = lib.exports(); 479 ports = lib.exports();
470 for (intptr_t i = 0; i < ports.Length(); i++) { 480 for (intptr_t i = 0; i < ports.Length(); i++) {
471 ns ^= ports.At(i); 481 ns ^= ports.At(i);
472 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, false); 482 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, false);
473 deps.Add(dep); 483 if (!dep.IsNull()) {
484 deps.Add(dep);
485 }
474 } 486 }
475 487
476 // Prefixed imports. 488 // Prefixed imports.
477 DictionaryIterator entries(lib); 489 DictionaryIterator entries(lib);
478 Object& entry = Object::Handle(); 490 Object& entry = Object::Handle();
479 while (entries.HasNext()) { 491 while (entries.HasNext()) {
480 entry = entries.GetNext(); 492 entry = entries.GetNext();
481 if (entry.IsLibraryPrefix()) { 493 if (entry.IsLibraryPrefix()) {
482 const LibraryPrefix& lib_prefix = LibraryPrefix::Cast(entry); 494 const LibraryPrefix& lib_prefix = LibraryPrefix::Cast(entry);
483 prefix = lib_prefix.name(); 495 prefix = lib_prefix.name();
484 ports = lib_prefix.imports(); 496 ports = lib_prefix.imports();
485 for (intptr_t i = 0; i < ports.Length(); i++) { 497 for (intptr_t i = 0; i < ports.Length(); i++) {
486 ns ^= ports.At(i); 498 ns ^= ports.At(i);
487 if (!ns.IsNull()) { 499 if (!ns.IsNull()) {
488 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true); 500 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true);
489 deps.Add(dep); 501 if (!dep.IsNull()) {
502 deps.Add(dep);
503 }
490 } 504 }
491 } 505 }
492 } 506 }
493 } 507 }
494 508
495 return deps.raw(); 509 return deps.raw();
496 } 510 }
497 511
498 static RawInstance* CreateTypeMirror(const AbstractType& type) { 512 static RawInstance* CreateTypeMirror(const AbstractType& type) {
499 if (type.IsTypeRef()) { 513 if (type.IsTypeRef()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 556
543 const Array& args = Array::Handle(Array::New(2)); 557 const Array& args = Array::Handle(Array::New(2));
544 args.SetAt(0, debug_name); 558 args.SetAt(0, debug_name);
545 args.SetAt(1, root_library_mirror); 559 args.SetAt(1, root_library_mirror);
546 return CreateMirror(Symbols::_LocalIsolateMirror(), args); 560 return CreateMirror(Symbols::_LocalIsolateMirror(), args);
547 } 561 }
548 562
549 563
550 static RawInstance* CreateMirrorSystem() { 564 static RawInstance* CreateMirrorSystem() {
551 Isolate* isolate = Isolate::Current(); 565 Isolate* isolate = Isolate::Current();
552 const GrowableObjectArray& libraries = 566 const GrowableObjectArray& libraries = GrowableObjectArray::Handle(
553 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 567 isolate, isolate->object_store()->libraries());
554 568
555 const intptr_t num_libraries = libraries.Length(); 569 const intptr_t num_libraries = libraries.Length();
556 const Array& library_mirrors = Array::Handle(Array::New(num_libraries)); 570 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle(
557 Library& library = Library::Handle(); 571 isolate, GrowableObjectArray::New(num_libraries));
558 Instance& library_mirror = Instance::Handle(); 572 Library& library = Library::Handle(isolate);
573 Instance& library_mirror = Instance::Handle(isolate);
559 574
560 for (int i = 0; i < num_libraries; i++) { 575 for (int i = 0; i < num_libraries; i++) {
561 library ^= libraries.At(i); 576 library ^= libraries.At(i);
562 library_mirror = CreateLibraryMirror(library); 577 library_mirror = CreateLibraryMirror(library);
563 library_mirrors.SetAt(i, library_mirror); 578 if (!library_mirror.IsNull()) {
579 library_mirrors.Add(library_mirror);
580 }
564 } 581 }
565 582
566 const Instance& isolate_mirror = Instance::Handle(CreateIsolateMirror()); 583 const Instance& isolate_mirror = Instance::Handle(CreateIsolateMirror());
567 584
568 const Array& args = Array::Handle(Array::New(2)); 585 const Array& args = Array::Handle(Array::New(2));
569 args.SetAt(0, library_mirrors); 586 args.SetAt(0, library_mirrors);
570 args.SetAt(1, isolate_mirror); 587 args.SetAt(1, isolate_mirror);
571 return CreateMirror(Symbols::_LocalMirrorSystem(), args); 588 return CreateMirror(Symbols::_LocalMirrorSystem(), args);
572 } 589 }
573 590
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 } 1966 }
1950 1967
1951 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 1968 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
1952 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
1953 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 1970 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
1954 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 1971 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
1955 } 1972 }
1956 1973
1957 1974
1958 } // namespace dart 1975 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/lib/mirrors/mirrors_reader_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698