Skip to content

Commit 43bbf73

Browse files
nateboschcommit-bot@chromium.org
authored andcommitted
Update doc comments for dart:js_util
- Format consistently with a header sentence. - Use `JavaScript` over `JS`, and surround references to the `@JS()` annotation with backticks. - Drop the word "efficiently" since it isn't true of the more commonly used API `jsify`. - Add a note about preferring `@anonymous` interop classes over `jsify` with a map. - Remove mention of `JsObject` since this isn't what gets returned. - Clarify that Dart objects can't be used from JavaScript, this is mentioned at the library level but it worth repeating on `jsify`. Change-Id: If7582db6440d96f20bb5b4e11bcc0ffe047d9d0a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135525 Commit-Queue: Nate Bosch <nbosch@google.com> Reviewed-by: Kathy Walrath <kathyw@google.com>
1 parent fb7e6ba commit 43bbf73

2 files changed

Lines changed: 32 additions & 26 deletions

File tree

sdk/lib/js_util/js_util.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
// @dart = 2.6
66

7-
/// Utility methods to efficiently manipulate typed JSInterop objects in cases
8-
/// where the name to call is not known at runtime. You should only use these
9-
/// methods when the same effect cannot be achieved with @JS annotations.
10-
/// These methods would be extension methods on JSObject if Dart supported
11-
/// extension methods.
7+
/// Utility methods to manipulate `package:js` annotated JavaScript interop
8+
/// objects in cases where the name to call is not known at runtime.
9+
///
10+
/// You should only use these methods when the same effect cannot be achieved
11+
/// with `@JS()` annotations.
1212
///
1313
/// {@category Web}
1414
library dart.js_util;
@@ -18,16 +18,19 @@ import 'dart:collection' show HashMap;
1818
import 'dart:async' show Completer;
1919
import 'dart:_js_helper' show convertDartClosureToJS;
2020

21-
/// WARNING: performance of this method is much worse than other util
22-
/// methods in this library. Only use this method as a last resort.
21+
/// Recursively converts a JSON-like collection to JavaScript compatible
22+
/// representation.
2323
///
24-
/// Recursively converts a JSON-like collection of Dart objects to a
25-
/// collection of JavaScript objects and returns a [JsObject] proxy to it.
24+
/// WARNING: performance of this method is much worse than other util
25+
/// methods in this library. Only use this method as a last resort. Prefer
26+
/// instead to use `@anonymous` `@JS()` annotated classes to create map-like
27+
/// objects for JS interop.
2628
///
27-
/// [object] must be a [Map] or [Iterable], the contents of which are also
28-
/// converted. Maps and Iterables are copied to a new JavaScript object.
29-
/// Primitives and other transferable values are directly converted to their
30-
/// JavaScript type, and all other objects are proxied.
29+
/// The argument must be a [Map] or [Iterable], the contents of which are also
30+
/// deeply converted. Maps are converted into JavaScript Objects. Iterables are
31+
/// converted into arrays. Strings, numbers, bools, and `@JS()` annotated
32+
/// objects are passed through unmodified. Dart objects are also passed through
33+
/// unmodified, but their members aren't usable from JavaScript.
3134
jsify(object) {
3235
if ((object is! Map) && (object is! Iterable)) {
3336
throw ArgumentError("object must be a Map or Iterable");

sdk_nnbd/lib/js_util/js_util.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// Utility methods to efficiently manipulate typed JSInterop objects in cases
6-
/// where the name to call is not known at runtime. You should only use these
7-
/// methods when the same effect cannot be achieved with @JS annotations.
8-
/// These methods would be extension methods on JSObject if Dart supported
9-
/// extension methods.
5+
/// Utility methods to manipulate `package:js` annotated JavaScript interop
6+
/// objects in cases where the name to call is not known at runtime.
7+
///
8+
/// You should only use these methods when the same effect cannot be achieved
9+
/// with `@JS()` annotations.
1010
///
1111
/// {@category Web}
1212
library dart.js_util;
@@ -16,16 +16,19 @@ import 'dart:collection' show HashMap;
1616
import 'dart:async' show Completer;
1717
import 'dart:_js_helper' show convertDartClosureToJS;
1818

19-
/// WARNING: performance of this method is much worse than other util
20-
/// methods in this library. Only use this method as a last resort.
19+
/// Recursively converts a JSON-like collection to JavaScript compatible
20+
/// representation.
2121
///
22-
/// Recursively converts a JSON-like collection of Dart objects to a
23-
/// collection of JavaScript objects and returns a [JsObject] proxy to it.
22+
/// WARNING: performance of this method is much worse than other util
23+
/// methods in this library. Only use this method as a last resort. Prefer
24+
/// instead to use `@anonymous` `@JS()` annotated classes to create map-like
25+
/// objects for JS interop.
2426
///
25-
/// [object] must be a [Map] or [Iterable], the contents of which are also
26-
/// converted. Maps and Iterables are copied to a new JavaScript object.
27-
/// Primitives and other transferable values are directly converted to their
28-
/// JavaScript type, and all other objects are proxied.
27+
/// The argument must be a [Map] or [Iterable], the contents of which are also
28+
/// deeply converted. Maps are converted into JavaScript objects. Iterables are
29+
/// converted into arrays. Strings, numbers, bools, and `@JS()` annotated
30+
/// objects are passed through unmodified. Dart objects are also passed through
31+
/// unmodified, but their members aren't usable from JavaScript.
2932
Object jsify(Object object) {
3033
if ((object is! Map) && (object is! Iterable)) {
3134
throw ArgumentError("object must be a Map or Iterable");

0 commit comments

Comments
 (0)