Skip to content

Commit 9837afa

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
[web] partial migration of native tests to support dartdevc
Most files are changed in two ways: * add `self.` so that the code can run with "use strict" (which ddc does by default when generating code) * call the js-helper that installs the interceptor/type-extensions in DDC on each test. This was mostly done mechanically and gets about 50% of the tests under dart2js/native running and passing in dartdevc. There are, however, many tests here that are dart2js-specific or for features we don't want to prioritize at this time (like custom elements), so after this the next step should probably be to reoarganize the tests and split them in general native support vs dart2js-specific. Change-Id: I37759d854f9f51c185789471454d37b6bc78af90 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177821 Reviewed-by: Stephen Adams <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 90e6fd4 commit 9837afa

File tree

185 files changed

+515
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+515
-358
lines changed

sdk/lib/_internal/js_dev_runtime/private/interceptors.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,8 @@ findInterceptorConstructorForType(Type? type) {}
239239
findConstructorForNativeSubclassType(Type? type, String name) {}
240240
getNativeInterceptor(object) {}
241241
setDispatchProperty(object, value) {}
242+
243+
// Added to allow dart2js and dartdevc to share tests
244+
// TODO(sigmund): revisit whether this method is still needed after reoganizing
245+
// all web tests.
246+
findInterceptorForType(Type? type) {}

tests/dart2js/native/abstract_class_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ void setup() {
2727
function A(){}
2828
function B(){}
2929
B.prototype.foo = function() { return 'B.foo'; };
30-
makeA = function(){return new A()};
31-
makeB = function(){return new B()};
30+
self.makeA = function(){return new A()};
31+
self.makeB = function(){return new B()};
3232
self.nativeConstructor(A);
3333
self.nativeConstructor(B);
34-
})()
35-
""");
34+
})()""");
35+
applyTestExtensions(['A', 'B']);
3636
}
3737

3838
main() {

tests/dart2js/native/bound_closure_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ void setup() {
4040
return 'CC.foo(' + u + ', ' + v + ')';
4141
};
4242
43-
makeBB = function(){return new BB()};
44-
makeCC = function(){return new CC()};
45-
inscrutable = function(a){return a;};
43+
self.makeBB = function(){return new BB()};
44+
self.makeCC = function(){return new CC()};
45+
self.inscrutable = function(a){return a;};
4646
4747
self.nativeConstructor(BB);
4848
self.nativeConstructor(CC);
4949
})()""");
50+
applyTestExtensions(['BB', 'CC']);
5051
}
5152

5253
main() {

tests/dart2js/native/browser_compat_1_prepatched_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void setup() {
3737
window.T1A = T1A;
3838
window.T1CrazyB = T1CrazyB;
3939
40-
makeT1A = function(){return new T1A()};
41-
makeT1B = function(){return new T1CrazyB()};
42-
makeT1C = function(){return new T1fakeA()};
40+
self.makeT1A = function(){return new T1A()};
41+
self.makeT1B = function(){return new T1CrazyB()};
42+
self.makeT1C = function(){return new T1fakeA()};
4343
4444
self.nativeConstructor(T1A);
4545
self.nativeConstructor(T1CrazyB);
@@ -71,6 +71,7 @@ void setup() {
7171
7272
dartNativeDispatchHooksTransformer = [transformer1];
7373
})()''');
74+
applyTestExtensions(['T1A', 'T1CrazyB', 'T1fakeA']);
7475
}
7576

7677
main() {

tests/dart2js/native/browser_compat_1_unpatched_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void setup() {
3838
window.T1A = T1A;
3939
window.T1CrazyB = T1CrazyB;
4040
41-
makeT1A = function(){return new T1A()};
42-
makeT1B = function(){return new T1CrazyB()};
43-
makeT1C = function(){return new T1fakeA()};
41+
self.makeT1A = function(){return new T1A()};
42+
self.makeT1B = function(){return new T1CrazyB()};
43+
self.makeT1C = function(){return new T1fakeA()};
4444
4545
self.nativeConstructor(T1A);
4646
self.nativeConstructor(T1CrazyB);
@@ -74,6 +74,7 @@ void setup() {
7474
7575
dartNativeDispatchHooksTransformer = [transformer1];
7676
})()""");
77+
applyTestExtensions(['T1A', 'T1CrazyB', 'T1fakeA']);
7778
}
7879

