本文整理匯總了Java中org.mozilla.javascript.Context類的典型用法代碼示例。如果您正苦於以下問題:Java Context類的具體用法?Java Context怎麽用?Java Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Context類屬於org.mozilla.javascript包,在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSandboxed
import org.mozilla.javascript.Context; //導入依賴的package包/類
public void testSandboxed() throws Exception
{
final Context cx = createContext();
final Require require = getSandboxedRequire(cx);
require.requireMain(cx, "testSandboxed");
// Also, test idempotent double-require of same main:
require.requireMain(cx, "testSandboxed");
// Also, test failed require of different main:
try {
require.requireMain(cx, "blah");
fail();
}
catch(IllegalStateException e) {
// Expected, success
}
}
示例2: executeNextStatement
import org.mozilla.javascript.Context; //導入依賴的package包/類
public boolean executeNextStatement(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (hasStatements()) {
if (currentChildStatement < numberOfStatements()) {
Statement st = (Statement) getStatements().get(currentChildStatement);
executeNextStatement(st, javascriptContext, scope);
if (bContinue)
return executeNextStatement(javascriptContext, scope);
}
else {
if (isLoop) {
currentChildStatement = 0;
if (bContinue)
return doLoop(javascriptContext, scope);
}
}
}
return true;
}
return false;
}
示例3: setFilter
import org.mozilla.javascript.Context; //導入依賴的package包/類
public void setFilter(String filter) throws ServiceException {
if (filter == null) {
filter = "";
}
if (!this.filter.equals(filter)) {
this.filter = filter;
if (filter.length() != 0) {
Context js_context = Context.enter();
try {
js_and.reset(filter);
js_or.reset(js_and.replaceAll(" && "));
filter = js_or.replaceAll(" || ");
js_filter = js_context.compileString(filter, "filter", 0, null);
} catch (EvaluatorException e) {
throw new ServiceException("Failed to compile JS filter : " + e.getMessage(), e);
} finally {
Context.exit();
}
} else {
js_filter = null;
}
bContinue = false;
}
}
示例4: compile
import org.mozilla.javascript.Context; //導入依賴的package包/類
Scriptable compile(Context cx, Scriptable scope, Object[] args)
{
if (args.length > 0 && args[0] instanceof NativeRegExp) {
if (args.length > 1 && args[1] != Undefined.instance) {
// report error
throw ScriptRuntime.typeError0("msg.bad.regexp.compile");
}
NativeRegExp thatObj = (NativeRegExp) args[0];
this.re = thatObj.re;
this.lastIndex = thatObj.lastIndex;
return this;
}
String s = args.length == 0 ? "" : ScriptRuntime.toString(args[0]);
String global = args.length > 1 && args[1] != Undefined.instance
? ScriptRuntime.toString(args[1])
: null;
this.re = (RECompiled)compileRE(cx, s, global, false);
this.lastIndex = 0;
return this;
}
示例5: testWithTwoScopes
import org.mozilla.javascript.Context; //導入依賴的package包/類
private void testWithTwoScopes(final String scriptScope1,
final String scriptScope2)
{
final ContextAction action = new ContextAction()
{
public Object run(final Context cx)
{
final Scriptable scope1 = cx.initStandardObjects(
new MySimpleScriptableObject("scope1"));
final Scriptable scope2 = cx.initStandardObjects(
new MySimpleScriptableObject("scope2"));
cx.evaluateString(scope2, scriptScope2, "source2", 1, null);
scope1.put("scope2", scope1, scope2);
return cx.evaluateString(scope1, scriptScope1, "source1", 1,
null);
}
};
Utils.runWithAllOptimizationLevels(action);
}
示例6: ensureScopePresent
import org.mozilla.javascript.Context; //導入依賴的package包/類
private void ensureScopePresent()
{
if (scope == null)
{
// Create a scope for the value conversion. This scope will be an empty scope exposing basic Object and Function, sufficient for value-conversion.
// In case no context is active for the current thread, we can safely enter end exit one to get hold of a scope
Context ctx = Context.getCurrentContext();
boolean closeContext = false;
if (ctx == null)
{
ctx = Context.enter();
closeContext = true;
}
scope = ctx.initStandardObjects();
scope.setParentScope(null);
if (closeContext)
{
// Only an exit call should be done when context didn't exist before
Context.exit();
}
}
}
示例7: getAspectsShort
import org.mozilla.javascript.Context; //導入依賴的package包/類
/**
* @return The array of aspects applied to this node as short prefix qname strings
*/
public Scriptable getAspectsShort()
{
final NamespaceService ns = this.services.getNamespaceService();
final Map<String, String> cache = new HashMap<String, String>();
final Set<QName> aspects = getAspectsSet();
final Object[] result = new Object[aspects.size()];
int count = 0;
for (final QName qname : aspects)
{
String prefix = cache.get(qname.getNamespaceURI());
if (prefix == null)
{
// first request for this namespace prefix, get and cache result
Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
cache.put(qname.getNamespaceURI(), prefix);
}
result[count++] = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName();
}
return Context.getCurrentContext().newArray(this.scope, result);
}
示例8: getActiveWorkflows
import org.mozilla.javascript.Context; //導入依賴的package包/類
/**
* Get active workflow instances this node belongs to
*
* @return the active workflow instances this node belongs to
*/
public Scriptable getActiveWorkflows()
{
if (this.activeWorkflows == null)
{
WorkflowService workflowService = this.services.getWorkflowService();
List<WorkflowInstance> workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true);
Object[] jsWorkflowInstances = new Object[workflowInstances.size()];
int index = 0;
for (WorkflowInstance workflowInstance : workflowInstances)
{
jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope);
}
this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances);
}
return this.activeWorkflows;
}
示例9: getContext
import org.mozilla.javascript.Context; //導入依賴的package包/類
@JSStaticFunction
public static Object getContext() {
Context jsContext = KakaoTalkListener.getJsEngines()[0].getContext();
ScriptableObject scope = KakaoTalkListener.getJsEngines()[0].getScope();
return jsContext.javaToJS(MainActivity.getContext(), scope);
}
示例10: execute
import org.mozilla.javascript.Context; //導入依賴的package包/類
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.execute(javascriptContext, scope)) {
Logger log = engine ? Engine.logEngine : Engine.logContext;
if(level.equals(Level.WARN.toString()) && log.isEnabledFor(Level.WARN))
log.warn(getEvalString(javascriptContext, scope));
else if(level.equals(Level.INFO.toString()) && log.isInfoEnabled())
log.info(getEvalString(javascriptContext, scope));
else if(level.equals(Level.DEBUG.toString()) && log.isDebugEnabled())
log.debug(getEvalString(javascriptContext, scope));
else if(level.equals(Level.TRACE.toString()) && log.isTraceEnabled())
log.trace(getEvalString(javascriptContext, scope));
else if(level.equals(Level.ERROR.toString()) && log.isEnabledFor(Level.ERROR))
log.error(getEvalString(javascriptContext, scope));
return true;
}
}
return false;
}
示例11: put
import org.mozilla.javascript.Context; //導入依賴的package包/類
@Override
public void put(String name, Scriptable start, Object value) {
if (name.equals("__proxy__")) {
NativeObject proxy = (NativeObject) value;
Object getter = proxy.get("get", start);
if (getter instanceof NativeFunction) {
mGetter = (NativeFunction) getter;
}
Object setter = proxy.get("set", start);
if (setter instanceof NativeFunction) {
mSetter = (NativeFunction) setter;
}
} else if (mSetter != null) {
mSetter.call(Context.getCurrentContext(), start, start, new Object[]{name, value});
} else {
super.put(name, start, value);
}
}
示例12: init
import org.mozilla.javascript.Context; //導入依賴的package包/類
public void init() {
//this can be initiated only once
if (mScriptContextFactory == null) {
mScriptContextFactory = new ScriptContextFactory();
ContextFactory.initGlobal(mScriptContextFactory);
}
mScriptContextFactory.setInterpreter(this);
rhino = Context.enter();
// observingDebugger = new ObservingDebugger();
// rhino.setDebugger(observingDebugger, new Integer(0));
// rhino.setGeneratingDebug(true);
// give some android love
rhino.setOptimizationLevel(-1);
scope = rhino.initStandardObjects();
//let rhino do some java <-> js transformations for us
rhino.getWrapFactory().setJavaPrimitiveWrap(false);
}
示例13: execute
import org.mozilla.javascript.Context; //導入依賴的package包/類
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.execute(javascriptContext, scope)) {
String referer = null;
try {
HtmlConnector connector = (HtmlConnector)getConnector();
com.twinsoft.convertigo.engine.Context ctx = getParentTransaction().context;
referer = connector.getHtmlParser().getReferer(ctx);
} catch (ClassCastException e) {
return false;
}
addToScope(scope, referer);
return true;
}
}
return false;
}
示例14: stepExecute
import org.mozilla.javascript.Context; //導入依賴的package包/類
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.stepExecute(javascriptContext, scope)) {
List<StepWithExpressions> parents = new ArrayList<StepWithExpressions>();
DatabaseObject parentStep = this.parent;
while (parentStep != null) {
try {
parents.add((StepWithExpressions) parentStep);
} catch (Exception e) {};
if (parentStep instanceof LoopStep) {
for (StepWithExpressions swe : parents)
swe.bContinue = false;
break;
}
parentStep = parentStep.getParent();
}
return true;
}
}
return false;
}
示例15: CompilerState
import org.mozilla.javascript.Context; //導入依賴的package包/類
CompilerState(Context cx, char[] source, int length, int flags)
{
this.cx = cx;
this.cpbegin = source;
this.cp = 0;
this.cpend = length;
this.flags = flags;
this.parenCount = 0;
this.classCount = 0;
this.progLength = 0;
}