From 2ed7779ff4ba2adb640516c271f1ce530d203f3b Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Fri, 13 Jun 2025 12:26:12 -0700 Subject: [PATCH] [dart:js_interop] Improve globalContext documentation Fixes https://github.com/dart-lang/sdk/issues/60900 "globalContext.name" is confusing because it implies that's the code it's executing rather than getting the property 'name' off of the globalContext getter. Also adds a library annotation with no @JS annotation in the example to make it clear there's no library renaming (because otherwise we'd be fetching the rename first off of globalContext). CoreLibraryReviewExempt: Doc-only change. Change-Id: I77cac4b9fd7c29f06c1c579879126031ad6b8dac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434523 Reviewed-by: Erik Ernst Commit-Queue: Srujan Gaddam --- sdk/lib/js_interop/js_interop.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/lib/js_interop/js_interop.dart b/sdk/lib/js_interop/js_interop.dart index 1706468645b..da4cfe5a066 100644 --- a/sdk/lib/js_interop/js_interop.dart +++ b/sdk/lib/js_interop/js_interop.dart @@ -1388,11 +1388,14 @@ extension JSAnyOperatorExtension on JSAny? { /// For example: /// /// ``` +/// library; +/// /// @JS() /// external String get name; /// ``` /// -/// Reading `name` will execute JavaScript code like `globalContext.name`. +/// Reading the top-level member `name` will execute JavaScript code like +/// `.name`. /// /// There are subtle differences depending on the compiler, but in general, /// [globalContext] can be treated like JavaScript's `globalThis`.