8024693: Various minor issues with JSONWriter used by script parser API

Reviewed-by: jlaskey, hannesw
This commit is contained in:
Athijegannathan Sundararajan 2013-09-12 22:16:40 +05:30
parent 58b4892936
commit a122ebe169
49 changed files with 4311 additions and 39 deletions

View File

@ -264,6 +264,13 @@ grant codeBase "file:/${basedir}/test/script/basic/*" {
permission java.util.PropertyPermission "nashorn.test.*", "read";
};
grant codeBase "file:/${basedir}/test/script/basic/parser/*" {
permission java.io.FilePermission "${basedir}/test/script/-", "read";
permission java.io.FilePermission "$${user.dir}", "read";
permission java.util.PropertyPermission "user.dir", "read";
permission java.util.PropertyPermission "nashorn.test.*", "read";
};
grant codeBase "file:/${basedir}/test/script/basic/JDK-8010946-privileged.js" {
permission java.util.PropertyPermission "java.security.policy", "read";
};

View File

@ -27,6 +27,7 @@ package jdk.nashorn.internal.ir.debug;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import jdk.nashorn.internal.codegen.CompilerConstants;
import jdk.nashorn.internal.ir.AccessNode;
import jdk.nashorn.internal.ir.BinaryNode;
@ -197,10 +198,10 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
comma();
final IdentNode label = breakNode.getLabel();
property("label");
if (label != null) {
property("label", label.getName());
label.accept(this);
} else {
property("label");
nullValue();
}
@ -256,13 +257,11 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
comma();
final Node guard = catchNode.getExceptionCondition();
property("guard");
if (guard != null) {
property("guard");
guard.accept(this);
} else {
nullValue();
comma();
}
comma();
property("body");
catchNode.getBody().accept(this);
@ -278,10 +277,10 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
comma();
final IdentNode label = continueNode.getLabel();
property("label");
if (label != null) {
property("label", label.getName());
label.accept(this);
} else {
property("label");
nullValue();
}
@ -299,13 +298,20 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
@Override
public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
// handle debugger statement
final Node expression = expressionStatement.getExpression();
if (expression instanceof RuntimeNode) {
expression.accept(this);
return false;
}
enterDefault(expressionStatement);
type("ExpressionStatement");
comma();
property("expression");
expressionStatement.getExpression().accept(this);
expression.accept(this);
return leave();
}
@ -388,13 +394,14 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
@Override
public boolean enterFunctionNode(final FunctionNode functionNode) {
enterDefault(functionNode);
final boolean program = functionNode.isProgram();
final String name;
if (program) {
name = "Program";
} else if (functionNode.isDeclared()) {
return emitProgram(functionNode);
}
enterDefault(functionNode);
final String name;
if (functionNode.isDeclared()) {
name = "FunctionDeclaration";
} else {
name = "FunctionExpression";
@ -402,24 +409,41 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
type(name);
comma();
if (! program) {
property("id");
if (functionNode.isAnonymous()) {
nullValue();
} else {
functionNode.getIdent().accept(this);
}
comma();
property("id");
if (functionNode.isAnonymous()) {
nullValue();
} else {
functionNode.getIdent().accept(this);
}
comma();
array("params", functionNode.getParameters());
comma();
arrayStart("defaults");
arrayEnd();
comma();
property("rest");
nullValue();
comma();
if (!program) {
array("params", functionNode.getParameters());
comma();
}
property("body");
functionNode.getBody().accept(this);
comma();
property("generator", false);
comma();
property("expression", false);
return leave();
}
private boolean emitProgram(final FunctionNode functionNode) {
enterDefault(functionNode);
type("Program");
comma();
// body consists of nested functions and statements
final List<Statement> stats = functionNode.getBody().getStatements();
@ -730,7 +754,31 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
tryNode.getBody().accept(this);
comma();
array("handlers", tryNode.getCatches());
final List<? extends Node> catches = tryNode.getCatches();
final List<CatchNode> guarded = new ArrayList<>();
CatchNode unguarded = null;
if (catches != null) {
for (Node n : catches) {
CatchNode cn = (CatchNode)n;
if (cn.getExceptionCondition() != null) {
guarded.add(cn);
} else {
assert unguarded == null: "too many unguarded?";
unguarded = cn;
}
}
}
array("guardedHandlers", guarded);
comma();
property("handler");
if (unguarded != null) {
unguarded.accept(this);
} else {
nullValue();
}
comma();
property("finalizer");
@ -760,8 +808,8 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
array("arguments", callNode.getArgs());
} else {
final boolean prefix;
final String operator;
final boolean prefix;
switch (tokenType) {
case INCPOSTFIX:
prefix = false;
@ -780,8 +828,9 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
prefix = true;
break;
default:
prefix = false;
prefix = true;
operator = tokenType.getName();
break;
}
type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
@ -802,6 +851,14 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
@Override
public boolean enterVarNode(final VarNode varNode) {
final Node init = varNode.getInit();
if (init instanceof FunctionNode && ((FunctionNode)init).isDeclared()) {
// function declaration - don't emit VariableDeclaration instead
// just emit FunctionDeclaration using 'init' Node.
init.accept(this);
return false;
}
enterDefault(varNode);
type("VariableDeclaration");
@ -816,11 +873,11 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
type("VariableDeclarator");
comma();
property("id", varNode.getName().toString());
property("id");
varNode.getName().accept(this);
comma();
property("init");
final Node init = varNode.getInit();
if (init != null) {
init.accept(this);
} else {
@ -855,7 +912,7 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
whileNode.getTest().accept(this);
comma();
property("block");
property("body");
whileNode.getBody().accept(this);
}
@ -894,23 +951,27 @@ public final class JSONWriter extends NodeVisitor<LexicalContext> {
return buf.toString();
}
private void property(final String key, final String value) {
private void property(final String key, final String value, final boolean escape) {
buf.append('"');
buf.append(key);
buf.append("\":");
if (value != null) {
buf.append('"');
if (escape) buf.append('"');
buf.append(value);
buf.append('"');
if (escape) buf.append('"');
}
}
private void property(final String key, final String value) {
property(key, value, true);
}
private void property(final String key, final boolean value) {
property(key, Boolean.toString(value));
property(key, Boolean.toString(value), false);
}
private void property(final String key, final int value) {
property(key, Integer.toString(value));
property(key, Integer.toString(value), false);
}
private void property(final String key) {

View File

@ -30,4 +30,4 @@
load("nashorn:parser.js");
var ast = parse("label: while(true) break label;");
print(JSON.stringify(ast));
print(JSON.stringify(ast, null, " "));

View File

@ -1 +1,36 @@
{"type":"Program","rest":null,"body":[{"type":"LabeledStatement","label":{"type":"Identifier","name":"label"},"body":{"type":"BlockStatement","body":[{"type":"WhileStatement","test":{"type":"Literal","value":true},"block":{"type":"BlockStatement","body":[{"type":"BreakStatement","label":"label"}]}}]}}]}
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "label"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "BreakStatement",
"label": {
"type": "Identifier",
"name": "label"
}
}
]
}
}
]
}
}
]
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check assignment e xyzpressions.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("xyz = 314");
printParse("xyz += 314");
printParse("xyz -= 314");
printParse("xyz *= 314");
printParse("xyz /= 314");
printParse("xyz %= 314");
printParse("xyz <<= 314");
printParse("xyz >>= 314");
printParse("xyz >>>= 314");
printParse("xyz &= 314");
printParse("xyz ^= 314");
printParse("xyz |= 314");

View File

@ -0,0 +1,240 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "+=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "-=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "*=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "/=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "%=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "<<=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": ">>=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": ">>>=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "&=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "^=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "|=",
"left": {
"type": "Identifier",
"name": "xyz"
},
"right": {
"type": "Literal",
"value": 314
}
}
}
]
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check binary operators.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("a * b")
printParse("a / b");
printParse("a % b");
printParse("a + b");
printParse("a - b");
printParse("a << b");
printParse("a >> b");
printParse("a >>> b");
printParse("a < b");
printParse("a > b");
printParse("a <= b");
printParse("a >= b");
printParse("a instanceof b");
printParse("a == b");
printParse("a != b");
printParse("a === b");
printParse("a !== b");
printParse("a & b");
printParse("a ^ b");
printParse("a | b");
printParse("a && b");
printParse("a || b");

View File

@ -0,0 +1,440 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "*",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "/",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "%",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "-",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "<<",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": ">>",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": ">>>",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "<",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": ">",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "<=",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": ">=",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "instanceof",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "==",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "!=",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "===",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "!==",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "&",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "^",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "|",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "LogicalExpression",
"operator": "&&",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "LogicalExpression",
"operator": "||",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Identifier",
"name": "b"
}
}
}
]
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check 'break' statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("while (true) { break; }");
printParse("loop: { while (true) { break loop } }");
printParse("loop: { for (;;) { break loop } }");

View File

@ -0,0 +1,92 @@
{
"type": "Program",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "BreakStatement",
"label": null
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "loop"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "BreakStatement",
"label": {
"type": "Identifier",
"name": "loop"
}
}
]
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "loop"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ForStatement",
"init": null,
"test": null,
"update": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "BreakStatement",
"label": {
"type": "Identifier",
"name": "loop"
}
}
]
}
}
]
}
}
]
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check ternary operator.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("a? b : c");

View File

@ -0,0 +1,23 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ConditionalExpression",
"test": {
"type": "Identifier",
"name": "a"
},
"consequent": {
"type": "Identifier",
"name": "b"
},
"alternate": {
"type": "Identifier",
"name": "c"
}
}
}
]
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check 'continue' statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("while (true) { continue; }");
printParse("begin: { while (true) { continue begin; } }");
printParse("start: { for(;;) { continue start; } }");

View File

@ -0,0 +1,92 @@
{
"type": "Program",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ContinueStatement",
"label": null
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "begin"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ContinueStatement",
"label": {
"type": "Identifier",
"name": "begin"
}
}
]
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "start"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ForStatement",
"init": null,
"test": null,
"update": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ContinueStatement",
"label": {
"type": "Identifier",
"name": "start"
}
}
]
}
}
]
}
}
]
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check debugger statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("debugger");

View File

@ -0,0 +1,8 @@
{
"type": "Program",
"body": [
{
"type": "DebuggerStatement"
}
]
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check 'function' statements and expressions.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("function hello() { print('hello') }")
printParse("function hello(a) { print(a) }")
printParse("function hello(a, b) { print(a, b) }")
printParse("var hello = function() { print('hello') };")
printParse("var hello = function hello() { print('hello') };")
printParse("(function(){})")
printParse("function test() { 'use strict' }");

View File

@ -0,0 +1,279 @@
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "hello"
},
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
},
"generator": false,
"expression": false
}
]
}
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "hello"
},
"params": [
{
"type": "Identifier",
"name": "a"
}
],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Identifier",
"name": "a"
}
]
}
}
]
},
"generator": false,
"expression": false
}
]
}
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "hello"
},
"params": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Identifier",
"name": "b"
}
],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Identifier",
"name": "b"
}
]
}
}
]
},
"generator": false,
"expression": false
}
]
}
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "hello"
},
"init": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
},
"generator": false,
"expression": false
}
}
]
}
]
}
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "hello"
},
"init": {
"type": "FunctionExpression",
"id": {
"type": "Identifier",
"name": "hello"
},
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
},
"generator": false,
"expression": false
}
}
]
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": []
},
"generator": false,
"expression": false
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "test"
},
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": "use strict"
}
}
]
},
"generator": false,
"expression": false
}
]
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check 'if' statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("if (js) { nashorn() }");
printParse("if (js) { nashorn() } else { java() }");

