diff --git a/js/rhino/org/mozilla/javascript/EcmaError.java b/js/rhino/org/mozilla/javascript/EcmaError.java new file mode 100644 index 000000000000..dc4e2ec0ae9f --- /dev/null +++ b/js/rhino/org/mozilla/javascript/EcmaError.java @@ -0,0 +1,58 @@ +/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Rhino code, released + * May 6, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1997-1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU Public License (the "GPL"), in which case the + * provisions of the GPL are applicable instead of those above. + * If you wish to allow use of your version of this file only + * under the terms of the GPL and not to allow others to use your + * version of this file under the NPL, indicate your decision by + * deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete + * the provisions above, a recipient may use your version of this + * file under either the NPL or the GPL. + */ + + +package org.mozilla.javascript; + +/** + * The class of exceptions thrown by the JavaScript engine. + */ +public class EcmaError extends EvaluatorException { + + /** + * Create an exception with the specified detail message. + * + * Errors internal to the JavaScript engine will simply throw a + * RuntimeException. + * + * @nativeError the NativeError object constructed for this error + */ + public EcmaError(NativeError nativeError) { + super("EcmaError"); + errorObject = nativeError; + } + + public NativeError errorObject; + +} diff --git a/js/rhino/org/mozilla/javascript/EvaluatorException.java b/js/rhino/org/mozilla/javascript/EvaluatorException.java index fc308e555dfe..afc57ede2732 100644 --- a/js/rhino/org/mozilla/javascript/EvaluatorException.java +++ b/js/rhino/org/mozilla/javascript/EvaluatorException.java @@ -52,11 +52,4 @@ public class EvaluatorException extends RuntimeException { super(detail); } - public EvaluatorException(Object nativeError) { - super("NativeError"); - errorObject = nativeError; - } - - Object errorObject; - } diff --git a/js/rhino/org/mozilla/javascript/Interpreter.java b/js/rhino/org/mozilla/javascript/Interpreter.java index 713930fcad1a..d1e3abf8461c 100644 --- a/js/rhino/org/mozilla/javascript/Interpreter.java +++ b/js/rhino/org/mozilla/javascript/Interpreter.java @@ -1802,46 +1802,28 @@ public class Interpreter extends LabelTable { } pc++; } - catch (EvaluatorException ee) { - if (ee.errorObject != null) { - // an EvaluatorException that is actually an offical - // ECMA error object, handle as if it were a JavaScriptException - stackTop = 0; - cx.interpreterSecurityDomain = null; - if (tryStackTop > 0) { - pc = catchStack[--tryStackTop]; - scope = scopeStack[tryStackTop]; - if (pc == 0) { - pc = finallyStack[tryStackTop]; - if (pc == 0) - throw ee; - stack[0] = ee.errorObject; - } - else - stack[0] = ee.errorObject; + catch (EcmaError ee) { + // an offical ECMA error object, + // handle as if it were a JavaScriptException + stackTop = 0; + cx.interpreterSecurityDomain = null; + if (tryStackTop > 0) { + pc = catchStack[--tryStackTop]; + scope = scopeStack[tryStackTop]; + if (pc == 0) { + pc = finallyStack[tryStackTop]; + if (pc == 0) + throw ee; + stack[0] = ee.errorObject; } else - throw ee; - // We caught an exception; restore this function's - // security domain. - cx.interpreterSecurityDomain = theData.securityDomain; + stack[0] = ee.errorObject; } - else { - // handle like any other RuntimeException, more code duplication - cx.interpreterSecurityDomain = null; - if (tryStackTop > 0) { - stackTop = 0; - stack[0] = ee; - pc = finallyStack[--tryStackTop]; - scope = scopeStack[tryStackTop]; - if (pc == 0) throw ee; - } - else - throw ee; - // We caught an exception; restore this function's - // security domain. - cx.interpreterSecurityDomain = theData.securityDomain; - } + else + throw ee; + // We caught an exception; restore this function's + // security domain. + cx.interpreterSecurityDomain = theData.securityDomain; } catch (JavaScriptException jsx) { stackTop = 0; diff --git a/js/rhino/org/mozilla/javascript/NativeGlobal.java b/js/rhino/org/mozilla/javascript/NativeGlobal.java index 579d985bee4c..04ceb2aa58f5 100644 --- a/js/rhino/org/mozilla/javascript/NativeGlobal.java +++ b/js/rhino/org/mozilla/javascript/NativeGlobal.java @@ -450,7 +450,7 @@ public class NativeGlobal { * See ECMA 15.11.6 */ - public static EvaluatorException constructError(Context cx, + public static EcmaError constructError(Context cx, String error, String message, Object scope) @@ -466,7 +466,7 @@ public class NativeGlobal { Object args[] = { message }; try { Object errorObject = cx.newObject(scopeObject, error, args); - return new EvaluatorException(errorObject); + return new EcmaError((NativeError)errorObject); } catch (PropertyException x) { throw new RuntimeException(x.toString()); diff --git a/js/rhino/org/mozilla/javascript/optimizer/Codegen.java b/js/rhino/org/mozilla/javascript/optimizer/Codegen.java index 8317005f9d99..673a1bebbd6b 100644 --- a/js/rhino/org/mozilla/javascript/optimizer/Codegen.java +++ b/js/rhino/org/mozilla/javascript/optimizer/Codegen.java @@ -2493,7 +2493,6 @@ if (true) { // javascript handler; unwrap exception and GOTO to javascript // catch area. if (catchTarget != null) { - int jsHandler = classFile.markHandler(acquireLabel()); // MS JVM gets cranky if the exception object is left on the stack @@ -2521,6 +2520,28 @@ if (true) { classFile.addExceptionHandler (startLabel, catchLabel, jsHandler, "org/mozilla/javascript/JavaScriptException"); + + + /* + we also need to catch EcmaErrors and feed the + associated error object to the handler + */ + jsHandler = classFile.markHandler(acquireLabel()); + exceptionObject = getNewWordLocal(); + astore(exceptionObject); + aload(savedVariableObject); + astore(variableObjectLocal); + aload(exceptionObject); + classFile.add(ByteCode.GETFIELD, + "org/mozilla/javascript/EcmaError", + "errorObject", "Lorg/mozilla/javascript/NativeError;"); + releaseWordLocal(exceptionObject); + addByteCode(ByteCode.GOTO, catchLabel); + classFile.addExceptionHandler + (startLabel, catchLabel, jsHandler, + "org/mozilla/javascript/EcmaError"); + + } // finally handler; catch all exceptions, store to a local; JSR to diff --git a/js/rhino/src/org/mozilla/javascript/EcmaError.java b/js/rhino/src/org/mozilla/javascript/EcmaError.java new file mode 100644 index 000000000000..dc4e2ec0ae9f --- /dev/null +++ b/js/rhino/src/org/mozilla/javascript/EcmaError.java @@ -0,0 +1,58 @@ +/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Rhino code, released + * May 6, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1997-1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU Public License (the "GPL"), in which case the + * provisions of the GPL are applicable instead of those above. + * If you wish to allow use of your version of this file only + * under the terms of the GPL and not to allow others to use your + * version of this file under the NPL, indicate your decision by + * deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete + * the provisions above, a recipient may use your version of this + * file under either the NPL or the GPL. + */ + + +package org.mozilla.javascript; + +/** + * The class of exceptions thrown by the JavaScript engine. + */ +public class EcmaError extends EvaluatorException { + + /** + * Create an exception with the specified detail message. + * + * Errors internal to the JavaScript engine will simply throw a + * RuntimeException. + * + * @nativeError the NativeError object constructed for this error + */ + public EcmaError(NativeError nativeError) { + super("EcmaError"); + errorObject = nativeError; + } + + public NativeError errorObject; + +} diff --git a/js/rhino/src/org/mozilla/javascript/EvaluatorException.java b/js/rhino/src/org/mozilla/javascript/EvaluatorException.java index fc308e555dfe..afc57ede2732 100644 --- a/js/rhino/src/org/mozilla/javascript/EvaluatorException.java +++ b/js/rhino/src/org/mozilla/javascript/EvaluatorException.java @@ -52,11 +52,4 @@ public class EvaluatorException extends RuntimeException { super(detail); } - public EvaluatorException(Object nativeError) { - super("NativeError"); - errorObject = nativeError; - } - - Object errorObject; - } diff --git a/js/rhino/src/org/mozilla/javascript/Interpreter.java b/js/rhino/src/org/mozilla/javascript/Interpreter.java index 713930fcad1a..d1e3abf8461c 100644 --- a/js/rhino/src/org/mozilla/javascript/Interpreter.java +++ b/js/rhino/src/org/mozilla/javascript/Interpreter.java @@ -1802,46 +1802,28 @@ public class Interpreter extends LabelTable { } pc++; } - catch (EvaluatorException ee) { - if (ee.errorObject != null) { - // an EvaluatorException that is actually an offical - // ECMA error object, handle as if it were a JavaScriptException - stackTop = 0; - cx.interpreterSecurityDomain = null; - if (tryStackTop > 0) { - pc = catchStack[--tryStackTop]; - scope = scopeStack[tryStackTop]; - if (pc == 0) { - pc = finallyStack[tryStackTop]; - if (pc == 0) - throw ee; - stack[0] = ee.errorObject; - } - else - stack[0] = ee.errorObject; + catch (EcmaError ee) { + // an offical ECMA error object, + // handle as if it were a JavaScriptException + stackTop = 0; + cx.interpreterSecurityDomain = null; + if (tryStackTop > 0) { + pc = catchStack[--tryStackTop]; + scope = scopeStack[tryStackTop]; + if (pc == 0) { + pc = finallyStack[tryStackTop]; + if (pc == 0) + throw ee; + stack[0] = ee.errorObject; } else - throw ee; - // We caught an exception; restore this function's - // security domain. - cx.interpreterSecurityDomain = theData.securityDomain; + stack[0] = ee.errorObject; } - else { - // handle like any other RuntimeException, more code duplication - cx.interpreterSecurityDomain = null; - if (tryStackTop > 0) { - stackTop = 0; - stack[0] = ee; - pc = finallyStack[--tryStackTop]; - scope = scopeStack[tryStackTop]; - if (pc == 0) throw ee; - } - else - throw ee; - // We caught an exception; restore this function's - // security domain. - cx.interpreterSecurityDomain = theData.securityDomain; - } + else + throw ee; + // We caught an exception; restore this function's + // security domain. + cx.interpreterSecurityDomain = theData.securityDomain; } catch (JavaScriptException jsx) { stackTop = 0; diff --git a/js/rhino/src/org/mozilla/javascript/NativeGlobal.java b/js/rhino/src/org/mozilla/javascript/NativeGlobal.java index 579d985bee4c..04ceb2aa58f5 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeGlobal.java +++ b/js/rhino/src/org/mozilla/javascript/NativeGlobal.java @@ -450,7 +450,7 @@ public class NativeGlobal { * See ECMA 15.11.6 */ - public static EvaluatorException constructError(Context cx, + public static EcmaError constructError(Context cx, String error, String message, Object scope) @@ -466,7 +466,7 @@ public class NativeGlobal { Object args[] = { message }; try { Object errorObject = cx.newObject(scopeObject, error, args); - return new EvaluatorException(errorObject); + return new EcmaError((NativeError)errorObject); } catch (PropertyException x) { throw new RuntimeException(x.toString()); diff --git a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java index 8317005f9d99..673a1bebbd6b 100644 --- a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java +++ b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java @@ -2493,7 +2493,6 @@ if (true) { // javascript handler; unwrap exception and GOTO to javascript // catch area. if (catchTarget != null) { - int jsHandler = classFile.markHandler(acquireLabel()); // MS JVM gets cranky if the exception object is left on the stack @@ -2521,6 +2520,28 @@ if (true) { classFile.addExceptionHandler (startLabel, catchLabel, jsHandler, "org/mozilla/javascript/JavaScriptException"); + + + /* + we also need to catch EcmaErrors and feed the + associated error object to the handler + */ + jsHandler = classFile.markHandler(acquireLabel()); + exceptionObject = getNewWordLocal(); + astore(exceptionObject); + aload(savedVariableObject); + astore(variableObjectLocal); + aload(exceptionObject); + classFile.add(ByteCode.GETFIELD, + "org/mozilla/javascript/EcmaError", + "errorObject", "Lorg/mozilla/javascript/NativeError;"); + releaseWordLocal(exceptionObject); + addByteCode(ByteCode.GOTO, catchLabel); + classFile.addExceptionHandler + (startLabel, catchLabel, jsHandler, + "org/mozilla/javascript/EcmaError"); + + } // finally handler; catch all exceptions, store to a local; JSR to