[ddc] Attaching default type arg member signatures to JS native types.
Fixes 'member not found' issues arising from accessing default type arguments from JS literals.
Change-Id: I7cdfddcd70ee42a2941c8cb666570e161077281b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307513
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
diff --git a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart
index c64b8c3..3a40702 100644
--- a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart
+++ b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart
@@ -484,8 +484,10 @@
final _extensionMap = JS('', 'new Map()');
+/// Adds Dart properties to native JS types.
void _applyExtension(jsType, dartExtType) {
- // TODO(vsm): Not all registered js types are real.
+ // Exit early when encountering a JS type without a prototype (such as
+ // structs).
if (jsType == null) return;
var jsProto = JS<Object?>('', '#.prototype', jsType);
if (jsProto == null) return;
@@ -509,7 +511,11 @@
if (JS('!', '# !== #', dartExtType, JS_CLASS_REF(JSFunction))) {
JS('', '#[#] = #', jsProto, _extensionType, dartExtType);
}
+
+ // Attach member signature tags.
JS('', '#[#] = #[#]', jsType, _methodSig, dartExtType, _methodSig);
+ JS('', '#[#] = #[#]', jsType, _methodsDefaultTypeArgSig, dartExtType,
+ _methodsDefaultTypeArgSig);
JS('', '#[#] = #[#]', jsType, _fieldSig, dartExtType, _fieldSig);
JS('', '#[#] = #[#]', jsType, _getterSig, dartExtType, _getterSig);
JS('', '#[#] = #[#]', jsType, _setterSig, dartExtType, _setterSig);
diff --git a/tests/web/dynamic_generic_method_resolution_test.dart b/tests/web/dynamic_generic_method_resolution_test.dart
new file mode 100644
index 0000000..a8ff737
--- /dev/null
+++ b/tests/web/dynamic_generic_method_resolution_test.dart
@@ -0,0 +1,11 @@
+// Copyright (c) 2023, 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.
+
+// Tests that generic function invocations have their default type arguments
+// resolved in a dynamic call when the type argument is a JS entity.
+
+void main() {
+ dynamic arrayLiteral = [];
+ arrayLiteral.map((v) => '$v');
+}