Skip to content

Commit ca7dd96

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
[dart2js] fix crash in program emitter
The emitter creates classes in bulk, and then later connects them together except for adding stubs for JS-interop is checks. We assumed the class for JavaScriptObject was previously created and stored stubs eagerly while creating classes. We believe this caused a crash with flutter because the class was not yet defined in that case. One theory why this wasn't hit as much externally is that we sort classes by location and process dart:* classes first. Flutter is the first use case where JS-interop classes can be defined within SDK libraries. Fixes #42612 Fixes #25517 Change-Id: Icad0a9a16ec0d05481ed60f581a23c9eeb1ed5d3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153943 Commit-Queue: Sigmund Cherem <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
1 parent 16e607e commit ca7dd96

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class ProgramBuilder {
163163

164164
Set<Class> _unneededNativeClasses;
165165

166+
List<StubMethod> _jsInteropIsChecks = [];
167+
166168
/// Classes that have been allocated during a profile run.
167169
///
168170
/// These classes should not be soft-deferred.
@@ -492,6 +494,8 @@ class ProgramBuilder {
492494
// a method in the case where there exist multiple JavaScript classes
493495
// that conflict on whether the member is a getter or a method.
494496
Class interceptorClass = _classes[_commonElements.jsJavaScriptObjectClass];
497+
498+
interceptorClass?.isChecks?.addAll(_jsInteropIsChecks);
495499
Set<String> stubNames = {};
496500
librariesMap
497501
.forEach((LibraryEntity library, List<ClassEntity> classElements, _) {
@@ -750,9 +754,7 @@ class ProgramBuilder {
750754
// Currently we generate duplicates if a class is implemented by multiple
751755
// js-interop classes.
752756
typeTests.forEachProperty(_sorter, (js.Name name, js.Node code) {
753-
_classes[_commonElements.jsJavaScriptObjectClass]
754-
.isChecks
755-
.add(_buildStubMethod(name, code));
757+
_jsInteropIsChecks.add(_buildStubMethod(name, code));
756758
});
757759
} else {
758760
for (Field field in instanceFields) {

0 commit comments

Comments
 (0)