From ee8abd0b88c60deecee2f35fa040032b663b7558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Tue, 26 Aug 2025 10:22:55 +0100 Subject: [PATCH] Fix JS interop annotations In a declaration like @JS('JSON') extension type _JSON._(JSObject _) implements JSObject { @JS('JSON.stringify') external static JSString _stringify(JSObject value); } When I call `_JSON._stringify(...)`, dart2js calls `JSON.stringify`, but dart2wasm calls `JSON.JSON.stringify`, which is wrong. Reading [1] it looks like the annotation `JSON.stringify` should just be `stringify`. If I do that the code works with both dart2wasm and dart2js. (I've reported dart2wasm's handling of the annotations above and we'll work on a fix for it on dart2wasm.) [1]: https://dart.dev/interop/js-interop/usage#js --- protobuf/lib/src/protobuf/json/json_web.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/protobuf/lib/src/protobuf/json/json_web.dart b/protobuf/lib/src/protobuf/json/json_web.dart index b0a8e2ec..6f3934bb 100644 --- a/protobuf/lib/src/protobuf/json/json_web.dart +++ b/protobuf/lib/src/protobuf/json/json_web.dart @@ -14,16 +14,16 @@ import '../utils.dart'; @JS('JSON') extension type _JSON._(JSObject _) implements JSObject { - @JS('JSON.stringify') + @JS('stringify') external static JSString _stringify(JSObject value); - @JS('JSON.parse') + @JS('parse') external static JSAny? _parse(JSString text); } @JS('Number') extension type _Number._(JSObject _) implements JSObject { - @JS('Number.isInteger') + @JS('isInteger') external static bool _isInteger(JSAny value); }