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

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

Issue 2984403002: dart2js_native tests: Migrate 'native STRING' to JS-calls (Closed)
Patch Set: the rest of the files Created 3 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
OLDNEW
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 'native_testing.dart'; 5 import 'native_testing.dart';
6 6
7 // Test that compiler is cautious with optimizations on native fields. The 7 // Test that compiler is cautious with optimizations on native fields. The
8 // motivation is that DOM properties are getters and setters with arbitrary 8 // motivation is that DOM properties are getters and setters with arbitrary
9 // effects. Setting CSSStyleDeclaration.borderLeft can canonicalize the value 9 // effects. Setting CSSStyleDeclaration.borderLeft can canonicalize the value
10 // and changes the value of CSSStyleDeclaration.border. 10 // and changes the value of CSSStyleDeclaration.border.
11 11
12 @Native("Foo") 12 @Native("Foo")
13 class Foo { 13 class Foo {
14 var a; 14 var a;
15 var b; 15 var b;
16 var ab; 16 var ab;
17 } 17 }
18 18
19 Foo makeFoo() native; 19 Foo makeFoo() native;
20 20
21 void setup() native """ 21 void setup() {
22 function Foo() { this.i = 0; } 22 JS('', r"""
23 (function(){
24 function Foo() { this.i = 0; }
23 25
24 Object.defineProperty(Foo.prototype, 'a', { 26 Object.defineProperty(Foo.prototype, 'a', {
25 get: function () { return (this._a || '') + ++this.i; }, 27 get: function () { return (this._a || '') + ++this.i; },
26 set: function (v) { this._a = v.toLowerCase(); } 28 set: function (v) { this._a = v.toLowerCase(); }
27 }); 29 });
28 30
29 Object.defineProperty(Foo.prototype, 'b', { 31 Object.defineProperty(Foo.prototype, 'b', {
30 get: function () { return this._b || ''; }, 32 get: function () { return this._b || ''; },
31 set: function (v) { this._b = v.toLowerCase(); } 33 set: function (v) { this._b = v.toLowerCase(); }
32 }); 34 });
33 35
34 Object.defineProperty(Foo.prototype, 'ab', { 36 Object.defineProperty(Foo.prototype, 'ab', {
35 get: function () { return this.a + ' ' + this.b; }, 37 get: function () { return this.a + ' ' + this.b; },
36 set: function (v) { 38 set: function (v) {
37 var s = v.split(' '); 39 var s = v.split(' ');
38 this.a = s[0]; 40 this.a = s[0];
39 this.b = s[1]; 41 this.b = s[1];
40 } 42 }
41 }); 43 });
42 44
43 makeFoo = function() { return new Foo() } 45 makeFoo = function() { return new Foo() };
44 46
45 self.nativeConstructor(Foo); 47 self.nativeConstructor(Foo);
46 """; 48 })()""");
49 }
47 50
48 test1() { 51 test1() {
49 var f = makeFoo(); 52 var f = makeFoo();
50 f.a = 'Hi'; 53 f.a = 'Hi';
51 f.b = 'There'; 54 f.b = 'There';
52 Expect.equals('hi1 there', f.ab); 55 Expect.equals('hi1 there', f.ab);
53 } 56 }
54 57
55 test2() { 58 test2() {
56 // Test for CSE. dart2js currently does CSE loads. Is this the right choice? 59 // Test for CSE. dart2js currently does CSE loads. Is this the right choice?
(...skipping 28 matching lines...) Expand all
85 } 88 }
86 89
87 main() { 90 main() {
88 nativeTesting(); 91 nativeTesting();
89 setup(); 92 setup();
90 (test1)(); 93 (test1)();
91 (test2)(); 94 (test2)();
92 (test3)(); 95 (test3)();
93 (test4)(); 96 (test4)();
94 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698