Skip to content

new Boolean("false") should be false #14

Description

@BobHanson

Java is different from JavaScript in that in Java, new Boolean(string) is true only when string.equalsIgnoreCase("true"), but in JavaScript, new Boolean(string) is true for anything other than "" or null.

Solution is to create in the j2s runtime a binding for Boolean.from(string), and then convert all instances of "new Boolean " to "Boolean.from" in Java2ScriptCompiler.outputJavaScript(...)

// the need is to have new Boolean(string), but that won't work with native Boolean
// so instead we have to do a lexical switch from "new Boolean" to "Boolean.from"
Boolean.from=Clazz.defineMethod(Boolean,"from",
($fz=function(name){
return new Boolean(typeof name == "string" ? name.equalsIgnoreCase("true") : !!name);
},$fz.isPrivate=true,$fz),"~S");

Fixed for j2sSwingJS.js 7/2016.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions