-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 812d26f into dev
- Loading branch information
Showing
12 changed files
with
149 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/lib/js/static_interop_test/external_static_member_lowerings_trusttypes_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
@JS() | ||
library external_static_member_lowerings_trusttypes_test; | ||
|
||
// ignore: IMPORT_INTERNAL_LIBRARY | ||
import 'dart:_js_interop'; | ||
|
||
import 'package:expect/minitest.dart'; | ||
import 'package:js/js.dart' show trustTypes, staticInterop; | ||
|
||
@JS() | ||
external dynamic eval(String code); | ||
|
||
@JS('ExternalStatic') | ||
@staticInterop | ||
@trustTypes | ||
class ExternalStaticTrustType { | ||
external static double field; | ||
external static double get getSet; | ||
external static double method(); | ||
} | ||
|
||
// dart2js is smart enough to see that the expectations below will never be true | ||
// as the types are incompatible. Therefore, it optimizes the expectation code | ||
// to *always fail*, even if the values are the same! Since we're breaking | ||
// soundness with @trustTypes, we need to confuse dart2js enough that it doesn't | ||
// do those optimizations, hence this. | ||
@pragma('dart2js:noInline') | ||
@pragma('dart2js:assumeDynamic') | ||
confuse(x) => x; | ||
|
||
void main() { | ||
eval(''' | ||
globalThis.ExternalStatic = function ExternalStatic() {} | ||
globalThis.ExternalStatic.method = function() { | ||
return 'method'; | ||
} | ||
globalThis.ExternalStatic.field = 'field'; | ||
globalThis.ExternalStatic.getSet = 'getSet'; | ||
'''); | ||
|
||
// Use wrong return type in conjunction with `@trustTypes`. | ||
expect(confuse(ExternalStaticTrustType.field), 'field'); | ||
|
||
expect(confuse(ExternalStaticTrustType.getSet), 'getSet'); | ||
|
||
expect(confuse(ExternalStaticTrustType.method()), 'method'); | ||
expect(confuse((ExternalStaticTrustType.method)()), 'method'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/lib_2/js/static_interop_test/external_static_member_lowerings_trusttypes_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
@JS() | ||
library external_static_member_lowerings_trusttypes_test; | ||
|
||
// ignore: IMPORT_INTERNAL_LIBRARY | ||
import 'dart:_js_interop'; | ||
|
||
import 'package:expect/minitest.dart'; | ||
import 'package:js/js.dart' show trustTypes, staticInterop; | ||
|
||
@JS() | ||
external dynamic eval(String code); | ||
|
||
@JS('ExternalStatic') | ||
@staticInterop | ||
@trustTypes | ||
class ExternalStaticTrustType { | ||
external static double field; | ||
external static double get getSet; | ||
external static double method(); | ||
} | ||
|
||
// dart2js is smart enough to see that the expectations below will never be true | ||
// as the types are incompatible. Therefore, it optimizes the expectation code | ||
// to *always fail*, even if the values are the same! Since we're breaking | ||
// soundness with @trustTypes, we need to confuse dart2js enough that it doesn't | ||
// do those optimizations, hence this. | ||
@pragma('dart2js:noInline') | ||
@pragma('dart2js:assumeDynamic') | ||
confuse(x) => x; | ||
|
||
void main() { | ||
eval(''' | ||
globalThis.ExternalStatic = function ExternalStatic() {} | ||
globalThis.ExternalStatic.method = function() { | ||
return 'method'; | ||
} | ||
globalThis.ExternalStatic.field = 'field'; | ||
globalThis.ExternalStatic.getSet = 'getSet'; | ||
'''); | ||
|
||
// Use wrong return type in conjunction with `@trustTypes`. | ||
expect(confuse(ExternalStaticTrustType.field), 'field'); | ||
|
||
expect(confuse(ExternalStaticTrustType.getSet), 'getSet'); | ||
|
||
expect(confuse(ExternalStaticTrustType.method()), 'method'); | ||
expect(confuse((ExternalStaticTrustType.method)()), 'method'); | ||
} |
Oops, something went wrong.