本文整理了Java中org.mozilla.javascript.Context.initStandardObjects()
方法的一些代码示例,展示了Context.initStandardObjects()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.initStandardObjects()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:initStandardObjects
[英]Initialize the standard objects. Creates instances of the standard objects and their constructors (Object, String, Number, Date, etc.), setting up 'scope' to act as a global object as in ECMA 15.1.
This method must be called to initialize a scope before scripts can be evaluated in that scope.
This method does not affect the Context it is called upon.
[中]初始化标准对象。创建标准对象及其构造函数(对象、字符串、数字、日期等)的实例,将“范围”设置为ECMA15.1中的全局对象。
必须调用此方法来初始化作用域,然后才能在该作用域中计算脚本。
此方法不影响调用它的上下文。
代码示例来源:origin: EngineHub/WorldEdit
private Scriptable setupScope(Context cx, ScriptContext context) {
ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable);
//ScriptableObject.putProperty(scope, "argv", Context.javaToJS(args, scope));
return scope;
}
}
代码示例来源:origin: stackoverflow.com
String script = "function abc(x,y) {return x+y;}";
Context context = Context.enter();
try {
ScriptableObject scope = context.initStandardObjects();
Scriptable that = context.newObject(scope);
Function fct = context.compileFunction(scope, script, "script", 1, null);
Object result = fct.call(
context, scope, that, new Object[] {2, 3});
System.out.println(Context.jsToJava(result, int.class));
} finally {
Context.exit();
}
代码示例来源:origin: stackoverflow.com
String script = "function abc(x,y) {return x+y;}"
+ "function def(u,v) {return u-v;}";
Context context = Context.enter();
try {
ScriptableObject scope = context.initStandardObjects();
context.evaluateString(scope, script, "script", 1, null);
Function fct = (Function)scope.get("abc", scope);
Object result = fct.call(
context, scope, scope, new Object[] {2, 3});
System.out.println(Context.jsToJava(result, int.class));
} 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: frohoff/ysoserial
NativeObject scriptableObject = (NativeObject) context.initStandardObjects();
代码示例来源:origin: stackoverflow.com
String[] names = {"print"};
shell.defineFunctionProperties(names, Shell.class, ScriptableObject.DONTENUM);
Scriptable scope = context.initStandardObjects(shell);
context.evaluateString(scope, "print('Hello, world!')", null, 0, null);
} finally {
代码示例来源:origin: facebook/stetho
private @NonNull ScriptableObject initJsScope(@NonNull Context jsContext) {
// Set the main Rhino goodies
ImporterTopLevel importerTopLevel = new ImporterTopLevel(jsContext);
ScriptableObject scope = jsContext.initStandardObjects(importerTopLevel, false);
ScriptableObject.putProperty(scope, "context", Context.javaToJS(mContext, scope));
try {
importClasses(jsContext, scope);
importPackages(jsContext, scope);
importConsole(scope);
importVariables(scope);
importFunctions(scope);
} catch (StethoJsException e) {
String message = String.format("%s\n%s", e.getMessage(), Log.getStackTraceString(e));
LogUtil.e(e, message);
CLog.writeToConsole(Console.MessageLevel.ERROR, Console.MessageSource.JAVASCRIPT, message);
}
return scope;
}
代码示例来源:origin: pentaho/pentaho-kettle
@BeforeClass
public static void setUp() throws Exception {
ctx = Context.enter();
scope = ctx.initStandardObjects();
}
代码示例来源:origin: apache/incubator-druid
private static Function compile(String function)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
final ScriptableObject scope = context.initStandardObjects();
final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
Context.exit();
return new Function()
{
@Override
public double apply(Object[] args)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
return Context.toNumber(fn.call(cx, scope, scope, args));
}
};
}
代码示例来源:origin: apache/incubator-druid
private static Function<Object, String> compile(String function)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
final ScriptableObject scope = context.initStandardObjects();
final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
Context.exit();
return new Function<Object, String>()
{
@Override
public String apply(Object input)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
final Object res = fn.call(cx, scope, scope, new Object[]{input});
return res != null ? Context.toString(res) : null;
}
};
}
代码示例来源:origin: apache/incubator-druid
private static Function<Object, Object> compile(String function)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(9);
final ScriptableObject scope = context.initStandardObjects();
final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
Context.exit();
return new Function<Object, Object>()
{
@Override
public Object apply(Object input)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
final Object res = fn.call(cx, scope, scope, new Object[]{input});
return res != null ? Context.toObject(res, scope) : null;
}
};
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
jsContext = ContextFactory.getGlobal().enterContext();
jsScope = jsContext.initStandardObjects();
view = new MappingJackson2XmlView();
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
jsContext = ContextFactory.getGlobal().enterContext();
jsScope = jsContext.initStandardObjects();
view = new MappingJackson2JsonView();
}
代码示例来源:origin: EngineHub/WorldEdit
Context cx = factory.enterContext();
ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable);
代码示例来源:origin: apache/incubator-druid
context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
final ScriptableObject scope = context.initStandardObjects();
代码示例来源:origin: pentaho/pentaho-kettle
scope = cx.initStandardObjects( null );
代码示例来源:origin: pentaho/pentaho-kettle
jsscope = jscx.initStandardObjects( null, false );
try {
jscx.setOptimizationLevel( Integer.valueOf( transMeta.environmentSubstitute( optimizationLevel ) ) );
代码示例来源:origin: pentaho/pentaho-kettle
jsscope = jscx.initStandardObjects( null, false );
代码示例来源:origin: pentaho/pentaho-kettle
jsscope = jscx.initStandardObjects( null, false );
代码示例来源:origin: pentaho/pentaho-kettle
data.scope = data.cx.initStandardObjects( null, false );
内容来源于网络,如有侵权,请联系作者删除!