use of com.github.anba.es6draft.Script in project es6draft by anba.
the class ShellFunctions method evalScript.
/**
* shell-function: {@code evalScript(sourceString, [options])}
*
* @param cx
* the execution context
* @param sourceString
* the source string
* @param options
* the options object (optional)
* @return the evaluation result
*/
@Function(name = "evalScript", arity = 1)
public Object evalScript(ExecutionContext cx, String sourceString, Object options) {
String name = "";
int line = 1;
Realm realm = cx.getRealm();
if (Type.isObject(options)) {
ScriptObject opts = Type.objectValue(options);
Object fileName = Get(cx, opts, "fileName");
if (!Type.isUndefined(fileName)) {
name = ToFlatString(cx, fileName);
}
Object lineNumber = Get(cx, opts, "lineNumber");
if (!Type.isUndefined(lineNumber)) {
line = ToInt32(cx, lineNumber);
}
Object g = Get(cx, opts, "global");
if (!Type.isUndefined(g)) {
if (!(g instanceof GlobalObject)) {
throw Errors.newError(cx, "invalid global argument");
}
realm = ((GlobalObject) g).getRealm();
}
Object r = Get(cx, opts, "realm");
if (!Type.isUndefined(r)) {
if (!(r instanceof RealmObject)) {
throw Errors.newError(cx, "invalid realm argument");
}
realm = ((RealmObject) r).getRealm();
}
}
Source source = new Source(name, line);
Script script = realm.getScriptLoader().script(source, sourceString);
return script.evaluate(realm);
}
use of com.github.anba.es6draft.Script in project es6draft by anba.
the class ShellGlobalObject method eval.
/**
* Parses, compiles and executes the javascript source code.
*
* @param source
* the source object
* @param sourceCode
* the source code
* @return the evaluation result
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
*/
public Object eval(Source source, String sourceCode) throws ParserException, CompilationException {
Realm realm = getRealm();
Script script = realm.getScriptLoader().script(source, sourceCode);
return script.evaluate(realm);
}
use of com.github.anba.es6draft.Script in project es6draft by anba.
the class ShellGlobalObject method include.
/**
* Parses, compiles and executes the javascript file. (Uses the script cache.)
*
* @param file
* the path to the script file
* @throws IOException
* if there was any I/O error
* @throws ParserException
* if the source contains any syntax errors
* @throws CompilationException
* if the parsed source could not be compiled
*/
public void include(Path file) throws IOException, ParserException, CompilationException {
Realm realm = getRealm();
ScriptCache scriptCache = getRuntimeContext().getScriptCache();
Path path = getRuntimeContext().getBaseDirectory().resolve(file);
Script script = scriptCache.get(realm.getScriptLoader(), path);
script.evaluate(realm);
}
use of com.github.anba.es6draft.Script in project es6draft by anba.
the class Eval method PerformEval.
/**
* 18.2.1.1 Runtime Semantics: PerformEval( x, evalRealm, strictCaller, direct)
*
* @param cx
* the execution context
* @param caller
* the caller execution context
* @param source
* the source string
* @param flags
* the eval flags
* @return the evaluation result
*/
private static Object PerformEval(ExecutionContext cx, ExecutionContext caller, Object source, int flags) {
boolean strictCaller = EvalFlags.Strict.isSet(flags);
boolean direct = EvalFlags.Direct.isSet(flags);
assert direct || cx == cx.getRealm().defaultContext() : "indirect eval with non-default context";
/* step 1 */
assert direct || !strictCaller;
/* step 2 */
if (!Type.isString(source)) {
return source;
}
/* step 3 */
Script script = script(cx, caller, Type.stringValue(source).toString(), flags);
/* step 4 */
if (script == null) {
return UNDEFINED;
}
/* steps 5-23 */
return script.evaluate(cx);
}
use of com.github.anba.es6draft.Script in project es6draft by anba.
the class Repl method eval.
/**
* REPL: Eval
*
* @param realm
* the realm instance
* @param parsedScript
* the parsed script node
* @return the evaluated script result
*/
private Object eval(Realm realm, com.github.anba.es6draft.ast.Script parsedScript) {
String className = "#typein_" + scriptCounter.incrementAndGet();
Script script;
if (options.noInterpreter) {
script = realm.getScriptLoader().compile(parsedScript, className);
} else {
script = realm.getScriptLoader().load(parsedScript, className);
}
return script.evaluate(realm);
}
Aggregations