From 0947f85299102b262189ab309af9319b50379ca7 Mon Sep 17 00:00:00 2001 From: Mayank Patke Date: Wed, 15 Oct 2025 15:38:35 -0700 Subject: [PATCH] [benchmarks] Migrate off package:js This also allows the BigIntParsePrint benchmark to actually run on dart2wasm. Bug: #61550 Change-Id: I6a6a6964d95195e8e06fcecbcad776045dddc733 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453682 Reviewed-by: Srujan Gaddam --- .../dart/BigIntParsePrint.dart | 2 +- .../BigIntParsePrint/dart/native_version.dart | 24 ++++----- .../dart/native_version_dummy.dart | 2 +- .../dart/native_version_javascript.dart | 52 ++++++++++--------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/benchmarks/BigIntParsePrint/dart/BigIntParsePrint.dart b/benchmarks/BigIntParsePrint/dart/BigIntParsePrint.dart index df3f19ff3ed..6fdb2476be6 100644 --- a/benchmarks/BigIntParsePrint/dart/BigIntParsePrint.dart +++ b/benchmarks/BigIntParsePrint/dart/BigIntParsePrint.dart @@ -10,7 +10,7 @@ import 'package:benchmark_harness/benchmark_harness.dart'; import 'package:fixnum/fixnum.dart'; import 'native_version_dummy.dart' - if (dart.library.js) 'native_version_javascript.dart'; + if (dart.library.js_interop) 'native_version_javascript.dart'; // Benchmark BigInt and Int64 formatting and parsing. diff --git a/benchmarks/BigIntParsePrint/dart/native_version.dart b/benchmarks/BigIntParsePrint/dart/native_version.dart index cfc64fafc99..cc6ebcccfdb 100644 --- a/benchmarks/BigIntParsePrint/dart/native_version.dart +++ b/benchmarks/BigIntParsePrint/dart/native_version.dart @@ -2,22 +2,22 @@ // 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. -abstract class NativeBigIntMethods { +abstract class NativeBigIntMethods { bool get enabled; - Object parse(String string); - String toStringMethod(Object value); + T parse(String string); + String toStringMethod(T value); - Object fromInt(int i); + T fromInt(int i); - Object get one; - Object get eight; + T get one; + T get eight; - int bitLength(Object value); - bool isEven(Object value); + int bitLength(T value); + bool isEven(T value); - Object add(Object left, Object right); - Object shiftLeft(Object value, Object count); - Object shiftRight(Object value, Object count); - Object subtract(Object left, Object right); + T add(T left, T right); + T shiftLeft(T value, T count); + T shiftRight(T value, T count); + T subtract(T left, T right); } diff --git a/benchmarks/BigIntParsePrint/dart/native_version_dummy.dart b/benchmarks/BigIntParsePrint/dart/native_version_dummy.dart index b3b83ecf43f..f48cd1fe0c5 100644 --- a/benchmarks/BigIntParsePrint/dart/native_version_dummy.dart +++ b/benchmarks/BigIntParsePrint/dart/native_version_dummy.dart @@ -6,7 +6,7 @@ import 'native_version.dart'; const NativeBigIntMethods nativeBigInt = _DummyMethods(); -class _DummyMethods implements NativeBigIntMethods { +class _DummyMethods implements NativeBigIntMethods { const _DummyMethods(); @override diff --git a/benchmarks/BigIntParsePrint/dart/native_version_javascript.dart b/benchmarks/BigIntParsePrint/dart/native_version_javascript.dart index 71f29d10032..40a160926fc 100644 --- a/benchmarks/BigIntParsePrint/dart/native_version_javascript.dart +++ b/benchmarks/BigIntParsePrint/dart/native_version_javascript.dart @@ -3,45 +3,45 @@ // BSD-style license that can be found in the LICENSE file. @JS() -library native_version_javascript; +library; + +import 'dart:js_interop'; -// ignore: deprecated_member_use -import 'package:js/js.dart'; import 'native_version.dart'; const NativeBigIntMethods nativeBigInt = _Methods(); @JS('eval') -external Object _eval(String s); +external JSAny? _eval(String s); @JS('bigint_parse') -external Object _parse(String s); +external JSBigInt _parse(String s); @JS('bigint_toString') -external String _toStringMethod(Object o); +external String _toStringMethod(JSBigInt o); @JS('bigint_bitLength') -external int _bitLength(Object o); +external int _bitLength(JSBigInt o); @JS('bigint_isEven') -external bool _isEven(Object o); +external bool _isEven(JSBigInt o); @JS('bigint_add') -external Object _add(Object left, Object right); +external JSBigInt _add(JSBigInt left, JSBigInt right); @JS('bigint_shiftLeft') -external Object _shiftLeft(Object o, Object i); +external JSBigInt _shiftLeft(JSBigInt o, JSBigInt i); @JS('bigint_shiftRight') -external Object _shiftRight(Object o, Object i); +external JSBigInt _shiftRight(JSBigInt o, JSBigInt i); @JS('bigint_subtract') -external Object _subtract(Object left, Object right); +external JSBigInt _subtract(JSBigInt left, JSBigInt right); @JS('bigint_fromInt') -external Object _fromInt(int i); +external JSBigInt _fromInt(int i); -class _Methods implements NativeBigIntMethods { +class _Methods implements NativeBigIntMethods { static bool _initialized = false; static bool _enabled = false; @@ -71,37 +71,39 @@ class _Methods implements NativeBigIntMethods { } @override - Object parse(String string) => _parse(string); + JSBigInt parse(String string) => _parse(string); @override - String toStringMethod(Object value) => _toStringMethod(value); + String toStringMethod(JSBigInt value) => _toStringMethod(value); @override - Object fromInt(int i) => _fromInt(i); + JSBigInt fromInt(int i) => _fromInt(i); @override - Object get one => _one; + JSBigInt get one => _one; @override - Object get eight => _eight; + JSBigInt get eight => _eight; @override - int bitLength(Object value) => _bitLength(value); + int bitLength(JSBigInt value) => _bitLength(value); @override - bool isEven(Object value) => _isEven(value); + bool isEven(JSBigInt value) => _isEven(value); @override - Object add(Object left, Object right) => _add(left, right); + JSBigInt add(JSBigInt left, JSBigInt right) => _add(left, right); @override - Object shiftLeft(Object value, Object count) => _shiftLeft(value, count); + JSBigInt shiftLeft(JSBigInt value, JSBigInt count) => + _shiftLeft(value, count); @override - Object shiftRight(Object value, Object count) => _shiftRight(value, count); + JSBigInt shiftRight(JSBigInt value, JSBigInt count) => + _shiftRight(value, count); @override - Object subtract(Object left, Object right) => _subtract(left, right); + JSBigInt subtract(JSBigInt left, JSBigInt right) => _subtract(left, right); } void _setup() {