View File

@ -0,0 +1,73 @@
{
"type": "Program",
"body": [
{
"type": "IfStatement",
"test": {
"type": "Identifier",
"name": "js"
},
"consequent": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "nashorn"
},
"arguments": []
}
}
]
},
"alternate": null
}
]
}
{
"type": "Program",
"body": [
{
"type": "IfStatement",
"test": {
"type": "Identifier",
"name": "js"
},
"consequent": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "nashorn"
},
"arguments": []
}
}
]
},
"alternate": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "java"
},
"arguments": []
}
}
]
}
}
]
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Test for labelled statements.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("begin: { for (;;) break begin }");
printParse("begin: { while (true) break begin }");

View File

@ -0,0 +1,71 @@
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "begin"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ForStatement",
"init": null,
"test": null,
"update": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "BreakStatement",
"label": {
"type": "Identifier",
"name": "begin"
}
}
]
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "LabeledStatement",
"label": {
"type": "Identifier",
"name": "begin"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "BreakStatement",
"label": {
"type": "Identifier",
"name": "begin"
}
}
]
}
}
]
}
}
]
}

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check left-hand-side expressions
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("a[3]");
printParse("a[b]");
printParse("a['foo']");
printParse("obj.foo");
printParse("obj.foo.bar");
printParse("new Type");
printParse("new Type()");
printParse("new Type(a, 'hello')");
printParse("new obj.Type");
printParse("new obj.Type()");
printParse("new obj.Type(a, 'hello')");
printParse("foo()")
printParse("obj.foo()");
printParse("foo(a,b)");
printParse("obj.foo(a, b)");

View File

@ -0,0 +1,344 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "a"
},
"property": {
"type": "Literal",
"value": 3
},
"computed": true
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "a"
},
"property": {
"type": "Identifier",
"name": "b"
},
"computed": true
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "a"
},
"property": {
"type": "Literal",
"value": "foo"
},
"computed": true
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "foo"
},
"computed": false
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "MemberExpression",
"object": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "foo"
},
"computed": false
},
"property": {
"type": "Identifier",
"name": "bar"
},
"computed": false
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "NewExpression",
"callee": {
"type": "Identifier",
"name": "Type"
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "NewExpression",
"callee": {
"type": "Identifier",
"name": "Type"
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "NewExpression",
"callee": {
"type": "Identifier",
"name": "Type"
},
"arguments": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "NewExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "Type"
},
"computed": false
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "NewExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "Type"
},
"computed": false
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "NewExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "Type"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "foo"
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "foo"
},
"computed": false
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "foo"
},
"arguments": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Identifier",
"name": "b"
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "foo"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Identifier",
"name": "b"
}
]
}
}
]
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests for loop statements.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("while(true) { print('hello') }")
printParse("do { print('hello') } while(true)")
printParse("for (i in obj) { print(obj[i]) }")
printParse("for each (i in obj) { print(i) }")
printParse("for (i = 0; i < 10; i++) { print(i) }")

View File

