当前位置: 首页>>代码示例>>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;未经允许,请勿转载。