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

Side by Side Diff: tests/lib/mirrors/invoke_private_test.dart

Issue 21430002: Allow InstanceMirror.invoke to find private members. Resolves issue 11771. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.invoke_test;
6
7 import 'dart:mirrors';
8
9 import 'package:expect/expect.dart';
10 import '../../async_helper.dart';
11
12 class C {
13 var _field;
14 C() : this._field = 'default';
15 C._named(this._field);
16
17 get _getter => 'get $_field';
18 set _setter(v) => _field = 'set $v';
19 _method(x, y, z) => '$x+$y+$z';
20
21 static var _staticField = 'initial';
22 static get _staticGetter => 'sget $_staticField';
23 static set _staticSetter(v) => _staticField = 'sset $v';
24 static _staticFunction(x, y) => "($x,$y)";
25 }
26
27 var _libraryField = 'a priori';
28 get _libraryGetter => 'lget $_libraryField';
29 set _librarySetter(v) => _libraryField = 'lset $v';
30 _libraryFunction(x,y) => '$x$y';
31
32 main() {
33 var result;
34
35 // InstanceMirror.
36 C c = new C();
37 InstanceMirror im = reflect(c);
38 result = im.invoke(const Symbol('_method'), [2,4,8]);
39 Expect.equals('2+4+8', result.reflectee);
40
41 result = im.getField(const Symbol('_getter'));
ahe 2013/08/02 06:45:24 It is a bug in the VM if it accepts this. When I
42 Expect.equals('get default', result.reflectee);
43 result = im.getField(const Symbol('_field'));
44 Expect.equals('default', result.reflectee);
45
46 im.setField(const Symbol('_setter'), 'foo');
47 Expect.equals('set foo', c._field);
48 im.setField(const Symbol('_field'), 'bar');
49 Expect.equals('bar', c._field);
50
51
52 // ClassMirror.
53 ClassMirror cm = reflectClass(C);
54 result = cm.invoke(const Symbol('_staticFunction'),[3,4]);
55 Expect.equals('(3,4)', result.reflectee);
56
57 result = cm.getField(const Symbol('_staticGetter'));
58 Expect.equals('sget initial', result.reflectee);
59 result = cm.getField(const Symbol('_staticField'));
60 Expect.equals('initial', result.reflectee);
61
62 cm.setField(const Symbol('_staticSetter'), 'sfoo');
63 Expect.equals('sset sfoo', C._staticField);
64 cm.setField(const Symbol('_staticField'), 'sbar');
65 Expect.equals('sbar', C._staticField);
66
67 result = cm.newInstance(const Symbol('_named'), ['my value']);
68 Expect.isTrue(result.reflectee is C);
69 Expect.equals('my value', result.reflectee._field);
70
71
72 // LibraryMirror.
73 LibraryMirror lm = cm.owner;
74 result = lm.invoke(const Symbol('_libraryFunction'),[':',')']);
75 Expect.equals(':)', result.reflectee);
76
77 result = lm.getField(const Symbol('_libraryGetter'));
78 Expect.equals('lget a priori', result.reflectee);
79 result = lm.getField(const Symbol('_libraryField'));
80 Expect.equals('a priori', result.reflectee);
81
82 lm.setField(const Symbol('_librarySetter'), 'lfoo');
83 Expect.equals('lset lfoo', _libraryField);
84 lm.setField(const Symbol('_libraryField'), 'lbar');
85 Expect.equals('lbar', _libraryField);
86 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698