Files
sdk/pkg/dart2wasm/tool/run_benchmark
Ömer Ağacan 590b656877 [dart2wasm] Update JS exception catching
This updates JS exception catching as discussed in #55481:

- Only catch JS exceptions when the exception type is `dynamic`,
  `Object`, or an extension of `JSValue`. (nullable or not)

  (Previously we also caught JS exceptions when the type is `Error`.)

- When the JS value caught in Wasm is `null` or `undefined`, box it as a
  non-interop class. For compatibility with dart2js, this class is
  copied from dart2js and has the same `toString` as the dart2js class.

- In other cases: box the JS values as `JSValue`. This means the value
  can be passed as any of the interop types, and can be passed back to
  JS without manual jsification.

Fixes #55481.

Issue: https://github.com/dart-lang/sdk/issues/55481
Change-Id: I23e73074729f740b90df2ca8b3c713fb39966556
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479640
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2026-02-24 01:43:10 -08:00

102 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (c) 2022, 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.
# Script to run a benchmark compiled using dart2wasm. Assumes the Dart repo's
# directory structure.
#
# This is also used by the test runner.
set -e
function follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
PROG_NAME="$(follow_links "$BASH_SOURCE")"
# Handle the case where dart-sdk/bin has been symlinked to.
PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
source "$PROG_DIR/utils.sh"
RUN_WASM="$SDK_DIR/pkg/dart2wasm/bin/run_wasm.js"
function host_os() {
if [[ `uname` == 'Darwin' ]]; then
echo 'macos'
else
echo 'linux'
fi
}
D8_BIN="$SDK_DIR/third_party/d8/$(host_os)/$(get_host_arch)/d8"
JSSHELL_BIN="$SDK_DIR/third_party/firefox_jsshell/js"
JSC_BIN="$SDK_DIR/third_party/jsc/jsc"
SHELL_BIN="$D8_BIN"
SHELL_OPTIONS=()
SHELL_ARG_SEPERATOR="--"
MJS_FILE=""
WASM_FILE=""
LINEAR_WASM_FILES=()
EXTRA_JS_FILES=()
while [ $# -gt 0 ]; do
case "$1" in
--d8)
SHELL_BIN="$D8_BIN"
SHELL_ARG_SEPERATOR="--"
shift
;;
--jsshell)
SHELL_BIN="$JSSHELL_BIN"
SHELL_ARG_SEPERATOR=""
shift
;;
--jsc)
SHELL_BIN="$JSC_BIN"
SHELL_ARG_SEPERATOR="--"
shift
;;
--shell-option=*)
SHELL_OPTIONS+=("${1#--shell-option=}")
shift
;;
*.js)
EXTRA_JS_FILES+=("$1")
shift
;;
*.wasm)
if [ -z "$WASM_FILE" ]; then
# First wasm file is the actual dart program
WASM_FILE="$(get_realpath "$1")"
MJS_FILE="${WASM_FILE%.wasm}.mjs"
else
# Following wasm files are imported linear memory modules
LINEAR_WASM_FILES+=("$1")
fi
shift
;;
*)
# Any arguments that are not the above will be arguments to the dart's
# main function.
break
;;
esac
done
exec "$SHELL_BIN" "${SHELL_OPTIONS[@]}" "${EXTRA_JS_FILES[@]}" "$RUN_WASM" $SHELL_ARG_SEPERATOR "$MJS_FILE" "$WASM_FILE" "${LINEAR_WASM_FILES[@]}" -- "$@"