@ -0,0 +1,212 @@
{
"type": "Program",
"body": [
{
"type": "WhileStatement",
"test": {
"type": "Literal",
"value": true
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "DoWhileStatement",
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Literal",
"value": "hello"
}
]
}
}
]
},
"test": {
"type": "Literal",
"value": true
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ForInStatement",
"left": {
"type": "Identifier",
"name": "i"
},
"right": {
"type": "Identifier",
"name": "obj"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "obj"
},
"property": {
"type": "Identifier",
"name": "i"
},
"computed": true
}
]
}
}
]
},
"each": false
}
]
}
{
"type": "Program",
"body": [
{
"type": "ForInStatement",
"left": {
"type": "Identifier",
"name": "i"
},
"right": {
"type": "Identifier",
"name": "obj"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Identifier",
"name": "i"
}
]
}
}
]
},
"each": true
}
]
}
{
"type": "Program",
"body": [
{
"type": "ForStatement",
"init": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "i"
},
"right": {
"type": "Literal",
"value": 0
}
},
"test": {
"type": "BinaryExpression",
"operator": "<",
"left": {
"type": "Identifier",
"name": "i"
},
"right": {
"type": "Literal",
"value": 10
}
},
"update": {
"type": "UpdateExpression",
"operator": "++",
"prefix": false,
"argument": {
"type": "Identifier",
"name": "i"
}
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "print"
},
"arguments": [
{
"type": "Identifier",
"name": "i"
}
]
}
}
]
}
}
]
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check assignment e xyzpressions.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("obj = {}");
printParse("p = { x: 10, y: 2 }");
printParse("p = { 'x': 10, 'y': 2 }");
printParse("p = { get x() { return xValue }, get y() { return yValue } }");

View File

@ -0,0 +1,189 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "obj"
},
"right": {
"type": "ObjectExpression",
"properties": []
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "p"
},
"right": {
"type": "ObjectExpression",
"properties": [
{
"key": {
"type": "Identifier",
"name": "x"
},
"value": {
"type": "Literal",
"value": 10
},
"kind": "init"
},
{
"key": {
"type": "Identifier",
"name": "y"
},
"value": {
"type": "Literal",
"value": 2
},
"kind": "init"
}
]
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "p"
},
"right": {
"type": "ObjectExpression",
"properties": [
{
"key": {
"type": "Literal",
"value": "x"
},
"value": {
"type": "Literal",
"value": 10
},
"kind": "init"
},
{
"key": {
"type": "Literal",
"value": "y"
},
"value": {
"type": "Literal",
"value": 2
},
"kind": "init"
}
]
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "p"
},
"right": {
"type": "ObjectExpression",
"properties": [
{
"key": {
"type": "Identifier",
"name": "x"
},
"value": {
"type": "FunctionExpression",
"id": {
"type": "Identifier",
"name": "get x"
},
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "Identifier",
"name": "xValue"
}
}
]
},
"generator": false,
"expression": false
},
"kind": "get"
},
{
"key": {
"type": "Identifier",
"name": "y"
},
"value": {
"type": "FunctionExpression",
"id": {
"type": "Identifier",
"name": "get y"
},
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "Identifier",
"name": "yValue"
}
}
]
},
"generator": false,
"expression": false
},
"kind": "get"
}
]
}
}
}
]
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests for parenthesis expressions.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("(2) + (1) + 4");
printParse("3 + (7) << (5)");

View File

@ -0,0 +1,56 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Literal",
"value": 2
},
"right": {
"type": "Literal",
"value": 1
}
},
"right": {
"type": "Literal",
"value": 4
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "<<",
"left": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Literal",
"value": 3
},
"right": {
"type": "Literal",
"value": 7
}
},
"right": {
"type": "Literal",
"value": 5
}
}
}
]
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check primary expressions.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("this");
printParse("foo");
printParse("null");
printParse("true");
printParse("false");
printParse("33");
printParse("3.14");
printParse("(10 + 3)*2");
printParse("({})");
printParse("({ x: 3 })");
printParse("[]");
printParse("[,,]");
printParse("[4, 5, 5]");

View File

