Hide ClosureMirror.findInContext behind a flag for 1.0.

Test findInContext does not wildcard privates. Fix confused test and implementation that expected inheritance of static members.

BUG=http://dartbug.com/13656
R=ahe@google.com, asiva@google.com, gbracha@google.com

Review URL: https://codereview.chromium.org//52953002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29697 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
rmacnak@google.com 2013-10-31 20:50:17 +00:00
parent 545bec0843
commit f3384bf0eb
8 changed files with 133 additions and 25 deletions

View file

@ -20,6 +20,9 @@ DEFINE_FLAG(bool, use_mirrored_compilation_error, false,
"Wrap compilation errors that occur during reflective access in a "
"MirroredCompilationError, rather than suspending the isolate.");
DEFINE_FLAG(bool, support_find_in_context, false,
"Experimental support for ClosureMirror.findInContext.");
static RawInstance* CreateMirror(const String& mirror_class_name,
const Array& constructor_arguments) {
const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary());
@ -721,12 +724,8 @@ static RawInstance* LookupStaticFunctionOrFieldInClass(
return result.raw();
}
Function& func = Function::Handle();
Class& lookup_class = Class::Handle(klass.raw());
while (func.IsNull() && !lookup_class.IsNull()) {
func ^= lookup_class.LookupStaticFunction(lookup_name);
lookup_class = lookup_class.SuperClass();
}
const Function& func =
Function::Handle(klass.LookupStaticFunction(lookup_name));
if (!func.IsNull()) {
const Function& closure_function = Function::Handle(
func.ImplicitClosureFunction());
@ -1424,6 +1423,10 @@ DEFINE_NATIVE_ENTRY(ClosureMirror_apply, 2) {
DEFINE_NATIVE_ENTRY(ClosureMirror_find_in_context, 2) {
if (!FLAG_support_find_in_context) {
return Object::empty_array().raw();
}
GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Array, lookup_parts, arguments->NativeArgAt(1));
ASSERT(lookup_parts.Length() >= 1 && lookup_parts.Length() <= 3);

View file

@ -469,6 +469,10 @@ class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl
throw new ArgumentError("Invalid symbol: ${name}");
}
List tuple = _computeFindInContext(_reflectee, parts);
if (tuple.length == 0) {
throw new UnsupportedError(
"ClosureMirror.findInContext not yet supported");
}
if (tuple[0]) {
return reflect(tuple[1]);
}

View file

@ -1593,8 +1593,9 @@ function(reflectee) {
// TODO(ahe): Implement these.
String get source => throw new UnimplementedError();
Future<InstanceMirror> findInContext(Symbol name)
=> throw new UnimplementedError();
InstanceMirror findInContext(Symbol name) {
throw new UnsupportedError("ClosureMirror.findInContext not yet supported");
}
}
class JsMethodMirror extends JsDeclarationMirror implements MethodMirror {

View file

@ -539,20 +539,7 @@ abstract class ClosureMirror implements InstanceMirror {
[Map<Symbol, dynamic> namedArguments]);
/**
* Looks up the value of a name in the scope of the closure. The
* result is a mirror on that value.
*
* Let *s* be the contents of the string used to construct the symbol [name].
*
* If the expression *s* occurs within the source code of the reflectee,
* and if any such occurrence refers to a declaration outside the reflectee,
* then let *v* be the result of evaluating the expression *s* at such
* an occurrence.
* If *s = this*, and the reflectee was defined within the instance scope of
* an object *o*, then let *v* be *o*.
*
* The returned value is the result of invoking the method [reflect] on
* *v*.
* Not yet supported. Calling this method throws an [UnsupportedError].
*/
InstanceMirror findInContext(Symbol name, {ifAbsent: null});
}

View file

@ -16,11 +16,12 @@ math/random_test: RuntimeError
mirrors/basic_types_in_dart_core_test: RuntimeError # Issue 14025
mirrors/class_declarations_test/none: RuntimeError # Issue 13440
mirrors/closures_test/none: RuntimeError # Issue 6490
mirrors/closure_mirror_find_in_context_test: Fail # Issue 6490
mirrors/constructor_kinds_test: RuntimeError # Issue 13799
mirrors/equality_test/02: RuntimeError # Issue 12333
mirrors/fake_function_with_call_test: RuntimeError # Issue 11612
mirrors/fake_function_without_call_test: RuntimeError # Issue 11612
mirrors/find_in_context_test: Fail # Issue 6490
mirrors/find_in_context_private_test: Fail # Issue 6490
mirrors/find_in_context_fake_function_test: Fail # Issue 6490
mirrors/function_type_mirror_test: RuntimeError # Issue 12166
mirrors/generics_test/01: RuntimeError # Issue 12087

View file

@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--support_find_in_context=true
// Regression test: this used to crash the VM.
library test.find_in_context_fake_function;

View file

@ -0,0 +1,104 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--support_find_in_context=true
library test.find_in_context_private;
import "dart:mirrors";
import "package:expect/expect.dart";
var _globalVariable = "globalVariable";
_globalFoo() => 17;
class S {
static _staticFooInS() => "staticFooInS";
static var _staticInS = "staticInS";
var _instanceInS = "instanceInS";
}
class C extends S {
static _staticFooInC() => "staticFooInC";
static var _staticInC = "staticInC";
var _instanceInC = "instanceInC";
_method() {
var _local = "local";
nested() {
var _innerLocal = "innerLocal";
print(this._instanceInC);
print(_local);
print(_innerLocal);
}
return nested;
}
}
doFindInContext(cm, name, value) {
Expect.equals(value,
cm.findInContext(name).reflectee);
}
dontFindInContext(cm, name) {
Expect.isNull(cm.findInContext(name));
}
main() {
LibraryMirror wrongLibrary = reflectClass(List).owner;
p(name) => MirrorSystem.getSymbol(name, wrongLibrary);
C c = new C();
// In the context of C._method.nested.
ClosureMirror cm = reflect(c._method());
// N.B.: innerLocal is only defined with respective to an activation of the
// closure 'nested', not the closure itself.
dontFindInContext(cm, #_innerLocal);
doFindInContext(cm, #_local, "local");
doFindInContext(cm, #_method, c._method);
doFindInContext(cm, #_instanceInC, "instanceInC");
doFindInContext(cm, #_staticInC, "staticInC");
doFindInContext(cm, #_staticFooInC, C._staticFooInC);
dontFindInContext(cm, #_staticInS);
dontFindInContext(cm, #_staticFooInS);
doFindInContext(cm, #_globalFoo, _globalFoo);
doFindInContext(cm, #_globalVariable, "globalVariable");
dontFindInContext(cm, p('_local'));
dontFindInContext(cm, p('_innerLocal'));
dontFindInContext(cm, p('_method'));
dontFindInContext(cm, p('_instanceInC'));
dontFindInContext(cm, p('_staticInC'));
dontFindInContext(cm, p('_staticFooInC'));
dontFindInContext(cm, p('_staticInS'));
dontFindInContext(cm, p('_staticFooInS'));
dontFindInContext(cm, p('_globalFoo'));
dontFindInContext(cm, p('_globalVariable'));
// In the context of C._method.
cm = reflect(c._method);
dontFindInContext(cm, #_innerLocal);
dontFindInContext(cm, #_local); // N.B.: See above.
doFindInContext(cm, #_method, c._method);
doFindInContext(cm, #_instanceInC, "instanceInC");
doFindInContext(cm, #_staticInC, "staticInC");
doFindInContext(cm, #_staticFooInC, C._staticFooInC);
dontFindInContext(cm, #_staticInS);
dontFindInContext(cm, #_staticFooInS);
doFindInContext(cm, #_globalFoo, _globalFoo);
doFindInContext(cm, #_globalVariable, "globalVariable");
dontFindInContext(cm, p('_local'));
dontFindInContext(cm, p('_innerLocal'));
dontFindInContext(cm, p('_method'));
dontFindInContext(cm, p('_instanceInC'));
dontFindInContext(cm, p('_staticInC'));
dontFindInContext(cm, p('_staticFooInC'));
dontFindInContext(cm, p('_staticInS'));
dontFindInContext(cm, p('_staticFooInS'));
dontFindInContext(cm, p('_globalFoo'));
dontFindInContext(cm, p('_globalVariable'));
}

View file

@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--support_find_in_context=true
import "dart:mirrors";
import "stringify.dart";
@ -69,12 +71,16 @@ main() {
Expect.equals(null, result);
result = cm.findInContext(#staticFooInS);
Expect.isFalse(result is InstanceMirror);
Expect.equals(null, result);
result = cm.findInContext(#S.staticFooInS);
Expect.isTrue(result is ClosureMirror);
expect("Instance(value = staticFooInS)", result.apply(const []));
result = cm.findInContext(#C.staticFooInS);
Expect.isTrue(result is ClosureMirror);
expect("Instance(value = staticFooInS)", result.apply(const []));
Expect.isFalse(result is InstanceMirror);
Expect.equals(null, result);
result = cm.findInContext(#C.staticInC);
expect("Instance(value = staticInC)", result);