Closed Bug 56158 Opened 24 years ago Closed 24 years ago

Error() constructor doesn't conform to ECMAv3

Categories

(Rhino Graveyard :: Core, defect, P3)

x86
Linux
defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: david, Assigned: norrisboyd)

Details

1) The Error() constructor does not set the message property when passed
   a message argument.  (See ECMAv3 15.11.2.1)

2) When Error() is called as a function rather than as a constructor
   (see ECMA v3: 15.11.1.1) it causes a Java exception to be thrown, and
   rhino exits.

Both problems exist in the rhinoTip.zip file dated 9/11/00.
The following rhino shell session demonstrates both bugs:

js> var e = new Error("message");
js> e
Error: 
js> e = Error("message");
Exception in thread "main" java.lang.RuntimeException:
org.mozilla.javascript.PropertyException: Constructor for "TypeError" not found.
        at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:500)
        at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:467)
        at
org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:600)
        at org.mozilla.javascript.ScriptRuntime.toString(ScriptRuntime.java:408)
        at org.mozilla.javascript.Context.toString(Context.java:1102)
        at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:243)
        at org.mozilla.javascript.tools.shell.Main.exec(Main.java:110)
        at org.mozilla.javascript.tools.shell.Main.main(Main.java:68)
Just missing code for the JavaScript constructor definition in Java:

    public static Object jsConstructor(Context cx, Object[] args, 
                                       Function funObj, boolean inNewExpr)
    {
        NativeError result = new NativeError();
        if (args.length >= 1) 
            result.put("message", result, cx.toString(args[0]));
        result.setPrototype(getClassPrototype(funObj, "Error"));
        return result;
    }
    
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Marking Verified -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.