@ -0,0 +1,199 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ThisExpression"
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Identifier",
"name": "foo"
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": null
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": true
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": false
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": 33
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": 3.14
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "*",
"left": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Literal",
"value": 10
},
"right": {
"type": "Literal",
"value": 3
}
},
"right": {
"type": "Literal",
"value": 2
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ObjectExpression",
"properties": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ObjectExpression",
"properties": [
{
"key": {
"type": "Identifier",
"name": "x"
},
"value": {
"type": "Literal",
"value": 3
},
"kind": "init"
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ArrayExpression",
"elements": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ArrayExpression",
"elements": [
null,
null
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ArrayExpression",
"elements": [
{
"type": "Literal",
"value": 4
},
{
"type": "Literal",
"value": 5
},
{
"type": "Literal",
"value": 5
}
]
}
}
]
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check 'return' statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("(function() { return })");
printParse("(function() { return res })");
printParse("(function() { return foo() })");

View File

@ -0,0 +1,88 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": null
}
]
},
"generator": false,
"expression": false
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "Identifier",
"name": "res"
}
}
]
},
"generator": false,
"expression": false
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "foo"
},
"arguments": []
}
}
]
},
"generator": false,
"expression": false
}
}
]
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests for switch statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("switch (key) {}");
printParse("switch (key) { case 2: hello(); break; }");
printParse("switch (key) { case 4: hello(); break; case 2: world(); break; default: break }");

View File

@ -0,0 +1,123 @@
{
"type": "Program",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "key"
},
"cases": []
}
]
}
{
"type": "Program",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "key"
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 2
},
"consequent": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "hello"
},
"arguments": []
}
},
{
"type": "BreakStatement",
"label": null
}
]
}
]
}
]
}
{
"type": "Program",
"body": [
{
"type": "SwitchStatement",
"discriminant": {
"type": "Identifier",
"name": "key"
},
"cases": [
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 4
},
"consequent": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "hello"
},
"arguments": []
}
},
{
"type": "BreakStatement",
"label": null
}
]
},
{
"type": "SwitchCase",
"test": {
"type": "Literal",
"value": 2
},
"consequent": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "world"
},
"arguments": []
}
},
{
"type": "BreakStatement",
"label": null
}
]
},
{
"type": "SwitchCase",
"test": null,
"consequent": [
{
"type": "BreakStatement",
"label": null
}
]
}
]
}
]
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests for throw statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("throw err");
printParse("throw 'wrong'");
printParse("throw new TypeError");
printParse("throw new TypeError('not an array')");
printParse("throw { msg: 'wrong!' }");

View File

@ -0,0 +1,85 @@
{
"type": "Program",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "Identifier",
"name": "err"
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "Literal",
"value": "wrong"
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "NewExpression",
"callee": {
"type": "Identifier",
"name": "TypeError"
},
"arguments": []
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "NewExpression",
"callee": {
"type": "Identifier",
"name": "TypeError"
},
"arguments": [
{
"type": "Literal",
"value": "not an array"
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "ObjectExpression",
"properties": [
{
"key": {
"type": "Identifier",
"name": "msg"
},
"value": {
"type": "Literal",
"value": "wrong!"
},
"kind": "init"
}
]
}
}
]
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check try..catch statements.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("try { } catch (e) { }");
printParse("try { } catch (e) { } finally {}");
printParse("try { } finally {}");
printParse("try { } catch (e) { handle() }");
printParse("try { that() } catch (e) { handle() } finally { clean() }");
printParse("try { that() } catch (e if e instanceof TypeError) { handle() } catch (e) { rest() }");

View File

