This could be because an Array created in the frame that loads your
GWT module, and an Array created in the top level window, are two
different types. I have had similar problems with third party
libraries that modified the prototypes of Array and Object. As a
workaround, try creating your array in the context of the top level
window.
On Oct 8, 8:25 am, Ecommand <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I have a problem trying to call an existing javascript method that
> takes a javascript Array as parameter and checks the type of the input
> parameter. When I pass a javascript Array created in a JSNI method to
> the existing method it doesn't preserve it's Array type, so the type
> check fails.
>
> Here's some code to examplify. Consider I have the javascript legacy
> function MyFunction that is in MyFunctions.js and I have included that
> in my module correctly.
>
> function MyFunction(a){
>
> if(a instanceof Array){
> alert("Hooray, I am an Array")
> //normally logic would be here
> } else {
> alert("No way, I am not an Array");
> //normally error if input is not array
> }
>
> }
>
> Now, I want to call this method using JSNI, so I wrap it in
> JMyFunction, like this :
>
> public static native void JMyFunction() /*-{
> var myArray = new Array();
> myArray[0] = "hello"
> if(myArray instanceof Array){
> $wnd.alert("Array is Array")}
> else{
> $wnd.alert("Array is not Array")
> }
> $wnd.MyArrayTest(myArray);
> }-*/;
>
> Calling JMyFunction lets two alert boxes pop up, respectively with the
> text:
>
> Array is Array
> No way, I'm not an array
>
> This is because myArray is no longer an Array once passed into
> MyFunction, but an Object. I can also check that with Firebug when
> generating detailed output.
>
> Does anybody know a smart workaround for this problem?
>
> I've read the following
> discussing:http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...
>
> The "solution" by Scott Blum does not work in my case. I can put all
> JavaScriptObjects in a JavaScriptObject that is a javascript Array and
> then pass that as an Array, but it will just as myArray in my example
> script, not be preserved as an Array when it arrives at the legacy
> javascript function (the code example above is probably clearer than
> my attempt at this explanation).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---