From 0edc02655cad55fa588dc8526b2c797715f195eb Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 15 Mar 2016 13:23:45 -0400 Subject: [PATCH 1/2] PARTIAL: Support testing ResolutionException *This patch is incomplete!* The goal of this patch is to allow Test262 tests to express `negative: SyntaxError` for module loading errors such as ambiguous import bindings. With this patch applied, the test runner fails with messages like this: > Expected: (((an instance of com.github.anba.es6draft.parser.ParserException or an instance of com.github.anba.es6draft.compiler.CompilationException or an instance of java.lang.StackOverflowError or an instance of com.github.anba.es6draft.runtime.modules.ResolutionException) or an instance of com.github.anba.es6draft.runtime.internal.ScriptException) and exception with error-message string matching 'SyntaxError') > but: exception with error-message string matching 'SyntaxError' error-message was "ambiguous export \"x\"" > Stacktrace was: com.github.anba.es6draft.runtime.modules.ResolutionException: ambiguous export "x" > [...] --- .../anba/es6draft/util/rules/ExceptionHandlers.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/github/anba/es6draft/util/rules/ExceptionHandlers.java b/src/test/java/com/github/anba/es6draft/util/rules/ExceptionHandlers.java index f147b5261..762eec085 100644 --- a/src/test/java/com/github/anba/es6draft/util/rules/ExceptionHandlers.java +++ b/src/test/java/com/github/anba/es6draft/util/rules/ExceptionHandlers.java @@ -21,6 +21,7 @@ import com.github.anba.es6draft.repl.global.StopExecutionException; import com.github.anba.es6draft.runtime.ExecutionContext; import com.github.anba.es6draft.runtime.internal.ScriptException; +import com.github.anba.es6draft.runtime.modules.ResolutionException; import com.github.anba.es6draft.util.TestAssertions; /** @@ -42,12 +43,12 @@ private static Iterable asIterable(Supplier> stream) { } /** - * {@link ExceptionHandler} for {@link ParserException}, {@link CompilationException} and {@link StackOverflowError} - * errors. + * {@link ExceptionHandler} for {@link ParserException}, {@link CompilationException}, {@link StackOverflowError} + * and {@link ResolutionException} errors. */ public static final class StandardErrorHandler extends ExceptionHandler { private static final Matcher defaultMatcher = anyInstanceOf(ParserException.class, - CompilationException.class, StackOverflowError.class); + CompilationException.class, StackOverflowError.class, ResolutionException.class); public StandardErrorHandler() { this(defaultMatcher()); @@ -110,11 +111,12 @@ public static Matcher defaultMatcher() { /** * {@link ExceptionHandler} for {@link ParserException}, {@link CompilationException}, {@link StackOverflowError} - * and {@link ScriptException} errors. + * {@link ScriptException}, and {@link ResolutionException} errors. */ public static final class IgnoreExceptionHandler extends ExceptionHandler { private static final Matcher defaultMatcher = anyInstanceOf(ParserException.class, - CompilationException.class, StackOverflowError.class, ScriptException.class); + CompilationException.class, StackOverflowError.class, ScriptException.class, + ResolutionException.class); public IgnoreExceptionHandler() { this(defaultMatcher()); From b6dd4ceb7531e69a0eff7218b9ec44e524cb68c8 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Mon, 28 Mar 2016 17:42:20 -0400 Subject: [PATCH 2/2] fixup! PARTIAL: Support testing ResolutionException --- .../anba/es6draft/runtime/modules/ResolutionException.java | 4 ++++ .../anba/es6draft/util/matchers/ErrorMessageMatcher.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/github/anba/es6draft/runtime/modules/ResolutionException.java b/src/main/java/com/github/anba/es6draft/runtime/modules/ResolutionException.java index 916624aaa..72fa1be29 100644 --- a/src/main/java/com/github/anba/es6draft/runtime/modules/ResolutionException.java +++ b/src/main/java/com/github/anba/es6draft/runtime/modules/ResolutionException.java @@ -53,4 +53,8 @@ public String getLocalizedMessage() { public ScriptException toScriptException(ExecutionContext cx) { throw Errors.newSyntaxError(cx, this, messageKey, messageArguments); } + + public String getScriptMessage(ExecutionContext cx) { + return Errors.newSyntaxError(cx, this, messageKey, messageArguments).getMessage(cx); + } } diff --git a/src/test/java/com/github/anba/es6draft/util/matchers/ErrorMessageMatcher.java b/src/test/java/com/github/anba/es6draft/util/matchers/ErrorMessageMatcher.java index a250c6a8b..331a34837 100644 --- a/src/test/java/com/github/anba/es6draft/util/matchers/ErrorMessageMatcher.java +++ b/src/test/java/com/github/anba/es6draft/util/matchers/ErrorMessageMatcher.java @@ -13,6 +13,7 @@ import com.github.anba.es6draft.runtime.ExecutionContext; import com.github.anba.es6draft.runtime.internal.Messages; import com.github.anba.es6draft.runtime.internal.ScriptException; +import com.github.anba.es6draft.runtime.modules.ResolutionException; /** * {@link Matcher} for script execution error messages. @@ -54,6 +55,9 @@ private String getMessage(T error) { if (error instanceof StackOverflowError) { return String.format("InternalError: %s", cx.getRealm().message(Messages.Key.StackOverflow)); } + if (error instanceof ResolutionException) { + return ((ResolutionException) error).getScriptMessage(cx); + } return error.getMessage(); } }