From 96d18d470e8e8ada9bcbc205ccb4dd32ea70a162 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Wed, 13 Mar 2024 18:44:59 +0100 Subject: [PATCH] SpecialRef: fix assigning to Symbol.__proto__ returning undefined (see https://github.com/HtmlUnit/htmlunit-rhino-fork/pull/15) --- src/org/mozilla/javascript/SpecialRef.java | 5 +++++ testsrc/jstests/es6/proto-property.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/org/mozilla/javascript/SpecialRef.java b/src/org/mozilla/javascript/SpecialRef.java index ac29466438..6c769c2714 100644 --- a/src/org/mozilla/javascript/SpecialRef.java +++ b/src/org/mozilla/javascript/SpecialRef.java @@ -114,10 +114,15 @@ public Object set(Context cx, Scriptable scope, Object value) { } final String typeOfValue = ScriptRuntime.typeof(value); + if (NativeSymbol.TYPE_NAME.equals(typeOfTarget)) { + return value; + } + if ((value != null && !"object".equals(typeOfValue)) || !"object".equals(typeOfTarget)) { return Undefined.instance; } + target.setPrototype(obj); } else { target.setPrototype(obj); diff --git a/testsrc/jstests/es6/proto-property.js b/testsrc/jstests/es6/proto-property.js index 09c470d4b8..5a5ee59595 100644 --- a/testsrc/jstests/es6/proto-property.js +++ b/testsrc/jstests/es6/proto-property.js @@ -42,4 +42,9 @@ assertTrue(f.__proto__ === undefined); assertTrue({ __proto__ : [] } instanceof Array); assertFalse({ __proto__(){} } instanceof Function) +// __proto__ on Symbol +var x = Symbol(); +var y = { foo: "bar" } +assertEquals({ foo: "bar" }, x.__proto__ = y); + "success"; \ No newline at end of file