Skip to content

Dart2JS-compiled app failing with type error, succeeds with DDC #49797

Closed
@elliette

Description

@elliette

Getting a JS type error (TypeError: a.gdt is not a function) after compiling the Dart Debug Extension with dart2js, but not when compiling it with DDC.

The changes that triggered this are here: dart-lang/webdev#1729

Details:

Original Dart:
Future<bool> _tryAttach(
    int contextId, Tab tab, bool launchInChromeDevTools) async {
  final successCompleter = Completer<bool>();
  chrome.debugger.sendCommand(
      Debuggee(tabId: tab.id),
      'Runtime.evaluate',
      InjectedParams(
          expression:
              '[window.\$dartExtensionUri, window.\$dartAppId, window.\$dartAppInstanceId, window.\$dwdsVersion]',
          returnByValue: true,
          contextId: contextId), allowInterop((dynamic evalResponse) {
    final value = evalResponse?.result?.value;
    final extensionUri = value?[0] as String?;
    final appId = value?[1] as String?;
    final instanceId = value?[2] as String?;
    final dwdsVersion = value?[3] as String?;
    if (extensionUri == null || appId == null || instanceId == null) {
      window.console
          .warn('Unable to debug app. Missing Dart debugging global variables');
      successCompleter.complete(false);
      return;
    }
    _startSseClient(
      Uri.parse(extensionUri),
      appId,
      instanceId,
      contextId,
      tab,
      dwdsVersion ?? '0.0.0',
      launchInChromeDevTools,
    );
    successCompleter.complete(true);
  }));
  return successCompleter.future;
}
Dart2JS (fails):

Error is TypeError: a.gdt is not a function (8th line from bottom)

A.hr.prototype={
$1(a){var s,r=this.a
if(a==null){s=A.i9(null)
s.error=J.i6(self.JSON,J.cx(J.ay(self.chrome)))
r.$1(s)}else r.$1(a)},
$0(){return this.$1(null)},
$C:"$1",
$R:0,
$D(){return[null]},
$S:45}
A.i0.prototype={
$1(a){if(a==null)J.cx(J.ay(self.chrome))},
$0(){return this.$1(null)},
$C:"$1",
$R:0,
$D(){return[null]},
$S:46}
A.hE.prototype={
$1(a){var s
if(a!=null){s=a.gdt()
if(s!=null)s.gdG()}window.toString
s=typeof console!="undefined"
s.toString
if(s)window.console.warn("Unable to debug app. Missing Dart debugging global variables")
this.a.aW(!1)
return},
$S:2}
DDC (succeeds):
  background._tryAttach = function _tryAttach(contextId, tab, launchInChromeDevTools) {
    return async.async(core.bool, function* _tryAttach() {
      let successCompleter = T.CompleterOfbool().new();
      dart.global.chrome.debugger.sendCommand({tabId: tab.id}, "Runtime.evaluate", {expression: "[window.$dartExtensionUri, window.$dartAppId, window.$dartAppInstanceId, window.$dwdsVersion]", returnByValue: true, contextId: contextId}, js.allowInterop(core.Function, dart.fn(evalResponse => {
        let t3, t2, t2$, t2$0, t2$1, t2$2, t2$3;
        let value = (t2 = evalResponse, t2 == null ? null : (t3 = dart.dload(t2, 'result'), t3 == null ? null : dart.dload(t3, 'value')));
        let extensionUri = T.StringN().as((t2$ = value, t2$ == null ? null : dart.dsend(t2$, '_get', [0])));
        let appId = T.StringN().as((t2$0 = value, t2$0 == null ? null : dart.dsend(t2$0, '_get', [1])));
        let instanceId = T.StringN().as((t2$1 = value, t2$1 == null ? null : dart.dsend(t2$1, '_get', [2])));
        let dwdsVersion = T.StringN().as((t2$2 = value, t2$2 == null ? null : dart.dsend(t2$2, '_get', [3])));
        if (extensionUri == null || appId == null || instanceId == null) {
          html.window[$console].warn("Unable to debug app. Missing Dart debugging global variables");
          successCompleter.complete(false);
          return;
        }
        background._startSseClient(core.Uri.parse(extensionUri), appId, instanceId, contextId, tab, (t2$3 = dwdsVersion, t2$3 == null ? "0.0.0" : t2$3), launchInChromeDevTools);
        successCompleter.complete(true);
      }, T.dynamicToNull())));
      return successCompleter.future;
    });
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.dart2js-ddc-discrepancyWhen dev and production compilations have different semanticsweb-dev-compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions