Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cheesy way to throw a syntax error after execution of a program

to catch illegal break/continue statements not nested within
iteration statements.  Should do better than this.
  • Loading branch information...
commit 0659a23109d7b3b74a6663d70df2e2e95d110f3d 1 parent 8d42e09
@bobmcwhirter bobmcwhirter authored
View
2  run-repl
@@ -1,5 +1,5 @@
#!/bin/sh
if [ ! -f target/dynjs-all.jar ]; then
- mvn clean package
+ mvn clean package -Pshade
fi
java -jar target/dynjs-all.jar --console $*
View
3  src/main/java/org/dynjs/runtime/DynJS.java
@@ -101,6 +101,9 @@ public Object execute(String program, String filename, int lineNumber) {
public Object execute(String program, String filename, int lineNumber, boolean forceStrict) {
JSProgram programObj = compile(this.context, program, filename, forceStrict);
Completion completion = this.context.execute(programObj);
+ if ( completion.type == Completion.Type.BREAK || completion.type == Completion.Type.CONTINUE ) {
+ throw new ThrowException( this.context, this.context.createSyntaxError( "illegal break or continue" ));
+ }
Object v = completion.value;
if (v instanceof Reference) {
return ((Reference) v).getValue(context);
View
1  src/main/java/org/dynjs/runtime/ExecutionContext.java
@@ -205,6 +205,7 @@ public ExecutionContext createFunctionExecutionContext(JSFunction function, Obje
public Completion executeCatch(BasicBlock block, String identifier, Object thrown) {
// 12.14
+ System.err.println( "catch " + thrown + " as " + identifier );
LexicalEnvironment oldEnv = this.lexicalEnvironment;
LexicalEnvironment catchEnv = LexicalEnvironment.newDeclarativeEnvironment(oldEnv);
catchEnv.getRecord().createMutableBinding(this, identifier, false);
View
3  src/main/java/org/dynjs/runtime/builtins/Eval.java
@@ -33,7 +33,8 @@ public Object call(ExecutionContext context, Object self, Object... args) {
Object code = args[0];
if (code != Types.UNDEFINED) {
try {
- return context.getGlobalObject().getRuntime().evaluate(code.toString());
+ Object result = context.getGlobalObject().getRuntime().evaluate(code.toString());
+ return result;
} catch (SyntaxError e) {
throw new ThrowException(context, context.createSyntaxError(e.getMessage()));
}
View
15 src/test/java/org/dynjs/runtime/ContinueStatementTest.java
@@ -0,0 +1,15 @@
+package org.dynjs.runtime;
+
+import static org.fest.assertions.Assertions.*;
+
+import org.dynjs.exception.ThrowException;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ContinueStatementTest extends AbstractDynJSTestSupport {
+
+ @Test(expected=ThrowException.class)
+ public void testIllegalContinue() {
+ eval( "continue;" );
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.