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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_method_rename2_test.dart

Issue 23477028: Remove dart2js_foreign. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 // Test the feature where the native string declares the native method's name.
6
7 import "package:expect/expect.dart";
8 import 'native_metadata.dart';
9
10 @Native("*A")
11 class A {
12 @Native('fooA')
13 int foo();
14 }
15
16 @Native("*B")
17 class B extends A {
18 @Native('fooB')
19 int foo();
20 }
21
22 @native makeA();
23 @native makeB();
24
25 @Native("""
26 // This code is all inside 'setup' and so not accesible from the global scope.
27 function inherits(child, parent) {
28 if (child.prototype.__proto__) {
29 child.prototype.__proto__ = parent.prototype;
30 } else {
31 function tmp() {};
32 tmp.prototype = parent.prototype;
33 child.prototype = new tmp();
34 child.prototype.constructor = child;
35 }
36 }
37 function A(){}
38 A.prototype.fooA = function(){return 100;};
39 function B(){}
40 inherits(B, A);
41 B.prototype.fooB = function(){return 200;};
42
43 makeA = function(){return new A};
44 makeB = function(){return new B};
45 """)
46 void setup();
47
48 testDynamic() {
49 var things = [makeA(), makeB()];
50 var a = things[0];
51 var b = things[1];
52
53 Expect.equals(100, a.foo());
54 Expect.equals(200, b.foo());
55
56 expectNoSuchMethod((){ a.fooA(); }, 'fooA should be invisible on A');
57 expectNoSuchMethod((){ b.fooA(); }, 'fooA should be invisible on B');
58
59 expectNoSuchMethod((){ a.fooB(); }, 'fooB should be absent on A');
60 expectNoSuchMethod((){ b.fooB(); }, 'fooA should be invisible on B');
61 }
62
63 testTyped() {
64 A a = makeA();
65 B b = makeB();
66
67 Expect.equals(100, a.foo());
68 Expect.equals(200, b.foo());
69 }
70
71 main() {
72 setup();
73
74 testDynamic();
75 testTyped();
76 }
77
78 expectNoSuchMethod(action, note) {
79 bool caught = false;
80 try {
81 action();
82 } catch (ex) {
83 caught = true;
84 Expect.isTrue(ex is NoSuchMethodError, note);
85 }
86 Expect.isTrue(caught, note);
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698