I get an error when I try to call the following function using a
java.util.Date type param as the argument.
function readDate(instant) {
print(typeof(instant));
return instant;
}
The error occurs when the typeof(instant) is evaluated. If i just
remove the print(typeof(instant)); line it works without a problem.
I'm I doing something wrong here?
Caused by: org.mozilla.javascript.EvaluatorException: Invalid
JavaScript value of type java.util.Date (test#2) at
org.wso2.javascript.rhino.JavaScriptErrorReporter.runtimeError(JavaScriptErrorReporter.java:
49) at org.mozilla.javascript.Context.reportRuntimeError(Context.java:
1030) at
org.mozilla.javascript.Context.reportRuntimeError(Context.java:1086)
at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:
1049) at
org.mozilla.javascript.ScriptRuntime.errorWithClassName(ScriptRuntime.java:
3603) at
org.mozilla.javascript.ScriptRuntime.typeof(ScriptRuntime.java:2305)
at org.mozilla.javascript.gen.c68._c1(test:4) at
org.mozilla.javascript.gen.c68.call(test) at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:
393) at
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:
2834) at org.mozilla.javascript.gen.c68.call(test) at
org.wso2.javascript.rhino.JavaScriptEngine.call(JavaScriptEngine.java:
178)
Thanks,
Keith
That's my guess, but hard to tell what. Can you provide more detail?
Here's what I get:
$ rhino
Rhino 1.6 release 7 2007 08 19
js> print(typeof(new java.util.Date()))
object
-- David P. Caldwell
http://www.inonit.com/
>From looking at ScriptRuntime.typeof, my guess is that a
java.util.Date object is getting into the Rhino runtime without being
properly wrapped as a JavaScript object.
--Norris
I have the following function in a jsfile.
function readDate(instant) {
print(typeof(instant));
return instant;
}
I use cx.evaluateReader and i evaluate this javaScript file.
Then I use rhino and get a handle to the readDate javaScript function.
Object[] functionArgs = { new java.util.Date()};
I then call the JavaScript Function using f.call(cx, this, this,
functionArgs); where f is the handle the the JS function.
When i do this I get the above error when the typeof check is
performed.
I hope you got the picture of what I was trying to explain.
Thanks,
Keith.
How can I wrap it as a JS object? I'm using the latest release.
Thanks,
Keith.
Yes using wrapFactory.wrapAsJavaObject did the trivk. Thanks for the
tip.
Thanks,
Keith.
On Oct 8, 8:49 pm, Norris Boyd <norrisb...@gmail.com> wrote:
After a wrapper the parameter using wrapperFactory now typeOf check
works. But if I echo the param out is come out as a NativeJavaObject
also the typeOf check gives Object. How can I pass this argument is so
that the typeOf check gives date?
Thanks,
Keith.
The typeof operator only returns "undefined", "object", "boolean",
"number", "string", and "function".
--N
Is there a way that I can create a NativeDate from within my code? As
NativeDate has package level access I cannot new it up.
Thanks,
Keith.
Use Context.newObject(scope, "Date", args).
--N