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


Java ScriptContext.getAttributesScope方法代碼示例

本文整理匯總了Java中javax.script.ScriptContext.getAttributesScope方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptContext.getAttributesScope方法的具體用法?Java ScriptContext.getAttributesScope怎麽用?Java ScriptContext.getAttributesScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.script.ScriptContext的用法示例。


在下文中一共展示了ScriptContext.getAttributesScope方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: __noSuchProperty__

import javax.script.ScriptContext; //導入方法依賴的package包/類
/**
 * Hook to search missing variables in ScriptContext if available
 * @param self used to detect if scope call or not (this function is 'strict')
 * @param name name of the variable missing
 * @return value of the missing variable or undefined (or TypeError for scope search)
 */
public static Object __noSuchProperty__(final Object self, final Object name) {
    final Global global = Global.instance();
    final ScriptContext sctxt = global.scontext;
    final String nameStr = name.toString();

    if (sctxt != null) {
        final int scope = sctxt.getAttributesScope(nameStr);
        if (scope != -1) {
            return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global);
        }
    }

    switch (nameStr) {
    case "context":
        return sctxt;
    case "engine":
        return global.engine;
    default:
        break;
    }

    if (self == UNDEFINED) {
        // scope access and so throw ReferenceError
        throw referenceError(global, "not.defined", nameStr);
    }

    return UNDEFINED;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:Global.java

示例2: __noSuchProperty__

import javax.script.ScriptContext; //導入方法依賴的package包/類
/**
 * Hook to search missing variables in ScriptContext if available
 * @param self used to detect if scope call or not (this function is 'strict')
 * @param name name of the variable missing
 * @return value of the missing variable or undefined (or TypeError for scope search)
 */
public static Object __noSuchProperty__(final Object self, final Object name) {
    final Global global = Global.instance();
    final ScriptContext sctxt = global.currentContext();
    final String nameStr = name.toString();

    if (sctxt != null) {
        final int scope = sctxt.getAttributesScope(nameStr);
        if (scope != -1) {
            return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global);
        }
    }

    switch (nameStr) {
    case "context":
        return sctxt;
    case "engine":
        return global.engine;
    default:
        break;
    }

    if (self == UNDEFINED) {
        // scope access and so throw ReferenceError
        throw referenceError(global, "not.defined", nameStr);
    }

    return UNDEFINED;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:Global.java

示例3: testScriptContext_NPE_IAE

import javax.script.ScriptContext; //導入方法依賴的package包/類
@Test
public void testScriptContext_NPE_IAE() throws Exception {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final ScriptContext c = e.getContext();
    try {
        c.getAttribute("");
        throw new AssertionError("should have thrown IAE");
    } catch (final IllegalArgumentException iae1) {}

    try {
        c.getAttribute(null);
        throw new AssertionError("should have thrown NPE");
    } catch (final NullPointerException npe1) {}

    try {
        c.getAttribute("", ScriptContext.ENGINE_SCOPE);
        throw new AssertionError("should have thrown IAE");
    } catch (final IllegalArgumentException iae2) {}

    try {
        c.getAttribute(null, ScriptContext.ENGINE_SCOPE);
        throw new AssertionError("should have thrown NPE");
    } catch (final NullPointerException npe2) {}

    try {
        c.removeAttribute("", ScriptContext.ENGINE_SCOPE);
        throw new AssertionError("should have thrown IAE");
    } catch (final IllegalArgumentException iae3) {}

    try {
        c.removeAttribute(null, ScriptContext.ENGINE_SCOPE);
        throw new AssertionError("should have thrown NPE");
    } catch (final NullPointerException npe3) {}

    try {
        c.setAttribute("", "value", ScriptContext.ENGINE_SCOPE);
        throw new AssertionError("should have thrown IAE");
    } catch (final IllegalArgumentException iae4) {}

    try {
        c.setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
        throw new AssertionError("should have thrown NPE");
    } catch (final NullPointerException npe4) {}

    try {
        c.getAttributesScope("");
        throw new AssertionError("should have thrown IAE");
    } catch (final IllegalArgumentException iae5) {}

    try {
        c.getAttributesScope(null);
        throw new AssertionError("should have thrown NPE");
    } catch (final NullPointerException npe5) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:56,代碼來源:ScopeTest.java


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