Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

typeof check throws error for param of type java.util.Date

335 views
Skip to first unread message

keith

unread,
Oct 7, 2007, 8:55:44 AM10/7/07
to
Hi,

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

David P. Caldwell

unread,
Oct 8, 2007, 9:46:51 AM10/8/07
to
On Oct 7, 8:55 am, keith <keithgchap...@gmail.com> wrote:
> Hi,
>
> 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?

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/

Norris Boyd

unread,
Oct 8, 2007, 11:49:22 AM10/8/07
to

>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

keith

unread,
Oct 8, 2007, 11:52:49 AM10/8/07
to
Its a bit tricky to explain this. I'll try my best though.

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.

keith

unread,
Oct 8, 2007, 11:53:59 AM10/8/07
to
Hi Norris,

How can I wrap it as a JS object? I'm using the latest release.

Thanks,
Keith.

keith

unread,
Oct 8, 2007, 12:45:53 PM10/8/07
to
Hi Norris,

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:

keith

unread,
Oct 19, 2007, 6:55:19 AM10/19/07
to
Hi Norris,

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.

Norris Boyd

unread,
Oct 19, 2007, 9:12:34 AM10/19/07
to

The typeof operator only returns "undefined", "object", "boolean",
"number", "string", and "function".

--N

keith

unread,
Oct 23, 2007, 12:53:10 AM10/23/07
to
Hi Norris,

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.

Norris Boyd

unread,
Oct 23, 2007, 11:12:08 AM10/23/07
to
On Oct 23, 12:53 am, keith <keithgchap...@gmail.com> wrote:
> Hi Norris,
>
> 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


0 new messages