public boolean applyObject(final Object input) { // one and only one context per thread final Context cx = Context.enter(); try { return applyInContext(cx, input); } finally { Context.exit(); } }
@Override public double estimateSelectivity(BitmapIndexSelector indexSelector) { final Context cx = Context.enter(); try { return Filters.estimateSelectivity(dimension, indexSelector, makeStringPredicate(cx)); } finally { Context.exit(); } }
@Override public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) { final Context cx = Context.enter(); try { return Filters.matchPredicate(dimension, selector, bitmapResultFactory, makeStringPredicate(cx)); } finally { Context.exit(); } }
public JavaScriptPredicateFactory(final String script, final ExtractionFn extractionFn) { Preconditions.checkNotNull(script, "script must not be null"); this.script = script; this.extractionFn = extractionFn; final Context cx = Context.enter(); try { cx.setOptimizationLevel(9); scope = cx.initStandardObjects(); fnApply = cx.compileFunction(scope, script, "script", 1, null); } finally { Context.exit(); } }
/** * Setups a proper javascript context so that it can run javascript code properly under android. * For android we need to disable bytecode generation since the android vms don't understand JVM bytecode. * @return a proper javascript context */ static @NonNull Context enterJsContext() { final Context jsContext = Context.enter(); // If we cause the context to throw a runtime exception from this point // we need to make sure that exit the context. try { jsContext.setLanguageVersion(Context.VERSION_1_8); // We can't let Rhino to optimize the JS and to use a JIT because it would generate JVM bytecode // and android runs on DEX bytecode. Instead we need to go in interpreted mode. jsContext.setOptimizationLevel(-1); } catch (RuntimeException e) { // Something bad happened to the javascript context but it might still be usable. // The first thing to do is to exit the context and then propagate the error. Context.exit(); throw e; } return jsContext; } }
IdScriptableObject idScriptableObject = (IdScriptableObject) nativeErrorConstructor.newInstance(); Context context = Context.enter();
public GalenJsExecutor() { this.context = Context.enter(); this.scope = new ImporterTopLevel(context); this.loadFunction = new JsFunctionLoad(); scope.defineProperty("load", loadFunction, ScriptableObject.DONTENUM); importAllMajorClasses(); }
@BeforeClass public static void setUp() throws Exception { ctx = Context.enter(); scope = ctx.initStandardObjects(); }
@Override @SuppressWarnings({ "unchecked" }) public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) { Context cx = Context.enter(); ScriptableObject scope = cx.initSafeStandardObjects(); String windowScript = "var window = {};var document = {};"; cx.evaluateString(scope, windowScript, "window", 1, null); HtmlParser parser = new HtmlParser(request.getUrl(), response.getContent()); for (Element ele : parser.$("script")) { String sc = ele.html(); if (StringUtils.isNotEmpty(sc)) { try { cx.evaluateString(scope, sc, "", 1, null); } catch (Exception ex) { // ex.printStackTrace(); } } } Map<String, Object> fieldMap = new HashMap<String, Object>(); Set<Field> jsVarFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(JSVar.class)); for (Field jsVarField : jsVarFields) { Object value = injectJsVarField(request, beanMap, jsVarField, cx, scope); if(value != null) { fieldMap.put(jsVarField.getName(), value); } } beanMap.putAll(fieldMap); Context.exit(); }
private void init() throws IOException, JSONException { this.uuid = database.getOrCreateUuid(); this.context = Context.enter(); context.setClassShutter(new RestrictiveClassShutter()); context.setOptimizationLevel(9);
/** * 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); }
/** * 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); }
/** * @return the javascript context for the current thread */ private Context getContext() { Context context = cx.get(); if (context == null) { context = Context.enter(); cx.set(context); } return context; }
/** * Makes sure the context is properly initialized. */ private void initContext() { if (Context.getCurrentContext() == null) { Context.enter(); } }
/** * 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(); } }
/** * 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(); } }
public boolean applyObject(final Object input) { // one and only one context per thread final Context cx = Context.enter(); try { return applyInContext(cx, input); } finally { Context.exit(); } }
@Override public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) { final Context cx = Context.enter(); try { return Filters.matchPredicate(dimension, selector, bitmapResultFactory, makeStringPredicate(cx)); } finally { Context.exit(); } }
@Override public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) { final Context cx = Context.enter(); try { return Filters.matchPredicate(dimension, selector, bitmapResultFactory, makeStringPredicate(cx)); } finally { Context.exit(); } }
@Override public double estimateSelectivity(BitmapIndexSelector indexSelector) { final Context cx = Context.enter(); try { return Filters.estimateSelectivity(dimension, indexSelector, makeStringPredicate(cx)); } finally { Context.exit(); } }