Skip to content

Commit 8d971e1

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
[ddc] do not enforce assertInterop on native methods from native tests
Change-Id: I3819da5708bc8a7f21d14d5531d9178c05839f45 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178140 Commit-Queue: Sigmund Cherem <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 9837afa commit 8d971e1

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

pkg/dev_compiler/lib/src/compiler/shared_compiler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
482482
/// Emits imports and extension methods into [items].
483483
@protected
484484
void emitImportsAndExtensionSymbols(List<js_ast.ModuleItem> items,
485-
{bool forceExtensionSymbols: false}) {
485+
{bool forceExtensionSymbols = false}) {
486486
var modules = <String, List<Library>>{};
487487

488488
for (var import in _imports.keys) {

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
24602460
js_ast.PropertyAccess _emitTopLevelNameNoInterop(NamedNode n,
24612461
{String suffix = ''}) {
24622462
// Some native tests use top-level native methods.
2463-
var isTopLevelNative = n is Member && _isNative(n);
2463+
var isTopLevelNative = n is Member && isNative(n);
24642464
return js_ast.PropertyAccess(
24652465
isTopLevelNative
24662466
? runtimeCall('global.self')
@@ -6229,31 +6229,3 @@ class _SwitchLabelState {
62296229

62306230
_SwitchLabelState(this.label, this.variable);
62316231
}
6232-
6233-
/// Whether [member] is declared native, as in:
6234-
///
6235-
/// void foo() native;
6236-
///
6237-
/// This syntax is only allowed in sdk libraries like `dart:html` and native
6238-
/// tests.
6239-
bool _isNative(Member member) {
6240-
// The CFE represents `native` members with the `external` bit and with an
6241-
// internal @ExternalName annotation.
6242-
if (member.isExternal &&
6243-
allowedNativeTest(member.enclosingLibrary.importUri)) {
6244-
for (var annotation in member.annotations) {
6245-
if (annotation is ConstantExpression) {
6246-
var constant = annotation.constant;
6247-
if (constant is InstanceConstant &&
6248-
constant.classNode.name == 'ExternalName' &&
6249-
_isDartInternal(constant.classNode.enclosingLibrary.importUri)) {
6250-
return true;
6251-
}
6252-
}
6253-
}
6254-
}
6255-
return false;
6256-
}
6257-
6258-
bool _isDartInternal(Uri uri) =>
6259-
uri.scheme == 'dart' && uri.path == '_internal';

pkg/dev_compiler/lib/src/kernel/js_interop.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ bool isAllowInterop(Expression node) {
4545
bool isJsMember(Member member) {
4646
// TODO(vsm): If we ever use external outside the SDK for non-JS interop,
4747
// we're need to fix this.
48-
return !_isLibrary(member.enclosingLibrary, ['dart:*']) && member.isExternal;
48+
return !_isLibrary(member.enclosingLibrary, ['dart:*']) &&
49+
member.isExternal &&
50+
!isNative(member);
4951
}
5052

5153
bool _annotationIsFromJSLibrary(String expectedName, Expression value) {

pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,28 @@ bool isKnownDartTypeImplementor(DartType t) {
353353
t is TypedefType ||
354354
t is VoidType;
355355
}
356+
357+
/// Whether [member] is declared native, as in:
358+
///
359+
/// void foo() native;
360+
///
361+
/// This syntax is only allowed in sdk libraries and native tests.
362+
bool isNative(Member member) =>
363+
// The CFE represents `native` members with the `external` bit and with an
364+
// internal @ExternalName annotation as a marker.
365+
member.isExternal && member.annotations.any(_isNativeMarkerAnnotation);
366+
367+
bool _isNativeMarkerAnnotation(Expression annotation) {
368+
if (annotation is ConstantExpression) {
369+
var constant = annotation.constant;
370+
if (constant is InstanceConstant &&
371+
constant.classNode.name == 'ExternalName' &&
372+
_isDartInternal(constant.classNode.enclosingLibrary.importUri)) {
373+
return true;
374+
}
375+
}
376+
return false;
377+
}
378+
379+
bool _isDartInternal(Uri uri) =>
380+
uri.scheme == 'dart' && uri.path == '_internal';

0 commit comments

Comments
 (0)