/// <summary> /// Creates an Agent. /// </summary> public Agent() { //https://tc39.github.io/ecma262/#sec-initializehostdefinedrealm var realm = new Realm(this, "Default"); var newContext = new ExecutionContext(realm, null, true); ExecutionContexts.Add(newContext); RunningExecutionContext = newContext; realm.SetRealmGlobalObject(null, null); realm.SetDefaultGlobalBindings(); }
/// <summary> /// Runs the next job. /// </summary> public void RunNextJob() { Debug.Assert(ExecutionContexts.Count == 1 && RunningExecutionContext == ExecutionContexts[0]); ExecutionContexts.Clear(); var nextQueue = promiseJobs.Count > 0 ? promiseJobs : scriptJobs; var nextPending = nextQueue.Dequeue(); var newContext = new ExecutionContext(nextPending.Realm, nextPending.ScriptOrModule, true); ExecutionContexts.Add(newContext); RunningExecutionContext = newContext; nextPending.Callback(); }