I use HTMLUnit to test a webpage with a 3rd party library (TinyMCE).
The library is using a WeakMap to has additional stuff for documents it stores (Documents being the keys of the WeakMap).
In all browsers this works fine.
However HTMLUnit is throwing a TypeError Expected argument of type object, but instead had type object (Which by description alone is kind of odd).
Investigation
I traced the problem to: documents are represented as DocumentProxy in HTMLUnit, which are not implementing Scriptable; and therefore not considered an object by Rhino (ScriptRuntime.isObject returns false).
Based on browser engines typeof domNode is object.
I think this is a bug, which needs a fix. However I am not sure if it's needed to be fix in htmlunit or in Rhino.
Steps to repeat
I attached a minimal reproduction project to illustrate the issue.
bug-demo.zip
(run ./gradlew test)