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

Unified Diff: pkg/dev_compiler/lib/js/amd/dart_sdk.js

Issue 2410453002: Handle private members in dart:mirrors (Closed)
Patch Set: Address comments, merge Created 4 years, 2 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:
Download patch
« no previous file with comments | « no previous file | pkg/dev_compiler/lib/js/common/dart_sdk.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/js/amd/dart_sdk.js
diff --git a/pkg/dev_compiler/lib/js/amd/dart_sdk.js b/pkg/dev_compiler/lib/js/amd/dart_sdk.js
index f842036a293f1e02e240c50fec8bce743203889f..26400c4b216823337200a1198557a5beb2cfc839 100644
--- a/pkg/dev_compiler/lib/js/amd/dart_sdk.js
+++ b/pkg/dev_compiler/lib/js/amd/dart_sdk.js
@@ -618,6 +618,7 @@ define([], function() {
let dynamicToMap = () => (dynamicToMap = dart.constFn(dart.definiteFunctionType(core.Map, [dart.dynamic])))();
let TypeAndInvocationTodynamic = () => (TypeAndInvocationTodynamic = dart.constFn(dart.definiteFunctionType(dart.dynamic, [core.Type, core.Invocation])))();
let SymbolAnddynamicTovoid = () => (SymbolAnddynamicTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [core.Symbol, dart.dynamic])))();
+ let MapOfSymbol$dynamicTodynamic = () => (MapOfSymbol$dynamicTodynamic = dart.constFn(dart.definiteFunctionType(dart.dynamic, [MapOfSymbol$dynamic()])))();
let StringAnddynamicTovoid = () => (StringAnddynamicTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [core.String, dart.dynamic])))();
let dynamicToTypeMirror = () => (dynamicToTypeMirror = dart.constFn(dart.definiteFunctionType(mirrors.TypeMirror, [dart.dynamic])))();
let dynamicAnddynamicAnddynamicTovoid = () => (dynamicAnddynamicAnddynamicTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [dart.dynamic, dart.dynamic, dart.dynamic])))();
@@ -13089,58 +13090,66 @@ define([], function() {
return _Lazy;
});
_js_mirrors._Lazy = _Lazy();
+ _js_mirrors._getNameForESSymbol = function(member) {
+ let str = dart.toString(member);
+ dart.assert(dart.test(str[dartx.startsWith]('Symbol(')) && dart.test(str[dartx.endsWith](')')));
+ return str[dartx.substring](7, dart.notNull(str[dartx.length]) - 1);
+ };
+ dart.lazyFn(_js_mirrors._getNameForESSymbol, () => dynamicToString());
+ _js_mirrors._toDartMap = function(data) {
+ if (data == null) return dart.map();
+ let map = _js_mirrors._dart.map(data);
+ let privateMembers = Object.getOwnPropertySymbols(data);
+ for (let member of core.Iterable._check(privateMembers)) {
+ let name = _js_mirrors._getNameForESSymbol(member);
+ map[dartx.set](name, data[member]);
+ }
+ return map;
+ };
+ dart.lazyFn(_js_mirrors._toDartMap, () => dynamicToMap());
_js_mirrors._getConstructors = function(obj) {
let sig = _js_mirrors._dart.getConstructorSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getConstructors, () => dynamicToMap());
_js_mirrors._getFields = function(obj) {
let sig = _js_mirrors._dart.getFieldSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getFields, () => dynamicToMap());
_js_mirrors._getMethods = function(obj) {
let sig = _js_mirrors._dart.getMethodSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getMethods, () => dynamicToMap());
_js_mirrors._getGetters = function(obj) {
let sig = _js_mirrors._dart.getGetterSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getGetters, () => dynamicToMap());
_js_mirrors._getSetters = function(obj) {
let sig = _js_mirrors._dart.getSetterSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getSetters, () => dynamicToMap());
_js_mirrors._getStaticFields = function(obj) {
let sig = _js_mirrors._dart.getStaticFieldSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getStaticFields, () => dynamicToMap());
_js_mirrors._getStatics = function(obj) {
let sig = _js_mirrors._dart.getStaticSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getStatics, () => dynamicToMap());
_js_mirrors._getStaticGetters = function(obj) {
let sig = _js_mirrors._dart.getStaticGetterSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getStaticGetters, () => dynamicToMap());
_js_mirrors._getStaticSetters = function(obj) {
let sig = _js_mirrors._dart.getStaticSetterSig(obj);
- if (sig == null) return dart.map();
- return _js_mirrors._dart.map(sig);
+ return _js_mirrors._toDartMap(sig);
};
dart.lazyFn(_js_mirrors._getStaticSetters, () => dynamicToMap());
_js_mirrors._unwrap = function(obj) {
@@ -13152,9 +13161,17 @@ define([], function() {
};
dart.fn(_js_mirrors._wrap, dynamicTodynamic$());
_js_mirrors._unimplemented = function(t, i) {
- dart.throw(new core.UnimplementedError(dart.str`${t}.${i.memberName} unimplemented`));
+ dart.throw(new core.UnimplementedError(dart.str`${t}.${_js_mirrors.getName(i.memberName)} unimplemented`));
};
dart.fn(_js_mirrors._unimplemented, TypeAndInvocationTodynamic());
+ _js_mirrors._toJsMap = function(map) {
+ let obj = {};
+ map[dartx.forEach](dart.fn((key, value) => {
+ obj[_js_mirrors.getName(key)] = value;
+ }, SymbolAnddynamicTovoid()));
+ return obj;
+ };
+ dart.lazyFn(_js_mirrors._toJsMap, () => MapOfSymbol$dynamicTodynamic());
_js_mirrors.JsMirror = class JsMirror extends core.Object {
noSuchMethod(i) {
_js_mirrors._unimplemented(this.runtimeType, i);
@@ -13248,7 +13265,7 @@ define([], function() {
}
};
_js_mirrors.JsObjectMirror[dart.implements] = () => [mirrors.ObjectMirror];
- const _toJsMap = Symbol('_toJsMap');
+ const _getAccessor = Symbol('_getAccessor');
_js_mirrors.JsInstanceMirror = class JsInstanceMirror extends _js_mirrors.JsObjectMirror {
get hasReflectee() {
return true;
@@ -13266,32 +13283,41 @@ define([], function() {
get hashCode() {
return (dart.notNull(core.identityHashCode(this.reflectee)) ^ 909522486) >>> 0;
}
- getField(symbol) {
+ [_getAccessor](reflectee, symbol, args, namedArgs) {
+ if (args === void 0) args = null;
+ if (namedArgs === void 0) namedArgs = null;
let name = _js_mirrors.getName(symbol);
- let field = _js_mirrors._dload(this.reflectee, name);
+ if (!dart.test(name[dartx.startsWith]('_'))) return name;
+ let privateMembers = Object.getOwnPropertySymbols(reflectee);
+ dart.dsend(privateMembers, 'addAll', Object.getOwnPropertySymbols(reflectee.__proto__));
+ for (let member of core.Iterable._check(privateMembers)) {
+ let privateName = _js_mirrors._getNameForESSymbol(member);
+ if (name == privateName) return member;
+ }
+ return new core.NoSuchMethodError(reflectee, symbol, args, namedArgs);
+ }
+ getField(symbol) {
+ let name = this[_getAccessor](this.reflectee, symbol);
+ let field = _js_mirrors._dload(this.reflectee, core.String._check(name));
return _js_mirrors.reflect(field);
}
setField(symbol, value) {
- let name = _js_mirrors.getName(symbol);
- _js_mirrors._dput(this.reflectee, name, value);
+ let name = this[_getAccessor](this.reflectee, symbol);
+ _js_mirrors._dput(this.reflectee, core.String._check(name), value);
return _js_mirrors.reflect(value);
}
invoke(symbol, args, namedArgs) {
if (namedArgs === void 0) namedArgs = null;
- let name = _js_mirrors.getName(symbol);
+ let name = this[_getAccessor](this.reflectee, symbol, args, namedArgs);
if (namedArgs != null) {
args = core.List.from(args);
- args[dartx.add](this[_toJsMap](namedArgs));
+ args[dartx.add](_js_mirrors._toJsMap(namedArgs));
}
- let result = _js_mirrors._dsend(this.reflectee, name, args);
+ let result = _js_mirrors._dsend(this.reflectee, core.String._check(name), args);
return _js_mirrors.reflect(result);
}
- [_toJsMap](map) {
- let obj = {};
- map[dartx.forEach](dart.fn((key, value) => {
- obj[_js_mirrors.getName(key)] = value;
- }, SymbolAnddynamicTovoid()));
- return obj;
+ toString() {
+ return dart.str`InstanceMirror on '${this.reflectee}'`;
}
delegate(...args) {
return this.noSuchMethod(new dart.InvocationImpl('delegate', args, {isMethod: true}));
@@ -13308,10 +13334,10 @@ define([], function() {
}),
methods: () => ({
'==': dart.definiteFunctionType(core.bool, [core.Object]),
+ [_getAccessor]: dart.definiteFunctionType(dart.dynamic, [dart.dynamic, core.Symbol], [core.List, MapOfSymbol$dynamic()]),
getField: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol]),
setField: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.Object]),
- invoke: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.List], [MapOfSymbol$dynamic()]),
- [_toJsMap]: dart.definiteFunctionType(dart.dynamic, [MapOfSymbol$dynamic()])
+ invoke: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.List], [MapOfSymbol$dynamic()])
})
});
_js_mirrors.JsClosureMirror = class JsClosureMirror extends _js_mirrors.JsInstanceMirror {
@@ -13322,7 +13348,7 @@ define([], function() {
if (namedArgs === void 0) namedArgs = null;
if (namedArgs != null) {
args = core.List.from(args);
- args[dartx.add](this[_toJsMap](namedArgs));
+ args[dartx.add](_js_mirrors._toJsMap(namedArgs));
}
let result = _js_mirrors._dcall(this.reflectee, args);
return _js_mirrors.reflect(result);
@@ -13447,6 +13473,25 @@ define([], function() {
let instance = name == 'new' || name == '' ? new (_js_mirrors._unwrap(this[_cls]))(...args) : new (_js_mirrors._unwrap(this[_cls]))[name](...args);
return _js_mirrors.reflect(instance);
}
+ getField(symbol) {
+ let name = _js_mirrors.getName(symbol);
+ return _js_mirrors.reflect(_js_mirrors._unwrap(this[_cls])[name]);
+ }
+ setField(symbol, value) {
+ let name = _js_mirrors.getName(symbol);
+ _js_mirrors._unwrap(this[_cls])[name] = value;
+ return _js_mirrors.reflect(value);
+ }
+ invoke(symbol, args, namedArgs) {
+ if (namedArgs === void 0) namedArgs = null;
+ let name = _js_mirrors.getName(symbol);
+ if (namedArgs != null) {
+ args = core.List.from(args);
+ args[dartx.add](_js_mirrors._toJsMap(namedArgs));
+ }
+ let result = _js_mirrors._unwrap(this[_cls])[name](...args);
+ return _js_mirrors.reflect(result);
+ }
get superinterfaces() {
let interfaceThunk = _js_mirrors._unwrap(this[_cls])[dart.implements];
if (interfaceThunk == null) {
@@ -13481,6 +13526,9 @@ define([], function() {
return mirrors.ClassMirror._check(_js_mirrors.reflectType(core.Type._check(_js_mirrors._wrap(_js_mirrors._unwrap(this[_cls]).__proto__))));
}
}
+ toString() {
+ return dart.str`ClassMirror on '${this[_cls]}'`;
+ }
get qualifiedName() {
return core.Symbol._check(this.noSuchMethod(new dart.InvocationImpl('qualifiedName', [], {isGetter: true})));
}
@@ -13505,15 +13553,6 @@ define([], function() {
get typeVariables() {
return ListOfTypeVariableMirror()._check(this.noSuchMethod(new dart.InvocationImpl('typeVariables', [], {isGetter: true})));
}
- invoke(...args) {
- return mirrors.InstanceMirror._check(this.noSuchMethod(new dart.InvocationImpl('invoke', args, {isMethod: true})));
- }
- getField(...args) {
- return mirrors.InstanceMirror._check(this.noSuchMethod(new dart.InvocationImpl('getField', args, {isMethod: true})));
- }
- setField(...args) {
- return mirrors.InstanceMirror._check(this.noSuchMethod(new dart.InvocationImpl('setField', args, {isMethod: true})));
- }
isSubclassOf(...args) {
return core.bool._check(this.noSuchMethod(new dart.InvocationImpl('isSubclassOf', args, {isMethod: true})));
}
@@ -13551,7 +13590,12 @@ define([], function() {
originalDeclaration: dart.definiteFunctionType(mirrors.TypeMirror, []),
superclass: dart.definiteFunctionType(mirrors.ClassMirror, [])
}),
- methods: () => ({newInstance: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.List], [MapOfSymbol$dynamic()])})
+ methods: () => ({
+ newInstance: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.List], [MapOfSymbol$dynamic()]),
+ getField: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol]),
+ setField: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.Object]),
+ invoke: dart.definiteFunctionType(mirrors.InstanceMirror, [core.Symbol, core.List], [MapOfSymbol$dynamic()])
+ })
});
const _name$ = Symbol('_name');
_js_mirrors.JsVariableMirror = class JsVariableMirror extends _js_mirrors.JsMirror {
@@ -13565,6 +13609,9 @@ define([], function() {
this.isStatic = false;
this.isFinal = false;
}
+ toString() {
+ return dart.str`VariableMirror on '${this[_name$]}'`;
+ }
get qualifiedName() {
return core.Symbol._check(this.noSuchMethod(new dart.InvocationImpl('qualifiedName', [], {isGetter: true})));
}
@@ -13601,6 +13648,9 @@ define([], function() {
_(name, t, annotations) {
super._(name, t, annotations);
}
+ toString() {
+ return dart.str`ParameterMirror on '${this[_name$]}'`;
+ }
get qualifiedName() {
return core.Symbol._check(this.noSuchMethod(new dart.InvocationImpl('qualifiedName', [], {isGetter: true})));
}
@@ -13717,6 +13767,9 @@ define([], function() {
}
this[_params] = ListOfParameterMirror().unmodifiable(params);
}
+ toString() {
+ return dart.str`MethodMirror on '${this[_name$]}'`;
+ }
get qualifiedName() {
return core.Symbol._check(this.noSuchMethod(new dart.InvocationImpl('qualifiedName', [], {isGetter: true})));
}
« no previous file with comments | « no previous file | pkg/dev_compiler/lib/js/common/dart_sdk.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698