Skip to content

Commit 97cf54c

Browse files
nateboschcommit-bot@chromium.org
authored andcommitted
Remove some stale JS interop known differences
Remove sections describing differences between dart2js and ddc that have since been resolved. Both ddc and dart2js will require use of `allowInterop` in all but unlikely edge cases. Both will be strict about argument types and count as long as `allowInterop` is used. Other fixes: - Fix spelling of "supersedes". - Use `List.from` over `list.cast().toList()` in example. Change-Id: If4ce0926a4460ed41ddea2714ee3324c60770d62 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136844 Commit-Queue: Nate Bosch <[email protected]> Auto-Submit: Nate Bosch <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 9e03c2c commit 97cf54c

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

pkg/js/README.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ that let you specify how your Dart code interoperates with JavaScript code.
55
The Dart-to-JavaScript compilers — dartdevc and dart2js — recognize these
66
annotations, using them to connect your Dart code with JavaScript.
77

8-
**Important:** This library supercedes `dart:js`, so don't import `dart:js`.
8+
**Important:** This library supersedes `dart:js`, so don't import `dart:js`.
99
Instead, import `package:js/js.dart`.
1010

1111
A second library in this package, `js_util`, provides low-level utilities
@@ -104,8 +104,6 @@ class Options {
104104
If you pass a Dart function to a JavaScript API as an argument,
105105
wrap the Dart function using `allowInterop()` or `allowInteropCaptureThis()`.
106106

107-
**Warning:** Although dart2js requires `allowInterop()`, dartdevc does not.
108-
109107
To make a Dart function callable from JavaScript _by name_, use a setter
110108
annotated with `@JS()`.
111109

@@ -151,25 +149,6 @@ conventions and type representation, and therefore have different challenges in
151149
JavaScript interop. There are currently some known differences in behavior and
152150
bugs in one or both compilers.
153151

154-
#### allowInterop is required in dart2js, optional in dartdevc
155-
156-
DDC uses the same calling conventions as JavaScript and so Dart functions passed
157-
as callbacks can be invoked without modification. In dart2js the calling
158-
conventions are different and so `allowInterop()` or `allowInteropCaptureThis()`
159-
must be used for any callback.
160-
161-
**Workaround:**: Always use `allowInterop()` even when not required in dartdevc.
162-
163-
#### Callbacks allow extra ignored arguments in DDC
164-
165-
In JavaScript a caller may pass any number of "extra" arguments to a function
166-
and they will be ignored. dartdevc follows this behavior, dart2js will have a runtime
167-
error if a function is invoked with more arguments than expected.
168-
169-
**Workaround:** Write functions that take the same number of arguments as will
170-
be passed from JavaScript. If the number is variable use optional positional
171-
arguments.
172-
173152
#### Dartdevc and dart2js have different representation for Maps
174153

175154
Passing a `Map<String, String>` as an argument to a JavaScript function will
@@ -210,8 +189,9 @@ from a JavaScript function cannot make guarantees about it's elements without
210189
inspecting each one. At runtime a check like `result is List` may succeed, while
211190
`result is List<String>` will always fail.
212191

213-
**Workaround:** Use a `.cast<String>().toList()` call to get a `List` with the
214-
expected reified type at runtime.
192+
**Workaround:** Use `.cast()` or construct a new `List` to get an instance with
193+
the expected reified type. For instance if you want a `List<String>` use
194+
`.cast<String>()` or `List<String>.from`.
215195

216196
#### The `JsObject` type from `dart:js` can't be used with `@JS()` annotation
217197

0 commit comments

Comments
 (0)