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

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

Side-by-side diff isn't available for this file because of its large size.
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 | « pkg/dev_compiler/lib/js/common/dart_sdk.js ('k') | pkg/dev_compiler/lib/js/legacy/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/es6/dart_sdk.js
diff --git a/pkg/dev_compiler/lib/js/es6/dart_sdk.js b/pkg/dev_compiler/lib/js/es6/dart_sdk.js
index be696798fe9c0a30632ba5f90a006c7d6ce73782..04e02ce472754f5596b2abbf49c3d24149cde457 100644
--- a/pkg/dev_compiler/lib/js/es6/dart_sdk.js
+++ b/pkg/dev_compiler/lib/js/es6/dart_sdk.js
@@ -616,6 +616,7 @@ let dynamicAndStringAndListTodynamic = () => (dynamicAndStringAndListTodynamic =
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])))();
@@ -13087,58 +13088,66 @@ _js_mirrors._Lazy$ = dart.generic(T => {
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) {
@@ -13150,9 +13159,17 @@ _js_mirrors._wrap = function(obj) {
};
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);
@@ -13246,7 +13263,7 @@ _js_mirrors.JsObjectMirror = class JsObjectMirror extends _js_mirrors.JsMirror {
}
};
_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;
@@ -13264,32 +13281,41 @@ _js_mirrors.JsInstanceMirror = class JsInstanceMirror extends _js_mirrors.JsObje
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}));
@@ -13306,10 +13332,10 @@ dart.setSignature(_js_mirrors.JsInstanceMirror, {
}),
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 {
@@ -13320,7 +13346,7 @@ _js_mirrors.JsClosureMirror = class JsClosureMirror extends _js_mirrors.JsInstan
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);
@@ -13445,6 +13471,25 @@ _js_mirrors.JsClassMirror = class JsClassMirror extends _js_mirrors.JsMirror {
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) {
@@ -13479,6 +13524,9 @@ _js_mirrors.JsClassMirror = class JsClassMirror extends _js_mirrors.JsMirror {
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})));
}
@@ -13503,15 +13551,6 @@ _js_mirrors.JsClassMirror = class JsClassMirror extends _js_mirrors.JsMirror {
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})));
}
@@ -13549,7 +13588,12 @@ dart.setSignature(_js_mirrors.JsClassMirror, {
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 {
@@ -13563,6 +13607,9 @@ _js_mirrors.JsVariableMirror = class JsVariableMirror extends _js_mirrors.JsMirr
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})));
}
@@ -13599,6 +13646,9 @@ _js_mirrors.JsParameterMirror = class JsParameterMirror extends _js_mirrors.JsVa
_(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})));
}
@@ -13715,6 +13765,9 @@ _js_mirrors.JsMethodMirror = class JsMethodMirror extends _js_mirrors.JsMirror {
}
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 | « pkg/dev_compiler/lib/js/common/dart_sdk.js ('k') | pkg/dev_compiler/lib/js/legacy/dart_sdk.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698