Skip to content

dart2js crashes with NoSuchMethodError on JS-interop code #42612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yjbanov opened this issue Jul 7, 2020 · 6 comments
Closed

dart2js crashes with NoSuchMethodError on JS-interop code #42612

yjbanov opened this issue Jul 7, 2020 · 6 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. customer-dart2js customer-flutter dart2js-crash P1 A high priority bug; for example, a single project is unusable or has many test failures web-js-interop Issues that impact all js interop

Comments

@yjbanov
Copy link

yjbanov commented Jul 7, 2020

I'm getting the following error trying to compile a Flutter app with engine changes in flutter/engine@4776107.

Target dart2js failed: Exception: Unhandled exception:                  
NoSuchMethodError: The getter 'isChecks' was called on null.
Receiver: null
Tried calling: isChecks
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      ProgramBuilder._buildClass.<anonymous closure> (package:compiler/src/js_emitter/program_builder/program_builder.dart:754:14)
#2      TypeTestProperties.forEachProperty.handleTypeTest (package:compiler/src/js_emitter/runtime_type_generator.dart:73:8)
#3      TypeTestProperties.forEachProperty (package:compiler/src/js_emitter/runtime_type_generator.dart:78:21)
#4      ProgramBuilder._buildClass (package:compiler/src/js_emitter/program_builder/program_builder.dart:752:17)
#5      List.forEach (dart:core-patch/growable_array.dart:290:8)
#6      ProgramBuilder.buildProgram.<anonymous closure> (package:compiler/src/js_emitter/program_builder/program_builder.dart:197:15)
#7      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
#8      ProgramBuilder.buildProgram (package:compiler/src/js_emitter/program_builder/program_builder.dart:196:10)
#9      EmitterImpl.emitProgram.<anonymous closure> (package:compiler/src/js_emitter/startup_emitter/emitter.dart:193:29)
#10     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:179:35)
#11     EmitterImpl.emitProgram (package:compiler/src/js_emitter/startup_emitter/emitter.dart:192:29)
#12     CodeEmitterTask.assembleProgram.<anonymous closure> (package:compiler/src/js_emitter/code_emitter_task.dart:147:26)
#13     CompilerTask.measure (package:compiler/src/common/tasks.dart:64:51)
#14     CodeEmitterTask.assembleProgram (package:compiler/src/js_emitter/code_emitter_task.dart:117:12)
#15     JsBackendStrategy.assembleProgram (package:compiler/src/js_model/js_strategy.dart:359:35)
#16     Compiler.runCodegenEnqueuer (package:compiler/src/compiler.dart:390:39)
#17     Compiler.generateJavaScriptCode (package:compiler/src/compiler.dart:284:9)
#18     Compiler.compileFromKernel.<anonymous closure> (package:compiler/src/compiler.dart:432:9)
#19     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:179:35)
#20     Compiler.compileFromKernel (package:compiler/src/compiler.dart:405:14)
#21     Compiler.runInternal (package:compiler/src/compiler.dart:257:13)
<asynchronous suspension>
#22     Compiler.run.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:212:38)
#23     new Future.sync (dart:async/future.dart:223:31)
#24     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:212:20)
#25     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:179:35)
#26     Compiler.run (package:compiler/src/compiler.dart:209:41)
#27     CompilerImpl.run.<anonymous closure>.<anonymous closure> (package:compiler/src/apiimpl.dart:91:22)
#28     _RootZone.runUnary (dart:async/zone.dart:1450:54)
#29     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#30     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#31     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#32     Future._completeWithValue (dart:async/future_impl.dart:529:5)
#33     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#34     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#35     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#36     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#37     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)

The pattern that seems to be triggering the error is the one we use to convert between Dart-side enums to an enum-like API in the CanvasKit JavaScript library. Here's an example:

@JS()
class SkFilterQualityEnum {
  external SkFilterQuality get None;
  external SkFilterQuality get Low;
  external SkFilterQuality get Medium;
  external SkFilterQuality get High;
}

@JS()
class SkFilterQuality {
  external int get value;
}

final List<SkFilterQuality> _skFilterQualitys = <SkFilterQuality>[
  canvasKitJs.FilterQuality.None,
  canvasKitJs.FilterQuality.Low,
  canvasKitJs.FilterQuality.Medium,
  canvasKitJs.FilterQuality.High,
];

SkFilterQuality toSkFilterQuality(ui.FilterQuality filterQuality) {
  return _skFilterQualitys[filterQuality.index];
}

If I comment out all usages of toSkFilterQuality (and similar functions) dart2js is happy.

/cc @rakudrama @fishythefish

@yjbanov yjbanov added web-js-interop Issues that impact all js interop customer-flutter dart2js-crash customer-dart2js crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop labels Jul 7, 2020
@yjbanov
Copy link
Author

yjbanov commented Jul 7, 2020

I changed the line

to the following:

        _classes[_commonElements.jsJavaScriptObjectClass]
            ?.isChecks
            ?.add(_buildStubMethod(name, code));

The code compiled and ran correctly, although I've no idea if this is a full fix.

@vsmenon vsmenon added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Jul 7, 2020
@vsmenon
Copy link
Member

vsmenon commented Jul 7, 2020

@sigmundch - looks like this is blocking FW. Is Yegor's fix a reasonable temporary workaround?

@yjbanov
Copy link
Author

yjbanov commented Jul 9, 2020

Is there an update for this issue? This is blocking flutter/engine#19562 and other upcoming Flutter web engine work.

@sigmundch
Copy link
Member

@yjbanov thanks for the ping, nothing to report, but we have one idea to try out. We'll reach out a bit later today with something to test on your end

@sigmundch
Copy link
Member

@yjbanov - could you try patching https://dart-review.googlesource.com/c/sdk/+/153943 and see if that resolves the issue?

@yjbanov
Copy link
Author

yjbanov commented Jul 11, 2020

Thanks for fixing this, @sigmundch !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. customer-dart2js customer-flutter dart2js-crash P1 A high priority bug; for example, a single project is unusable or has many test failures web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

3 participants