Javascript bug if (...) return 0; else { }


Hello Jules,

Something like this trips Juce JS parser:

if (a==0) return 0; else return 1;

From what it looks like to me, the return statement parser does not take the semicolon after the expression. If I remove the semicolon before else, then it works.


Also the '||' operator does not behave like in other Javascript compilers in relation to undefined. For example:

return arr[tooLargeIndex] || defaultValue;

The above in Google V8 will return defaultValue.


And I also suggest implementing typeof operator. I implemented it as a function for my own code, but it requires using parentheses.

    static var jstypeof(const var::NativeFunctionArgs &a)
        if (a.numArguments<1) return var("undefined");
        if (a.arguments[0].isUndefined()) return "undefined";
        if (a.arguments[0].isVoid())      return "void";
        if (a.arguments[0].isString())    return "string";
        if (a.arguments[0].isInt() || a.arguments[0].isInt64() || a.arguments[0].isDouble()) return "number";
        if (a.arguments[0].isObject())    return "object";
        return "unknown";