|
osdir.com mailing list archive |
|
Subject: JavaScript vs Java Date - msg#00147List: mozilla.devel.jsengI have this test program which I exepcted to return true. I construct a Java date to be 10/30/2004 and an equivalent JS date. However, when I compare them by calling getTime(), the result is always false. Thanks for any pointers. T Hammoud import java.util.Date; import org.mozilla.javascript.Context; import org.mozilla.javascript.Function; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.WrapFactory; public class JavaDate { public void runJavaScriptTest(int n) { Context cx = Context.enter(); try { ScriptableObject scope = cx.initStandardObjects(); cx.setWrapFactory(new MyWrapFactory()); String s = "function foo(javaConvertedDate) {return new Date(2004, 10, 30).getTime() == javaConvertedDate.getTime()} "; Function f = cx.compileFunction(scope, s, "<cmd>", 1, null); Object args[] = {new Date("10/30/2004")}; Object rc = f.call(cx, scope, f, args); <================================= It is always false. System.out.println("Test1 Call result " + rc + " :" + rc.getClass()); } catch (Exception e) { e.printStackTrace(); } finally { // Exit from the context. Context.exit(); } } static class MyWrapFactory extends WrapFactory { public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, java.lang.Object javaObject, java.lang.Class staticType) { if (javaObject instanceof java.util.Date) { long time=((java.util.Date) javaObject).getTime(); return cx.newObject(scope, "Date", new Object[] { new Double(time) }); } return super.wrapAsJavaObject(cx, scope, javaObject, staticType); } } public static void main(String[] args) { JavaDate myTest = new JavaDate(); myTest.runJavaScriptTest(1); } }
Thread at a glance:
Previous Message by Date: (click to view message preview)Re: Class propertiesThanks. Halfway there. Now I know its possible. But I need the other half aswell. :) How is such a class property defined from within the SpiderMonkey perspective, i.e. in my C source counterpart. I want the 'modeOut' to have a predefined (read-only) value. It's been buggin me for quite a while now. Using a getter for the property requires an instance, so there must be another way. TIA /Niklas "Martin Honnen" <mahotrash@xxxxxxxx> wrote in message news:clrc2o$nlc3@xxxxxxxxxxxxxxxxxxxxxx > > > Niklas Lindquist wrote: > > > Is it at all possible to create class properties (as oppose to instance > > properties). > > What I would like to achieve is something similar to C enums to use as > > parameters for certain functions. > > > > Example: > > var s = new Stream; > > s.open(Stream.modeOut); > > function Stream () { } > Stream.modeOut = 42; > can certainly be done in JavaScript. > > > -- > > Martin Honnen > http://JavaScript.FAQTs.com/ Next Message by Date: click to view message previewclient-side Javascript HTTPHello, Does anyone out there know if there's a way for client-side Javascript to fetch a text file via HTTP and read its contents into a variable? The best I can do so far is creating an IFRAME element (via DOM), which does display the text I want, but from there I can't find a way to read the frame's contents into a veriable. Sorry if this is the wrong NG for this question; if there's a better one, I'm happy to post there. Thanks! regards, -Felipe Gasper Previous Message by Thread: click to view message previewalternatives to Rhino JS that support MSIE functions ?I have just started using FitNesse, HtmlUnit and the Rhino JS engine to develop some acceptance tests, and I ran across several unsupported IE specific commands, such as window.showModalDialog() which produces pop-up window dialogs. I am considering what the best options are to the "IE specific" problem: 1. re-write the test cases around the problem areas, catch and ignore script errors ( this is what I have started to do ). 2. search for alternatives to the Rhino JS engine any thoughts would be greatly appreciated, -John H. Next Message by Thread: click to view message previewclient-side Javascript HTTPHello, Does anyone out there know if there's a way for client-side Javascript to fetch a text file via HTTP and read its contents into a variable? The best I can do so far is creating an IFRAME element (via DOM), which does display the text I want, but from there I can't find a way to read the frame's contents into a veriable. Sorry if this is the wrong NG for this question; if there's a better one, I'm happy to post there. Thanks! regards, -Felipe Gasper
Web Hosting Reviews from OSDir.com Sister Site iBizWebHosting.com
|
|