Skip to content

Commit 9bb446a

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Record if MethodDeclaration has NativeFunctionBody, so it external.
This fixes the issue with failing DDC tests like this: co19_2/LayoutTests/fast/media/matchmedium-query-api_t01 [email protected], [email protected] TypeError: html.window.styleMedia[$matchMedium] is not a function Change-Id: Ic7a80c53122cdc3e0bcce835b5717413e342ce74 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111862 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 0e24437 commit 9bb446a

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_flags.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ class AstBinaryFlags {
166166
TypedLiteral,
167167
);
168168

169+
static final _isNative = _checkBit(
170+
8,
171+
MethodDeclaration,
172+
);
173+
169174
static final _isNew = _checkBit(
170175
0,
171176
InstanceCreationExpression,
@@ -246,6 +251,7 @@ class AstBinaryFlags {
246251
bool isGet: false,
247252
bool isLate: false,
248253
bool isMap: false,
254+
bool isNative: false,
249255
bool isNew: false,
250256
bool isOperator: false,
251257
bool isRequired: false,
@@ -338,6 +344,9 @@ class AstBinaryFlags {
338344
if (isMap) {
339345
result |= _isMap;
340346
}
347+
if (isNative) {
348+
result |= _isNative;
349+
}
341350
if (isNew) {
342351
result |= _isNew;
343352
}
@@ -476,6 +485,10 @@ class AstBinaryFlags {
476485
return (flags & _isMap) != 0;
477486
}
478487

488+
static bool isNative(int flags) {
489+
return (flags & _isNative) != 0;
490+
}
491+
479492
static bool isNew(int flags) {
480493
return (flags & _isNew) != 0;
481494
}

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,15 @@ class AstBinaryReader {
11081108
}
11091109

11101110
MethodDeclaration _read_methodDeclaration(LinkedNode data) {
1111+
FunctionBody body;
1112+
if (AstBinaryFlags.isNative(data.flags)) {
1113+
body = AstTestFactory.nativeFunctionBody('');
1114+
} else if (AstBinaryFlags.isAbstract(data.flags)) {
1115+
body = AstTestFactory.emptyFunctionBody();
1116+
} else {
1117+
body = AstTestFactory.blockFunctionBody(AstTestFactory.block());
1118+
}
1119+
11111120
var node = astFactory.methodDeclaration(
11121121
_readDocumentationComment(data),
11131122
_readNodeListLazy(data.annotatedNode_metadata),
@@ -1124,9 +1133,7 @@ class AstBinaryReader {
11241133
_declaredIdentifier(data),
11251134
_readNode(data.methodDeclaration_typeParameters),
11261135
_readNodeLazy(data.methodDeclaration_formalParameters),
1127-
AstBinaryFlags.isAbstract(data.flags)
1128-
? AstTestFactory.emptyFunctionBody()
1129-
: AstTestFactory.blockFunctionBody(AstTestFactory.block()),
1136+
body,
11301137
);
11311138
LazyMethodDeclaration.setData(node, data);
11321139
return node;

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ class AstBinaryWriter extends ThrowingAstVisitor<LinkedNodeBuilder> {
924924
isExternal: node.externalKeyword != null,
925925
isGenerator: node.body?.isGenerator ?? false,
926926
isGet: node.isGetter,
927+
isNative: node.body is NativeFunctionBody,
927928
isOperator: node.operatorKeyword != null,
928929
isSet: node.isSetter,
929930
isStatic: node.isStatic,

pkg/analyzer/lib/src/summary2/linked_unit_context.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ class LinkedUnitContext {
779779
} else if (node is FunctionDeclaration) {
780780
return node.externalKeyword != null;
781781
} else if (node is MethodDeclaration) {
782-
return node.externalKeyword != null;
782+
return node.externalKeyword != null || node.body is NativeFunctionBody;
783783
} else {
784784
throw UnimplementedError('${node.runtimeType}');
785785
}
@@ -831,6 +831,14 @@ class LinkedUnitContext {
831831
throw UnimplementedError('${node.runtimeType}');
832832
}
833833

834+
bool isNative(AstNode node) {
835+
if (node is MethodDeclaration) {
836+
return node.body is NativeFunctionBody;
837+
} else {
838+
throw UnimplementedError('${node.runtimeType}');
839+
}
840+
}
841+
834842
bool isSetter(AstNode node) {
835843
if (node is FunctionDeclaration) {
836844
return node.isSetter;

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,19 @@ class C {
11071107
''');
11081108
}
11091109

1110+
test_class_getter_native() async {
1111+
var library = await checkLibrary('''
1112+
class C {
1113+
int get x() native;
1114+
}
1115+
''');
1116+
checkElementText(library, r'''
1117+
class C {
1118+
external int get x;
1119+
}
1120+
''');
1121+
}
1122+
11101123
test_class_getter_static() async {
11111124
var library = await checkLibrary('class C { static int get x => null; }');
11121125
checkElementText(library, r'''
@@ -1221,6 +1234,19 @@ class B extends A {
12211234
''');
12221235
}
12231236

1237+
test_class_method_native() async {
1238+
var library = await checkLibrary('''
1239+
class C {
1240+
int m() native;
1241+
}
1242+
''');
1243+
checkElementText(library, r'''
1244+
class C {
1245+
external int m() {}
1246+
}
1247+
''');
1248+
}
1249+
12241250
test_class_method_params() async {
12251251
var library = await checkLibrary('class C { f(x, y) {} }');
12261252
checkElementText(library, r'''
@@ -1621,6 +1647,19 @@ class C {
16211647
''');
16221648
}
16231649

1650+
test_class_setter_native() async {
1651+
var library = await checkLibrary('''
1652+
class C {
1653+
void set x(int value) native;
1654+
}
1655+
''');
1656+
checkElementText(library, r'''
1657+
class C {
1658+
external void set x(int value);
1659+
}
1660+
''');
1661+
}
1662+
16241663
test_class_setter_static() async {
16251664
var library =
16261665
await checkLibrary('class C { static void set x(int value) {} }');

0 commit comments

Comments
 (0)