"this" problems when upgrading to Rhino 1.8.0 -

33 views
Skip to first unread message

mich.b...@gmail.com

unread,
Feb 4, 2025, 1:05:08 AMFeb 4
to mozilla-rhino
Hello everyone,

I recently updated to Rhino 1.8.0 from  1.7.14. First - it's great to see that new versions are coming out, and big thanks to everyone involved.

All in all the update was pretty easy, but the following code breaks at runtime:

        String code = "ns.forEach(e=>javaSet.add(e))";

        try ( Context cx = Context.enter() ) {
            ScriptableObject tlScope = cx.initStandardObjects();
            Set<Object> javaSet = new HashSet<>();
            tlScope.put("ns", tlScope, ns);
            tlScope.put("javaSet", tlScope, javaSet);
            cx.evaluateString(tlScope, code, "", 1, null);

            return new NativeSetStub(javaSet);
        }


Reporting the error: org.mozilla.javascript.EcmaError: TypeError: Method "forEach" called on incompatible object. (#1)

From what I gather, this means that the Set instance ns is not a Set object when the "forEach" method is called, but I may be wrong.

Any ideas?

Thanks,
Michael

mich.b...@gmail.com

unread,
Feb 5, 2025, 12:54:05 AMFeb 5
to mozilla-rhino
Deep debugging update: The error is sent from NativeSet::realThis, because the NativeSet instance's instanceOfSet field is set to false. NativeSet.java, line 180.

This might have to do with the set coming from a continuation. Any help is highly appreciated :-)

mich.b...@gmail.com

unread,
Feb 20, 2025, 3:16:05 PMFeb 20
to mozilla-rhino
Workaround: serialize with a scope generated by `context.initStandardObjects()`. See https://github.com/mozilla/rhino/issues/1839 for more info.
Reply all
Reply to author
Forward
0 new messages