7980
main() {

tests/dart2js/native/browser_compat_2_test.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ T1B.prototype.name = function() { return "B"; };
5959
T1C.prototype.name = function() { return "C"; };
6060
T1D.prototype.name = function() { return "D"; };
6161
62-
makeT1A = function(){return new T1A()};
63-
makeT1B = function(){return new T1B()};
64-
makeT1C = function(){return new T1C()};
65-
makeT1D = function(){return new T1D()};
62+
self.makeT1A = function(){return new T1A()};
63+
self.makeT1B = function(){return new T1B()};
64+
self.makeT1C = function(){return new T1C()};
65+
self.makeT1D = function(){return new T1D()};
6666
6767
self.nativeConstructor(T1A);
6868
self.nativeConstructor(T1B);
6969
self.nativeConstructor(T1C);
7070
self.nativeConstructor(T1D);
7171
7272
var getTagCount = 0;
73-
getTagCallCount = function() { return getTagCount; };
74-
clearTagCallCount = function() { getTagCount = 0; };
73+
self.getTagCallCount = function() { return getTagCount; };
74+
self.clearTagCallCount = function() { getTagCount = 0; };
7575
7676
function transformer1(hooks) {
7777
var getTag = hooks.getTag;
@@ -102,8 +102,9 @@ function transformer2(hooks) {
102102
hooks.getTag = getTagNew;
103103
}
104104
105-
dartNativeDispatchHooksTransformer = [transformer1, transformer2];
105+
self.dartNativeDispatchHooksTransformer = [transformer1, transformer2];
106106
})()''');
107+
applyTestExtensions(['T1A', 'T1B', 'T1C', 'T1D']);
107108
}
108109

109110
main() {

tests/dart2js/native/core_type_check_native_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ void setup() {
3131
JS('', r"""
3232
(function(){
3333
function A() {};
34-
makeA = function() { return new A(); };
34+
self.makeA = function() { return new A(); };
3535
function B() {};
36-
makeB = function() { return new B(); };
36+
self.makeB = function() { return new B(); };
3737
function C() {};
38-
makeC = function() { return new C(); };
38+
self.makeC = function() { return new C(); };
3939
function D() {};
40-
makeD = function() { return new D(); };
40+
self.makeD = function() { return new D(); };
4141
4242
self.nativeConstructor(A);
4343
self.nativeConstructor(B);
4444
self.nativeConstructor(C);
4545
self.nativeConstructor(D);
46-
})()
47-
""");
46+
})()""");
47+
applyTestExtensions(['A', 'B', 'C', 'D']);
4848
}
4949

5050
checkTest(value, expectComparable, expectPattern) {

tests/dart2js/native/dispatch_property_initialization_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void setup() {
2323
2424
self.nativeConstructor(Foo);
2525
})()""");
26+
applyTestExtensions(['Foo']);
2627
}
2728

2829
main() {

tests/dart2js/native/downcast_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ function B(){}
4646
inherits(B, A);
4747
A.prototype.read = function() { return this._x; };
4848
A.prototype.write = function(x) { this._x = x; };
49-
makeA = function(){return new A()};
50-
makeB = function(){return new B()};
49+
self.makeA = function(){return new A()};
50+
self.makeB = function(){return new B()};
5151
5252
self.nativeConstructor(A);
5353
self.nativeConstructor(B);
5454
})()""");
55+
applyTestExtensions(['A', 'B']);
5556
}
5657

5758
class C {}

tests/dart2js/native/error_safeToString_test.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,46 @@ makeR() native;
3636
void setup() {
3737
JS('', r"""
3838
(function(){
39-
makeA = function(){return {hello: 123};};
39+
self.makeA = function(){return {hello: 123};};
4040
4141
function BB(){}
42-
makeB = function(){return new BB();};
42+
self.makeB = function(){return new BB();};
4343
4444
function CC(){}
45-
makeC = function(){
45+
self.makeC = function(){
4646
var x = new CC();
4747
x.constructor = null; // Foils constructor lookup.
4848
return x;
4949
};
5050
5151
function DD(){}
52-
makeD = function(){
52+
self.makeD = function(){
5353
var x = new DD();
5454
x.constructor = {name: 'DDxxx'}; // Foils constructor lookup.
5555
return x;
5656
};
5757
5858
function EE(){}
59-
makeE = function(){
59+
self.makeE = function(){
6060
var x = new EE();
6161
x.constructor = function Liar(){}; // Looks like a legitimate constructor.
6262
return x;
6363
};
6464
6565
function PPPP(){}
66-
makeP = function(){return new PPPP();};
66+
self.makeP = function(){return new PPPP();};
6767
6868
function QQQQ(){}
69-
makeQ = function(){return new QQQQ();};
69+
self.makeQ = function(){return new QQQQ();};
7070
7171
function RRRR(){}
72-
makeR = function(){return new RRRR();};
72+
self.makeR = function(){return new RRRR();};
7373
7474
self.nativeConstructor(PPPP);
7575
self.nativeConstructor(QQQQ);
7676
self.nativeConstructor(RRRR);
7777
})()""");
78+
applyTestExtensions(['PPPP', 'QQQQ', 'RRRR']);
7879
}
7980

8081
expectTypeName(expectedName, s) {

tests/dart2js/native/event_loop_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ void setup() {
2020
(function(){
2121
function A() {}
2222
A.prototype.foo = function(f) { return f(); };
23-
makeA = function() { return new A(); };
23+
self.makeA = function() { return new A(); };
2424
self.nativeConstructor(A);
2525
})()""");
26+
applyTestExtensions(['A']);
2627
}
2728

2829
main() {

tests/dart2js/native/fake_thing_2_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ void setup() {
2323
(function(){
2424
function A() {}
2525
A.prototype.$isThing = true;
26-
make1 = function(){return new A()};
27-
make2 = function(){return {$isThing: true}};
26+
self.make1 = function(){return new A()};
27+
self.make2 = function(){return {$isThing: true}};
2828
function NT() {}
2929
NT.prototype.$isThing = true;
30-
make3 = function(){return new NT()};
30+
self.make3 = function(){return new NT()};
3131
3232
self.nativeConstructor(NT);
3333
})()""");
34+
applyTestExtensions(['NT']);
3435
}
3536

3637
main() {

tests/dart2js/native/fake_thing_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ void setup() {
2121
(function(){
2222
function A() {}
2323
A.prototype.$isThing = true;
24-
make1 = function(){return new A();};
25-
make2 = function(){return {$isThing: true}};
24+
self.make1 = function(){return new A();};
25+
self.make2 = function(){return {$isThing: true}};
2626
})()""");
2727
}
2828

tests/dart2js/native/field_type2_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void setup() {
1919
(function(){
2020
// This code is all inside 'setup' and so not accessible from the global scope.
2121
function Node(parent){ this.parentNode = parent; }
22-
makeNode = function(p){return new Node(p);};
22+
self.makeNode = function(p){return new Node(p);};
2323
2424
self.nativeConstructor(Node);
2525
})()""");
26+
applyTestExtensions(['Node']);
2627
}
2728

2829
main() {

tests/dart2js/native/field_type_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ void setup() {
4848
(function(){
4949
// This code is inside 'setup' and so not accessible from the global scope.
5050
function Node(parent){ this.parentNode = parent; }
51-
makeNode = function(p){return new Node(p);};
51+
self.makeNode = function(p){return new Node(p);};
5252
self.nativeConstructor(Node);
5353
})()""");
54+
applyTestExtensions(['Node']);
5455
}
5556

5657
main() {

tests/dart2js/native/fixup_get_tag_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ void setup() {
3333
function B(){ }
3434
B.prototype.token = function () { return 'isB'; };
3535
36-
makeA = function() { return new A(); };
37-
makeB = function() { return new B(); };
36+
self.makeA = function() { return new A(); };
37+
self.makeB = function() { return new B(); };
3838
3939
self.nativeConstructor(A);
4040
})()""");
41+
applyTestExtensions(['A']);
4142
}
4243

4344
makeA() native;

tests/dart2js/native/foreign_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void main() {
3333
// Ensure there will be isNaN and NaN variable names.
3434
var isNaN = called ? 42 : 44;
3535
var NaN = called ? 52 : 54;
36-
Expect.isFalse(JS('bool', 'isNaN(#)', isNaN));
37-
Expect.isFalse(JS('bool', 'isNaN(#)', NaN));
38-
Expect.isTrue(JS('bool', 'isNaN(#)', double.nan));
36+
Expect.isFalse(JS('bool', 'self.isNaN(#)', isNaN));
37+
Expect.isFalse(JS('bool', 'self.isNaN(#)', NaN));
38+
Expect.isTrue(JS('bool', 'self.isNaN(#)', double.nan));
3939
}

tests/dart2js/native/hash_code_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ void setup() {
2020
(function(){
2121
function A() {}
2222
function B() {}
23-
makeA = function(){return new A()};
24-
makeB = function(){return new B()};
23+
self.makeA = function(){return new A()};
24+
self.makeB = function(){return new B()};
2525
2626
self.nativeConstructor(A);
2727
self.nativeConstructor(B);
2828
})()""");
29+
applyTestExtensions(['A', 'B']);
2930
}
3031

3132
main() {

tests/dart2js/native/issue9182_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ void setup() {
2828
JS('', r"""
2929
(function(){
3030
function A(){}
31-
makeA = function() { return new A() };
31+
self.makeA = function() { return new A() };
3232
self.nativeConstructor(A);
3333
})()""");
34+
applyTestExtensions(['A']);
3435
}
3536

3637
makeA() native;

tests/dart2js/native/jsobject_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ makeQ() native;
2727
void setup() {
2828
JS('', r"""
2929
(function(){
30-
makeA = function(){return {hello: 123};};
30+
self.makeA = function(){return {hello: 123};};
3131
3232
function BB(){}
33-
makeB = function(){return new BB();};
33+
self.makeB = function(){return new BB();};
3434
3535
function QQ(){}
36-
makeQ = function(){return new QQ();};
36+
self.makeQ = function(){return new QQ();};
3737
3838
self.nativeConstructor(QQ);
3939
})()""");
40+
applyTestExtensions(['QQ']);
4041
}
4142

4243
class Is<T> {

tests/dart2js/native/name_conflict_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ void setup() {
3535
function I(){}
3636
I.prototype.read = function() { return this._x; };
3737
I.prototype.write = function(x) { this._x = x; };
38-
makeI = function(){return new I()};
38+
self.makeI = function(){return new I()};
3939
self.nativeConstructor(I);
4040
})()""");
41+
applyTestExtensions(['I']);
4142
}
4243

4344
// A pure Dart implementation of I.

tests/dart2js/native/native_call_arity1_frog_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ void setup() {
3737
function B() {}
3838
B.prototype.foo = function () { return arguments.length; };
3939
40-
makeA = function(){return new A()};
41-
makeB = function(){return new B()};
40+
self.makeA = function(){return new A()};
41+
self.makeB = function(){return new B()};
4242
4343
self.nativeConstructor(A);
4444
self.nativeConstructor(B);
4545
})()""");
46+
applyTestExtensions(['A', 'B']);
4647
}
4748

4849
testDynamicContext() {

0 commit comments

Comments
 (0)