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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_class_inheritance1_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 to see if resolving a hidden native class's method interferes with
6 // subsequent resolving the subclass's method. This might happen if the
7 // superclass caches the method in the prototype, so shadowing the dispatcher
8 // stored on Object.prototype.
9
10 import "package:expect/expect.dart";
11 import 'native_metadata.dart';
12
13 // Version 1: It might be possible to call foo directly.
14 @Native("*A1")
15 class A1 {
16 @native foo();
17 }
18
19 @Native("*B1")
20 class B1 extends A1 {
21 @native foo();
22 }
23
24 @native makeA1();
25 @native makeB1();
26
27
28 // Version 2: foo needs some kind of trampoline.
29 @Native("*A2")
30 class A2 {
31 @native foo([a=99]);
32 }
33
34 @Native("*B2")
35 class B2 extends A2 {
36 @native foo([z=1000]);
37 }
38
39 @native makeA2();
40 @native makeB2();
41
42 @Native("""
43 // This code is all inside 'setup' and so not accesible from the global scope.
44 function inherits(child, parent) {
45 if (child.prototype.__proto__) {
46 child.prototype.__proto__ = parent.prototype;
47 } else {
48 function tmp() {};
49 tmp.prototype = parent.prototype;
50 child.prototype = new tmp();
51 child.prototype.constructor = child;
52 }
53 }
54 function A1(){}
55 function B1(){}
56 inherits(B1, A1);
57 A1.prototype.foo = function(){return 100;}
58 B1.prototype.foo = function(){return 200;}
59
60 makeA1 = function(){return new A1};
61 makeB1 = function(){return new B1};
62
63 function A2(){}
64 function B2(){}
65 inherits(B2, A2);
66 A2.prototype.foo = function(a){return a + 10000;}
67 B2.prototype.foo = function(z){return z + 20000;}
68
69 makeA2 = function(){return new A2};
70 makeB2 = function(){return new B2};
71 """)
72 void setup();
73
74
75 main() {
76 setup();
77
78 var a1 = makeA1();
79 var b1 = makeB1();
80 Expect.equals(100, a1.foo());
81 Expect.equals(200, b1.foo());
82
83 var a2 = makeA2();
84 var b2 = makeB2();
85 Expect.equals(10000 + 99, a2.foo());
86 Expect.equals(20000 + 1000, b2.foo());
87
88 Expect.equals(10000 + 1, a2.foo(1));
89 Expect.equals(20000 + 2, b2.foo(2));
90
91 bool caught = false;
92 try {
93 a1.foo(20);
94 } catch (ex) {
95 caught = true;
96 Expect.isTrue(ex is NoSuchMethodError);
97 }
98 Expect.isTrue(caught, 'a1.foo(20) should throw');
99
100 caught = false;
101 try {
102 var x = 123;
103 x.foo(20);
104 } catch (ex) {
105 caught = true;
106 Expect.isTrue(ex is NoSuchMethodError);
107 }
108 Expect.isTrue(caught, "x.foo(20) should throw");
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698