use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class LocaleTest method testLookup_en_GB.
@Test
public void testLookup_en_GB() throws Exception {
String languageTag = "en-GB";
Realm realm = newRealm(languageTag);
assertEquals(languageTag, realm.getLocale().toLanguageTag());
assertEquals("en-GB", resolvedLocaleLookup(realm, Intl.Collator));
assertEquals("en-GB", resolvedLocaleLookup(realm, Intl.DateTimeFormat));
assertEquals("en-GB", resolvedLocaleLookup(realm, Intl.NumberFormat));
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class TestGlobals method newGlobal.
public final GLOBAL newGlobal(Console console, TEST test) throws MalformedNameException, ResolutionException, IOException, URISyntaxException {
RuntimeContext context = createContext(console, test);
World world = new World(context);
Realm realm = world.newInitializedRealm();
// Evaluate additional initialization scripts and modules
TestModuleLoader<?> moduleLoader = (TestModuleLoader<?>) world.getModuleLoader();
for (ModuleRecord module : modules.allModules) {
moduleLoader.defineFromTemplate(module, realm);
}
for (ModuleRecord module : modules.mainModules) {
ModuleRecord testModule = moduleLoader.get(module.getSourceCodeId(), realm);
testModule.instantiate();
testModule.evaluate();
}
for (Script script : scripts) {
script.evaluate(realm);
}
@SuppressWarnings("unchecked") GLOBAL global = (GLOBAL) realm.getGlobalObject();
return global;
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class ScriptCodeGenerator method generateGlobalScriptEvaluation.
/**
* 15.1.7 Runtime Semantics: ScriptEvaluation
*
* @param node
* the script node
* @param scriptInit
* the script declaration instantiation method
* @param scriptBody
* the script body method
* @param mv
* the instruction visitor
*/
private static void generateGlobalScriptEvaluation(Script node, MethodName scriptInit, MethodName scriptBody, ScriptEvalVisitor mv) {
Variable<ExecutionContext> callerContext = mv.getCallerContext();
Variable<com.github.anba.es6draft.Script> script = mv.getScript();
Variable<Realm> realm = mv.newVariable("realm", Realm.class);
Variable<ExecutionContext> scriptCxt = mv.newVariable("scriptCxt", ExecutionContext.class);
Variable<ExecutionContext> oldScriptContext = mv.newVariable("oldScriptContext", ExecutionContext.class);
Variable<Object> result = mv.newVariable("result", Object.class);
Variable<Throwable> throwable = mv.newVariable("throwable", Throwable.class);
getRealm(callerContext, realm, mv);
/* steps 1-2 (not applicable) */
/* steps 3-7 */
newScriptExecutionContext(realm, script, scriptCxt, mv);
/* step 8 */
getScriptContext(realm, oldScriptContext, mv);
/* step 9 */
setScriptContext(realm, scriptCxt, mv);
TryCatchLabel startFinally = new TryCatchLabel(), endFinally = new TryCatchLabel();
TryCatchLabel handlerFinally = new TryCatchLabel();
mv.mark(startFinally);
{
/* step 10 */
mv.load(scriptCxt);
mv.invoke(scriptInit);
/* steps 11-12 */
mv.load(scriptCxt);
mv.invoke(scriptBody);
mv.store(result);
/* steps 13-15 */
setScriptContext(realm, oldScriptContext, mv);
/* step 16 */
mv.load(result);
mv._return();
}
mv.mark(endFinally);
// Exception: Restore script context and then rethrow exception
mv.finallyHandler(handlerFinally);
mv.store(throwable);
/* steps 13-15 */
setScriptContext(realm, oldScriptContext, mv);
mv.load(throwable);
mv.athrow();
mv.tryFinally(startFinally, endFinally, handlerFinally);
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class InterpretedScriptBody method evalScriptEvaluation.
/**
* 18.2.1.1 Runtime Semantics: PerformEval( x, evalRealm, strictCaller, direct)
*
* @param cx
* the execution context
* @param script
* the script object
* @param interpreter
* the interpreter
* @return the script evaluation result
*/
private Object evalScriptEvaluation(ExecutionContext cx, Script script, Interpreter interpreter) {
// TODO: Skip allocating lex-env if not needed
/* steps 1-5 (not applicable) */
/* steps 6-7 */
boolean strictEval = parsedScript.isStrict();
/* step 8 (omitted) */
/* steps 9-10 */
LexicalEnvironment<DeclarativeEnvironmentRecord> lexEnv;
LexicalEnvironment<?> varEnv;
if (parsedScript.isDirectEval()) {
/* step 9 */
lexEnv = newDeclarativeEnvironment(cx.getLexicalEnvironment());
varEnv = cx.getVariableEnvironment();
} else {
Realm evalRealm = cx.getRealm();
/* step 10 */
lexEnv = newDeclarativeEnvironment(evalRealm.getGlobalEnv());
varEnv = evalRealm.getGlobalEnv();
}
/* step 11 */
if (strictEval) {
varEnv = lexEnv;
}
/* steps 12-19 */
ExecutionContext evalCxt = newEvalExecutionContext(cx, script, varEnv, lexEnv);
/* step 20 */
EvalDeclarationInstantiation(evalCxt, parsedScript, varEnv, lexEnv);
/* steps 21-25 */
return parsedScript.accept(interpreter, evalCxt);
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class PromisePrototype method PerformPromiseThen.
/**
* 25.4.5.3.1 PerformPromiseThen ( promise, onFulfilled, onRejected, resultCapability )
*
* @param <PROMISE>
* the promise type
* @param cx
* the execution context
* @param promise
* the promise object
* @param onFulfilled
* the onFulfilled handler
* @param onRejected
* the onRejected handler
* @param resultCapability
* the new promise capability record
* @return the new promise object
*/
public static <PROMISE extends ScriptObject> PROMISE PerformPromiseThen(ExecutionContext cx, PromiseObject promise, Object onFulfilled, Object onRejected, PromiseCapability<PROMISE> resultCapability) {
/* step 3 */
if (!IsCallable(onFulfilled)) {
onFulfilled = null;
}
/* step 4 */
if (!IsCallable(onRejected)) {
onRejected = null;
}
ZoneObject currentZone = cx.getRealm().getCurrentZone();
/* step 5 */
PromiseReaction fulfillReaction = new PromiseReaction(resultCapability, PromiseReaction.Type.Fulfill, (Callable) onFulfilled, currentZone);
/* step 6 */
PromiseReaction rejectReaction = new PromiseReaction(resultCapability, PromiseReaction.Type.Reject, (Callable) onRejected, currentZone);
/* step 7 */
if (promise.getState() == PromiseObject.State.Pending) {
promise.addFulfillReaction(fulfillReaction);
promise.addRejectReaction(rejectReaction);
promise.notifyRejectReaction(rejectReaction);
} else /* step 8 */
if (promise.getState() == PromiseObject.State.Fulfilled) {
Object value = promise.getResult();
Realm realm = cx.getRealm();
realm.enqueuePromiseJob(new PromiseReactionJob(realm, fulfillReaction, value));
} else /* step 9 */
{
assert promise.getState() == PromiseObject.State.Rejected;
Object reason = promise.getResult();
Realm realm = cx.getRealm();
realm.enqueuePromiseJob(new PromiseReactionJob(realm, rejectReaction, reason));
promise.notifyRejectReaction(rejectReaction);
}
/* step 11 */
return resultCapability.getPromise();
}
Aggregations