本文整理匯總了Java中org.mozilla.javascript.Context.newObject方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.newObject方法的具體用法?Java Context.newObject怎麽用?Java Context.newObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.newObject方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runJsTest
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void runJsTest(Context cx, Scriptable shared, String name, String source) {
// create a lightweight top-level scope
Scriptable scope = cx.newObject(shared);
scope.setPrototype(shared);
System.out.print(name + ": ");
Object result;
try {
result = cx.evaluateString(scope, source, "jstest input", 1, null);
} catch (RuntimeException e) {
System.out.println("FAILED");
throw e;
}
assertTrue(result != null);
assertTrue("success".equals(result));
System.out.println("passed");
}
示例2: executeModuleScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private Scriptable executeModuleScript(Context cx, String id,
Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
final ScriptableObject moduleObject = (ScriptableObject)cx.newObject(
nativeScope);
URI uri = moduleScript.getUri();
URI base = moduleScript.getBase();
defineReadOnlyProperty(moduleObject, "id", id);
if(!sandboxed) {
defineReadOnlyProperty(moduleObject, "uri", uri.toString());
}
final Scriptable executionScope = new ModuleScope(nativeScope, uri, base);
// Set this so it can access the global JS environment objects.
// This means we're currently using the "MGN" approach (ModuleScript
// with Global Natives) as specified here:
// <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension>
executionScope.put("exports", executionScope, exports);
executionScope.put("module", executionScope, moduleObject);
moduleObject.put("exports", moduleObject, exports);
install(executionScope);
if(isMain) {
defineReadOnlyProperty(this, "main", moduleObject);
}
executeOptionalScript(preExec, cx, executionScope);
moduleScript.getScript().exec(cx, executionScope);
executeOptionalScript(postExec, cx, executionScope);
return ScriptRuntime.toObject(cx, nativeScope,
ScriptableObject.getProperty(moduleObject, "exports"));
}
示例3: js_subarray
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private Object js_subarray(Context cx, Scriptable scope, int s, int e)
{
int start = (s < 0 ? length + s : s);
int end = (e < 0 ? length + e : e);
// Clamping behavior as described by the spec.
start = Math.max(0, start);
end = Math.min(length, end);
int len = Math.max(0, (end - start));
int byteOff = Math.min(start * getBytesPerElement(), arrayBuffer.getLength());
return
cx.newObject(scope, getClassName(),
new Object[]{arrayBuffer, byteOff, len});
}
示例4: executeModuleScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private Scriptable executeModuleScript(Context cx, String id,
Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
final ScriptableObject moduleObject = (ScriptableObject)cx.newObject(
nativeScope);
URI uri = moduleScript.getUri();
URI base = moduleScript.getBase();
defineReadOnlyProperty(moduleObject, "id", id);
if(!sandboxed) {
defineReadOnlyProperty(moduleObject, "uri", uri.toString());
}
final Scriptable executionScope = new ModuleScope(nativeScope, uri, base);
// Set this so it can access the global JS environment objects.
// This means we're currently using the "MGN" approach (ModuleScript
// with Global Natives) as specified here:
// <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension>
executionScope.put("exports", executionScope, exports);
executionScope.put("module", executionScope, moduleObject);
moduleObject.put("exports", moduleObject, exports);
install(executionScope);
if(isMain) {
defineReadOnlyProperty(this, "main", moduleObject);
}
executeOptionalScript(preExec, cx, executionScope);
moduleScript.getScript().exec(cx, executionScope);
executeOptionalScript(postExec, cx, executionScope);
return ScriptRuntime.toObject(nativeScope,
ScriptableObject.getProperty(moduleObject, "exports"));
}
示例5: run
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void run() {
Context context = factory.enterContext();
try {
// Run each script in its own scope, to keep global variables
// defined in each script separate
Scriptable threadScope = context.newObject(globalScope);
threadScope.setPrototype(globalScope);
threadScope.setParentScope(null);
script.exec(context, threadScope);
} catch (Exception ee) {
ee.printStackTrace();
} finally {
Context.exit();
}
}
示例6: createNewTopLevelScope
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
ScriptableObject createNewTopLevelScope(final Context cx) {
final ScriptableObject scope = (ScriptableObject) cx.newObject(library);
scope.setPrototype(library);
scope.setParentScope(null);
return scope;
}
示例7: makeArrayBuffer
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private NativeArrayBuffer makeArrayBuffer(Context cx, Scriptable scope, int length)
{
return (NativeArrayBuffer)cx.newObject(scope, NativeArrayBuffer.CLASS_NAME,
new Object[] { length });
}