Actually, it'd be difficult for us to debug as well. As I said, most
likely your Java Map passed is being treated as a (JS) script object -
and it is not. Please note that Nashorn uses wrapperless Java objects
with scripts - so scripts see the exposed Java objects as plain Java
objects. So, the solution would be to use an actual script object in
such cases.
-Sundar
On 12/16/2015 8:52 PM, Kasmeroglu, Daniel wrote:
On Mi, 2015-12-16 at 20:11 +0530, Sundararajan Athijegannathan wrote:
If the script function t4 expects that "t4_context" is a script object
and so calls Object.prototype function or any JS function that expects
"this" to be a script object, you'll get a TypeError (per spec.). We
need bit more information on the code of "t4" to help further.
The code of 't4' is a problem here as it's generated by Handlebars. It's
ScriptObjectMirror presentation results in:
--8>--
[_setup -> function (setupOptions) {
if (!compiled) {
compiled = compileInput();
}
return compiled._setup(setupOptions);
}]
[_child -> function (i, data, blockParams, depths) {
if (!compiled) {
compiled = compileInput();
}
return compiled._child(i, data, blockParams, depths);
}]
--<8--
However I don't expect anyone to investigate this code further as I
think this might require quite a bit of work
(https://github.com/wycats/handlebars.js/tree/master). It's essentially
a template which will render it's content with the supplied hash in
question.
Last but not least I figured out a workaround which seem to work fine.
I'm simply adding the entries of the map 't4_context' and I'm generating
the template function call accordingly. F.e.
t4(t4_context)
turns into
t4({'assets': assets, 'def': def})
Nevertheless if someone knows an answer to the problem it would be nice
to know.
-Sundar
On 12/16/2015 7:31 PM, Kasmeroglu, Daniel wrote:
Hi there,
First of all: thanks for the great work with Nashorn.
Unfortunately I'm currently a little bit stuck as I don't get what I'm
doing wrong here.
Here's a simple code snippet that explains what I'm doing:
--<8--
ScriptEngine engine = ...
Map<String, Object> context = ...
engine.put("t4_context", context);
engine.eval("t4(t4_context);");
--8>--
The variable 't4' is a compiled template generated through Handlebars
(so it's a function taking a hash).
Unfortunately I don't get it running as there's the following complain:
--<8--
Caused by: <function>:30 TypeError: {assets=dodo} is not an Object
--8>--
It's clear to me that the issue is caused since the java object
'context' isn't an instance of 'ScriptObject'. However it isn't clear to
me why this happens.
It would be nice to give me a hint of what I'm doing wrong or to point
me to some helpful documentation.
Thanks in advance.