當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.newObject方法代碼示例

本文整理匯總了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");
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:17,代碼來源:JsTestsBase.java

示例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"));
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:30,代碼來源:Require.java

示例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});
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:16,代碼來源:NativeTypedArrayView.java

示例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"));
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:30,代碼來源:Require.java

示例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();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:16,代碼來源:Bug421071Test.java

示例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;
}
 
開發者ID:szegedi,項目名稱:spring-web-jsflow,代碼行數:7,代碼來源:ScriptStorage.java

示例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 });
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:6,代碼來源:NativeTypedArrayView.java


注:本文中的org.mozilla.javascript.Context.newObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。