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

Unified Diff: pkg/dev_compiler/lib/js/legacy/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/es6/dart_sdk.js ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/js/legacy/dart_sdk.js
diff --git a/pkg/dev_compiler/lib/js/legacy/dart_sdk.js b/pkg/dev_compiler/lib/js/legacy/dart_sdk.js
index c3c2fe23da853f11d24474de5dfae668a03f0b41..4b7fd1db9690eb69a432330a4d2c0a3c5b648678 100644
--- a/pkg/dev_compiler/lib/js/legacy/dart_sdk.js
+++ b/pkg/dev_compiler/lib/js/legacy/dart_sdk.js
@@ -619,6 +619,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
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])))();
@@ -13090,58 +13091,66 @@ dart_library.library('dart_sdk', null, /* Imports */[
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) {
@@ -13153,9 +13162,17 @@ dart_library.library('dart_sdk', null, /* Imports */[
};
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);
@@ -13249,7 +13266,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
}
};
_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;
@@ -13267,32 +13284,41 @@ dart_library.library('dart_sdk', null, /* Imports */[
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}));
@@ -13309,10 +13335,10 @@ dart_library.library('dart_sdk', null, /* Imports */[
}),
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 {
@@ -13323,7 +13349,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
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);
@@ -13448,6 +13474,25 @@ dart_library.library('dart_sdk', null, /* Imports */[
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) {
@@ -13482,6 +13527,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
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})));
}
@@ -13506,15 +13554,6 @@ dart_library.library('dart_sdk', null, /* Imports */[
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})));
}
@@ -13552,7 +13591,12 @@ dart_library.library('dart_sdk', null, /* Imports */[
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 {
@@ -13566,6 +13610,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
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})));
}
@@ -13602,6 +13649,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
_(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})));
}
@@ -13718,6 +13768,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
}
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/es6/dart_sdk.js ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698