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

Side by Side Diff: tests/compiler/dart2js_native/native_class_fields_test.dart

Issue 2383273002: Revert "Add native_testing library to mock @Native classes" (Closed)
Patch Set: 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:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "native_testing.dart"; 5 import "dart:_js_helper";
6 import "package:expect/expect.dart";
6 7
7 // Verify that native fields on classes are not renamed by the minifier. 8 // Verify that native fields on classes are not renamed by the minifier.
8 @Native("A") 9 @Native("A")
9 class A { 10 class A {
10 int myLongPropertyName; 11 int myLongPropertyName;
11 int getValue; 12 int getValue;
12 13
13 int method(int z) => myLongPropertyName; 14 int method(int z) => myLongPropertyName;
14 } 15 }
15 16
16 void setup() native r""" 17 void setup() native r"""
17 function getter() { 18 function getter() {
18 return ++this.getValue; 19 return ++this.getValue;
19 } 20 }
20 21
21 function setter(x) { 22 function setter(x) {
22 this.getValue += 10; 23 this.getValue += 10;
23 } 24 }
24 25
25 function A(){ 26 function A(){
26 var a = Object.create( 27 var a = Object.create(
27 { constructor: A}, 28 { constructor: { name: 'A'}},
28 { myLongPropertyName: { get: getter, 29 { myLongPropertyName: { get: getter,
29 set: setter, 30 set: setter,
30 configurable: false, 31 configurable: false,
31 writeable: false 32 writeable: false
32 } 33 }
33 }); 34 });
34 a.getValue = 0; 35 a.getValue = 0;
35 return a; 36 return a;
36 } 37 }
37 38
38 makeA = function(){return new A;}; 39 makeA = function(){return new A;};
39 self.nativeConstructor(A);
40 """; 40 """;
41 41
42 A makeA() native ; 42 A makeA() native ;
43 43
44 main() { 44 main() {
45 nativeTesting();
46 setup(); 45 setup();
47 var a = makeA(); 46 var a = makeA();
48 a.myLongPropertyName = 21; 47 a.myLongPropertyName = 21;
49 int gotten = a.myLongPropertyName; 48 int gotten = a.myLongPropertyName;
50 Expect.equals(11, gotten); 49 Expect.equals(11, gotten);
51 50
52 // Force interceptor dispatch.
53 confuse(a).myLongPropertyName = 99;
54 gotten = confuse(a).myLongPropertyName;
55 Expect.equals(22, gotten);
56
57 var a2 = makeA(); 51 var a2 = makeA();
58 if (a2 is A) { 52 if (a2 is A) {
59 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted 53 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted
60 // to access myLongPropertyName directly, using its minified name. But 54 // to access myLongPropertyName directly, using its minified name. But
61 // renaming of native properties can only work using getters and setters 55 // renaming of native properties can only work using getters and setters
62 // that access the original name. 56 // that access the original name.
63 a2.myLongPropertyName = 21; 57 a2.myLongPropertyName = 21;
64 int gotten = a2.myLongPropertyName; 58 int gotten = a2.myLongPropertyName;
65 Expect.equals(11, gotten); 59 Expect.equals(11, gotten);
66 } 60 }
67 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698