本文整理匯總了Java中org.mozilla.javascript.Context.enter方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.enter方法的具體用法?Java Context.enter怎麽用?Java Context.enter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.enter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decryptSignature
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
Context context = Context.enter();
context.setOptimizationLevel(-1);
Object result;
try {
ScriptableObject scope = context.initStandardObjects();
context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
Function decryptionFunc = (Function) scope.get("decrypt", scope);
result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
} catch (Exception e) {
throw new DecryptException("could not get decrypt signature", e);
} finally {
Context.exit();
}
return result == null ? "" : result.toString();
}
示例2: setUp
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
// set up a reference map
reference = new LinkedHashMap<Object, Object>();
reference.put("a", "a");
reference.put("b", Boolean.TRUE);
reference.put("c", new HashMap<Object, Object>());
reference.put(new Integer(1), new Integer(42));
// get a js object as map
Context context = Context.enter();
ScriptableObject scope = context.initStandardObjects();
map = (Map<Object, Object>) context.evaluateString(scope,
"({ a: 'a', b: true, c: new java.util.HashMap(), 1: 42});",
"testsrc", 1, null);
Context.exit();
}
示例3: setUp
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
// set up a reference map
reference = new ArrayList<Object>();
reference.add("a");
reference.add(Boolean.TRUE);
reference.add(new HashMap<Object, Object>());
reference.add(new Integer(42));
reference.add("a");
// get a js object as map
Context context = Context.enter();
ScriptableObject scope = context.initStandardObjects();
list = (List<Object>) context.evaluateString(scope,
"(['a', true, new java.util.HashMap(), 42, 'a']);",
"testsrc", 1, null);
Context.exit();
}
示例4: parse
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static Scriptable parse(File source, String encoding, Action<Context> contextConfig) {
Context context = Context.enter();
if (contextConfig != null) {
contextConfig.execute(context);
}
Scriptable scope = context.initStandardObjects();
try {
Reader reader = new InputStreamReader(new FileInputStream(source), encoding);
try {
context.evaluateReader(scope, reader, source.getName(), 0, null);
} finally {
reader.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
Context.exit();
}
return scope;
}
示例5: 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);
}
示例6: decipherKey
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
* After finding the decrypted code in the js html5 player code
* run the code passing the encryptedSig parameter
*
* @param encryptedSig
* @param html5player
* @return
* @throws Exception
*/
private static String decipherKey(String encryptedSig, String html5player)
throws Exception {
String decipherFunc = loadFunction(html5player);
Context context = Context.enter();
// Rhino interpreted mode
context.setOptimizationLevel(-1);
Object result = null;
try {
ScriptableObject scope = context.initStandardObjects();
context.evaluateString(scope, decipherFunc, "decipherFunc", 1, null);
Function decryptionFunc = (Function) scope.get("decrypt", scope);
result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
} catch (Exception e) {
e.printStackTrace();
} finally {
Context.exit();
}
if (result == null) {
return "";
} else {
return result.toString();
}
}
示例7: executeString
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
* @see org.alfresco.service.cmr.repository.ScriptProcessor#executeString(java.lang.String, java.util.Map)
*/
public Object executeString(String source, Map<String, Object> model)
{
try
{
// compile the script based on the node content
Script script;
Context cx = Context.enter();
try
{
script = cx.compileString(resolveScriptImports(source), "AlfrescoJS", 1, null);
}
finally
{
Context.exit();
}
return executeScriptImpl(script, model, true, "string script");
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute supplied script: " + err.getMessage(), err);
}
}
示例8: testJavaApi
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testJavaApi() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
cx.executeScriptWithContinuations(script, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
cx.resumeContinuation(cont, scope, null);
}
} finally {
Context.exit();
}
}
示例9: 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;
}
}
示例10: start
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void start() {
try {
Context ctx = Context.enter();
scope = ctx.initStandardObjects();
scope.put("pacMethods", scope, new PacScriptMethods());
ctx.evaluateString(scope, getScriptContent(), "pac", 0, null);
for (PacScriptMethods.jsFunctions function : PacScriptMethods.jsFunctions.values()) {
ctx.evaluateString(scope,
"function " + function.name() + " () {" + "return pacMethods." + function.name() + ".apply(pacMethods, arguments); }",
function.name(), 0, null);
}
} catch (IOException e) {
Engine.logProxyManager.error("(PacManager) Failed to declare PacScriptMethods wrapper", e);
} finally {
Context.exit();
}
}
示例11: testErrorOnEvalCall
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
* Since a continuation can only capture JavaScript frames and not Java
* frames, ensure that Rhino throws an exception when the JavaScript frames
* don't reach all the way to the code called by
* executeScriptWithContinuations or callFunctionWithContinuations.
*/
public void testErrorOnEvalCall() {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
Script script = cx.compileString("eval('myObject.f(3);');",
"test source", 1, null);
cx.executeScriptWithContinuations(script, globalScope);
fail("Should throw IllegalStateException");
} catch (WrappedException we) {
Throwable t = we.getWrappedException();
assertTrue(t instanceof IllegalStateException);
assertTrue(t.getMessage().startsWith("Cannot capture continuation"));
} finally {
Context.exit();
}
}
示例12: load
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
* load
* @param response
*/
public void load( WebResponse response ) {
Function onLoadEvent=null;
try {
Context context = Context.enter();
context.initStandardObjects( null );
HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument();
if (!(htmlDocument instanceof HTMLDocumentImpl)) return;
HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody();
if (body == null) return;
onLoadEvent = body.getOnloadEvent();
if (onLoadEvent == null) return;
onLoadEvent.call( context, body, body, new Object[0] );
} catch (JavaScriptException e) {
ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString());
// HttpUnitUtils.handleException(e);
} catch (EcmaError ee) {
//throw ee;
ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString());
} finally {
Context.exit();
}
}
示例13: testScriptWithNestedContinuations
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testScriptWithNestedContinuations() {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1); // must use interpreter mode
Script script = cx.compileString("myObject.g( myObject.f(1) ) + 2;",
"test source", 1, null);
cx.executeScriptWithContinuations(script, globalScope);
fail("Should throw ContinuationPending");
} catch (ContinuationPending pending) {
try {
Object applicationState = pending.getApplicationState();
assertEquals(new Integer(1), applicationState);
int saved = (Integer) applicationState;
cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
fail("Should throw another ContinuationPending");
} catch (ContinuationPending pending2) {
Object applicationState2 = pending2.getApplicationState();
assertEquals(new Integer(4), applicationState2);
int saved2 = (Integer) applicationState2;
Object result2 = cx.resumeContinuation(pending2.getContinuation(), globalScope, saved2 + 2);
assertEquals(8, ((Number)result2).intValue());
}
} finally {
Context.exit();
}
}
示例14: helper
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void helper(String source) {
Context cx = Context.enter();
Context.ClassShutterSetter setter = cx.getClassShutterSetter();
try {
Scriptable globalScope = cx.initStandardObjects();
if (setter == null) {
setter = classShutterSetter;
} else {
classShutterSetter = setter;
}
setter.setClassShutter(new OpaqueShutter());
cx.evaluateString(globalScope, source, "test source", 1, null);
} finally {
setter.setClassShutter(null);
Context.exit();
}
}
示例15: testJsApi
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testJsApi() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
}