mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:56:57 +00:00
b101a7d002
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
51 lines
1.7 KiB
Dart
51 lines
1.7 KiB
Dart
// Copyright (c) 2019, 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.
|
|
|
|
// @dart = 2.9
|
|
|
|
// Test throwing exceptions from an imported function.
|
|
|
|
import "package:expect/expect.dart";
|
|
import "package:wasm/wasm.dart";
|
|
import "dart:typed_data";
|
|
|
|
void main() {
|
|
// void fn() {
|
|
// a();
|
|
// b();
|
|
// }
|
|
var data = Uint8List.fromList([
|
|
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
|
|
0x00, 0x00, 0x02, 0x11, 0x02, 0x03, 0x65, 0x6e, 0x76, 0x01, 0x61, 0x00,
|
|
0x00, 0x03, 0x65, 0x6e, 0x76, 0x01, 0x62, 0x00, 0x00, 0x03, 0x02, 0x01,
|
|
0x00, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00,
|
|
0x02, 0x06, 0x08, 0x01, 0x7f, 0x01, 0x41, 0x80, 0x88, 0x04, 0x0b, 0x07,
|
|
0x0f, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x02,
|
|
0x66, 0x6e, 0x00, 0x02, 0x0a, 0x10, 0x01, 0x0e, 0x00, 0x10, 0x80, 0x80,
|
|
0x80, 0x80, 0x00, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x0b,
|
|
]);
|
|
|
|
bool called_b = false;
|
|
var thrownException = Exception("Hello exception!");
|
|
var inst = WasmModule(data).instantiate().addFunction("env", "a", () {
|
|
throw thrownException;
|
|
}).addFunction("env", "b", () {
|
|
called_b = true;
|
|
}).build();
|
|
var fn = inst.lookupFunction("fn");
|
|
Expect.throws(() => fn(), (Exception e) => e == thrownException);
|
|
Expect.isFalse(called_b);
|
|
|
|
bool called_a = false;
|
|
inst = WasmModule(data).instantiate().addFunction("env", "a", () {
|
|
called_a = true;
|
|
}).addFunction("env", "b", () {
|
|
called_b = true;
|
|
}).build();
|
|
fn = inst.lookupFunction("fn");
|
|
fn();
|
|
Expect.isTrue(called_a);
|
|
Expect.isTrue(called_b);
|
|
}
|