Open pavelhoral opened 2 months ago
Added the docs
tag as well, as in the end, we'll need to update the docs for implementing custom host objects as well: currently all examples are about implementing the Scriptable interface, but while that works, it doesn't result in host objects that extend
Object, which is a best practice nowadays
I was playing with this a bit in a project that is using RhinoJS and I am not able to fix it on my end as NativeObject
's assign method calls package private method putImpl
that I am not able to override:
The ScriptableObject#putImpl
method is tightly coupled with the private slotMap
property. This prevents subclasses to intercept such call (e.g. when the object represents custom java.util.Map
wrappers).
The issue
This is related to #780, which changed how
Object.assign
works. That change makes sense as it aligns the implementation with the ECMA specification. However it is a breaking change for all customScriptableObject
based classes (not only inside RhinoJS itself, but in depending projects as well).Symptoms
Classes extending
ScriptableObject
quite often only override basicget
/put
/has
/getIds
methods. Trying to useObject.assign
ends with error due to missing attribute slot:Quick solution to the issue
The first solution that comes to my mind is to make sure that missing attribute slot does not end with exception... at least not in case when called from
Object.assign
as the specification clearly states the following:So undefined property attributes is a well defined state... the property should be skipped.
Proper solution
Previous quick solution still means 1.7.15+ brought breaking changes for custom
ScriptableObject
implementations. I would appreciate if there would be clear example how customNativeObject
/IdScriptableObject
/ScriptableObject
should be implemented... in the case ofIdScriptableObject
implementation I guess one needs to overridefindInstanceIdInfo
method?Footnote
Not sure if this is a partial duplicate of #1549. That issue's description is a bit cryptic for me.