@@ -290,6 +290,7 @@ class WebEntrypointBuilder implements Builder {
290
290
if (! isAppEntrypoint) return ;
291
291
292
292
final compilationSteps = < Future > [];
293
+ Dart2WasmBootstrapResult ? dart2WasmResult;
293
294
294
295
for (final compiler in options.compilers) {
295
296
switch (compiler.compiler) {
@@ -311,17 +312,21 @@ class WebEntrypointBuilder implements Builder {
311
312
entrypointExtension: compiler.extension ,
312
313
));
313
314
case WebCompiler .Dart2Wasm :
314
- compilationSteps.add (bootstrapDart2Wasm (
315
- buildStep, compiler.compilerArguments, compiler.extension ));
315
+ compilationSteps.add (Future (() async {
316
+ dart2WasmResult = await bootstrapDart2Wasm (
317
+ buildStep, compiler.compilerArguments, compiler.extension );
318
+ }));
316
319
}
317
320
}
318
321
await Future .wait (compilationSteps);
319
- if (_generateLoader (buildStep.inputId) case (var id, var loader)? ) {
322
+ if (_generateLoader (buildStep.inputId, dart2WasmResult)
323
+ case (var id, var loader)? ) {
320
324
await buildStep.writeAsString (id, loader);
321
325
}
322
326
}
323
327
324
- (AssetId , String )? _generateLoader (AssetId input) {
328
+ (AssetId , String )? _generateLoader (
329
+ AssetId input, Dart2WasmBootstrapResult ? dart2WasmResult) {
325
330
var loaderExtension = options.loaderExtension;
326
331
var wasmCompiler = options.optionsFor (WebCompiler .Dart2Wasm );
327
332
if (loaderExtension == null || wasmCompiler == null ) {
@@ -350,17 +355,13 @@ function relativeURL(ref) {
350
355
// If we're compiling to JS, start a feature detection to prefer wasm but
351
356
// fall back to JS if necessary.
352
357
if (jsCompiler != null ) {
353
- loaderResult.writeln ('''
354
- function supportsWasmGC() {
355
- // This attempts to instantiate a wasm module that only will validate if the
356
- // final WasmGC spec is implemented in the browser.
357
- //
358
- // Copied from https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/gc/index.js
359
- const bytes = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 95, 1, 120, 0];
360
- return 'WebAssembly' in self && WebAssembly.validate(new Uint8Array(bytes));
361
- }
358
+ final supportCheck = dart2WasmResult? .supportExpression ??
359
+ "'WebAssembly' in self && "
360
+ 'WebAssembly.validate(new Uint8Array('
361
+ '[0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 95, 1, 120, 0]));' ;
362
362
363
- if (supportsWasmGC()) {
363
+ loaderResult.writeln ('''
364
+ if ($supportCheck ) {
364
365
''' );
365
366
}
366
367
0 commit comments