jdk.nashorn.internal.runtime.ECMAException Java Examples
The following examples show how to use
jdk.nashorn.internal.runtime.ECMAException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeError.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #2
Source File: ScriptObjectMirror.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
@Override public Object getDefaultValue(final Class<?> hint) { return inGlobal(new Callable<Object>() { @Override public Object call() { try { return sobj.getDefaultValue(hint); } catch (final ECMAException e) { // We're catching ECMAException (likely TypeError), and translating it to // UnsupportedOperationException. This in turn will be translated into TypeError of the // caller's Global by JSType#toPrimitive(JSObject,Class) therefore ensuring that it's // recognized as "instanceof TypeError" in the caller. throw new UnsupportedOperationException(e.getMessage(), e); } } }); }
Example #3
Source File: NativeError.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #4
Source File: NativeError.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #5
Source File: NativeError.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #6
Source File: ScriptObjectMirror.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public Object getDefaultValue(final Class<?> hint) { return inGlobal(new Callable<Object>() { @Override public Object call() { try { return sobj.getDefaultValue(hint); } catch (final ECMAException e) { // We're catching ECMAException (likely TypeError), and translating it to // UnsupportedOperationException. This in turn will be translated into TypeError of the // caller's Global by JSType#toPrimitive(JSObject,Class) therefore ensuring that it's // recognized as "instanceof TypeError" in the caller. throw new UnsupportedOperationException(e.getMessage(), e); } } }); }
Example #7
Source File: ScriptObjectMirror.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Object getDefaultValue(final Class<?> hint) { return inGlobal(new Callable<Object>() { @Override public Object call() { try { return sobj.getDefaultValue(hint); } catch (final ECMAException e) { // We're catching ECMAException (likely TypeError), and translating it to // UnsupportedOperationException. This in turn will be translated into TypeError of the // caller's Global by JSType#toPrimitive(JSObject,Class) therefore ensuring that it's // recognized as "instanceof TypeError" in the caller. throw new UnsupportedOperationException(e.getMessage(), e); } } }); }
Example #8
Source File: ScriptObjectMirror.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public Object getDefaultValue(final Class<?> hint) { return inGlobal(new Callable<Object>() { @Override public Object call() { try { return sobj.getDefaultValue(hint); } catch (final ECMAException e) { // We're catching ECMAException (likely TypeError), and translating it to // UnsupportedOperationException. This in turn will be translated into TypeError of the // caller's Global by JSType#toPrimitive(JSObject,Class) therefore ensuring that it's // recognized as "instanceof TypeError" in the caller. throw new UnsupportedOperationException(e.getMessage(), e); } } }); }
Example #9
Source File: NativeError.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #10
Source File: NativeError.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #11
Source File: ScriptObjectMirror.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public Object getDefaultValue(final Class<?> hint) { return inGlobal(new Callable<Object>() { @Override public Object call() { try { return sobj.getDefaultValue(hint); } catch (final ECMAException e) { // We're catching ECMAException (likely TypeError), and translating it to // UnsupportedOperationException. This in turn will be translated into TypeError of the // caller's Global by JSType#toPrimitive(JSObject,Class) therefore ensuring that it's // recognized as "instanceof TypeError" in the caller. throw new UnsupportedOperationException(e.getMessage(), e); } } }); }
Example #12
Source File: NativeError.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { final ScriptObject sobj = Global.checkObject(self); if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { final Object value = getScriptStackString(sobj, (Throwable)exception); if (sobj.hasOwnProperty(STACK)) { sobj.put(STACK, value, false); } else { sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); } return value; } return UNDEFINED; }
Example #13
Source File: CodeGenerator.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public boolean enterThrowNode(final ThrowNode throwNode) { lineNumber(throwNode); if (throwNode.isSyntheticRethrow()) { //do not wrap whatever this is in an ecma exception, just rethrow it load(throwNode.getExpression()); method.athrow(); return false; } method._new(ECMAException.class).dup(); final Source source = lc.getCurrentFunction().getSource(); final Expression expression = throwNode.getExpression(); final int position = throwNode.position(); final int line = throwNode.getLineNumber(); final int column = source.getColumn(position); load(expression, Type.OBJECT); method.load(source.getName()); method.load(line); method.load(column); method.invoke(ECMAException.THROW_INIT); method.athrow(); return false; }
Example #14
Source File: NativeError.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #15
Source File: ScriptLanguageFixture.java From hsac-fitnesse-fixtures with Apache License 2.0 | 5 votes |
protected RuntimeException getExceptionToThrow(ScriptException e) { Throwable cause = e.getCause(); String message; if (cause instanceof ECMAException) { message = cause.toString(); } else { message = e.getMessage(); } return new SlimFixtureException(false, message, e); }
Example #16
Source File: NativeError.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #17
Source File: NativeError.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { Global.checkObject(self); final ScriptObject sobj = (ScriptObject)self; if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { return getScriptStackString(sobj, (Throwable)exception); } return ""; }
Example #18
Source File: NativeError.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #19
Source File: NativeError.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #20
Source File: NativeError.java From nashorn with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.stack * "stack" property is a string typed value containing JavaScript stack frames. * Each frame information is separated bv "\n" character. * * @param self self reference * * @return value of "stack" property */ public static Object getStack(final Object self) { Global.checkObject(self); final ScriptObject sobj = (ScriptObject)self; if (sobj.has(STACK)) { return sobj.get(STACK); } final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { return getScriptStackString(sobj, (Throwable)exception); } return ""; }
Example #21
Source File: NativeError.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #22
Source File: NashornCompleter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Is this a ECMAScript SyntaxError thrown for parse issue at the given line and column? * * @param exp Throwable to check * @param line line number to check * @param column column number to check * * @return true if the given Throwable is a ECMAScript SyntaxError at given line, column */ boolean isSyntaxErrorAt(final Throwable exp, final int line, final int column) { if (exp instanceof ECMAException) { final ECMAException eexp = (ECMAException)exp; if (eexp.getThrown() instanceof NativeSyntaxError) { return isParseErrorAt(eexp.getCause(), line, column); } } return false; }
Example #23
Source File: NativeError.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { Global.checkObject(self); final ScriptObject sobj = (ScriptObject)self; final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #24
Source File: NativeError.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { final ScriptObject sobj = Global.checkObject(self); final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #25
Source File: NativeError.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided. * * @param self self reference * @param errorObj the error object * @return undefined */ @SuppressWarnings("unused") @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object captureStackTrace(final Object self, final Object errorObj) { Global.checkObject(errorObj); final ScriptObject sobj = (ScriptObject)errorObj; new ECMAException(sobj, null); //constructor has side effects sobj.delete("stack", false); final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK); final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK); sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); return UNDEFINED; }
Example #26
Source File: NativeError.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Nashorn extension: Error.prototype.getStackTrace() * "stack" property is an array typed value containing {@link StackTraceElement} * objects of JavaScript stack frames. * * @param self self reference * * @return stack trace as a script array. */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getStackTrace(final Object self) { Global.checkObject(self); final ScriptObject sobj = (ScriptObject)self; final Object exception = ECMAException.getException(sobj); Object[] res; if (exception instanceof Throwable) { res = NashornException.getScriptFrames((Throwable)exception); } else { res = ScriptRuntime.EMPTY_ARRAY; } return new NativeArray(res); }
Example #27
Source File: CodeGenerator.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public boolean enterThrowNode(final ThrowNode throwNode) { lineNumber(throwNode); if (throwNode.isSyntheticRethrow()) { //do not wrap whatever this is in an ecma exception, just rethrow it load(throwNode.getExpression()); method.athrow(); return false; } method._new(ECMAException.class).dup(); final Source source = lc.getCurrentFunction().getSource(); final Expression expression = throwNode.getExpression(); final int position = throwNode.position(); final int line = throwNode.getLineNumber(); final int column = source.getColumn(position); load(expression, Type.OBJECT); method.load(source.getName()); method.load(line); method.load(column); method.invoke(ECMAException.THROW_INIT); method.athrow(); return false; }
Example #28
Source File: Module.java From nashorn-commonjs-modules with MIT License | 4 votes |
private void throwModuleNotFoundException(String module) throws ScriptException { Bindings error = (Bindings) errorConstructor.newObject("Module not found: " + module); error.put("code", "MODULE_NOT_FOUND"); throw new ECMAException(error, null); }
Example #29
Source File: AdaptationResult.java From hottub with GNU General Public License v2.0 | 4 votes |
ECMAException typeError() { return ECMAErrors.typeError("extend." + outcome, messageArgs); }
Example #30
Source File: AdaptationResult.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
ECMAException typeError() { return ECMAErrors.typeError("extend." + outcome, messageArgs); }