Search in sources :

Example 6 with ScriptException

use of com.github.anba.es6draft.runtime.internal.ScriptException in project es6draft by anba.

the class WeakMapConstructor method construct.

/**
     * 23.3.1.1 WeakMap ([ iterable ])
     */
@Override
public WeakMapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    WeakMapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakMapPrototype, WeakMapObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return map;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, map, "set");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
    }
    Callable adder = (Callable) _adder;
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextItem = iter.next();
            if (!Type.isObject(nextItem)) {
                throw newTypeError(calleeContext, Messages.Key.WeakMapPairNotObject);
            }
            ScriptObject item = Type.objectValue(nextItem);
            Object k = Get(calleeContext, item, 0);
            Object v = Get(calleeContext, item, 1);
            adder.call(calleeContext, map, k, v);
        }
        return map;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 7 with ScriptException

use of com.github.anba.es6draft.runtime.internal.ScriptException in project es6draft by anba.

the class WeakSetConstructor method construct.

/**
     * 23.4.1.1 WeakSet ([ iterable ])
     */
@Override
public WeakSetObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    WeakSetObject set = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakSetPrototype, WeakSetObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return set;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, set, "add");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "add");
    }
    Callable adder = (Callable) _adder;
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextValue = iter.next();
            adder.call(calleeContext, set, nextValue);
        }
        return set;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 8 with ScriptException

use of com.github.anba.es6draft.runtime.internal.ScriptException in project es6draft by anba.

the class TestAssertions method withFilteredStackTrace.

private static ScriptException withFilteredStackTrace(ScriptException e) {
    if (!FILTER_STACK_TRACE) {
        return e;
    }
    ScriptException exception = new ScriptException(e.getValue(), e.getCause());
    exception.setStackTrace(filterStackTrace(e));
    return exception;
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException)

Example 9 with ScriptException

use of com.github.anba.es6draft.runtime.internal.ScriptException in project es6draft by anba.

the class TestAssertions method toAssertionError.

/**
     * Creates a new {@link AssertionError} for the script exception.
     * 
     * @param cx
     *            the execution context
     * @param e
     *            the script exception
     * @return a new assertion error
     */
public static AssertionError toAssertionError(ExecutionContext cx, ScriptException e) {
    ScriptException exception = withFilteredStackTrace(e);
    AssertionError error = new AssertionError(exception.getMessage(cx), exception);
    error.setStackTrace(exception.getScriptStackTrace());
    return error;
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException)

Example 10 with ScriptException

use of com.github.anba.es6draft.runtime.internal.ScriptException in project es6draft by anba.

the class StatementGenerator method emitCatchBlock.

private Completion emitCatchBlock(TryStatement node, Variable<LexicalEnvironment<?>> savedEnv, TryCatchLabel handlerCatch, TryCatchLabel handlerCatchStackOverflow, CodeVisitor mv) {
    boolean hasFinally = node.getFinallyBlock() != null;
    CatchNode catchNode = node.getCatchNode();
    List<GuardedCatchNode> guardedCatchNodes = node.getGuardedCatchNodes();
    assert catchNode != null || !guardedCatchNodes.isEmpty();
    // StackOverflowError -> ScriptException
    mv.catchHandler(handlerCatchStackOverflow, Types.Error);
    mv.invoke(Methods.ScriptRuntime_stackOverflowError);
    mv.loadExecutionContext();
    mv.invoke(Methods.ScriptRuntime_toInternalError);
    mv.catchHandler(handlerCatch, Types.ScriptException);
    restoreEnvironment(savedEnv, mv);
    if (hasFinally) {
        mv.enterWrapped();
    }
    Completion catchResult;
    if (!guardedCatchNodes.isEmpty()) {
        mv.enterVariableScope();
        Variable<ScriptException> exception = mv.newVariable("exception", ScriptException.class);
        Jump catchWithGuardedLabel = new Jump();
        mv.store(exception);
        Completion result = null;
        for (GuardedCatchNode guardedCatchNode : guardedCatchNodes) {
            mv.load(exception);
            Completion guardedResult = CatchClauseEvaluation(guardedCatchNode, catchWithGuardedLabel, mv);
            result = result != null ? result.select(guardedResult) : guardedResult;
        }
        assert result != null;
        if (catchNode != null) {
            mv.load(exception);
            catchResult = CatchClauseEvaluation(catchNode, mv);
        } else {
            mv.load(exception);
            mv.athrow();
            catchResult = Completion.Throw;
        }
        if (!result.isAbrupt()) {
            mv.mark(catchWithGuardedLabel);
        }
        mv.exitVariableScope();
        catchResult = catchResult.select(result);
    } else {
        catchResult = CatchClauseEvaluation(catchNode, mv);
    }
    if (hasFinally) {
        mv.exitWrapped();
    }
    return catchResult.nonEmpty();
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) Jump(com.github.anba.es6draft.compiler.assembler.Jump)

Aggregations

ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)14 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)7 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)7 Callable (com.github.anba.es6draft.runtime.types.Callable)6 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)5 Realm (com.github.anba.es6draft.runtime.Realm)4 Script (com.github.anba.es6draft.Script)2 Jump (com.github.anba.es6draft.compiler.assembler.Jump)2 ExecutionContext.newScriptingExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext)2 Console (com.github.anba.es6draft.runtime.internal.Console)2 RuntimeContext (com.github.anba.es6draft.runtime.internal.RuntimeContext)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)2 IOException (java.io.IOException)2 CompilationException (com.github.anba.es6draft.compiler.CompilationException)1 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)1 Variable (com.github.anba.es6draft.compiler.assembler.Variable)1 ParserException (com.github.anba.es6draft.parser.ParserException)1 ToSource (com.github.anba.es6draft.repl.SourceBuilder.ToSource)1 SharedFunctions.loadScript (com.github.anba.es6draft.repl.global.SharedFunctions.loadScript)1