Fri, 22 Feb 2013 12:22:16 +0100
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
Reviewed-by: attila, hannesw
1.1 --- a/src/jdk/nashorn/api/scripting/NashornException.java Fri Feb 22 11:27:40 2013 +0100 1.2 +++ b/src/jdk/nashorn/api/scripting/NashornException.java Fri Feb 22 12:22:16 2013 +0100 1.3 @@ -25,100 +25,115 @@ 1.4 1.5 package jdk.nashorn.api.scripting; 1.6 1.7 +import jdk.nashorn.internal.runtime.ECMAErrors; 1.8 + 1.9 /** 1.10 - * This is base exception for all Nashorn exceptions. These originate from user's 1.11 - * ECMAScript code. Example: script parse errors, exceptions thrown from scripts. 1.12 - * Note that ScriptEngine methods like "eval", "invokeMethod", "invokeFunction" 1.13 - * will wrap this as ScriptException and throw it. But, there are cases where user 1.14 - * may need to access this exception (or implementation defined subtype of this). 1.15 - * For example, if java interface is implemented by a script object or Java access 1.16 - * to script object properties via java.util.Map interface. In these cases, user 1.17 - * code will get an instance of this or implementation defined subclass. 1.18 + * This is base exception for all Nashorn exceptions. These originate from 1.19 + * user's ECMAScript code. Example: script parse errors, exceptions thrown from 1.20 + * scripts. Note that ScriptEngine methods like "eval", "invokeMethod", 1.21 + * "invokeFunction" will wrap this as ScriptException and throw it. But, there 1.22 + * are cases where user may need to access this exception (or implementation 1.23 + * defined subtype of this). For example, if java interface is implemented by a 1.24 + * script object or Java access to script object properties via java.util.Map 1.25 + * interface. In these cases, user code will get an instance of this or 1.26 + * implementation defined subclass. 1.27 */ 1.28 @SuppressWarnings("serial") 1.29 -public class NashornException extends RuntimeException { 1.30 +public abstract class NashornException extends RuntimeException { 1.31 // script file name 1.32 - private String fileName; 1.33 + private final String fileName; 1.34 // script line number 1.35 - private int line; 1.36 + private final int line; 1.37 // script column number 1.38 - private int column; 1.39 + private final int column; 1.40 1.41 /** script source name used for "engine.js" */ 1.42 - protected static final String ENGINE_SCRIPT_SOURCE_NAME = "nashorn:engine/resources/engine.js"; 1.43 + public static final String ENGINE_SCRIPT_SOURCE_NAME = "nashorn:engine/resources/engine.js"; 1.44 1.45 /** 1.46 * Constructor 1.47 * 1.48 - * @param msg exception message 1.49 + * @param msg exception message 1.50 + * @param fileName file name 1.51 + * @param line line number 1.52 + * @param column column number 1.53 */ 1.54 - protected NashornException(final String msg) { 1.55 - super(msg); 1.56 - } 1.57 - 1.58 - /** 1.59 - * Constructor 1.60 - * @param msg exception message 1.61 - * @param cause exception cause 1.62 - */ 1.63 - protected NashornException(final String msg, final Throwable cause) { 1.64 - super(msg, cause); 1.65 + protected NashornException(final String msg, final String fileName, final int line, final int column) { 1.66 + this(msg, null, fileName, line, column); 1.67 } 1.68 1.69 /** 1.70 * Constructor 1.71 * 1.72 - * @param cause exception cause 1.73 + * @param msg exception message 1.74 + * @param cause exception cause 1.75 + * @param fileName file name 1.76 + * @param line line number 1.77 + * @param column column number 1.78 */ 1.79 - protected NashornException(final Throwable cause) { 1.80 - super(cause); 1.81 + protected NashornException(final String msg, final Throwable cause, final String fileName, final int line, final int column) { 1.82 + super(msg, cause == null ? null : cause); 1.83 + this.fileName = fileName; 1.84 + this.line = line; 1.85 + this.column = column; 1.86 } 1.87 1.88 - /** 1.89 - * Get the source file name for this {@code NashornException} 1.90 - * @return the file name 1.91 - */ 1.92 - public final String getFileName() { 1.93 - return fileName; 1.94 - } 1.95 + /** 1.96 + * Constructor 1.97 + * 1.98 + * @param msg exception message 1.99 + * @param cause exception cause 1.100 + */ 1.101 + protected NashornException(final String msg, final Throwable cause) { 1.102 + super(msg, cause == null ? null : cause); 1.103 + // This is not so pretty - but it gets the job done. Note that the stack 1.104 + // trace has been already filled by "fillInStackTrace" call from 1.105 + // Throwable 1.106 + // constructor and so we don't pay additional cost for it. 1.107 + 1.108 + // Hard luck - no column number info 1.109 + this.column = -1; 1.110 + 1.111 + // Find the first JavaScript frame by walking and set file, line from it 1.112 + // Usually, we should be able to find it in just few frames depth. 1.113 + for (final StackTraceElement ste : getStackTrace()) { 1.114 + if (ECMAErrors.isScriptFrame(ste)) { 1.115 + // Whatever here is compiled from JavaScript code 1.116 + this.fileName = ste.getFileName(); 1.117 + this.line = ste.getLineNumber(); 1.118 + return; 1.119 + } 1.120 + } 1.121 + 1.122 + this.fileName = null; 1.123 + this.line = 0; 1.124 + } 1.125 1.126 /** 1.127 - * Set the source file name for this {@code NashornException} 1.128 - * @param fileName file name 1.129 + * Get the source file name for this {@code NashornException} 1.130 + * 1.131 + * @return the file name 1.132 */ 1.133 - protected final void setFileName(final String fileName) { 1.134 - this.fileName = fileName; 1.135 - } 1.136 + public final String getFileName() { 1.137 + return fileName; 1.138 + } 1.139 1.140 /** 1.141 * Get the line number for this {@code NashornException} 1.142 + * 1.143 * @return the line number 1.144 */ 1.145 - public final int getLineNumber() { 1.146 - return line; 1.147 - } 1.148 - 1.149 - /** 1.150 - * Set the line number for this {@code NashornException} 1.151 - * @param line line number 1.152 - */ 1.153 - protected final void setLineNumber(final int line) { 1.154 - this.line = line; 1.155 - } 1.156 + public final int getLineNumber() { 1.157 + return line; 1.158 + } 1.159 1.160 /** 1.161 * Get the column for this {@code NashornException} 1.162 + * 1.163 * @return the column 1.164 */ 1.165 public final int getColumnNumber() { 1.166 return column; 1.167 } 1.168 1.169 - /** 1.170 - * Set the column number for this {@code NashornException} 1.171 - * @param column the column 1.172 - */ 1.173 - public final void setColumnNumber(final int column) { 1.174 - this.column = column; 1.175 - } 1.176 }
2.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Fri Feb 22 11:27:40 2013 +0100 2.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Fri Feb 22 12:22:16 2013 +0100 2.3 @@ -122,9 +122,8 @@ 2.4 if (reader instanceof URLReader) { 2.5 final URL url = ((URLReader)reader).getURL(); 2.6 return evalImpl(compileImpl(new Source(url.toString(), url), ctxt), ctxt); 2.7 - } else { 2.8 - return evalImpl(Source.readFully(reader), ctxt); 2.9 } 2.10 + return evalImpl(Source.readFully(reader), ctxt); 2.11 } catch (final IOException e) { 2.12 throw new ScriptException(e); 2.13 } 2.14 @@ -240,7 +239,7 @@ 2.15 2.16 if (self == UNDEFINED) { 2.17 // scope access and so throw ReferenceError 2.18 - referenceError(ctxtGlobal, "not.defined", name); 2.19 + throw referenceError(ctxtGlobal, "not.defined", name); 2.20 } 2.21 2.22 return UNDEFINED;
3.1 --- a/src/jdk/nashorn/api/scripting/URLReader.java Fri Feb 22 11:27:40 2013 +0100 3.2 +++ b/src/jdk/nashorn/api/scripting/URLReader.java Fri Feb 22 12:22:16 2013 +0100 3.3 @@ -40,6 +40,11 @@ 3.4 // lazily initialized underlying reader for URL 3.5 private Reader reader; 3.6 3.7 + /** 3.8 + * Constructor 3.9 + * 3.10 + * @param url URL for this URLReader 3.11 + */ 3.12 public URLReader(final URL url) { 3.13 this.url = url; 3.14 }
4.1 --- a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java Fri Feb 22 11:27:40 2013 +0100 4.2 +++ b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java Fri Feb 22 12:22:16 2013 +0100 4.3 @@ -157,7 +157,7 @@ 4.4 if (getter == UNDEFINED || getter instanceof ScriptFunction) { 4.5 this.get = getter; 4.6 } else { 4.7 - typeError("not.a.function", ScriptRuntime.safeToString(getter)); 4.8 + throw typeError("not.a.function", ScriptRuntime.safeToString(getter)); 4.9 } 4.10 } else { 4.11 delete(GET, strict); 4.12 @@ -168,7 +168,7 @@ 4.13 if (setter == UNDEFINED || setter instanceof ScriptFunction) { 4.14 this.set = setter; 4.15 } else { 4.16 - typeError("not.a.function", ScriptRuntime.safeToString(setter)); 4.17 + throw typeError("not.a.function", ScriptRuntime.safeToString(setter)); 4.18 } 4.19 } else { 4.20 delete(SET, strict);
5.1 --- a/src/jdk/nashorn/internal/objects/Global.java Fri Feb 22 11:27:40 2013 +0100 5.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Fri Feb 22 12:22:16 2013 +0100 5.3 @@ -485,7 +485,7 @@ 5.4 return value; 5.5 } 5.6 } 5.7 - typeError(this, "cannot.get.default.string"); 5.8 + throw typeError(this, "cannot.get.default.string"); 5.9 } 5.10 5.11 if (hint == Number.class) { 5.12 @@ -505,7 +505,7 @@ 5.13 } 5.14 } 5.15 5.16 - typeError(this, "cannot.get.default.number"); 5.17 + throw typeError(this, "cannot.get.default.number"); 5.18 } 5.19 } catch (final RuntimeException | Error e) { 5.20 throw e; 5.21 @@ -1177,7 +1177,7 @@ 5.22 */ 5.23 public static Object toObject(final Object obj) { 5.24 if (obj == null || obj == UNDEFINED) { 5.25 - typeError("not.an.object", ScriptRuntime.safeToString(obj)); 5.26 + throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); 5.27 } 5.28 5.29 if (obj instanceof ScriptObject) { 5.30 @@ -1294,7 +1294,7 @@ 5.31 */ 5.32 public static void checkObject(final Object obj) { 5.33 if (!(obj instanceof ScriptObject)) { 5.34 - typeError("not.an.object", ScriptRuntime.safeToString(obj)); 5.35 + throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); 5.36 } 5.37 } 5.38 5.39 @@ -1306,7 +1306,7 @@ 5.40 */ 5.41 public static void checkObjectCoercible(final Object obj) { 5.42 if (obj == null || obj == UNDEFINED) { 5.43 - typeError("not.an.object", ScriptRuntime.safeToString(obj)); 5.44 + throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); 5.45 } 5.46 } 5.47
6.1 --- a/src/jdk/nashorn/internal/objects/NativeArguments.java Fri Feb 22 11:27:40 2013 +0100 6.2 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Fri Feb 22 12:22:16 2013 +0100 6.3 @@ -485,7 +485,7 @@ 6.4 final boolean allowed = super.defineOwnProperty(key, propertyDesc, false); 6.5 if (!allowed) { 6.6 if (reject) { 6.7 - typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 6.8 + throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 6.9 } 6.10 return false; 6.11 }
7.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Fri Feb 22 11:27:40 2013 +0100 7.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Fri Feb 22 12:22:16 2013 +0100 7.3 @@ -181,7 +181,7 @@ 7.4 // Step 3g 7.5 if (!oldLenDesc.isWritable()) { 7.6 if (reject) { 7.7 - typeError("property.not.writable", "length", ScriptRuntime.safeToString(this)); 7.8 + throw typeError("property.not.writable", "length", ScriptRuntime.safeToString(this)); 7.9 } 7.10 return false; 7.11 } 7.12 @@ -210,7 +210,7 @@ 7.13 } 7.14 super.defineOwnProperty("length", newLenDesc, false); 7.15 if (reject) { 7.16 - typeError("property.not.writable", "length", ScriptRuntime.safeToString(this)); 7.17 + throw typeError("property.not.writable", "length", ScriptRuntime.safeToString(this)); 7.18 } 7.19 return false; 7.20 } 7.21 @@ -235,7 +235,7 @@ 7.22 // setting an element beyond current length, but 'length' is not writable 7.23 if (longIndex >= oldLen && !oldLenDesc.isWritable()) { 7.24 if (reject) { 7.25 - typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this)); 7.26 + throw typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this)); 7.27 } 7.28 return false; 7.29 } 7.30 @@ -247,7 +247,7 @@ 7.31 // Step 4d 7.32 if (!succeeded) { 7.33 if (reject) { 7.34 - typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 7.35 + throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 7.36 } 7.37 return false; 7.38 } 7.39 @@ -324,7 +324,7 @@ 7.40 } 7.41 } 7.42 if (reject) { 7.43 - rangeError("inappropriate.array.length", ScriptRuntime.safeToString(length)); 7.44 + throw rangeError("inappropriate.array.length", ScriptRuntime.safeToString(length)); 7.45 } 7.46 return -1; 7.47 } 7.48 @@ -380,7 +380,7 @@ 7.49 if (toLocaleString instanceof ScriptFunction) { 7.50 sb.append((String)TO_LOCALE_STRING.getInvoker().invokeExact(toLocaleString, sobj)); 7.51 } else { 7.52 - typeError("not.a.function", "toLocaleString"); 7.53 + throw typeError("not.a.function", "toLocaleString"); 7.54 } 7.55 } 7.56 } catch (final Error|RuntimeException t) { 7.57 @@ -433,7 +433,7 @@ 7.58 */ 7.59 final double numberLength = ((Number) len).doubleValue(); 7.60 if (length != numberLength) { 7.61 - rangeError("inappropriate.array.length", JSType.toString(numberLength)); 7.62 + throw rangeError("inappropriate.array.length", JSType.toString(numberLength)); 7.63 } 7.64 7.65 return new NativeArray(length); 7.66 @@ -623,8 +623,7 @@ 7.67 7.68 return element; 7.69 } catch (final ClassCastException | NullPointerException e) { 7.70 - typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.71 - return ScriptRuntime.UNDEFINED; 7.72 + throw typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.73 } 7.74 } 7.75 7.76 @@ -659,8 +658,7 @@ 7.77 7.78 return len; 7.79 } catch (final ClassCastException | NullPointerException e) { 7.80 - typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.81 - return ScriptRuntime.UNDEFINED; 7.82 + throw typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.83 } 7.84 } 7.85 7.86 @@ -698,8 +696,7 @@ 7.87 } 7.88 return sobj; 7.89 } catch (final ClassCastException | NullPointerException e) { 7.90 - typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.91 - return ScriptRuntime.UNDEFINED; 7.92 + throw typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.93 } 7.94 } 7.95 7.96 @@ -864,8 +861,7 @@ 7.97 7.98 return sobj; 7.99 } catch (final ClassCastException | NullPointerException e) { 7.100 - typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.101 - return ScriptRuntime.UNDEFINED; 7.102 + throw typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.103 } 7.104 } 7.105 7.106 @@ -1079,7 +1075,7 @@ 7.107 } 7.108 } 7.109 } catch (final ClassCastException | NullPointerException e) { 7.110 - typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.111 + throw typeError("not.an.object", ScriptRuntime.safeToString(self)); 7.112 } 7.113 7.114 return -1; 7.115 @@ -1201,14 +1197,14 @@ 7.116 Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED; 7.117 7.118 if (callbackfn == ScriptRuntime.UNDEFINED) { 7.119 - typeError("not.a.function", "undefined"); 7.120 + throw typeError("not.a.function", "undefined"); 7.121 } 7.122 7.123 if (!initialValuePresent) { 7.124 if (iter.hasNext()) { 7.125 initialValue = iter.next(); 7.126 } else { 7.127 - typeError("array.reduce.invalid.init"); 7.128 + throw typeError("array.reduce.invalid.init"); 7.129 } 7.130 } 7.131
8.1 --- a/src/jdk/nashorn/internal/objects/NativeBoolean.java Fri Feb 22 11:27:40 2013 +0100 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java Fri Feb 22 12:22:16 2013 +0100 8.3 @@ -145,8 +145,7 @@ 8.4 } else if (self != null && self == Global.instance().getBooleanPrototype()) { 8.5 return false; 8.6 } else { 8.7 - typeError("not.a.boolean", ScriptRuntime.safeToString(self)); 8.8 - return false; 8.9 + throw typeError("not.a.boolean", ScriptRuntime.safeToString(self)); 8.10 } 8.11 } 8.12
9.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java Fri Feb 22 11:27:40 2013 +0100 9.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java Fri Feb 22 12:22:16 2013 +0100 9.3 @@ -867,14 +867,12 @@ 9.4 if (func instanceof ScriptFunction) { 9.5 return TO_ISO_STRING.getInvoker().invokeExact(func, sobj, key); 9.6 } 9.7 - typeError("not.a.function", ScriptRuntime.safeToString(func)); 9.8 + throw typeError("not.a.function", ScriptRuntime.safeToString(func)); 9.9 } catch (final RuntimeException | Error e) { 9.10 throw e; 9.11 } catch (final Throwable t) { 9.12 throw new RuntimeException(t); 9.13 } 9.14 - 9.15 - return null; 9.16 } 9.17 9.18 // -- Internals below this point 9.19 @@ -1006,9 +1004,7 @@ 9.20 return sb.toString(); 9.21 } 9.22 9.23 - rangeError("invalid.date"); 9.24 - 9.25 - return INVALID_DATE; 9.26 + throw rangeError("invalid.date"); 9.27 } 9.28 9.29 private static String toISOStringImpl(final Object self) { 9.30 @@ -1035,9 +1031,7 @@ 9.31 return sb.toString(); 9.32 } 9.33 9.34 - rangeError("invalid.date"); 9.35 - 9.36 - return INVALID_DATE; 9.37 + throw rangeError("invalid.date"); 9.38 } 9.39 9.40 // ECMA 15.9.1.2 Day (t) 9.41 @@ -1268,8 +1262,7 @@ 9.42 } else if (self != null && self == Global.instance().getDatePrototype()) { 9.43 return Global.instance().DEFAULT_DATE; 9.44 } else { 9.45 - typeError("not.a.date", ScriptRuntime.safeToString(self)); 9.46 - return null; 9.47 + throw typeError("not.a.date", ScriptRuntime.safeToString(self)); 9.48 } 9.49 } 9.50
10.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java Fri Feb 22 11:27:40 2013 +0100 10.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Fri Feb 22 12:22:16 2013 +0100 10.3 @@ -38,6 +38,7 @@ 10.4 import jdk.nashorn.internal.objects.annotations.Property; 10.5 import jdk.nashorn.internal.objects.annotations.ScriptClass; 10.6 import jdk.nashorn.internal.objects.annotations.Where; 10.7 +import jdk.nashorn.internal.runtime.ECMAErrors; 10.8 import jdk.nashorn.internal.runtime.ECMAException; 10.9 import jdk.nashorn.internal.runtime.JSType; 10.10 import jdk.nashorn.internal.runtime.ScriptObject; 10.11 @@ -246,7 +247,7 @@ 10.12 final StackTraceElement[] frames = ((Throwable)exception).getStackTrace(); 10.13 final List<StackTraceElement> filtered = new ArrayList<>(); 10.14 for (final StackTraceElement st : frames) { 10.15 - if (ECMAException.isScriptFrame(st)) { 10.16 + if (ECMAErrors.isScriptFrame(st)) { 10.17 filtered.add(st); 10.18 } 10.19 }
11.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java Fri Feb 22 11:27:40 2013 +0100 11.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java Fri Feb 22 12:22:16 2013 +0100 11.3 @@ -60,8 +60,7 @@ 11.4 @Function(attributes = Attribute.NOT_ENUMERABLE) 11.5 public static Object toString(final Object self) { 11.6 if (!(self instanceof ScriptFunction)) { 11.7 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.8 - return UNDEFINED; 11.9 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.10 } 11.11 return ((ScriptFunction)self).toSource(); 11.12 } 11.13 @@ -77,8 +76,7 @@ 11.14 @Function(attributes = Attribute.NOT_ENUMERABLE) 11.15 public static Object apply(final Object self, final Object thiz, final Object array) { 11.16 if (!(self instanceof ScriptFunction)) { 11.17 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.18 - return UNDEFINED; 11.19 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.20 } 11.21 11.22 Object[] args = null; 11.23 @@ -91,12 +89,12 @@ 11.24 final Object len = sobj.getLength(); 11.25 11.26 if (len == UNDEFINED || len == null) { 11.27 - typeError("function.apply.expects.array"); 11.28 + throw typeError("function.apply.expects.array"); 11.29 } 11.30 11.31 final int n = (int)JSType.toUint32(len); 11.32 if (n != JSType.toNumber(len)) { 11.33 - typeError("function.apply.expects.array"); 11.34 + throw typeError("function.apply.expects.array"); 11.35 } 11.36 11.37 args = new Object[(int)JSType.toUint32(len)]; 11.38 @@ -111,7 +109,7 @@ 11.39 } else if (array == null || array == UNDEFINED) { 11.40 args = ScriptRuntime.EMPTY_ARRAY; 11.41 } else { 11.42 - typeError("function.apply.expects.array"); 11.43 + throw typeError("function.apply.expects.array"); 11.44 } 11.45 11.46 return ScriptRuntime.apply((ScriptFunction)self, thiz, args); 11.47 @@ -127,8 +125,7 @@ 11.48 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 11.49 public static Object call(final Object self, final Object... args) { 11.50 if (!(self instanceof ScriptFunction)) { 11.51 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.52 - return UNDEFINED; 11.53 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.54 } 11.55 11.56 Object thiz = (args.length == 0) ? UNDEFINED : args[0]; 11.57 @@ -154,8 +151,7 @@ 11.58 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 11.59 public static Object bind(final Object self, final Object... args) { 11.60 if (!(self instanceof ScriptFunction)) { 11.61 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.62 - return UNDEFINED; 11.63 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.64 } 11.65 11.66 final Object thiz = (args.length == 0) ? UNDEFINED : args[0]; 11.67 @@ -180,8 +176,7 @@ 11.68 @Function(attributes = Attribute.NOT_ENUMERABLE) 11.69 public static Object toSource(final Object self) { 11.70 if (!(self instanceof ScriptFunction)) { 11.71 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.72 - return UNDEFINED; 11.73 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 11.74 } 11.75 return ((ScriptFunction)self).toSource(); 11.76 }
12.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Fri Feb 22 11:27:40 2013 +0100 12.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Fri Feb 22 12:22:16 2013 +0100 12.3 @@ -541,8 +541,7 @@ 12.4 Object adaptee; 12.5 12.6 if (args == null || args.length == 0) { 12.7 - typeError("not.an.object", "null"); 12.8 - return null; //won't reach, but fixed warning 12.9 + throw typeError("not.an.object", "null"); 12.10 } 12.11 12.12 switch (args.length) { 12.13 @@ -565,7 +564,7 @@ 12.14 } 12.15 12.16 if (!(adaptee instanceof ScriptObject)) { 12.17 - typeError("not.an.object", ScriptRuntime.safeToString(adaptee)); 12.18 + throw typeError("not.an.object", ScriptRuntime.safeToString(adaptee)); 12.19 } 12.20 12.21 if (proto != null && !(proto instanceof ScriptObject)) { 12.22 @@ -624,8 +623,7 @@ 12.23 func.makeBoundFunction(this, new Object[] { name })), 0, Object.class), 12.24 adaptee.getMap().getProtoGetSwitchPoint(__call__), testJSAdaptor(adaptee, null, null, null)); 12.25 } 12.26 - typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this)); 12.27 - break; 12.28 + throw typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this)); 12.29 default: 12.30 break; 12.31 } 12.32 @@ -697,8 +695,7 @@ 12.33 12.34 switch (hook) { 12.35 case __call__: 12.36 - typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this)); 12.37 - throw new AssertionError("should not reach here"); 12.38 + throw typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this)); 12.39 default: 12.40 final MethodHandle methodHandle = hook.equals(__put__) ? 12.41 MH.asType(Lookup.EMPTY_SETTER, type) :
13.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java Fri Feb 22 11:27:40 2013 +0100 13.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java Fri Feb 22 12:22:16 2013 +0100 13.3 @@ -241,7 +241,7 @@ 13.4 // Spec: The abstract operation JO(value) serializes an object. 13.5 private static String JO(final ScriptObject value, final StringifyState state) { 13.6 if (state.stack.containsKey(value)) { 13.7 - typeError("JSON.stringify.cyclic"); 13.8 + throw typeError("JSON.stringify.cyclic"); 13.9 } 13.10 13.11 state.stack.put(value, value); 13.12 @@ -317,7 +317,7 @@ 13.13 // Spec: The abstract operation JA(value) serializes an array. 13.14 private static Object JA(final NativeArray value, final StringifyState state) { 13.15 if (state.stack.containsKey(value)) { 13.16 - typeError("JSON.stringify.cyclic"); 13.17 + throw typeError("JSON.stringify.cyclic"); 13.18 } 13.19 13.20 state.stack.put(value, value);
14.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java Fri Feb 22 11:27:40 2013 +0100 14.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java Fri Feb 22 12:22:16 2013 +0100 14.3 @@ -287,9 +287,7 @@ 14.4 return new NativeArray(copyArray((boolean[])objArray)); 14.5 } 14.6 14.7 - typeError("cant.convert.to.javascript.array", objArray.getClass().getName()); 14.8 - 14.9 - throw new AssertionError(); 14.10 + throw typeError("cant.convert.to.javascript.array", objArray.getClass().getName()); 14.11 } 14.12 14.13 private static int[] copyArray(final byte[] in) { 14.14 @@ -384,8 +382,7 @@ 14.15 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 14.16 public static Object extend(final Object self, final Object... types) { 14.17 if(types == null || types.length == 0) { 14.18 - typeError("extend.expects.at.least.one.argument"); 14.19 - throw new AssertionError(); //circumvent warning for types == null below 14.20 + throw typeError("extend.expects.at.least.one.argument"); 14.21 } 14.22 final Class<?>[] stypes = new Class<?>[types.length]; 14.23 try { 14.24 @@ -393,7 +390,7 @@ 14.25 stypes[i] = ((StaticClass)types[i]).getRepresentedClass(); 14.26 } 14.27 } catch(final ClassCastException e) { 14.28 - typeError("extend.expects.java.types"); 14.29 + throw typeError("extend.expects.java.types"); 14.30 } 14.31 return JavaAdapterFactory.getAdapterClassFor(stypes); 14.32 }
15.1 --- a/src/jdk/nashorn/internal/objects/NativeNumber.java Fri Feb 22 11:27:40 2013 +0100 15.2 +++ b/src/jdk/nashorn/internal/objects/NativeNumber.java Fri Feb 22 12:22:16 2013 +0100 15.3 @@ -185,8 +185,7 @@ 15.4 public static Object toFixed(final Object self, final Object fractionDigits) { 15.5 final int f = JSType.toInteger(fractionDigits); 15.6 if (f < 0 || f > 20) { 15.7 - rangeError("invalid.fraction.digits", "toFixed"); 15.8 - return UNDEFINED; 15.9 + throw rangeError("invalid.fraction.digits", "toFixed"); 15.10 } 15.11 15.12 final double x = getNumberValue(self); 15.13 @@ -227,8 +226,7 @@ 15.14 } 15.15 15.16 if (fractionDigits != UNDEFINED && (f < 0 || f > 20)) { 15.17 - rangeError("invalid.fraction.digits", "toExponential"); 15.18 - return UNDEFINED; 15.19 + throw rangeError("invalid.fraction.digits", "toExponential"); 15.20 } 15.21 15.22 final String res = String.format(Locale.US, "%1." + f + "e", x); 15.23 @@ -258,8 +256,7 @@ 15.24 } 15.25 15.26 if (p < 1 || p > 21) { 15.27 - rangeError("invalid.precision"); 15.28 - return UNDEFINED; 15.29 + throw rangeError("invalid.precision"); 15.30 } 15.31 15.32 // workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6469160 15.33 @@ -283,7 +280,7 @@ 15.34 final int intRadix = JSType.toInteger(radix); 15.35 if (intRadix != 10) { 15.36 if (intRadix < 2 || intRadix > 36) { 15.37 - rangeError("invalid.radix"); 15.38 + throw rangeError("invalid.radix"); 15.39 } 15.40 return JSType.toString(getNumberValue(self), intRadix); 15.41 } 15.42 @@ -338,8 +335,7 @@ 15.43 } else if (self != null && self == Global.instance().getNumberPrototype()) { 15.44 return 0.0; 15.45 } else { 15.46 - typeError("not.a.number", ScriptRuntime.safeToString(self)); 15.47 - return Double.NaN; 15.48 + throw typeError("not.a.number", ScriptRuntime.safeToString(self)); 15.49 } 15.50 } 15.51
16.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Fri Feb 22 11:27:40 2013 +0100 16.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Fri Feb 22 12:22:16 2013 +0100 16.3 @@ -331,8 +331,7 @@ 16.4 throw new RuntimeException(t); 16.5 } 16.6 16.7 - typeError("not.a.function", "toString"); 16.8 - throw new AssertionError(); // never reached 16.9 + throw typeError("not.a.function", "toString"); 16.10 } 16.11 16.12 return ScriptRuntime.builtinObjectToString(self);
17.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Fri Feb 22 11:27:40 2013 +0100 17.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Fri Feb 22 12:22:16 2013 +0100 17.3 @@ -224,7 +224,7 @@ 17.4 if (!flagsDefined) { 17.5 return (NativeRegExp)regexp; // 15.10.3.1 - undefined flags and regexp as 17.6 } 17.7 - typeError("regex.cant.supply.flags"); 17.8 + throw typeError("regex.cant.supply.flags"); 17.9 } 17.10 patternString = JSType.toString(regexp); 17.11 } 17.12 @@ -880,8 +880,7 @@ 17.13 } else if (self != null && self == Global.instance().getRegExpPrototype()) { 17.14 return Global.instance().DEFAULT_REGEXP; 17.15 } else { 17.16 - typeError("not.a.regexp", ScriptRuntime.safeToString(self)); 17.17 - return null; 17.18 + throw typeError("not.a.regexp", ScriptRuntime.safeToString(self)); 17.19 } 17.20 } 17.21
18.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java Fri Feb 22 11:27:40 2013 +0100 18.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java Fri Feb 22 12:22:16 2013 +0100 18.3 @@ -342,7 +342,7 @@ 18.4 private boolean checkDeleteIndex(final int index, final boolean strict) { 18.5 if (isValid(index)) { 18.6 if (strict) { 18.7 - typeError("cant.delete.property", Integer.toString(index), ScriptRuntime.safeToString(this)); 18.8 + throw typeError("cant.delete.property", Integer.toString(index), ScriptRuntime.safeToString(this)); 18.9 } 18.10 return true; 18.11 } 18.12 @@ -1141,8 +1141,7 @@ 18.13 } else if (self != null && self == Global.instance().getStringPrototype()) { 18.14 return ""; 18.15 } else { 18.16 - typeError("not.a.string", ScriptRuntime.safeToString(self)); 18.17 - return null; 18.18 + throw typeError("not.a.string", ScriptRuntime.safeToString(self)); 18.19 } 18.20 } 18.21 18.22 @@ -1156,8 +1155,7 @@ 18.23 } else if (self != null && self == Global.instance().getStringPrototype()) { 18.24 return ""; 18.25 } else { 18.26 - typeError( "not.a.string", ScriptRuntime.safeToString(self)); 18.27 - return null; 18.28 + throw typeError( "not.a.string", ScriptRuntime.safeToString(self)); 18.29 } 18.30 } 18.31
19.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java Fri Feb 22 11:27:40 2013 +0100 19.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java Fri Feb 22 12:22:16 2013 +0100 19.3 @@ -214,9 +214,7 @@ 19.4 final int lineNum = source.getLine(position); 19.5 final int columnNum = source.getColumn(position); 19.6 final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken); 19.7 - final ParserException exp = new ParserException(formatted, source, lineNum, columnNum, errorToken); 19.8 - exp.setErrorType(errorType); 19.9 - throw exp; 19.10 + throw new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken); 19.11 } 19.12 19.13 /** 19.14 @@ -239,9 +237,7 @@ 19.15 final int position = Token.descPosition(token); 19.16 final int column = position - linePosition; 19.17 final String formatted = ErrorManager.format(message, source, line, column, token); 19.18 - final ParserException exp = new ParserException(formatted, source, line, column, token); 19.19 - exp.setErrorType(errorType); 19.20 - throw exp; 19.21 + throw new ParserException(errorType, formatted, source, line, column, token); 19.22 } 19.23 19.24 /**
20.1 --- a/src/jdk/nashorn/internal/parser/Lexer.java Fri Feb 22 11:27:40 2013 +0100 20.2 +++ b/src/jdk/nashorn/internal/parser/Lexer.java Fri Feb 22 12:22:16 2013 +0100 20.3 @@ -45,6 +45,7 @@ 20.4 20.5 import jdk.nashorn.internal.runtime.ECMAErrors; 20.6 import jdk.nashorn.internal.runtime.ErrorManager; 20.7 +import jdk.nashorn.internal.runtime.JSErrorType; 20.8 import jdk.nashorn.internal.runtime.JSType; 20.9 import jdk.nashorn.internal.runtime.ParserException; 20.10 import jdk.nashorn.internal.runtime.Source; 20.11 @@ -1598,7 +1599,7 @@ 20.12 final int lineNum = source.getLine(pos); 20.13 final int columnNum = source.getColumn(pos); 20.14 final String formatted = ErrorManager.format(message, source, lineNum, columnNum, token); 20.15 - throw new ParserException(formatted, source, lineNum, columnNum, token); 20.16 + throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, lineNum, columnNum, token); 20.17 } 20.18 20.19 /**
21.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Fri Feb 22 11:27:40 2013 +0100 21.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Fri Feb 22 12:22:16 2013 +0100 21.3 @@ -671,9 +671,7 @@ 21.4 return evaluateSource(source, scope, scope); 21.5 } 21.6 21.7 - typeError("cant.load.script", ScriptRuntime.safeToString(from)); 21.8 - 21.9 - return UNDEFINED; 21.10 + throw typeError("cant.load.script", ScriptRuntime.safeToString(from)); 21.11 } 21.12 21.13 /**
22.1 --- a/src/jdk/nashorn/internal/runtime/ECMAErrors.java Fri Feb 22 11:27:40 2013 +0100 22.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAErrors.java Fri Feb 22 12:22:16 2013 +0100 22.3 @@ -31,6 +31,9 @@ 22.4 import java.util.Locale; 22.5 import java.util.ResourceBundle; 22.6 22.7 +import jdk.nashorn.api.scripting.NashornException; 22.8 +import jdk.nashorn.internal.scripts.JS$; 22.9 + 22.10 /** 22.11 * Helper class to throw various standard "ECMA error" exceptions such as Error, ReferenceError, TypeError etc. 22.12 */ 22.13 @@ -49,36 +52,44 @@ 22.14 }); 22.15 } 22.16 22.17 + /** We assume that compiler generates script classes into the known package. */ 22.18 + private static final String scriptPackage; 22.19 + static { 22.20 + String name = JS$.class.getName(); 22.21 + scriptPackage = name.substring(0, name.lastIndexOf('.')); 22.22 + } 22.23 + 22.24 private ECMAErrors() { 22.25 } 22.26 22.27 - private static void throwError(final Object thrown, final Throwable cause) { 22.28 - throw new ECMAException(thrown, cause); 22.29 + private static ECMAException error(final Object thrown, final Throwable cause) { 22.30 + return new ECMAException(thrown, cause); 22.31 } 22.32 22.33 /** 22.34 * Error dispatch mechanism. 22.35 - * Throw a {@link ParserException} as the correct JavaScript error 22.36 + * Create a {@link ParserException} as the correct JavaScript error 22.37 * 22.38 * @param e {@code ParserException} for error dispatcher 22.39 + * 22.40 + * @return the resulting {@link ECMAException} 22.41 */ 22.42 - public static void throwAsEcmaException(final ParserException e) { 22.43 - throwAsEcmaException(Context.getGlobalTrusted(), e); 22.44 + public static ECMAException asEcmaException(final ParserException e) { 22.45 + return asEcmaException(Context.getGlobalTrusted(), e); 22.46 } 22.47 22.48 /** 22.49 * Error dispatch mechanism. 22.50 - * Throw a {@link ParserException} as the correct JavaScript error 22.51 + * Create a {@link ParserException} as the correct JavaScript error 22.52 * 22.53 * @param global global scope object 22.54 * @param e {@code ParserException} for error dispatcher 22.55 + * 22.56 + * @return the resulting {@link ECMAException} 22.57 */ 22.58 - public static void throwAsEcmaException(final ScriptObject global, final ParserException e) { 22.59 + public static ECMAException asEcmaException(final ScriptObject global, final ParserException e) { 22.60 final JSErrorType errorType = e.getErrorType(); 22.61 - if (errorType == null) { 22.62 - // no errorType set, throw ParserException object 'as is' 22.63 - throw e; 22.64 - } 22.65 + assert errorType != null : "error type for " + e + " was null"; 22.66 22.67 final GlobalObject globalObj = (GlobalObject)global; 22.68 final String msg = e.getMessage(); 22.69 @@ -86,256 +97,288 @@ 22.70 // translate to ECMAScript Error object using error type 22.71 switch (errorType) { 22.72 case ERROR: 22.73 - throwError(globalObj.newError(msg), e); 22.74 - break; 22.75 + return error(globalObj.newError(msg), e); 22.76 case EVAL_ERROR: 22.77 - throwError(globalObj.newEvalError(msg), e); 22.78 - break; 22.79 + return error(globalObj.newEvalError(msg), e); 22.80 case RANGE_ERROR: 22.81 - throwError(globalObj.newRangeError(msg), e); 22.82 - break; 22.83 + return error(globalObj.newRangeError(msg), e); 22.84 case REFERENCE_ERROR: 22.85 - throwError(globalObj.newReferenceError(msg), e); 22.86 - break; 22.87 + return error(globalObj.newReferenceError(msg), e); 22.88 case SYNTAX_ERROR: 22.89 - throwError(globalObj.newSyntaxError(msg), e); 22.90 - break; 22.91 + return error(globalObj.newSyntaxError(msg), e); 22.92 case TYPE_ERROR: 22.93 - throwError(globalObj.newTypeError(msg), e); 22.94 - break; 22.95 + return error(globalObj.newTypeError(msg), e); 22.96 case URI_ERROR: 22.97 - throwError(globalObj.newURIError(msg), e); 22.98 - break; 22.99 + return error(globalObj.newURIError(msg), e); 22.100 default: 22.101 - break; 22.102 + // should not happen - perhaps unknown error type? 22.103 + throw new AssertionError(e.getMessage()); 22.104 } 22.105 + } 22.106 22.107 - // should not happen - perhaps unknown error type? 22.108 - throw e; 22.109 - } 22.110 /** 22.111 - * Throw a syntax error (ECMA 15.11.6.4) 22.112 + * Create a syntax error (ECMA 15.11.6.4) 22.113 * 22.114 * @param msgId resource tag for error message 22.115 * @param args arguments to resource 22.116 + * 22.117 + * @return the resulting {@link ECMAException} 22.118 */ 22.119 - public static void syntaxError(final String msgId, final String... args) { 22.120 - syntaxError(Context.getGlobalTrusted(), msgId, args); 22.121 + public static ECMAException syntaxError(final String msgId, final String... args) { 22.122 + return syntaxError(Context.getGlobalTrusted(), msgId, args); 22.123 } 22.124 22.125 /** 22.126 - * Throw a syntax error (ECMA 15.11.6.4) 22.127 + * Create a syntax error (ECMA 15.11.6.4) 22.128 * 22.129 * @param global global scope object 22.130 * @param msgId resource tag for error message 22.131 * @param args arguments to resource 22.132 + * 22.133 + * @return the resulting {@link ECMAException} 22.134 */ 22.135 - public static void syntaxError(final ScriptObject global, final String msgId, final String... args) { 22.136 - syntaxError(global, null, msgId, args); 22.137 + public static ECMAException syntaxError(final ScriptObject global, final String msgId, final String... args) { 22.138 + return syntaxError(global, null, msgId, args); 22.139 } 22.140 22.141 /** 22.142 - * Throw a syntax error (ECMA 15.11.6.4) 22.143 + * Create a syntax error (ECMA 15.11.6.4) 22.144 * 22.145 * @param cause native Java {@code Throwable} that is the cause of error 22.146 * @param msgId resource tag for error message 22.147 * @param args arguments to resource 22.148 + * 22.149 + * @return the resulting {@link ECMAException} 22.150 */ 22.151 - public static void syntaxError(final Throwable cause, final String msgId, final String... args) { 22.152 - syntaxError(Context.getGlobalTrusted(), cause, msgId, args); 22.153 + public static ECMAException syntaxError(final Throwable cause, final String msgId, final String... args) { 22.154 + return syntaxError(Context.getGlobalTrusted(), cause, msgId, args); 22.155 } 22.156 22.157 /** 22.158 - * Throw a syntax error (ECMA 15.11.6.4) 22.159 + * Create a syntax error (ECMA 15.11.6.4) 22.160 * 22.161 * @param global global scope object 22.162 * @param cause native Java {@code Throwable} that is the cause of error 22.163 * @param msgId resource tag for error message 22.164 * @param args arguments to resource 22.165 + * 22.166 + * @return the resulting {@link ECMAException} 22.167 */ 22.168 - public static void syntaxError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.169 + public static ECMAException syntaxError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.170 final String msg = getMessage("syntax.error." + msgId, args); 22.171 - throwError(((GlobalObject)global).newSyntaxError(msg), cause); 22.172 + return error(((GlobalObject)global).newSyntaxError(msg), cause); 22.173 } 22.174 22.175 /** 22.176 - * Throw a type error (ECMA 15.11.6.5) 22.177 + * Create a type error (ECMA 15.11.6.5) 22.178 * 22.179 * @param msgId resource tag for error message 22.180 * @param args arguments to resource 22.181 + * 22.182 + * @return the resulting {@link ECMAException} 22.183 */ 22.184 - public static void typeError(final String msgId, final String... args) { 22.185 - typeError(Context.getGlobalTrusted(), msgId, args); 22.186 + public static ECMAException typeError(final String msgId, final String... args) { 22.187 + return typeError(Context.getGlobalTrusted(), msgId, args); 22.188 } 22.189 22.190 /** 22.191 - * Throw a type error (ECMA 15.11.6.5) 22.192 + * Create a type error (ECMA 15.11.6.5) 22.193 * 22.194 * @param global global scope object 22.195 * @param msgId resource tag for error message 22.196 * @param args arguments to resource 22.197 + * 22.198 + * @return the resulting {@link ECMAException} 22.199 */ 22.200 - public static void typeError(final ScriptObject global, final String msgId, final String... args) { 22.201 - typeError(global, null, msgId, args); 22.202 + public static ECMAException typeError(final ScriptObject global, final String msgId, final String... args) { 22.203 + return typeError(global, null, msgId, args); 22.204 } 22.205 22.206 /** 22.207 - * Throw a type error (ECMA 15.11.6.5) 22.208 + * Create a type error (ECMA 15.11.6.5) 22.209 * 22.210 * @param cause native Java {@code Throwable} that is the cause of error 22.211 * @param msgId resource tag for error message 22.212 * @param args arguments to resource 22.213 + * 22.214 + * @return the resulting {@link ECMAException} 22.215 */ 22.216 - public static void typeError(final Throwable cause, final String msgId, final String... args) { 22.217 - typeError(Context.getGlobalTrusted(), cause, msgId, args); 22.218 + public static ECMAException typeError(final Throwable cause, final String msgId, final String... args) { 22.219 + return typeError(Context.getGlobalTrusted(), cause, msgId, args); 22.220 } 22.221 22.222 /** 22.223 - * Throw a type error (ECMA 15.11.6.5) 22.224 + * Create a type error (ECMA 15.11.6.5) 22.225 * 22.226 * @param global global scope object 22.227 * @param cause native Java {@code Throwable} that is the cause of error 22.228 * @param msgId resource tag for error message 22.229 * @param args arguments to resource 22.230 + * 22.231 + * @return the resulting {@link ECMAException} 22.232 */ 22.233 - public static void typeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.234 + public static ECMAException typeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.235 final String msg = getMessage("type.error." + msgId, args); 22.236 - throwError(((GlobalObject)global).newTypeError(msg), cause); 22.237 + return error(((GlobalObject)global).newTypeError(msg), cause); 22.238 } 22.239 22.240 /** 22.241 - * Throw a range error (ECMA 15.11.6.2) 22.242 + * Create a range error (ECMA 15.11.6.2) 22.243 * 22.244 * @param msgId resource tag for error message 22.245 * @param args arguments to resource 22.246 + * 22.247 + * @return the resulting {@link ECMAException} 22.248 */ 22.249 - public static void rangeError(final String msgId, final String... args) { 22.250 - rangeError(Context.getGlobalTrusted(), msgId, args); 22.251 + public static ECMAException rangeError(final String msgId, final String... args) { 22.252 + return rangeError(Context.getGlobalTrusted(), msgId, args); 22.253 } 22.254 22.255 /** 22.256 - * Throw a range error (ECMA 15.11.6.2) 22.257 + * Create a range error (ECMA 15.11.6.2) 22.258 * 22.259 * @param global global scope object 22.260 * @param msgId resource tag for error message 22.261 * @param args arguments to resource 22.262 + * 22.263 + * @return the resulting {@link ECMAException} 22.264 */ 22.265 - public static void rangeError(final ScriptObject global, final String msgId, final String... args) { 22.266 - rangeError(global, null, msgId, args); 22.267 + public static ECMAException rangeError(final ScriptObject global, final String msgId, final String... args) { 22.268 + return rangeError(global, null, msgId, args); 22.269 } 22.270 22.271 /** 22.272 - * Throw a range error (ECMA 15.11.6.2) 22.273 + * Create a range error (ECMA 15.11.6.2) 22.274 * 22.275 * @param cause native Java {@code Throwable} that is the cause of error 22.276 * @param msgId resource tag for error message 22.277 * @param args arguments to resource 22.278 + * 22.279 + * @return the resulting {@link ECMAException} 22.280 */ 22.281 - public static void rangeError(final Throwable cause, final String msgId, final String... args) { 22.282 - rangeError(Context.getGlobalTrusted(), cause, msgId, args); 22.283 + public static ECMAException rangeError(final Throwable cause, final String msgId, final String... args) { 22.284 + return rangeError(Context.getGlobalTrusted(), cause, msgId, args); 22.285 } 22.286 22.287 /** 22.288 - * Throw a range error (ECMA 15.11.6.2) 22.289 + * Create a range error (ECMA 15.11.6.2) 22.290 * 22.291 * @param global global scope object 22.292 * @param cause native Java {@code Throwable} that is the cause of error 22.293 * @param msgId resource tag for error message 22.294 * @param args arguments to resource 22.295 + * 22.296 + * @return the resulting {@link ECMAException} 22.297 */ 22.298 - public static void rangeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.299 + public static ECMAException rangeError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.300 final String msg = getMessage("range.error." + msgId, args); 22.301 - throwError(((GlobalObject)global).newRangeError(msg), cause); 22.302 + return error(((GlobalObject)global).newRangeError(msg), cause); 22.303 } 22.304 22.305 /** 22.306 - * Throw a reference error (ECMA 15.11.6.3) 22.307 + * Create a reference error (ECMA 15.11.6.3) 22.308 * 22.309 * @param msgId resource tag for error message 22.310 * @param args arguments to resource 22.311 + * 22.312 + * @return the resulting {@link ECMAException} 22.313 */ 22.314 - public static void referenceError(final String msgId, final String... args) { 22.315 - referenceError(Context.getGlobalTrusted(), msgId, args); 22.316 + public static ECMAException referenceError(final String msgId, final String... args) { 22.317 + return referenceError(Context.getGlobalTrusted(), msgId, args); 22.318 } 22.319 22.320 /** 22.321 - * Throw a reference error (ECMA 15.11.6.3) 22.322 + * Create a reference error (ECMA 15.11.6.3) 22.323 * 22.324 * @param global global scope object 22.325 * @param msgId resource tag for error message 22.326 * @param args arguments to resource 22.327 + * 22.328 + * @return the resulting {@link ECMAException} 22.329 */ 22.330 - public static void referenceError(final ScriptObject global, final String msgId, final String... args) { 22.331 - referenceError(global, null, msgId, args); 22.332 + public static ECMAException referenceError(final ScriptObject global, final String msgId, final String... args) { 22.333 + return referenceError(global, null, msgId, args); 22.334 } 22.335 22.336 /** 22.337 - * Throw a reference error (ECMA 15.11.6.3) 22.338 + * Create a reference error (ECMA 15.11.6.3) 22.339 * 22.340 * @param cause native Java {@code Throwable} that is the cause of error 22.341 * @param msgId resource tag for error message 22.342 * @param args arguments to resource 22.343 + * 22.344 + * @return the resulting {@link ECMAException} 22.345 */ 22.346 - public static void referenceError(final Throwable cause, final String msgId, final String... args) { 22.347 - referenceError(Context.getGlobalTrusted(), cause, msgId, args); 22.348 + public static ECMAException referenceError(final Throwable cause, final String msgId, final String... args) { 22.349 + return referenceError(Context.getGlobalTrusted(), cause, msgId, args); 22.350 } 22.351 22.352 /** 22.353 - * Throw a reference error (ECMA 15.11.6.3) 22.354 + * Create a reference error (ECMA 15.11.6.3) 22.355 * 22.356 * @param global global scope object 22.357 * @param cause native Java {@code Throwable} that is the cause of error 22.358 * @param msgId resource tag for error message 22.359 * @param args arguments to resource 22.360 + * 22.361 + * @return the resulting {@link ECMAException} 22.362 */ 22.363 - public static void referenceError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.364 + public static ECMAException referenceError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.365 final String msg = getMessage("reference.error." + msgId, args); 22.366 - throwError(((GlobalObject)global).newReferenceError(msg), cause); 22.367 + return error(((GlobalObject)global).newReferenceError(msg), cause); 22.368 } 22.369 22.370 /** 22.371 - * Throw a URI error (ECMA 15.11.6.6) 22.372 + * Create a URI error (ECMA 15.11.6.6) 22.373 * 22.374 * @param msgId resource tag for error message 22.375 * @param args arguments to resource 22.376 + * 22.377 + * @return the resulting {@link ECMAException} 22.378 */ 22.379 - public static void uriError(final String msgId, final String... args) { 22.380 - uriError(Context.getGlobalTrusted(), msgId, args); 22.381 + public static ECMAException uriError(final String msgId, final String... args) { 22.382 + return uriError(Context.getGlobalTrusted(), msgId, args); 22.383 } 22.384 22.385 /** 22.386 - * Throw a URI error (ECMA 15.11.6.6) 22.387 + * Create a URI error (ECMA 15.11.6.6) 22.388 * 22.389 * @param global global scope object 22.390 * @param msgId resource tag for error message 22.391 * @param args arguments to resource 22.392 + * 22.393 + * @return the resulting {@link ECMAException} 22.394 */ 22.395 - public static void uriError(final ScriptObject global, final String msgId, final String... args) { 22.396 - uriError(global, null, msgId, args); 22.397 + public static ECMAException uriError(final ScriptObject global, final String msgId, final String... args) { 22.398 + return uriError(global, null, msgId, args); 22.399 } 22.400 22.401 /** 22.402 - * Throw a URI error (ECMA 15.11.6.6) 22.403 + * Create a URI error (ECMA 15.11.6.6) 22.404 * 22.405 * @param cause native Java {@code Throwable} that is the cause of error 22.406 * @param msgId resource tag for error message 22.407 * @param args arguments to resource 22.408 + * 22.409 + * @return the resulting {@link ECMAException} 22.410 */ 22.411 - public static void uriError(final Throwable cause, final String msgId, final String... args) { 22.412 - uriError(Context.getGlobalTrusted(), cause, msgId, args); 22.413 + public static ECMAException uriError(final Throwable cause, final String msgId, final String... args) { 22.414 + return uriError(Context.getGlobalTrusted(), cause, msgId, args); 22.415 } 22.416 22.417 /** 22.418 - * Throw a URI error (ECMA 15.11.6.6) 22.419 + * Create a URI error (ECMA 15.11.6.6) 22.420 * 22.421 * @param global global scope object 22.422 * @param cause native Java {@code Throwable} that is the cause of error 22.423 * @param msgId resource tag for error message 22.424 * @param args arguments to resource 22.425 + * 22.426 + * @return the resulting {@link ECMAException} 22.427 */ 22.428 - public static void uriError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.429 + public static ECMAException uriError(final ScriptObject global, final Throwable cause, final String msgId, final String... args) { 22.430 final String msg = getMessage("uri.error." + msgId, args); 22.431 - throwError(((GlobalObject)global).newURIError(msg), cause); 22.432 + return error(((GlobalObject)global).newURIError(msg), cause); 22.433 } 22.434 22.435 /** 22.436 @@ -356,4 +399,27 @@ 22.437 } 22.438 } 22.439 22.440 + 22.441 + /** 22.442 + * Check if a stack trace element is in JavaScript 22.443 + * 22.444 + * @param frame frame 22.445 + * 22.446 + * @return true if frame is in the script 22.447 + */ 22.448 + public static boolean isScriptFrame(final StackTraceElement frame) { 22.449 + final String className = frame.getClassName(); 22.450 + 22.451 + // Look for script package in class name (into which compiler puts generated code) 22.452 + if (className.startsWith(scriptPackage)) { 22.453 + final String source = frame.getFileName(); 22.454 + /* 22.455 + * Make sure that it is not some Java code that Nashorn has in that package! 22.456 + * also, we don't want to report JavaScript code that lives in script engine implementation 22.457 + * We want to report only user's own scripts and not any of our own scripts like "engine.js" 22.458 + */ 22.459 + return source != null && !source.endsWith(".java") && !source.contains(NashornException.ENGINE_SCRIPT_SOURCE_NAME); 22.460 + } 22.461 + return false; 22.462 + } 22.463 }
23.1 --- a/src/jdk/nashorn/internal/runtime/ECMAException.java Fri Feb 22 11:27:40 2013 +0100 23.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAException.java Fri Feb 22 12:22:16 2013 +0100 23.3 @@ -33,7 +33,6 @@ 23.4 import jdk.nashorn.api.scripting.NashornException; 23.5 import jdk.nashorn.internal.codegen.CompilerConstants.Call; 23.6 import jdk.nashorn.internal.codegen.CompilerConstants.FieldAccess; 23.7 -import jdk.nashorn.internal.scripts.JS$; 23.8 23.9 /** 23.10 * Exception used to implement ECMAScript "throw" from scripts. The actual thrown 23.11 @@ -54,13 +53,6 @@ 23.12 23.13 private static final String EXCEPTION_PROPERTY = "nashornException"; 23.14 23.15 - /** We assume that compiler generates script classes into the known package. */ 23.16 - private static final String scriptPackage; 23.17 - static { 23.18 - String name = JS$.class.getName(); 23.19 - scriptPackage = name.substring(0, name.lastIndexOf('.')); 23.20 - } 23.21 - 23.22 /** Object thrown. */ 23.23 public final Object thrown; 23.24 23.25 @@ -74,10 +66,7 @@ 23.26 * @param column column number of throw 23.27 */ 23.28 public ECMAException(final Object thrown, final String fileName, final int line, final int column) { 23.29 - super(ScriptRuntime.safeToString(thrown), asThrowable(thrown)); 23.30 - setFileName(fileName); 23.31 - setLineNumber(line); 23.32 - setColumnNumber(column); 23.33 + super(ScriptRuntime.safeToString(thrown), asThrowable(thrown), fileName, line, column); 23.34 this.thrown = thrown; 23.35 setExceptionToThrown(); 23.36 } 23.37 @@ -93,8 +82,6 @@ 23.38 super(ScriptRuntime.safeToString(thrown), cause); 23.39 this.thrown = thrown; 23.40 setExceptionToThrown(); 23.41 - // location is not directly available, get it from stack trace 23.42 - setLocationFromStack(); 23.43 } 23.44 23.45 /** 23.46 @@ -143,29 +130,6 @@ 23.47 } 23.48 23.49 /** 23.50 - * Check if a stack trace element is in JavaScript 23.51 - * 23.52 - * @param frame frame 23.53 - * 23.54 - * @return true if frame is in the script 23.55 - */ 23.56 - public static boolean isScriptFrame(final StackTraceElement frame) { 23.57 - final String className = frame.getClassName(); 23.58 - 23.59 - // Look for script package in class name (into which compiler puts generated code) 23.60 - if (className.startsWith(scriptPackage)) { 23.61 - final String source = frame.getFileName(); 23.62 - /* 23.63 - * Make sure that it is not some Java code that Nashorn has in that package! 23.64 - * also, we don't want to report JavaScript code that lives in script engine implementation 23.65 - * We want to report only user's own scripts and not any of our own scripts like "engine.js" 23.66 - */ 23.67 - return source != null && !source.endsWith(".java") && !source.contains(ENGINE_SCRIPT_SOURCE_NAME); 23.68 - } 23.69 - return false; 23.70 - } 23.71 - 23.72 - /** 23.73 * Print the stack trace for a {@code ScriptObject} representing an error 23.74 * 23.75 * @param errObj the error object 23.76 @@ -295,23 +259,4 @@ 23.77 } 23.78 } 23.79 } 23.80 - 23.81 - private void setLocationFromStack() { 23.82 - // This is not so pretty - but it gets the job done. Note that the stack 23.83 - // trace has been already filled by "fillInStackTrace" call from Throwable 23.84 - // constructor and so we don't pay additional cost for it. 23.85 - 23.86 - // Find the first JavaScript frame by walking and set file, line from it 23.87 - // Usually, we should be able to find it in just few frames depth. 23.88 - for (final StackTraceElement ste : getStackTrace()) { 23.89 - if (isScriptFrame(ste)) { 23.90 - // Whatever here is compiled from JavaScript code 23.91 - setFileName(ste.getFileName()); 23.92 - setLineNumber(ste.getLineNumber()); 23.93 - // Hard luck - no column number info 23.94 - setColumnNumber(-1); 23.95 - break; 23.96 - } 23.97 - } 23.98 - } 23.99 }
24.1 --- a/src/jdk/nashorn/internal/runtime/ErrorManager.java Fri Feb 22 11:27:40 2013 +0100 24.2 +++ b/src/jdk/nashorn/internal/runtime/ErrorManager.java Fri Feb 22 12:22:16 2013 +0100 24.3 @@ -79,7 +79,7 @@ 24.4 } 24.5 24.6 if (limit != 0 && count > limit) { 24.7 - rangeError("too.many.errors", Integer.toString(limit)); 24.8 + throw rangeError("too.many.errors", Integer.toString(limit)); 24.9 } 24.10 } 24.11
25.1 --- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java Fri Feb 22 11:27:40 2013 +0100 25.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java Fri Feb 22 12:22:16 2013 +0100 25.3 @@ -79,8 +79,7 @@ 25.4 try { 25.5 node = parser.parse(); 25.6 } catch (final ParserException e) { 25.7 - ECMAErrors.syntaxError(e, "invalid.json", e.getMessage()); 25.8 - return ScriptRuntime.UNDEFINED; 25.9 + throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage()); 25.10 } 25.11 25.12 final ScriptObject global = Context.getGlobalTrusted();
26.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Fri Feb 22 11:27:40 2013 +0100 26.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Fri Feb 22 12:22:16 2013 +0100 26.3 @@ -248,7 +248,7 @@ 26.4 final Object result = sobj.getDefaultValue(hint); 26.5 26.6 if (!isPrimitive(result)) { 26.7 - typeError("bad.default.value", result.toString()); 26.8 + throw typeError("bad.default.value", result.toString()); 26.9 } 26.10 26.11 return result; 26.12 @@ -823,7 +823,7 @@ 26.13 */ 26.14 public static Object toScriptObject(final ScriptObject global, final Object obj) { 26.15 if (nullOrUndefined(obj)) { 26.16 - typeError(global, "not.an.object", ScriptRuntime.safeToString(obj)); 26.17 + throw typeError(global, "not.an.object", ScriptRuntime.safeToString(obj)); 26.18 } 26.19 26.20 if (obj instanceof ScriptObject) {
27.1 --- a/src/jdk/nashorn/internal/runtime/ParserException.java Fri Feb 22 11:27:40 2013 +0100 27.2 +++ b/src/jdk/nashorn/internal/runtime/ParserException.java Fri Feb 22 12:22:16 2013 +0100 27.3 @@ -34,11 +34,11 @@ 27.4 @SuppressWarnings("serial") 27.5 public final class ParserException extends NashornException { 27.6 // Source from which this ParserException originated 27.7 - private Source source; 27.8 + private final Source source; 27.9 // token responsible for this exception 27.10 - private long token; 27.11 + private final long token; 27.12 // if this is traslated as ECMA error, which type should be used? 27.13 - private JSErrorType errorType; 27.14 + private final JSErrorType errorType; 27.15 27.16 /** 27.17 * Constructor 27.18 @@ -46,29 +46,25 @@ 27.19 * @param msg exception message for this parser error. 27.20 */ 27.21 public ParserException(final String msg) { 27.22 - this(msg, null, -1, -1, -1); 27.23 + this(JSErrorType.SYNTAX_ERROR, msg, null, -1, -1, -1); 27.24 } 27.25 27.26 /** 27.27 * Constructor 27.28 * 27.29 - * @param msg exception message 27.30 - * @param source source from which this exception originates 27.31 - * @param line line number of exception 27.32 - * @param column column number of exception 27.33 - * @param token token from which this exception originates 27.34 + * @param errorType error type 27.35 + * @param msg exception message 27.36 + * @param source source from which this exception originates 27.37 + * @param line line number of exception 27.38 + * @param column column number of exception 27.39 + * @param token token from which this exception originates 27.40 * 27.41 */ 27.42 - public ParserException(final String msg, final Source source, final int line, final int column, final long token) { 27.43 - super(msg); 27.44 - setSource(source); 27.45 - if (source != null) { 27.46 - setFileName(source.getName()); 27.47 - } 27.48 - setLineNumber(line); 27.49 - setColumnNumber(column); 27.50 - setToken(token); 27.51 - setErrorType(JSErrorType.SYNTAX_ERROR); 27.52 + public ParserException(final JSErrorType errorType, final String msg, final Source source, final int line, final int column, final long token) { 27.53 + super(msg, source != null ? source.getName() : null, line, column); 27.54 + this.source = source; 27.55 + this.token = token; 27.56 + this.errorType = errorType; 27.57 } 27.58 27.59 /** 27.60 @@ -80,14 +76,6 @@ 27.61 } 27.62 27.63 /** 27.64 - * Set the {@code Source} of this {@code ParserException} 27.65 - * @param source script source 27.66 - */ 27.67 - public void setSource(Source source) { 27.68 - this.source = source; 27.69 - } 27.70 - 27.71 - /** 27.72 * Get the token responsible for this {@code ParserException} 27.73 * @return token 27.74 */ 27.75 @@ -96,14 +84,6 @@ 27.76 } 27.77 27.78 /** 27.79 - * Set the errand token of this {@code ParserException} 27.80 - * @param token token responsible for this ParserException 27.81 - */ 27.82 - public void setToken(final long token) { 27.83 - this.token = token; 27.84 - } 27.85 - 27.86 - /** 27.87 * Get token position within source where the error originated. 27.88 * @return token position if available, else -1 27.89 */ 27.90 @@ -120,18 +100,10 @@ 27.91 } 27.92 27.93 /** 27.94 - * Set the {@code JSErrorType} of this {@code ParserException} 27.95 - * @param errorType error type 27.96 - */ 27.97 - public void setErrorType(final JSErrorType errorType) { 27.98 - this.errorType = errorType; 27.99 - } 27.100 - 27.101 - /** 27.102 * Throw this {@code ParserException} as one of the 7 native JavaScript errors 27.103 */ 27.104 public void throwAsEcmaException() { 27.105 - ECMAErrors.throwAsEcmaException(this); 27.106 + throw ECMAErrors.asEcmaException(this); 27.107 } 27.108 27.109 /** 27.110 @@ -139,7 +111,7 @@ 27.111 * @param global global scope object 27.112 */ 27.113 public void throwAsEcmaException(final ScriptObject global) { 27.114 - ECMAErrors.throwAsEcmaException(global, this); 27.115 + throw ECMAErrors.asEcmaException(global, this); 27.116 } 27.117 } 27.118
28.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Fri Feb 22 11:27:40 2013 +0100 28.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Fri Feb 22 12:22:16 2013 +0100 28.3 @@ -135,7 +135,7 @@ 28.4 public boolean isInstance(final ScriptObject instance) { 28.5 final Object basePrototype = getTargetFunction().getPrototype(); 28.6 if (!(basePrototype instanceof ScriptObject)) { 28.7 - typeError("prototype.not.an.object", ScriptRuntime.safeToString(getTargetFunction()), ScriptRuntime.safeToString(basePrototype)); 28.8 + throw typeError("prototype.not.an.object", ScriptRuntime.safeToString(getTargetFunction()), ScriptRuntime.safeToString(basePrototype)); 28.9 } 28.10 28.11 for (ScriptObject proto = instance.getProto(); proto != null; proto = proto.getProto()) {
29.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Fri Feb 22 11:27:40 2013 +0100 29.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Fri Feb 22 12:22:16 2013 +0100 29.3 @@ -290,7 +290,7 @@ 29.4 29.5 MethodHandle getBestConstructor(MethodType descType) { 29.6 if (!isConstructor()) { 29.7 - typeError("not.a.constructor", toSource()); 29.8 + throw typeError("not.a.constructor", toSource()); 29.9 } 29.10 return SpecializedMethodChooser.candidateWithLowestWeight(descType, getConstructor(), getConstructSpecializations()); 29.11 }
30.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Feb 22 11:27:40 2013 +0100 30.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Feb 22 12:22:16 2013 +0100 30.3 @@ -278,13 +278,13 @@ 30.4 final PropertyDescriptor desc; 30.5 if (isDataDescriptor()) { 30.6 if (has(SET) || has(GET)) { 30.7 - typeError((ScriptObject)global, "inconsistent.property.descriptor"); 30.8 + throw typeError((ScriptObject)global, "inconsistent.property.descriptor"); 30.9 } 30.10 30.11 desc = global.newDataDescriptor(UNDEFINED, false, false, false); 30.12 } else if (isAccessorDescriptor()) { 30.13 if (has(VALUE) || has(WRITABLE)) { 30.14 - typeError((ScriptObject)global, "inconsistent.property.descriptor"); 30.15 + throw typeError((ScriptObject)global, "inconsistent.property.descriptor"); 30.16 } 30.17 30.18 desc = global.newAccessorDescriptor(UNDEFINED, UNDEFINED, false, false); 30.19 @@ -308,8 +308,7 @@ 30.20 return ((ScriptObject)obj).toPropertyDescriptor(); 30.21 } 30.22 30.23 - typeError(global, "not.an.object", ScriptRuntime.safeToString(obj)); 30.24 - return null; 30.25 + throw typeError(global, "not.an.object", ScriptRuntime.safeToString(obj)); 30.26 } 30.27 30.28 /** 30.29 @@ -401,7 +400,7 @@ 30.30 } 30.31 // new property added to non-extensible object 30.32 if (reject) { 30.33 - typeError(global, "object.non.extensible", name, ScriptRuntime.safeToString(this)); 30.34 + throw typeError(global, "object.non.extensible", name, ScriptRuntime.safeToString(this)); 30.35 } 30.36 return false; 30.37 } 30.38 @@ -424,7 +423,7 @@ 30.39 if (newDesc.has(CONFIGURABLE) && newDesc.isConfigurable()) { 30.40 // not configurable can not be made configurable 30.41 if (reject) { 30.42 - typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.43 + throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.44 } 30.45 return false; 30.46 } 30.47 @@ -433,7 +432,7 @@ 30.48 currentDesc.isEnumerable() != newDesc.isEnumerable()) { 30.49 // cannot make non-enumerable as enumerable or vice-versa 30.50 if (reject) { 30.51 - typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.52 + throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.53 } 30.54 return false; 30.55 } 30.56 @@ -448,7 +447,7 @@ 30.57 if (newDesc.has(WRITABLE) && newDesc.isWritable() || 30.58 newDesc.has(VALUE) && ! ScriptRuntime.sameValue(currentDesc.getValue(), newDesc.getValue())) { 30.59 if (reject) { 30.60 - typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.61 + throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.62 } 30.63 return false; 30.64 } 30.65 @@ -477,7 +476,7 @@ 30.66 if (newDesc.has(PropertyDescriptor.GET) && ! ScriptRuntime.sameValue(currentDesc.getGetter(), newDesc.getGetter()) || 30.67 newDesc.has(PropertyDescriptor.SET) && ! ScriptRuntime.sameValue(currentDesc.getSetter(), newDesc.getSetter())) { 30.68 if (reject) { 30.69 - typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.70 + throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.71 } 30.72 return false; 30.73 } 30.74 @@ -492,7 +491,7 @@ 30.75 if (! currentDesc.isConfigurable()) { 30.76 // not configurable can not be made configurable 30.77 if (reject) { 30.78 - typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.79 + throw typeError(global, "cant.redefine.property", name, ScriptRuntime.safeToString(this)); 30.80 } 30.81 return false; 30.82 } 30.83 @@ -1150,7 +1149,7 @@ 30.84 if (newProtoObject instanceof ScriptObject) { 30.85 setProto((ScriptObject)newProtoObject); 30.86 } else { 30.87 - typeError(global, "cant.set.proto.to.non.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(newProto)); 30.88 + throw typeError(global, "cant.set.proto.to.non.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(newProto)); 30.89 } 30.90 } 30.91 } 30.92 @@ -1638,8 +1637,7 @@ 30.93 } 30.94 30.95 private GuardedInvocation notAFunction() { 30.96 - typeError("not.a.function", ScriptRuntime.safeToString(this)); 30.97 - return null; 30.98 + throw typeError("not.a.function", ScriptRuntime.safeToString(this)); 30.99 } 30.100 30.101 /** 30.102 @@ -1815,7 +1813,7 @@ 30.103 private GuardedInvocation createEmptySetMethod(final CallSiteDescriptor desc, String strictErrorMessage, boolean canBeFastScope) { 30.104 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 30.105 if (NashornCallSiteDescriptor.isStrict(desc)) { 30.106 - typeError(strictErrorMessage, name, ScriptRuntime.safeToString((this))); 30.107 + throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString((this))); 30.108 } 30.109 assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc); 30.110 final PropertyMap myMap = getMap(); 30.111 @@ -1842,8 +1840,7 @@ 30.112 private boolean trySetEmbedOrSpill(final CallSiteDescriptor desc, final PropertyMap oldMap, final PropertyMap newMap, final Object value) { 30.113 final boolean isStrict = NashornCallSiteDescriptor.isStrict(desc); 30.114 if (!isExtensible() && isStrict) { 30.115 - typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(this)); 30.116 - throw new AssertionError(); // never reached 30.117 + throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(this)); 30.118 } else if (compareAndSetMap(oldMap, newMap)) { 30.119 return true; 30.120 } else { 30.121 @@ -1859,7 +1856,7 @@ 30.122 30.123 if (!obj.isExtensible()) { 30.124 if (isStrict) { 30.125 - typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj)); 30.126 + throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj)); 30.127 } 30.128 } else if (obj.compareAndSetMap(oldMap, newMap)) { 30.129 obj.spill = new Object[SPILL_RATE]; 30.130 @@ -1876,7 +1873,7 @@ 30.131 30.132 if (!obj.isExtensible()) { 30.133 if (isStrict) { 30.134 - typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj)); 30.135 + throw typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj)); 30.136 } 30.137 } else if (obj.compareAndSetMap(oldMap, newMap)) { 30.138 final int oldLength = obj.spill.length; 30.139 @@ -1968,7 +1965,7 @@ 30.140 } 30.141 30.142 if (scopeAccess) { 30.143 - referenceError("not.defined", name); 30.144 + throw referenceError("not.defined", name); 30.145 } 30.146 30.147 return createEmptyGetter(desc, name); 30.148 @@ -2569,7 +2566,7 @@ 30.149 if (longIndex >= oldLength) { 30.150 if (!isExtensible()) { 30.151 if (strict) { 30.152 - typeError("object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this)); 30.153 + throw typeError("object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this)); 30.154 } 30.155 return; 30.156 } 30.157 @@ -2618,7 +2615,7 @@ 30.158 if (f != null) { 30.159 if (!f.getProperty().isWritable()) { 30.160 if (strict) { 30.161 - typeError("property.not.writable", key, ScriptRuntime.safeToString(this)); 30.162 + throw typeError("property.not.writable", key, ScriptRuntime.safeToString(this)); 30.163 } 30.164 30.165 return; 30.166 @@ -2634,7 +2631,7 @@ 30.167 } 30.168 } else if (!isExtensible()) { 30.169 if (strict) { 30.170 - typeError("object.non.extensible", key, ScriptRuntime.safeToString(this)); 30.171 + throw typeError("object.non.extensible", key, ScriptRuntime.safeToString(this)); 30.172 } 30.173 } else { 30.174 spill(key, value); 30.175 @@ -3121,7 +3118,7 @@ 30.176 30.177 if (!find.getProperty().isConfigurable()) { 30.178 if (strict) { 30.179 - typeError("cant.delete.property", propName, ScriptRuntime.safeToString(this)); 30.180 + throw typeError("cant.delete.property", propName, ScriptRuntime.safeToString(this)); 30.181 } 30.182 return false; 30.183 } 30.184 @@ -3291,7 +3288,7 @@ 30.185 throw new RuntimeException(t); 30.186 } 30.187 } else if (name != null) { 30.188 - typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self)); 30.189 + throw typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self)); 30.190 } 30.191 } 30.192
31.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Fri Feb 22 11:27:40 2013 +0100 31.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Fri Feb 22 12:22:16 2013 +0100 31.3 @@ -426,9 +426,9 @@ 31.4 public static ScriptObject openWith(final ScriptObject scope, final Object expression) { 31.5 final ScriptObject global = Context.getGlobalTrusted(); 31.6 if (expression == UNDEFINED) { 31.7 - typeError(global, "cant.apply.with.to.undefined"); 31.8 + throw typeError(global, "cant.apply.with.to.undefined"); 31.9 } else if (expression == null) { 31.10 - typeError(global, "cant.apply.with.to.null"); 31.11 + throw typeError(global, "cant.apply.with.to.null"); 31.12 } 31.13 31.14 final ScriptObject withObject = new WithObject(scope, JSType.toScriptObject(global, expression)); 31.15 @@ -527,7 +527,7 @@ 31.16 } else if (object instanceof Undefined) { 31.17 obj = ((Undefined)obj).get(property); 31.18 } else if (object == null) { 31.19 - typeError("cant.get.property", safeToString(property), "null"); 31.20 + throw typeError("cant.get.property", safeToString(property), "null"); 31.21 } else if (JSType.isPrimitive(obj)) { 31.22 obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property); 31.23 } else { 31.24 @@ -565,8 +565,7 @@ 31.25 * @return undefined 31.26 */ 31.27 public static Object REFERENCE_ERROR(final Object lhs, final Object rhs, final Object msg) { 31.28 - referenceError("cant.be.used.as.lhs", Objects.toString(msg)); 31.29 - return UNDEFINED; 31.30 + throw referenceError("cant.be.used.as.lhs", Objects.toString(msg)); 31.31 } 31.32 31.33 /** 31.34 @@ -588,7 +587,7 @@ 31.35 } 31.36 31.37 if (obj == null) { 31.38 - typeError("cant.delete.property", safeToString(property), "null"); 31.39 + throw typeError("cant.delete.property", safeToString(property), "null"); 31.40 } 31.41 31.42 if (JSType.isPrimitive(obj)) { 31.43 @@ -612,7 +611,7 @@ 31.44 */ 31.45 public static boolean FAIL_DELETE(final Object property, final Object strict) { 31.46 if (Boolean.TRUE.equals(strict)) { 31.47 - syntaxError("strict.cant.delete", safeToString(property)); 31.48 + throw syntaxError("strict.cant.delete", safeToString(property)); 31.49 } 31.50 return false; 31.51 } 31.52 @@ -789,9 +788,7 @@ 31.53 return false; 31.54 } 31.55 31.56 - typeError("in.with.non.object", rvalType.toString().toLowerCase()); 31.57 - 31.58 - return false; 31.59 + throw typeError("in.with.non.object", rvalType.toString().toLowerCase()); 31.60 } 31.61 31.62 /** 31.63 @@ -814,9 +811,7 @@ 31.64 return ((StaticClass)clazz).getRepresentedClass().isInstance(obj); 31.65 } 31.66 31.67 - typeError("instanceof.on.non.object"); 31.68 - 31.69 - return false; 31.70 + throw typeError("instanceof.on.non.object"); 31.71 } 31.72 31.73 /**
32.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Fri Feb 22 11:27:40 2013 +0100 32.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Fri Feb 22 12:22:16 2013 +0100 32.3 @@ -109,8 +109,7 @@ 32.4 } 32.5 32.6 if (f == null || !f.isFile()) { 32.7 - typeError("not.a.file", ScriptRuntime.safeToString(file)); 32.8 - return UNDEFINED; 32.9 + throw typeError("not.a.file", ScriptRuntime.safeToString(file)); 32.10 } 32.11 32.12 return new String(Source.readFully(f));
33.1 --- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Fri Feb 22 11:27:40 2013 +0100 33.2 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Fri Feb 22 12:22:16 2013 +0100 33.3 @@ -139,7 +139,7 @@ 33.4 // In strict mode, assignment can not create a new variable. 33.5 // See also ECMA Annex C item 4. ReferenceError is thrown. 33.6 if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) { 33.7 - referenceError("not.defined", getName()); 33.8 + throw referenceError("not.defined", getName()); 33.9 } 33.10 } 33.11
34.1 --- a/src/jdk/nashorn/internal/runtime/URIUtils.java Fri Feb 22 11:27:40 2013 +0100 34.2 +++ b/src/jdk/nashorn/internal/runtime/URIUtils.java Fri Feb 22 12:22:16 2013 +0100 34.3 @@ -93,8 +93,7 @@ 34.4 try { 34.5 sb.append(toHexEscape(V)); 34.6 } catch (final Exception e) { 34.7 - uriError( e, "bad.uri", string, Integer.toString(k)); 34.8 - return null; 34.9 + throw uriError(e, "bad.uri", string, Integer.toString(k)); 34.10 } 34.11 } 34.12 34.13 @@ -179,8 +178,7 @@ 34.14 try { 34.15 V = ucs4Char(bbuf); 34.16 } catch (final Exception e) { 34.17 - uriError(e, "bad.uri", string, Integer.toString(k)); 34.18 - return null; 34.19 + throw uriError(e, "bad.uri", string, Integer.toString(k)); 34.20 } 34.21 if (V < 0x10000) { 34.22 C = (char) V; 34.23 @@ -269,8 +267,7 @@ 34.24 } 34.25 34.26 private static String error(final String string, final int index) { 34.27 - uriError("bad.uri", string, Integer.toString(index)); 34.28 - return null; 34.29 + throw uriError("bad.uri", string, Integer.toString(index)); 34.30 } 34.31 34.32 // 'uriEscaped' except for alphanumeric chars
35.1 --- a/src/jdk/nashorn/internal/runtime/Undefined.java Fri Feb 22 11:27:40 2013 +0100 35.2 +++ b/src/jdk/nashorn/internal/runtime/Undefined.java Fri Feb 22 12:22:16 2013 +0100 35.3 @@ -97,30 +97,26 @@ 35.4 switch (operator) { 35.5 case "new": 35.6 case "call": 35.7 - lookupTypeError("cant.call.undefined", desc); 35.8 - break; 35.9 + throw lookupTypeError("cant.call.undefined", desc); 35.10 case "callMethod": 35.11 - lookupTypeError("cant.read.property.of.undefined", desc); 35.12 + throw lookupTypeError("cant.read.property.of.undefined", desc); 35.13 // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself 35.14 // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are 35.15 // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the 35.16 // operation has an associated name or not. 35.17 - break; 35.18 case "getProp": 35.19 case "getElem": 35.20 case "getMethod": 35.21 if (desc.getNameTokenCount() < 3) { 35.22 return findGetIndexMethod(desc); 35.23 } 35.24 - lookupTypeError("cant.read.property.of.undefined", desc); 35.25 - break; 35.26 + throw lookupTypeError("cant.read.property.of.undefined", desc); 35.27 case "setProp": 35.28 case "setElem": 35.29 if (desc.getNameTokenCount() < 3) { 35.30 return findSetIndexMethod(desc); 35.31 } 35.32 - lookupTypeError("cant.set.property.of.undefined", desc); 35.33 - break; 35.34 + throw lookupTypeError("cant.set.property.of.undefined", desc); 35.35 default: 35.36 break; 35.37 } 35.38 @@ -128,8 +124,8 @@ 35.39 return null; 35.40 } 35.41 35.42 - private static void lookupTypeError(final String msg, final CallSiteDescriptor desc) { 35.43 - typeError(msg, desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null); 35.44 + private static ECMAException lookupTypeError(final String msg, final CallSiteDescriptor desc) { 35.45 + return typeError(msg, desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null); 35.46 } 35.47 35.48 /** 35.49 @@ -174,19 +170,17 @@ 35.50 35.51 @Override 35.52 public Object get(final Object key) { 35.53 - typeError("cant.read.property.of.undefined", ScriptRuntime.safeToString(key)); 35.54 - return ScriptRuntime.UNDEFINED; 35.55 + throw typeError("cant.read.property.of.undefined", ScriptRuntime.safeToString(key)); 35.56 } 35.57 35.58 @Override 35.59 public void set(final Object key, final Object value, final boolean strict) { 35.60 - typeError("cant.set.property.of.undefined", ScriptRuntime.safeToString(key)); 35.61 + throw typeError("cant.set.property.of.undefined", ScriptRuntime.safeToString(key)); 35.62 } 35.63 35.64 @Override 35.65 public boolean delete(final Object key, final boolean strict) { 35.66 - typeError("cant.delete.property.of.undefined", ScriptRuntime.safeToString(key)); 35.67 - return false; 35.68 + throw typeError("cant.delete.property.of.undefined", ScriptRuntime.safeToString(key)); 35.69 } 35.70 35.71 @Override
36.1 --- a/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java Fri Feb 22 11:27:40 2013 +0100 36.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/FrozenArrayFilter.java Fri Feb 22 12:22:16 2013 +0100 36.3 @@ -46,7 +46,7 @@ 36.4 @Override 36.5 public ArrayData set(final int index, final int value, final boolean strict) { 36.6 if (strict) { 36.7 - typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.8 + throw typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.9 } 36.10 return this; 36.11 } 36.12 @@ -54,7 +54,7 @@ 36.13 @Override 36.14 public ArrayData set(final int index, final long value, final boolean strict) { 36.15 if (strict) { 36.16 - typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.17 + throw typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.18 } 36.19 return this; 36.20 } 36.21 @@ -62,7 +62,7 @@ 36.22 @Override 36.23 public ArrayData set(final int index, final double value, final boolean strict) { 36.24 if (strict) { 36.25 - typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.26 + throw typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.27 } 36.28 return this; 36.29 } 36.30 @@ -70,7 +70,7 @@ 36.31 @Override 36.32 public ArrayData set(final int index, final Object value, final boolean strict) { 36.33 if (strict) { 36.34 - typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.35 + throw typeError("cant.set.property", Integer.toString(index), "frozen array"); 36.36 } 36.37 return this; 36.38 }
37.1 --- a/src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java Fri Feb 22 11:27:40 2013 +0100 37.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/IteratorAction.java Fri Feb 22 12:22:16 2013 +0100 37.3 @@ -97,8 +97,7 @@ 37.4 */ 37.5 public final T apply() { 37.6 if (!(callbackfn instanceof ScriptFunction)) { 37.7 - typeError("not.a.function", ScriptRuntime.safeToString(callbackfn)); 37.8 - return result; 37.9 + throw typeError("not.a.function", ScriptRuntime.safeToString(callbackfn)); 37.10 } 37.11 final ScriptFunction func = ((ScriptFunction)callbackfn); 37.12 // for non-strict callback, need to translate undefined thisArg to be global object
38.1 --- a/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java Fri Feb 22 11:27:40 2013 +0100 38.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java Fri Feb 22 12:22:16 2013 +0100 38.3 @@ -46,7 +46,7 @@ 38.4 @Override 38.5 public boolean canDelete(final int index, final boolean strict) { 38.6 if (strict) { 38.7 - typeError("cant.delete.property", Integer.toString(index), "sealed array"); 38.8 + throw typeError("cant.delete.property", Integer.toString(index), "sealed array"); 38.9 } 38.10 return false; 38.11 }
39.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Fri Feb 22 11:27:40 2013 +0100 39.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Fri Feb 22 12:22:16 2013 +0100 39.3 @@ -705,8 +705,7 @@ 39.4 */ 39.5 public static MethodHandle getHandle(final Object obj, final String name, final MethodType type, final boolean varArg) { 39.6 if (! (obj instanceof ScriptObject)) { 39.7 - typeError("not.an.object", ScriptRuntime.safeToString(obj)); 39.8 - throw new AssertionError(); 39.9 + throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); 39.10 } 39.11 39.12 final ScriptObject sobj = (ScriptObject)obj; 39.13 @@ -721,8 +720,7 @@ 39.14 } else if(fnObj == null || fnObj instanceof Undefined) { 39.15 return null; 39.16 } else { 39.17 - typeError("not.a.function", name); 39.18 - throw new AssertionError(); 39.19 + throw typeError("not.a.function", name); 39.20 } 39.21 } 39.22 39.23 @@ -1093,7 +1091,7 @@ 39.24 39.25 void typeError() { 39.26 assert adaptationOutcome != AdaptationOutcome.SUCCESS; 39.27 - ECMAErrors.typeError("extend." + adaptationOutcome, classList); 39.28 + throw ECMAErrors.typeError("extend." + adaptationOutcome, classList); 39.29 } 39.30 } 39.31 39.32 @@ -1236,8 +1234,7 @@ 39.33 while(it.hasNext()) { 39.34 b.append(", ").append(it.next().clazz.getCanonicalName()); 39.35 } 39.36 - typeError("extend.ambiguous.defining.class", b.toString()); 39.37 - throw new AssertionError(); // never reached 39.38 + throw typeError("extend.ambiguous.defining.class", b.toString()); 39.39 } 39.40 39.41 /**
40.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java Fri Feb 22 11:27:40 2013 +0100 40.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java Fri Feb 22 12:22:16 2013 +0100 40.3 @@ -109,7 +109,7 @@ 40.4 return Character.valueOf((char) ival); 40.5 } 40.6 40.7 - typeError("cant.convert.number.to.char"); 40.8 + throw typeError("cant.convert.number.to.char"); 40.9 } 40.10 40.11 final String s = toString(o); 40.12 @@ -118,7 +118,7 @@ 40.13 } 40.14 40.15 if (s.length() != 1) { 40.16 - typeError("cant.convert.string.to.char"); 40.17 + throw typeError("cant.convert.string.to.char"); 40.18 } 40.19 40.20 return s.charAt(0);
41.1 --- a/src/jdk/nashorn/internal/runtime/linker/Lookup.java Fri Feb 22 11:27:40 2013 +0100 41.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Lookup.java Fri Feb 22 12:22:16 2013 +0100 41.3 @@ -111,8 +111,7 @@ 41.4 * @return undefined (but throws error before return point) 41.5 */ 41.6 public static Object typeErrorThrowerGetter(final Object self) { 41.7 - typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self)); 41.8 - return UNDEFINED; 41.9 + throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self)); 41.10 } 41.11 41.12 /** 41.13 @@ -122,7 +121,7 @@ 41.14 * @param value (ignored) 41.15 */ 41.16 public static void typeErrorThrowerSetter(final Object self, final Object value) { 41.17 - typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self)); 41.18 + throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self)); 41.19 } 41.20 41.21 /**
42.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Fri Feb 22 11:27:40 2013 +0100 42.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Fri Feb 22 12:22:16 2013 +0100 42.3 @@ -80,22 +80,17 @@ 42.4 switch (operator) { 42.5 case "new": 42.6 if(BeansLinker.isDynamicMethod(self)) { 42.7 - typeError("method.not.constructor", ScriptRuntime.safeToString(self)); 42.8 - } else { 42.9 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 42.10 + throw typeError("method.not.constructor", ScriptRuntime.safeToString(self)); 42.11 } 42.12 - break; 42.13 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 42.14 case "call": 42.15 if(BeansLinker.isDynamicMethod(self)) { 42.16 - typeError("no.method.matches.args", ScriptRuntime.safeToString(self)); 42.17 - } else { 42.18 - typeError("not.a.function", ScriptRuntime.safeToString(self)); 42.19 + throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self)); 42.20 } 42.21 - break; 42.22 + throw typeError("not.a.function", ScriptRuntime.safeToString(self)); 42.23 case "callMethod": 42.24 case "getMethod": 42.25 - typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self)); 42.26 - break; 42.27 + throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self)); 42.28 case "getProp": 42.29 case "getElem": 42.30 if (desc.getOperand() != null) { 42.31 @@ -130,20 +125,16 @@ 42.32 switch (operator) { 42.33 case "new": 42.34 case "call": 42.35 - typeError("not.a.function", "null"); 42.36 - break; 42.37 + throw typeError("not.a.function", "null"); 42.38 case "callMethod": 42.39 case "getMethod": 42.40 - typeError("no.such.function", getArgument(linkRequest), "null"); 42.41 - break; 42.42 + throw typeError("no.such.function", getArgument(linkRequest), "null"); 42.43 case "getProp": 42.44 case "getElem": 42.45 - typeError("cant.get.property", getArgument(linkRequest), "null"); 42.46 - break; 42.47 + throw typeError("cant.get.property", getArgument(linkRequest), "null"); 42.48 case "setProp": 42.49 case "setElem": 42.50 - typeError("cant.set.property", getArgument(linkRequest), "null"); 42.51 - break; 42.52 + throw typeError("cant.set.property", getArgument(linkRequest), "null"); 42.53 default: 42.54 break; 42.55 }
43.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java Fri Feb 22 11:27:40 2013 +0100 43.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java Fri Feb 22 12:22:16 2013 +0100 43.3 @@ -93,7 +93,7 @@ 43.4 43.5 private static GuardedInvocation checkNullConstructor(final GuardedInvocation ctorInvocation, final Class<?> receiverClass) { 43.6 if(ctorInvocation == null) { 43.7 - ECMAErrors.typeError("no.constructor.matches.args", receiverClass.getName()); 43.8 + throw ECMAErrors.typeError("no.constructor.matches.args", receiverClass.getName()); 43.9 } 43.10 return ctorInvocation; 43.11 }