com.googlecode.jslint4java
Class TimeLimitedContextFactory

java.lang.Object
  extended by org.mozilla.javascript.ContextFactory
      extended by com.googlecode.jslint4java.TimeLimitedContextFactory

public class TimeLimitedContextFactory
extends org.mozilla.javascript.ContextFactory

A ContextFactory that allows specification of a timeout. This is mostly copied from the example in the ContextFactory javadocs.


Nested Class Summary
static class TimeLimitedContextFactory.TimeExceededException
           
 
Nested classes/interfaces inherited from class org.mozilla.javascript.ContextFactory
org.mozilla.javascript.ContextFactory.GlobalSetter, org.mozilla.javascript.ContextFactory.Listener
 
Constructor Summary
TimeLimitedContextFactory(long maxTime, TimeUnit timeUnit)
          Create a new TimeLimitedContextFactory.
 
Method Summary
protected  Object doTopCall(org.mozilla.javascript.Callable callable, org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable thisObj, Object[] args)
          Record start time in context.
protected  org.mozilla.javascript.Context makeContext()
          Create a TimeLimitedContext that runs the observer every 10k ops.
protected  void observeInstructionCount(org.mozilla.javascript.Context cx, int instructionCount)
          Enforce time restrictions.
 
Methods inherited from class org.mozilla.javascript.ContextFactory
addListener, call, checkNotSealed, createClassLoader, enter, enterContext, enterContext, exit, getApplicationClassLoader, getE4xImplementationFactory, getGlobal, getGlobalSetter, hasExplicitGlobal, hasFeature, initApplicationClassLoader, initGlobal, isSealed, onContextCreated, onContextReleased, removeListener, seal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeLimitedContextFactory

public TimeLimitedContextFactory(long maxTime,
                                 TimeUnit timeUnit)
Create a new TimeLimitedContextFactory.

Parameters:
maxTime - the maximum amount of time that a JavaScript execution is allowed to take.
timeUnit - the unit of maxTime.
Method Detail

makeContext

protected org.mozilla.javascript.Context makeContext()
Create a TimeLimitedContext that runs the observer every 10k ops.

Overrides:
makeContext in class org.mozilla.javascript.ContextFactory

doTopCall

protected Object doTopCall(org.mozilla.javascript.Callable callable,
                           org.mozilla.javascript.Context cx,
                           org.mozilla.javascript.Scriptable scope,
                           org.mozilla.javascript.Scriptable thisObj,
                           Object[] args)
Record start time in context.

Overrides:
doTopCall in class org.mozilla.javascript.ContextFactory

observeInstructionCount

protected void observeInstructionCount(org.mozilla.javascript.Context cx,
                                       int instructionCount)
Enforce time restrictions.

Overrides:
observeInstructionCount in class org.mozilla.javascript.ContextFactory


Copyright © 2007-2012. All Rights Reserved.