Java源码示例:jdk.nashorn.internal.runtime.ECMAException

示例1
/**
 * 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;
}
 
示例2
@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);
            }
        }
    });
}
 
示例3
@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);
            }
        }
    });
}
 
示例4
/**
 * 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;
}
 
示例5
@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);
            }
        }
    });
}
 
示例6
/**
 * 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;
}
 
示例7
@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);
            }
        }
    });
}
 
示例8
/**
 * 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;
}
 
示例9
/**
 * 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;
}
 
示例10
@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);
            }
        }
    });
}
 
示例11
/**
 * 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;
}
 
示例12
/**
 * 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;
}
 
示例13
/**
 * 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 "";
}
 
示例14
/**
 * 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);
}
 
示例15
/**
 * 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);
}
 
示例16
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);
}
 
示例17
/**
 * 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);
}
 
示例18
/**
 * 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);
}
 
示例19
/**
 * 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 "";
}
 
示例20
/**
 * 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);
}
 
示例21
/**
 * 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;
}
 
示例22
/**
 * 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);
}
 
示例23
/**
 * 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);
}
 
示例24
/**
 * 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;
}
 
示例25
/**
 * 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);
}
 
示例26
@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;
}
 
示例27
@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;
}
 
示例28
private static ECMAException notAnObject(final Object obj) {
    return typeError("not.an.object", ScriptRuntime.safeToString(obj));
}
 
示例29
private static ECMAException notAnObject(final Object obj) {
    return typeError("not.an.object", ScriptRuntime.safeToString(obj));
}
 
示例30
private static ECMAException notFunction(final Object obj) {
    return typeError("not.a.function", ScriptRuntime.safeToString(obj));
}