Skip to content

Commit fd1cb89

Browse files
committed
docs: simplify verbose JavaDoc documentation
Reduce class-level documentation verbosity by ~70%: - Focus on 'what' rather than detailed 'how' explanations - Remove verbose @param/@return/@throws from methods - Maintain essential information for API understanding
1 parent bd3508d commit fd1cb89

File tree

3 files changed

+16
-128
lines changed

3 files changed

+16
-128
lines changed

rhino/src/main/java/org/mozilla/javascript/FinalizationQueue.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
/**
1414
* Shared finalization queue infrastructure for FinalizationRegistry.
1515
*
16-
* <p>Provides a shared ReferenceQueue (for JVM efficiency per aardvark179's recommendation) and
17-
* polling mechanism during JavaScript execution. Each FinalizationRegistry manages its own state
18-
* while using this shared infrastructure for GC detection.
19-
*
20-
* <p>This design avoids the overhead of multiple ReferenceQueues while maintaining proper
21-
* separation of registry-specific logic.
16+
* <p>Provides shared ReferenceQueue for JVM efficiency and GC detection polling.
2217
*/
2318
public class FinalizationQueue {
2419

rhino/src/main/java/org/mozilla/javascript/NativeFinalizationRegistry.java

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,8 @@
1515
/**
1616
* Implementation of ECMAScript 2021 FinalizationRegistry.
1717
*
18-
* <p>FinalizationRegistry allows JavaScript code to register cleanup callbacks that are called when
19-
* objects are garbage collected. This implementation provides:
20-
*
21-
* <ul>
22-
* <li>Self-contained design - each registry manages its own registrations
23-
* <li>Shared ReferenceQueue for JVM efficiency (per aardvark179's recommendation)
24-
* <li>Integration with Rhino's Context finalization infrastructure
25-
* <li>Thread-safe registration/unregistration using concurrent data structures
26-
* <li>Bounded cleanup processing to prevent performance issues
27-
* </ul>
28-
*
29-
* <p>Key methods:
30-
*
31-
* <ul>
32-
* <li>{@code register(target, heldValue, unregisterToken)} - register object for cleanup
33-
* <li>{@code unregister(token)} - remove registrations by token
34-
* <li>{@code cleanupSome(callback)} - process pending cleanups synchronously
35-
* </ul>
18+
* <p>Allows JavaScript code to register cleanup callbacks for garbage collected objects. Uses
19+
* shared ReferenceQueue for efficiency and integrates with Rhino's Context system.
3620
*
3721
* @see <a href="https://tc39.es/ecma262/#sec-finalization-registry-objects">ECMAScript
3822
* FinalizationRegistry</a>
@@ -59,14 +43,7 @@ public class NativeFinalizationRegistry extends ScriptableObject {
5943
/** Temporary callback override for cleanupSome() method */
6044
private volatile Function cleanupSomeCallback = null;
6145

62-
/**
63-
* Initialize the FinalizationRegistry constructor and prototype in the given scope.
64-
*
65-
* @param cx the JavaScript context
66-
* @param scope the scope to install FinalizationRegistry in
67-
* @param sealed whether to seal the constructor and prototype
68-
* @return the FinalizationRegistry constructor function
69-
*/
46+
/** Initialize FinalizationRegistry constructor and prototype. */
7047
public static Object init(Context cx, Scriptable scope, boolean sealed) {
7148
LambdaConstructor constructor =
7249
new LambdaConstructor(
@@ -120,24 +97,12 @@ public static Object init(Context cx, Scriptable scope, boolean sealed) {
12097
return constructor;
12198
}
12299

123-
/**
124-
* Private constructor for FinalizationRegistry instances.
125-
*
126-
* @param cleanupCallback the function to call when objects are finalized
127-
*/
100+
/** Private constructor for FinalizationRegistry instances. */
128101
private NativeFinalizationRegistry(Function cleanupCallback) {
129102
this.cleanupCallback = cleanupCallback;
130103
}
131104

132-
/**
133-
* JavaScript constructor implementation.
134-
*
135-
* @param cx the JavaScript context
136-
* @param scope the constructor scope
137-
* @param args constructor arguments (first must be a function)
138-
* @return new FinalizationRegistry instance
139-
* @throws TypeError if callback is not a function
140-
*/
105+
/** JavaScript constructor implementation. */
141106
private static NativeFinalizationRegistry jsConstructor(
142107
Context cx, Scriptable scope, Object[] args) {
143108
if (args.length < 1 || !(args[0] instanceof Function)) {
@@ -153,16 +118,7 @@ private static NativeFinalizationRegistry jsConstructor(
153118
return registry;
154119
}
155120

156-
/**
157-
* JavaScript register() method implementation.
158-
*
159-
* @param cx the JavaScript context (unused but required by Rhino)
160-
* @param scope the method scope (unused but required by Rhino)
161-
* @param thisObj the 'this' object (must be FinalizationRegistry)
162-
* @param args method arguments: target, heldValue, [unregisterToken]
163-
* @return undefined
164-
* @throws TypeError if arguments are invalid
165-
*/
121+
/** JavaScript register() method implementation. */
166122
private static Object register(
167123
Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
168124
NativeFinalizationRegistry registry = realThis(thisObj, "register");
@@ -198,31 +154,14 @@ private static Object register(
198154
return Undefined.instance;
199155
}
200156

201-
/**
202-
* JavaScript unregister() method implementation.
203-
*
204-
* @param cx the JavaScript context (unused but required by Rhino)
205-
* @param scope the method scope (unused but required by Rhino)
206-
* @param thisObj the 'this' object (must be FinalizationRegistry)
207-
* @param args method arguments: unregisterToken
208-
* @return boolean indicating whether any registrations were removed
209-
*/
157+
/** JavaScript unregister() method implementation. */
210158
private static Object unregister(
211159
Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
212160
NativeFinalizationRegistry registry = realThis(thisObj, "unregister");
213161
return registry.unregisterToken(args);
214162
}
215163

216-
/**
217-
* JavaScript cleanupSome() method implementation.
218-
*
219-
* @param cx the JavaScript context
220-
* @param scope the method scope (unused but required by Rhino)
221-
* @param thisObj the 'this' object (must be FinalizationRegistry)
222-
* @param args method arguments: [callback]
223-
* @return undefined
224-
* @throws TypeError if callback is provided but not a function
225-
*/
164+
/** JavaScript cleanupSome() method implementation. */
226165
private static Object cleanupSome(
227166
Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
228167
NativeFinalizationRegistry registry = realThis(thisObj, "cleanupSome");
@@ -411,17 +350,8 @@ private void processCleanups(Context cx, int maxCleanups) {
411350
/**
412351
* Clean up when this registry is being GC'd.
413352
*
414-
* <p>Note: finalize() is deprecated in Java 9+ but is still the most appropriate mechanism for
415-
* this use case. The newer Cleaner API is not suitable because:
416-
*
417-
* <ul>
418-
* <li>FinalizationRegistry needs dynamic registration/unregistration
419-
* <li>Cleaner requires static cleanup actions defined at object creation
420-
* <li>We need to clear references when the registry itself is collected
421-
* </ul>
422-
*
423-
* <p>This is intentionally using finalize() as recommended by aardvark179 for this specific use
424-
* case where we need to clean up when the registry itself is GC'd.
353+
* <p>Uses finalize() over Cleaner API due to dynamic registration requirements. Recommended by
354+
* aardvark179 for this specific GC cleanup use case.
425355
*/
426356
@Override
427357
@SuppressWarnings({"deprecation", "finalize", "Finalize"})

rhino/src/main/java/org/mozilla/javascript/NativeWeakRef.java

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,10 @@
1111
/**
1212
* Implementation of ECMAScript 2021 WeakRef.
1313
*
14-
* <p>WeakRef allows holding a weak reference to an object without preventing its garbage
15-
* collection. This is useful for caches, mappings, or any scenario where you want to reference an
16-
* object without keeping it alive.
17-
*
18-
* <p>Key features:
19-
*
20-
* <ul>
21-
* <li>Weak reference semantics - target can be garbage collected
22-
* <li>Single {@code deref()} method to access target if still alive
23-
* <li>Returns undefined if target has been collected
24-
* <li>Thread-safe access using standard Java WeakReference
25-
* <li>Coordinates with FinalizationRegistry for consistent GC behavior
26-
* </ul>
27-
*
28-
* <p>Unlike FinalizationRegistry which reacts to object finalization, WeakRef simply provides a way
29-
* to check if an object is still reachable without keeping it alive.
14+
* <p>Allows holding weak references to objects without preventing garbage collection. Provides
15+
* {@code deref()} method to access target if still alive.
3016
*
3117
* @see <a href="https://tc39.es/ecma262/#sec-weak-ref-objects">ECMAScript WeakRef Objects</a>
32-
* @see NativeFinalizationRegistry
3318
*/
3419
public class NativeWeakRef extends ScriptableObject {
3520
private static final long serialVersionUID = 1L;
@@ -41,14 +26,7 @@ public class NativeWeakRef extends ScriptableObject {
4126
/** The weak reference to the target object */
4227
private WeakReference<Object> weakReference;
4328

44-
/**
45-
* Initialize the WeakRef constructor and prototype in the given scope.
46-
*
47-
* @param cx the JavaScript context
48-
* @param scope the scope to install WeakRef in
49-
* @param sealed whether to seal the constructor and prototype
50-
* @return the WeakRef constructor function
51-
*/
29+
/** Initialize WeakRef constructor and prototype. */
5230
static Object init(Context cx, Scriptable scope, boolean sealed) {
5331
LambdaConstructor constructor =
5432
new LambdaConstructor(
@@ -81,15 +59,7 @@ static Object init(Context cx, Scriptable scope, boolean sealed) {
8159
return constructor;
8260
}
8361

84-
/**
85-
* JavaScript constructor implementation.
86-
*
87-
* @param cx the JavaScript context
88-
* @param scope the constructor scope
89-
* @param args constructor arguments (first must be an object)
90-
* @return new WeakRef instance
91-
* @throws TypeError if target is not an object
92-
*/
62+
/** JavaScript constructor implementation. */
9363
private static Scriptable jsConstructor(Context cx, Scriptable scope, Object[] args) {
9464
if (args.length < 1) {
9565
throw ScriptRuntime.typeErrorById(
@@ -121,14 +91,7 @@ private static boolean isValidTarget(Object target) {
12191
return ScriptRuntime.isObject(target);
12292
}
12393

124-
/**
125-
* Validate and cast 'this' object to WeakRef.
126-
*
127-
* @param thisObj the 'this' object from JavaScript call
128-
* @param name method name for error messages
129-
* @return validated WeakRef instance
130-
* @throws TypeError if thisObj is not a proper WeakRef
131-
*/
94+
/** Validate and cast 'this' object to WeakRef. */
13295
private static NativeWeakRef realThis(Scriptable thisObj, String name) {
13396
if (!(thisObj instanceof NativeWeakRef)) {
13497
throw ScriptRuntime.typeErrorById("msg.incompat.call", CLASS_NAME + '.' + name);

0 commit comments

Comments
 (0)