本文整理了Java中org.mozilla.javascript.Context.enter()
方法的一些代码示例,展示了Context.enter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.enter()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:enter
[英]Same as calling ContextFactory#enterContext() on the global ContextFactory instance.
[中]与在全局ContextFactory实例上调用ContextFactory#enterContext()相同。
代码示例来源:origin: apache/incubator-druid
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();
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public double estimateSelectivity(BitmapIndexSelector indexSelector)
{
final Context cx = Context.enter();
try {
return Filters.estimateSelectivity(dimension, indexSelector, makeStringPredicate(cx));
}
finally {
Context.exit();
}
}
代码示例来源:origin: apache/incubator-druid
@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();
}
}
代码示例来源:origin: apache/incubator-druid
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();
}
}
代码示例来源:origin: facebook/stetho
/**
* 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;
}
}
代码示例来源:origin: frohoff/ysoserial
IdScriptableObject idScriptableObject = (IdScriptableObject) nativeErrorConstructor.newInstance();
Context context = Context.enter();
代码示例来源:origin: galenframework/galen
public GalenJsExecutor() {
this.context = Context.enter();
this.scope = new ImporterTopLevel(context);
this.loadFunction = new JsFunctionLoad();
scope.defineProperty("load", loadFunction, ScriptableObject.DONTENUM);
importAllMajorClasses();
}
代码示例来源:origin: pentaho/pentaho-kettle
@BeforeClass
public static void setUp() throws Exception {
ctx = Context.enter();
scope = ctx.initStandardObjects();
}
代码示例来源:origin: xtuhcy/gecco
@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();
}
代码示例来源:origin: rnewson/couchdb-lucene
private void init() throws IOException, JSONException {
this.uuid = database.getOrCreateUuid();
this.context = Context.enter();
context.setClassShutter(new RestrictiveClassShutter());
context.setOptimizationLevel(9);
代码示例来源:origin: rhino/js
/**
* 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);
}
代码示例来源:origin: geogebra/geogebra
/**
* 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);
}
代码示例来源:origin: org.apache.pig/pig
/**
* @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;
}
代码示例来源:origin: alexo/wro4j
/**
* Makes sure the context is properly initialized.
*/
private void initContext() {
if (Context.getCurrentContext() == null) {
Context.enter();
}
}
代码示例来源:origin: rhino/js
/**
* 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();
}
}
代码示例来源:origin: geogebra/geogebra
/**
* 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();
}
}
代码示例来源:origin: io.druid/druid-processing
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();
}
}
代码示例来源:origin: io.druid/druid-processing
@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();
}
}
代码示例来源:origin: org.apache.druid/druid-processing
@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();
}
}
代码示例来源:origin: org.apache.druid/druid-processing
@Override
public double estimateSelectivity(BitmapIndexSelector indexSelector)
{
final Context cx = Context.enter();
try {
return Filters.estimateSelectivity(dimension, indexSelector, makeStringPredicate(cx));
}
finally {
Context.exit();
}
}
内容来源于网络,如有侵权,请联系作者删除!