Skip to content

Commit

Permalink
SpecialRef: fix assigning to Symbol.__proto__ returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Mar 15, 2024
1 parent 9cc5f6b commit 96d18d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/org/mozilla/javascript/SpecialRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions testsrc/jstests/es6/proto-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 96d18d4

Please sign in to comment.