@ -0,0 +1,305 @@
{
"type": "Program",
"body": [
{
"type": "BlockStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "TryStatement",
"block": {
"type": "BlockStatement",
"body": []
},
"guardedHandlers": [],
"handler": {
"type": "CatchClause",
"param": {
"type": "Identifier",
"name": "e"
},
"body": {
"type": "BlockStatement",
"body": []
}
},
"finalizer": null
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "BlockStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "TryStatement",
"block": {
"type": "BlockStatement",
"body": []
},
"guardedHandlers": [],
"handler": {
"type": "CatchClause",
"param": {
"type": "Identifier",
"name": "e"
},
"body": {
"type": "BlockStatement",
"body": []
}
},
"finalizer": {
"type": "BlockStatement",
"body": []
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "BlockStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "TryStatement",
"block": {
"type": "BlockStatement",
"body": []
},
"guardedHandlers": [],
"handler": null,
"finalizer": {
"type": "BlockStatement",
"body": []
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "BlockStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "TryStatement",
"block": {
"type": "BlockStatement",
"body": []
},
"guardedHandlers": [],
"handler": {
"type": "CatchClause",
"param": {
"type": "Identifier",
"name": "e"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "handle"
},
"arguments": []
}
}
]
}
},
"finalizer": null
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "BlockStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "TryStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "that"
},
"arguments": []
}
}
]
},
"guardedHandlers": [],
"handler": {
"type": "CatchClause",
"param": {
"type": "Identifier",
"name": "e"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "handle"
},
"arguments": []
}
}
]
}
},
"finalizer": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "clean"
},
"arguments": []
}
}
]
}
}
]
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "BlockStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "TryStatement",
"block": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "that"
},
"arguments": []
}
}
]
},
"guardedHandlers": [
{
"type": "CatchClause",
"param": {
"type": "Identifier",
"name": "e"
},
"guard": {
"type": "BinaryExpression",
"operator": "instanceof",
"left": {
"type": "Identifier",
"name": "e"
},
"right": {
"type": "Identifier",
"name": "TypeError"
}
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "handle"
},
"arguments": []
}
}
]
}
}
],
"handler": {
"type": "CatchClause",
"param": {
"type": "Identifier",
"name": "e"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "rest"
},
"arguments": []
}
}
]
}
},
"finalizer": null
}
]
}
}
]
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check unary operators.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("x++");
printParse("x--");
printParse("delete x");
printParse("void x");
printParse("typeof x");
printParse("++x");
printParse("--x");
printParse("+x");
printParse("-x");
printParse("~x");
printParse("!x");

View File

@ -0,0 +1,187 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UpdateExpression",
"operator": "++",
"prefix": false,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UpdateExpression",
"operator": "--",
"prefix": false,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "delete",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "void",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "typeof",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UpdateExpression",
"operator": "++",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UpdateExpression",
"operator": "--",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "+",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "-",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "~",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "UnaryExpression",
"operator": "!",
"prefix": true,
"argument": {
"type": "Identifier",
"name": "x"
}
}
}
]
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check if statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("'use strict'");
printParse("function f() { 'use strict' }");

View File

@ -0,0 +1,41 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": "use strict"
}
}
]
}
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "f"
},
"params": [],
"defaults": [],
"rest": null,
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": "use strict"
}
}
]
},
"generator": false,
"expression": false
}
]
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @subtest
*/
// utilitity for parser tests
load("nashorn:parser.js");
function printParse(code) {
print(JSON.stringify(parse(code), null, ' '));
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests to check variable declarations.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
// no initialization
printParse("var a");
printParse("var a, b");
// init single, multiple
printParse("var a = 'hello'");
printParse("var a = 1, b = 2, c = 3");

View File

@ -0,0 +1,123 @@
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "a"
},
"init": null
}
]
}
]
}
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "a"
},
"init": null
}
]
},
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "b"
},
"init": null
}
]
}
]
}
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "a"
},
"init": {
"type": "Literal",
"value": "hello"
}
}
]
}
]
}
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "a"
},
"init": {
"type": "Literal",
"value": 1
}
}
]
},
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "b"
},
"init": {
"type": "Literal",
"value": 2
}
}
]
},
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "c"
},
"init": {
"type": "Literal",
"value": 3
}
}
]
}
]
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Tests for 'with' statement.
*
* @test
* @run
*/
load(__DIR__ + "util.js");
printParse("with (scope) { x = y }");

View File

@ -0,0 +1,32 @@
{
"type": "Program",
"body": [
{
"type": "WithStatement",
"object": {
"type": "Identifier",
"name": "scope"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "x"
},
"right": {
"type": "Identifier",
"name": "y"
}
}
}
]
}
}
]
}