dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

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

Closed elliette closed 2 years ago

elliette commented 2 years ago

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: https://github.com/dart-lang/webdev/pull/1729

Details:

Original Dart: ``` Future _tryAttach( int contextId, Tab tab, bool launchInChromeDevTools) async { final successCompleter = Completer(); 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; }); }; ```
elliette commented 2 years ago

Got help offline from @srujzs, dart2js compilation works as expected if evalResponse is given a JS-interop type (change), therefore closing.