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;
}
}
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;
}
}
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;
}
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;
}
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();
}
Aggregations