OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 "dart:_js_helper"; | 5 import 'native_testing.dart'; |
6 import "package:expect/expect.dart"; | |
7 | 6 |
8 // Test that compiler is cautious with optimizations on native fields. The | 7 // Test that compiler is cautious with optimizations on native fields. The |
9 // motivation is that DOM properties are getters and setters with arbitrary | 8 // motivation is that DOM properties are getters and setters with arbitrary |
10 // effects. Setting CSSStyleDeclaration.borderLeft can canonicalize the value | 9 // effects. Setting CSSStyleDeclaration.borderLeft can canonicalize the value |
11 // and changes the value of CSSStyleDeclaration.border. | 10 // and changes the value of CSSStyleDeclaration.border. |
12 | 11 |
13 @Native("Foo") | 12 @Native("Foo") |
14 class Foo { | 13 class Foo { |
15 var a; | 14 var a; |
16 var b; | 15 var b; |
(...skipping 18 matching lines...) Expand all Loading... |
35 Object.defineProperty(Foo.prototype, 'ab', { | 34 Object.defineProperty(Foo.prototype, 'ab', { |
36 get: function () { return this.a + ' ' + this.b; }, | 35 get: function () { return this.a + ' ' + this.b; }, |
37 set: function (v) { | 36 set: function (v) { |
38 var s = v.split(' '); | 37 var s = v.split(' '); |
39 this.a = s[0]; | 38 this.a = s[0]; |
40 this.b = s[1]; | 39 this.b = s[1]; |
41 } | 40 } |
42 }); | 41 }); |
43 | 42 |
44 makeFoo = function() { return new Foo() } | 43 makeFoo = function() { return new Foo() } |
| 44 |
| 45 self.nativeConstructor(Foo); |
45 """; | 46 """; |
46 | 47 |
47 test1() { | 48 test1() { |
48 var f = makeFoo(); | 49 var f = makeFoo(); |
49 f.a = 'Hi'; | 50 f.a = 'Hi'; |
50 f.b = 'There'; | 51 f.b = 'There'; |
51 Expect.equals('hi1 there', f.ab); | 52 Expect.equals('hi1 there', f.ab); |
52 } | 53 } |
53 | 54 |
54 test2() { | 55 test2() { |
(...skipping 22 matching lines...) Expand all Loading... |
77 | 78 |
78 test4() { | 79 test4() { |
79 // Must not store-forward. | 80 // Must not store-forward. |
80 var f = makeFoo(); | 81 var f = makeFoo(); |
81 f.a = 'A'; | 82 f.a = 'A'; |
82 var a2 = f.a; | 83 var a2 = f.a; |
83 Expect.equals('a1', a2); | 84 Expect.equals('a1', a2); |
84 } | 85 } |
85 | 86 |
86 main() { | 87 main() { |
| 88 nativeTesting(); |
87 setup(); | 89 setup(); |
88 (test1)(); | 90 (test1)(); |
89 (test2)(); | 91 (test2)(); |
90 (test3)(); | 92 (test3)(); |
91 (test4)(); | 93 (test4)(); |
92 } | 94 } |
OLD | NEW |