Skip to content

Commit 97f1921

Browse files
committed
Fix ES2021 WeakRef and FinalizationRegistry symbol support
- Update isValidTarget() in NativeWeakRef to accept Symbol targets - Update isValidTarget() and canBeHeldWeakly() in NativeFinalizationRegistry to accept Symbols - Addresses test262 failures for symbols-as-weakmap-keys feature - Improves compliance with ES2021 specification requiring symbol support Fixes major category of test262 failures including: - built-ins/WeakRef/prototype/deref/return-symbol-target.js - built-ins/FinalizationRegistry/prototype/register/throws-when-unregisterToken-not-undefined-and-cannot-be-held-weakly.js
1 parent 50ca74a commit 97f1921

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ protected void finalize() throws Throwable {
376376
* @return true if target is a valid object that can be registered
377377
*/
378378
private static boolean isValidTarget(Object target) {
379-
return ScriptRuntime.isObject(target);
379+
return ScriptRuntime.isObject(target) || (target instanceof Symbol);
380380
}
381381

382382
/**
@@ -386,7 +386,7 @@ private static boolean isValidTarget(Object target) {
386386
* @return true if value can be used as an unregister token
387387
*/
388388
private static boolean canBeHeldWeakly(Object value) {
389-
return ScriptRuntime.isObject(value);
389+
return ScriptRuntime.isObject(value) || (value instanceof Symbol);
390390
}
391391

392392
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static Scriptable jsConstructor(Context cx, Scriptable scope, Object[] a
8888
* @return true if target is a valid object that can be weakly referenced
8989
*/
9090
private static boolean isValidTarget(Object target) {
91-
return ScriptRuntime.isObject(target);
91+
return ScriptRuntime.isObject(target) || (target instanceof Symbol);
9292
}
9393

9494
/** Validate and cast 'this' object to WeakRef. */

0 commit comments

Comments
 (0)