/** * Same as calling {@link ContextFactory#enterContext()} on the global * ContextFactory instance. * @return a Context associated with the current thread * @see #getCurrentContext() * @see #exit() * @see #call(ContextAction) */ public static Context enter() { return enter(null); }
/** * Get a Context associated with the current thread, using the given * Context if need be. * <p> * The same as <code>enterContext()</code> except that <code>cx</code> * is associated with the current thread and returned if the current thread * has no associated context and <code>cx</code> is not associated with any * other thread. * @param cx a Context to associate with the thread if possible * @return a Context associated with the current thread * @see #enterContext() * @see #call(ContextAction) * @throws IllegalStateException if <code>cx</code> is already associated * with a different thread */ public final Context enterContext(Context cx) { return Context.enter(cx, this); } }
/** * Get a Context associated with the current thread, using * the given Context if need be. * <p> * The same as <code>enter()</code> except that <code>cx</code> * is associated with the current thread and returned if * the current thread has no associated context and <code>cx</code> * is not associated with any other thread. * @param cx a Context to associate with the thread if possible * @return a Context associated with the current thread * @deprecated use {@link ContextFactory#enterContext(Context)} instead as * this method relies on usage of a static singleton "global" ContextFactory. * @see ContextFactory#enterContext(Context) * @see ContextFactory#call(ContextAction) */ public static Context enter(Context cx) { return enter(cx, ContextFactory.getGlobal()); }
/** * The method implements {@link ContextFactory#call(ContextAction)} logic. */ static Object call(ContextFactory factory, ContextAction action) { Context cx = enter(null, factory); try { return action.run(cx); } finally { exit(); } }
@Before public void before() throws Exception { this.context = Context.enter(); this.compiledScripts = compileScripts(context, getScriptResourceNames()); }
/** * Calls the {@code callback} given in parameter once for each value pair in the list, in insertion order. * @param callback function to execute for each element */ @JsxFunction({CHROME, FF}) public void forEach(final Object callback) { final List<DomNode> nodes = getElements(); final Context context = Context.enter(); try { final Function function = (Function) callback; final Scriptable scope = getParentScope(); for (int i = 0; i < nodes.size(); i++) { function.call(context, scope, this, new Object[] { nodes.get(i).getScriptableObject(), i, this}); } } finally { Context.exit(); } } }
/** * Calls the {@code callback} given in parameter once for each value pair in the list, in insertion order. * @param callback function to execute for each element */ @JsxFunction({CHROME, FF}) public void forEach(final Object callback) { final List<DomNode> nodes = getElements(); final Context context = Context.enter(); try { final Function function = (Function) callback; final Scriptable scope = getParentScope(); for (int i = 0; i < nodes.size(); i++) { function.call(context, scope, this, new Object[] { nodes.get(i).getScriptableObject(), i, this}); } } finally { Context.exit(); } } }
@Override public void run() { final Context cx = Context.enter(); try { Function toExecute = null;
@Override public void run() { final Context cx = Context.enter(); try { Function toExecute = null;
/** * Creates a new event instance. * * @param target the event target * @param type the event type * @param state the state object */ public PopStateEvent(final EventTarget target, final String type, final Object state) { super(target, type); if (state instanceof NativeObject && getBrowserVersion().hasFeature(JS_POP_STATE_EVENT_CLONE_STATE)) { final NativeObject old = (NativeObject) state; final NativeObject newState = new NativeObject(); Context.enter(); try { for (final Object o : ScriptableObject.getPropertyIds(old)) { final String property = Context.toString(o); newState.defineProperty(property, ScriptableObject.getProperty(old, property), ScriptableObject.EMPTY); } } finally { Context.exit(); } state_ = newState; } else { state_ = state; } }
/** * Creates a new event instance. * * @param target the event target * @param type the event type * @param state the state object */ public PopStateEvent(final EventTarget target, final String type, final Object state) { super(target, type); if (state instanceof NativeObject && getBrowserVersion().hasFeature(JS_POP_STATE_EVENT_CLONE_STATE)) { final NativeObject old = (NativeObject) state; final NativeObject newState = new NativeObject(); Context.enter(); try { for (final Object o : ScriptableObject.getPropertyIds(old)) { final String property = Context.toString(o); newState.defineProperty(property, ScriptableObject.getProperty(old, property), ScriptableObject.EMPTY); } } finally { Context.exit(); } state_ = newState; } else { state_ = state; } }
final Context cx = Context.enter(); try { final ProxyAutoConfig config = new ProxyAutoConfig();
final Context cx = Context.enter(); try { final ProxyAutoConfig config = new ProxyAutoConfig();