use of com.github.anba.es6draft.parser.Parser in project es6draft by anba.
the class ScriptLoader method evalScript.
/**
* Parses and compiles the javascript eval-script.
*
* @param source
* the script source descriptor
* @param sourceCode
* the source code
* @param evalOptions
* the eval parser options
* @return the compiled script
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
*/
public Script evalScript(Source source, String sourceCode, EnumSet<Parser.Option> evalOptions) throws ParserException, CompilationException {
Parser parser = new Parser(context, source, evalOptions);
com.github.anba.es6draft.ast.Script parsedScript = parser.parseScript(sourceCode);
if (parsedScript.getStatements().isEmpty()) {
return null;
}
return load(parsedScript, nextEvalName());
}
use of com.github.anba.es6draft.parser.Parser in project es6draft by anba.
the class ScriptLoader method asyncFunction.
/**
* Parses and compiles the javascript async function.
*
* @param source
* the script source descriptor
* @param formals
* the formal parameters
* @param bodyText
* the async function body
* @return the compiled async function
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
*/
public CompiledFunction asyncFunction(Source source, String formals, String bodyText) throws ParserException, CompilationException {
Parser parser = new Parser(context, source);
AsyncFunctionDefinition asyncDef = parser.parseAsyncFunction(formals, bodyText);
return compile(asyncDef, nextFunctionName());
}
use of com.github.anba.es6draft.parser.Parser in project es6draft by anba.
the class ScriptLoader method generator.
/**
* Parses and compiles the javascript generator function.
*
* @param source
* the script source descriptor
* @param formals
* the formal parameters
* @param bodyText
* the generator function body
* @return the compiled generator function
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
*/
public CompiledFunction generator(Source source, String formals, String bodyText) throws ParserException, CompilationException {
Parser parser = new Parser(context, source);
GeneratorDefinition generatorDef = parser.parseGenerator(formals, bodyText);
return compile(generatorDef, nextFunctionName());
}
use of com.github.anba.es6draft.parser.Parser in project es6draft by anba.
the class ScriptLoader method function.
/**
* Parses and compiles the javascript function.
*
* @param source
* the script source descriptor
* @param formals
* the formal parameters
* @param bodyText
* the function body
* @return the compiled function
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
*/
public CompiledFunction function(Source source, String formals, String bodyText) throws ParserException, CompilationException {
Parser parser = new Parser(context, source);
FunctionDefinition functionDef = parser.parseFunction(formals, bodyText);
return compile(functionDef, nextFunctionName());
}
use of com.github.anba.es6draft.parser.Parser in project es6draft by anba.
the class Test262TestRealm method executeStrict.
/**
* Executes the supplied test object.
*
* @param test
* the test-info object
* @throws ParserException
* if the module source contains any syntax errors
* @throws CompilationException
* if the parsed module source cannot be compiled
*/
void executeStrict(Test262Info test) throws ParserException, CompilationException {
// Return early if no source code is available.
if (sourceCode == null) {
return;
}
assert !test.isAsync() || async != null;
assert !(test.isModule() || test.isRaw());
Realm realm = get();
// Parse the test-script
Source source = new Source(test.toFile(), test.getScript().toString(), 1);
ScriptLoader scriptLoader = realm.getScriptLoader();
EnumSet<Parser.Option> parserOptions = EnumSet.copyOf(realm.getRuntimeContext().getParserOptions());
parserOptions.add(Parser.Option.Strict);
Parser parser = new Parser(realm.getRuntimeContext(), source, parserOptions);
com.github.anba.es6draft.ast.Script parsedScript = parser.parseScript(sourceCode);
// Evaluate the test-script
Script script = scriptLoader.load(parsedScript);
script.evaluate(realm);
// Wait for pending jobs to finish
waitForPendingJobs(realm, test);
}
Aggregations