当前位置: 首页>>代码示例>>Java>>正文


Java ScriptFunction类代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptFunction的典型用法代码示例。如果您正苦于以下问题:Java ScriptFunction类的具体用法?Java ScriptFunction怎么用?Java ScriptFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScriptFunction类属于jdk.nashorn.internal.runtime包,在下文中一共展示了ScriptFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evalImpl

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
private static Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException {
    if (script == null) {
        return null;
    }
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != ctxtGlobal);
    try {
        if (globalChanged) {
            Context.setGlobal(ctxtGlobal);
        }

        ctxtGlobal.setScriptContext(ctxt);
        return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal));
    } catch (final Exception e) {
        throwAsScriptException(e, ctxtGlobal);
        throw new AssertionError("should not reach here");
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:NashornScriptEngine.java

示例2: dumpCounters

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * Dump all Nashorn debug mode counters. Calling this may be better if
 * you want to print all counters. This way you can avoid too many callsites
 * due to counter access itself!!
 * @param self self reference
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object dumpCounters(final Object self) {
    final PrintWriter out = Context.getCurrentErr();

    out.println("ScriptObject count " + ScriptObject.getCount());
    out.println("Scope count " + Scope.getScopeCount());
    out.println("ScriptObject listeners added " + PropertyListeners.getListenersAdded());
    out.println("ScriptObject listeners removed " + PropertyListeners.getListenersRemoved());
    out.println("ScriptFunction constructor calls " + ScriptFunction.getConstructorCount());
    out.println("ScriptFunction invokes " + ScriptFunction.getInvokes());
    out.println("ScriptFunction allocations " + ScriptFunction.getAllocations());
    out.println("PropertyMap count " + PropertyMap.getCount());
    out.println("PropertyMap cloned " + PropertyMap.getClonedCount());
    out.println("PropertyMap history hit " + PropertyMap.getHistoryHit());
    out.println("PropertyMap proto invalidations " + PropertyMap.getProtoInvalidations());
    out.println("PropertyMap proto history hit " + PropertyMap.getProtoHistoryHit());
    out.println("PropertyMap setProtoNewMapCount " + PropertyMap.getSetProtoNewMapCount());
    out.println("Callsite count " + LinkerCallSite.getCount());
    out.println("Callsite misses " + LinkerCallSite.getMissCount());
    out.println("Callsite misses by site at " + LinkerCallSite.getMissSamplingPercentage() + "%");

    LinkerCallSite.getMissCounts(out);

    return UNDEFINED;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:NativeDebug.java

示例3: compileImpl

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
private ScriptFunction compileImpl(final Source source, final Global newGlobal) throws ScriptException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != newGlobal);
    try {
        if (globalChanged) {
            Context.setGlobal(newGlobal);
        }

        return nashornContext.compileScript(source, newGlobal);
    } catch (final Exception e) {
        throwAsScriptException(e, newGlobal);
        throw new AssertionError("should not reach here");
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:NashornScriptEngine.java

示例4: isInterfaceImplemented

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
private static boolean isInterfaceImplemented(final Class<?> iface, final ScriptObject sobj) {
    for (final Method method : iface.getMethods()) {
        // ignore methods of java.lang.Object class
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }

        // skip check for default methods - non-abstract, interface methods
        if (! Modifier.isAbstract(method.getModifiers())) {
            continue;
        }

        final Object obj = sobj.get(method.getName());
        if (! (obj instanceof ScriptFunction)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:NashornScriptEngine.java

示例5: replace

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * ECMA 15.5.4.11 String.prototype.replace (searchValue, replaceValue)
 * @param self        self reference
 * @param string      item to replace
 * @param replacement item to replace it with
 * @return string after replacement
 * @throws Throwable if replacement fails
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String replace(final Object self, final Object string, final Object replacement) throws Throwable {

    final String str = checkObjectToString(self);

    final NativeRegExp nativeRegExp;
    if (string instanceof NativeRegExp) {
        nativeRegExp = (NativeRegExp) string;
    } else {
        nativeRegExp = NativeRegExp.flatRegExp(JSType.toString(string));
    }

    if (replacement instanceof ScriptFunction) {
        return nativeRegExp.replace(str, "", (ScriptFunction)replacement);
    }

    return nativeRegExp.replace(str, JSType.toString(replacement), null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:NativeString.java

示例6: propertyIterator

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
@Override
public Iterator<String> propertyIterator() {
    // Try __getIds__ first, if not found then try __getKeys__
    // In jdk6, we had added "__getIds__" so this is just for compatibility.
    Object func = adaptee.get(__getIds__);
    if (!(func instanceof ScriptFunction)) {
        func = adaptee.get(__getKeys__);
    }

    Object obj;
    if (func instanceof ScriptFunction) {
        obj = ScriptRuntime.apply((ScriptFunction)func, adaptee);
    } else {
        obj = new NativeArray(0);
    }

    final List<String> array = new ArrayList<>();
    for (final Iterator<Object> iter = ArrayLikeIterator.arrayLikeIterator(obj); iter.hasNext(); ) {
        array.add((String)iter.next());
    }

    return array.iterator();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:NativeJSAdapter.java

示例7: extractBuiltinProperties

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
private List<jdk.nashorn.internal.runtime.Property> extractBuiltinProperties(final String name, final ScriptObject func) {
    final List<jdk.nashorn.internal.runtime.Property> list = new ArrayList<>();

    list.addAll(Arrays.asList(func.getMap().getProperties()));

    if (func instanceof ScriptFunction) {
        final ScriptObject proto = ScriptFunction.getPrototype((ScriptFunction)func);
        if (proto != null) {
            list.addAll(Arrays.asList(proto.getMap().getProperties()));
        }
    }

    final jdk.nashorn.internal.runtime.Property prop = getProperty(name);
    if (prop != null) {
        list.add(prop);
    }

    return list;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Global.java

示例8: compileErrorTest

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
@Test
public void compileErrorTest() {
    final Options options = new Options("");
    final ErrorManager errors = new ErrorManager();
    final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
    final Global oldGlobal = Context.getGlobal();
    Context.setGlobal(cx.createGlobal());
    try {
        final ScriptFunction script = cx.compileScript(sourceFor("<evalCompileErrorTest>", "*/"), Context.getGlobal());
        if (script != null) {
            fail("Invalid script compiled without errors");
        }
        if (errors.getNumberOfErrors() != 1) {
            fail("Wrong number of errors: " + errors.getNumberOfErrors());
        }
    } finally {
        Context.setGlobal(oldGlobal);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ContextTest.java

示例9: getCallSiteType

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
MethodType getCallSiteType(final FunctionNode functionNode) {
    final Type[] types = paramTypeMap.get(functionNode.getId());
    if (types == null) {
        return null;
    }

    MethodType mt = MethodType.methodType(returnTypeMap.get(functionNode.getId()).getTypeClass());
    if (needsCallee) {
        mt = mt.appendParameterTypes(ScriptFunction.class);
    }

    mt = mt.appendParameterTypes(Object.class); //this

    for (final Type type : types) {
        if (type == null) {
            return null; // not all parameter information is supplied
        }
        mt = mt.appendParameterTypes(type.getTypeClass());
    }

    return mt;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:TypeMap.java

示例10: function

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * ECMA 15.3.2.1 new Function (p1, p2, ... , pn, body)
 *
 * Constructor
 *
 * @param newObj is the new operator used for constructing this function
 * @param self   self reference
 * @param args   arguments
 * @return new NativeFunction
 */
@Constructor(arity = 1)
public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append("(function (");
    final String funcBody;
    if (args.length > 0) {
        final StringBuilder paramListBuf = new StringBuilder();
        for (int i = 0; i < args.length - 1; i++) {
            paramListBuf.append(JSType.toString(args[i]));
            if (i < args.length - 2) {
                paramListBuf.append(",");
            }
        }

        // now convert function body to a string
        funcBody = JSType.toString(args[args.length - 1]);

        final String paramList = paramListBuf.toString();
        if (!paramList.isEmpty()) {
            checkFunctionParameters(paramList);
            sb.append(paramList);
        }
    } else {
        funcBody = null;
    }

    sb.append(") {\n");
    if (args.length > 0) {
        checkFunctionBody(funcBody);
        sb.append(funcBody);
        sb.append('\n');
    }
    sb.append("})");

    final Global global = Global.instance();
    final Context context = global.getContext();
    return (ScriptFunction)context.eval(global, sb.toString(), global, "<function>");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:NativeFunction.java

示例11: toString

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * ECMA 15.3.4.2 Function.prototype.toString ( )
 *
 * @param self self reference
 * @return string representation of Function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toString(final Object self) {
    if (!(self instanceof ScriptFunction)) {
        throw typeError("not.a.function", ScriptRuntime.safeToString(self));
    }
    return ((ScriptFunction)self).toSource();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:NativeFunction.java

示例12: apply

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * ECMA 15.3.4.3 Function.prototype.apply (thisArg, argArray)
 *
 * @param self   self reference
 * @param thiz   {@code this} arg for apply
 * @param array  array of argument for apply
 * @return result of apply
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object apply(final Object self, final Object thiz, final Object array) {
    checkCallable(self);

    final Object[] args = toApplyArgs(array);

    if (self instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)self, thiz, args);
    } else if (self instanceof JSObject) {
        return ((JSObject)self).call(thiz, args);
    }
    throw new AssertionError("Should not reach here");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:NativeFunction.java

示例13: addShellBuiltins

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * Adds jjs shell interactive mode builtin functions to global scope.
 */
public void addShellBuiltins() {
    Object value = ScriptFunction.createBuiltin("input", ShellFunctions.INPUT);
    addOwnProperty("input", Attribute.NOT_ENUMERABLE, value);

    value = ScriptFunction.createBuiltin("evalinput", ShellFunctions.EVALINPUT);
    addOwnProperty("evalinput", Attribute.NOT_ENUMERABLE, value);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:Global.java

示例14: function

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * ECMA 15.3.2.1 new Function (p1, p2, ... , pn, body)
 *
 * Constructor
 *
 * @param newObj is the new operator used for constructing this function
 * @param self   self reference
 * @param args   arguments
 * @return new NativeFunction
 */
@Constructor(arity = 1)
public static ScriptFunction function(final boolean newObj, final Object self, final Object... args) {
    final StringBuilder sb = new StringBuilder();

    sb.append("(function (");
    final String funcBody;
    if (args.length > 0) {
        final StringBuilder paramListBuf = new StringBuilder();
        for (int i = 0; i < args.length - 1; i++) {
            paramListBuf.append(JSType.toString(args[i]));
            if (i < args.length - 2) {
                paramListBuf.append(",");
            }
        }

        // now convert function body to a string
        funcBody = JSType.toString(args[args.length - 1]);

        final String paramList = paramListBuf.toString();
        if (!paramList.isEmpty()) {
            checkFunctionParameters(paramList);
            sb.append(paramList);
        }
    } else {
        funcBody = null;
    }

    sb.append(") {\n");
    if (args.length > 0) {
        checkFunctionBody(funcBody);
        sb.append(funcBody);
        sb.append('\n');
    }
    sb.append("})");

    final Global global = Global.instance();

    return (ScriptFunction)Global.directEval(global, sb.toString(), global, "<function>", global.isStrictContext());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:NativeFunction.java

示例15: captureStackTrace

import jdk.nashorn.internal.runtime.ScriptFunction; //导入依赖的package包/类
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    final ScriptObject sobj = Global.checkObject(errorObj);
    initException(sobj);
    sobj.delete(STACK, false);
    if (! sobj.has("stack")) {
        final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
        final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
        sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    }
    return UNDEFINED;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:NativeError.java


注:本文中的jdk.nashorn.internal.runtime.ScriptFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。