RHINO USAGE WARNING: Missed Context.javaToJS() - new reason

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
Pippoflash
Posts: 135
Joined: 30 Jan 2006, 17:16
Contact:

RHINO USAGE WARNING: Missed Context.javaToJS() - new reason

Postby Pippoflash » 29 Aug 2012, 08:40

Hi,
after long fighting with thousands of:

Code: Select all

Rhino runtime detected object it.gotoandplay.smartfoxserver.data.User of class it.gotoandplay.smartfoxserver.data.User where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.


I have noticed another reason:

    if (user) - triggers it
    if (Boolean(user)) - triggers it
    trace("User: " + Boolean(user)) - triggers it
    if (user != null) - doesn't trigger it
    trace("User: " + (user != null)) - doesn't trigger it

Been looking for this for a long time. Hope it can help.
-----------------------
www.pippoflash.com
-----------------------
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: RHINO USAGE WARNING: Missed Context.javaToJS() - new rea

Postby rjgtav » 29 Aug 2012, 13:01

Hi, Thanks for noticing it.
Does this happen every time you run that code or only under some considerable server load?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Pippoflash
Posts: 135
Joined: 30 Jan 2006, 17:16
Contact:

Re: RHINO USAGE WARNING: Missed Context.javaToJS() - new rea

Postby Pippoflash » 29 Aug 2012, 15:00

Every time,
on local machine with just 2 users connected.
It is consistent here (sfs 1.6.9)
It still happens probably somewhere elsein production, can't reproduce locally. I'll add more info when I get them.
-----------------------

www.pippoflash.com

-----------------------
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: RHINO USAGE WARNING: Missed Context.javaToJS() - new rea

Postby Lapo » 30 Aug 2012, 09:29

Yes, that's an elusive error from the Rhino JS engine.
In essence you will find that error every time the Rhino engine expects a native JS type but for some reason it is given a Java object.

Code: Select all

if (user) - triggers it

yes, because this should return true/false only for JS native types

Code: Select all

if (Boolean(user)) - triggers it

Again, it expects a native true/false, while you are passing a java Object
trace("User: " + Boolean(user)) - triggers it

As above, can't convert a Java object to a native Bool

Code: Select all

if (user != null) - doesn't trigger it

This one is the correct form to check if any object (JS and Java) is null

Code: Select all

trace("User: " + (user != null)) - doesn't trigger it

Same as above.

Other examples that would trigger it could be

Code: Select all

myNumber = myNumber + User

Code: Select all

myString = myString + User


Another very common example is when a certain variable is holding a roomID (number) instead of a Room (Java Object), that's a common cause of confusion.
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 25 guests