mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
Errors as exceptions working from generated code.
This commit is contained in:
parent
5b2cb149d2
commit
fe413b9972
58
js/rhino/org/mozilla/javascript/EcmaError.java
Normal file
58
js/rhino/org/mozilla/javascript/EcmaError.java
Normal file
@ -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;
|
||||
|
||||
}
|
@ -52,11 +52,4 @@ public class EvaluatorException extends RuntimeException {
|
||||
super(detail);
|
||||
}
|
||||
|
||||
public EvaluatorException(Object nativeError) {
|
||||
super("NativeError");
|
||||
errorObject = nativeError;
|
||||
}
|
||||
|
||||
Object errorObject;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
58
js/rhino/src/org/mozilla/javascript/EcmaError.java
Normal file
58
js/rhino/src/org/mozilla/javascript/EcmaError.java
Normal file
@ -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;
|
||||
|
||||
}
|
@ -52,11 +52,4 @@ public class EvaluatorException extends RuntimeException {
|
||||
super(detail);
|
||||
}
|
||||
|
||||
public EvaluatorException(Object nativeError) {
|
||||
super("NativeError");
|
||||
errorObject = nativeError;
|
||||
}
|
||||
|
||||
Object errorObject;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user