/** * Called by ModuleSpace in Development Mode when running onModuleLoads. */ private static boolean enter() { assert entryDepth >= 0 : "Negative entryDepth value at entry " + entryDepth; if (GWT.isScript() && entryDepth != 0) { double now = Duration.currentTimeMillis(); if (now - watchdogEntryDepthLastScheduled > WATCHDOG_ENTRY_DEPTH_CHECK_INTERVAL_MS) { watchdogEntryDepthLastScheduled = now; watchdogEntryDepthTimerId = watchdogEntryDepthSchedule(); } } // We want to disable some actions in the reentrant case if (entryDepth++ == 0) { SchedulerImpl.INSTANCE.flushEntryCommands(); return true; } return false; }
/** * Called by ModuleSpace in Development Mode when running onModuleLoads. */ private static void exit(boolean initialEntry) { if (initialEntry) { SchedulerImpl.INSTANCE.flushFinallyCommands(); } // Decrement after we call flush entryDepth--; assert entryDepth >= 0 : "Negative entryDepth value at exit " + entryDepth; if (initialEntry) { assert entryDepth == 0 : "Depth not 0" + entryDepth; if (GWT.isScript() && watchdogEntryDepthTimerId != -1) { watchdogEntryDepthCancel(watchdogEntryDepthTimerId); watchdogEntryDepthTimerId = -1; } } }
/** * Called by Flusher. */ void flushPostEventPumpCommands() { if (deferredCommands != null) { JsArray<Task> oldDeferred = deferredCommands; deferredCommands = null; /* We might not have any incremental commands queued. */ if (incrementalCommands == null) { incrementalCommands = createQueue(); } runScheduledTasks(oldDeferred, incrementalCommands); } if (incrementalCommands != null) { incrementalCommands = runRepeatingTasks(incrementalCommands); } }
public boolean execute() { flushRunning = true; flushPostEventPumpCommands(); /* * No finally here, we want this to be clear only on a normal exit. An * abnormal exit would indicate that an exception isn't being caught * correctly or that a slow script warning canceled the timer. */ flushRunning = false; return shouldBeRunning = isWorkQueued(); } }
@Override public void scheduleIncremental(RepeatingCommand cmd) { // Push repeating commands onto the same initial queue for relative order deferredCommands = push(deferredCommands, Task.create(cmd)); maybeSchedulePostEventPumpCommands(); }
@Override public void scheduleEntry(ScheduledCommand cmd) { entryCommands = push(entryCommands, Task.create(cmd)); }
Duration duration = createDuration(); while (duration.elapsedMillis() < TIME_SLICE) { boolean executedSomeTask = false; JsArray<Task> newTasks = createQueue();
/** * Central dispatching function for events emitted by DOM objects * @param event The DOM event * @param node The object processing the event * @param elem The object emitting the event */ public void dispatch(NativeEvent event, OMNode node, Element elem) { //Window.alert("type=" + event.getType()); SchedulerImpl.INSTANCE.flushEntryCommands(); String eventName = event.getType(); if ("mouseover".equals(eventName) || "mouseout".equals(eventName)) { // Mouseover and mouseout deserve special treatment // to solve issues described in: // http://www.quirksmode.org/js/events_mouse.html // For SVG, it seems better to test against the tree rooted at // evt.currentTarget than againt the subtree rooted at evt.target if (isChildOf((Node)event.getCurrentEventTarget().cast(), (Node)event.getRelatedEventTarget().cast())) { return; } } node.dispatch(event); SchedulerImpl.INSTANCE.flushFinallyCommands(); }
/** * Called by {@link Impl#entry(JavaScriptObject)}. */ public void flushEntryCommands() { if (entryCommands != null) { JsArray<Task> rescheduled = null; // This do-while loop handles commands scheduling commands do { JsArray<Task> oldQueue = entryCommands; entryCommands = null; rescheduled = runScheduledTasks(oldQueue, rescheduled); } while (entryCommands != null); entryCommands = rescheduled; } }
/** * Provides lazy-init pattern for the task queues. */ private static JsArray<Task> push(JsArray<Task> queue, Task task) { if (queue == null) { queue = createQueue(); } queue.push(task); return queue; }
@Override public void scheduleDeferred(ScheduledCommand cmd) { deferredCommands = push(deferredCommands, Task.create(cmd)); maybeSchedulePostEventPumpCommands(); }
@Override public void scheduleFinally(ScheduledCommand cmd) { finallyCommands = push(finallyCommands, Task.create(cmd)); }
public boolean execute() { flushRunning = true; flushPostEventPumpCommands(); /* * No finally here, we want this to be clear only on a normal exit. An * abnormal exit would indicate that an exception isn't being caught * correctly or that a slow script warning canceled the timer. */ flushRunning = false; return shouldBeRunning = isWorkQueued(); } }
Duration duration = createDuration(); while (duration.elapsedMillis() < TIME_SLICE) { boolean executedSomeTask = false; JsArray<Task> newTasks = createQueue();
/** * Central dispatching function for events emitted by DOM objects * @param event The DOM event * @param node The object processing the event * @param elem The object emitting the event */ public void dispatch(NativeEvent event, OMNode node, Element elem) { //Window.alert("type=" + event.getType()); SchedulerImpl.INSTANCE.flushEntryCommands(); String eventName = event.getType(); if ("mouseover".equals(eventName) || "mouseout".equals(eventName)) { // Mouseover and mouseout deserve special treatment // to solve issues described in: // http://www.quirksmode.org/js/events_mouse.html // For SVG, it seems better to test against the tree rooted at // evt.currentTarget than againt the subtree rooted at evt.target if (isChildOf((Node)event.getCurrentEventTarget().cast(), (Node)event.getRelatedEventTarget().cast())) { return; } } node.dispatch(event); SchedulerImpl.INSTANCE.flushFinallyCommands(); }
/** * Called by {@link Impl#entry(JavaScriptObject)}. */ public void flushFinallyCommands() { if (finallyCommands != null) { JsArray<Task> rescheduled = null; // This do-while loop handles commands scheduling commands do { JsArray<Task> oldQueue = finallyCommands; finallyCommands = null; rescheduled = runScheduledTasks(oldQueue, rescheduled); } while (finallyCommands != null); finallyCommands = rescheduled; } }
/** * Provides lazy-init pattern for the task queues. */ private static JsArray<Task> push(JsArray<Task> queue, Task task) { if (queue == null) { queue = createQueue(); } queue.push(task); return queue; }
/** * Called by Flusher. */ void flushPostEventPumpCommands() { if (deferredCommands != null) { JsArray<Task> oldDeferred = deferredCommands; deferredCommands = null; /* We might not have any incremental commands queued. */ if (incrementalCommands == null) { incrementalCommands = createQueue(); } runScheduledTasks(oldDeferred, incrementalCommands); } if (incrementalCommands != null) { incrementalCommands = runRepeatingTasks(incrementalCommands); } }
@Override public void scheduleIncremental(RepeatingCommand cmd) { // Push repeating commands onto the same initial queue for relative order deferredCommands = push(deferredCommands, Task.create(cmd)); maybeSchedulePostEventPumpCommands(); }
@Override public void scheduleEntry(RepeatingCommand cmd) { entryCommands = push(entryCommands, Task.create(cmd)); }