Closed Bug 267145 Opened 20 years ago Closed 20 years ago

Failure in assignment of string value into a boolean property: EvaluatorException is thrown.

Categories

(Rhino Graveyard :: Core, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: vitaly.zilberman, Assigned: igor)

Details

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
Build Identifier: rhino1_5R4.1

E.g., 

<HTML>
<HEAD> 
</HEAD> 

<BODY>
<FORM METHOD=POST  id=myForm>
   <select name="countrySelect" class="dropdown">
      <option  selected=true>-UK-</option>
      <option>-USA-</option>
      <option>-Israel-</option>
   </select>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Unlucky assignment..... 
  document.forms[0].countrySelect.options[1].selected="true"  

//-->
</SCRIPT>
</FORM>
</BODY>
</HTML>


Reproducible: Always
Steps to Reproduce:
1. Open the example page....
2. 
3. 

Actual Results:  
The error message thrown by the exception ("Could not convert true to boolean") 
is seen....

Expected Results:  
Assign true for each attempt of non-null string assignment into the boolean 
variable, and false - otherwise. This behaviour is supported by IE... :-(

Run www.dhl.com. The script code initializing the form select object
(js/splash.js --> fnShowAllCtry()) uses the same syntax for assignment..

.....
  if (searchcountries[j][0] == ("United States Of America"))
   {
    optElm.options[j].selected = "true";
   }
......
This is not a Rhino bug which is just a JavaScript engine implementing core
ECMAScript in Java. Please report this to creators of an application that uses
Rhino to implement DOM access.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Hi Igor,
Thanks for your quick answer.

May be we did not explain ourselves correctly.
Our application uses rhino as a script engine. While loading www.dhl.com which 
contains the java script described above, we get an exception thrown by a Rhino 
class NativeJavaObject. The exception is thrown as a result of the string to 
boolean assignment shown in the bug description.

Here is the problematic code section we're talking about, which was found while 
debugging the application that uses Rhino:

org.mozilla.javascript.NativeJavaObject.coerceType()....
{
........

        case JSTYPE_STRING:
            if ...........................
            else if ((type.isPrimitive() && type != Boolean.TYPE) ||
                     ScriptRuntime.NumberClass.isAssignableFrom(type)) {
                return coerceToNumber(type, value, useErrorHandler);
            }
            else {
                reportConversionError(value, type, !useErrorHandler);
            }
            break;

........
}

In our case we get to the last "else" clause which calls the 
reportConversionError() meeting boolean as a type and String as a value, hence, 
no conversion (which we need) is made.
Thanks.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
NativeJavaObject is not suitable for mapping Java DOM implementations into JS
world of MSIE. If you want to allow a conversions like in you example (which
violates LiveConnect standard which NatievJavaObject implements), I would
suggest to copy NativeJavaObject.java/JavaMemebers.java sources to custom
classes and then subclass WrapFactory to override wrapAsJavaObject to return
your custom wrappers of DOM objects. 

Marking the bug as invalid since LiveConnect does not allow to convert JS
strings to boolean, see
http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html , section
3.3.4 Strings which does not list Java boolean as acceptable conversion target
for JS strings.
Status: REOPENED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.