Files
sdk/tests/web/wasm/deferred_loading_js_callback_helper.dart
Nate Biggs 43f234799e [dart2wasm] Fix JS callback wrappers invoked in deferred modules.
The generated callback wrappers were referring to exported functions via
'dartInstance.exports' which is always the main module. But in order to
avoid bloating the main module we put some of these JS exports into
submodules.

So the wrapper must be fetched from the correct module that defines the
wrapped function. In order to facilitate this we give each module a
self-reference that it can then pass up to the JS wrapper as an
externref.

Change-Id: Id2514de2c13d38a0cee1f6c935e45a9ef826f805
Fixes: https://github.com/dart-lang/sdk/issues/62094
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464820
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-12-01 12:12:48 -08:00

21 lines
480 B
Dart

// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:js_interop';
int closureCalled = 0;
JSFunction? func;
void Function()? clos;
void deferredMain() {
void closure() {
closureCalled++;
}
final jsClosure = closure.toJS;
jsClosure.callAsFunction();
clos = closure;
func = jsClosure;
}