JsVariableMirror.type returns JsMirrorSystem._dynamicType instead of JsClassMirror of variable #12410
Labels
closed-obsolete
Closed as the reported issue is no longer relevant
library-mirrors
P2
A bug or feature request we're likely to work on
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
web-dart2js
This issue was originally filed by ak...@gmail.com
Problem repeats on Linux and Windows on Chrome, Chromium, FireFox, IE.
I'm expecting to have ClassMirror of 'type' property in VariableMirror and it does really return it in DartVM:
VariableMirror.type => ClassMirror
so I can instantiate variable with 'newInstance' method of ClassMirror.
In JavaScript VM it does return JsTypeMirror of dynamic type:
TypeMirror get type => JsMirrorSystem._dynamicType;
(from https://code.google.com/p/dart/source/browse/trunk/dart/sdk/lib/_internal/compiler/implementation/lib/js_mirrors.dart?r=23894)
and fails with next exception:
Uncaught TypeError: Object #<JsTypeMirror> has no method 'newInstance$2'
Use example code below to test:
import 'dart:html';
import 'dart:mirrors';
void main() {
DivElement div = query("#sample_container_id");
div.text = testMirrors();
}
class A {
B b;
}
class B {
String name = "Unknown";
B();
}
String testMirrors() {
// Make an instance of class A
A a = new A();
// Get instance mirror of class A
InstanceMirror aIM = reflect(a);
// Get class mirror of class A
ClassMirror aCM = aIM.type;
// Find 'b' variable mirror in class mirror of class A
VariableMirror bVM = aCM.variables.values.first;
// Get class mirror of variable mirror of 'b'
ClassMirror bCM = bVM.type;
try {
// Instantiate variable 'b'
InstanceMirror bIM = bCM.newInstance(const Symbol(""), []);
// Assign instance of variable 'b' to instance of class A
aIM.setField(const Symbol("b"), bIM.reflectee);
} on Exception catch(ex) {
print(ex);
}
// Return 'name' of 'b' of 'a'
return a.b.name;
}
String symbolAsString(Symbol symbol) => MirrorSystem.getName(symbol);
The text was updated successfully, but these errors were encountered: