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


Java ScriptRuntime.apply方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptRuntime.apply方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptRuntime.apply方法的具体用法?Java ScriptRuntime.apply怎么用?Java ScriptRuntime.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.runtime.ScriptRuntime的用法示例。


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

示例1: call

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
/**
 * ECMA 15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, ... ] ] )
 *
 * @param self self reference
 * @param args arguments for call
 * @return result of call
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object call(final Object self, final Object... args) {
    checkCallable(self);

    final Object thiz = (args.length == 0) ? UNDEFINED : args[0];
    Object[] arguments;

    if (args.length > 1) {
        arguments = new Object[args.length - 1];
        System.arraycopy(args, 1, arguments, 0, arguments.length);
    } else {
        arguments = ScriptRuntime.EMPTY_ARRAY;
    }

    if (self instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)self, thiz, arguments);
    } else if (self instanceof JSObject) {
        return ((JSObject)self).call(thiz, arguments);
    }

    throw new AssertionError("should not reach here");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:NativeFunction.java

示例2: propertyIterator

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的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

示例3: propertyIterator

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的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, this);
    } 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:NativeJSAdapter.java

示例4: apply

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的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

示例5: callAdaptee

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private Object callAdaptee(final Object retValue, final String name, final Object... args) {
    final Object func = adaptee.get(name);
    if (func instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)func, adaptee, args);
    }
    return retValue;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:NativeJSAdapter.java

示例6: logEvent

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private static void logEvent(final RuntimeEvent<?> event) {
    if (event != null) {
        final Global global = Context.getGlobal();
        if (global.has("Debug")) {
            final ScriptObject debug = (ScriptObject)global.get("Debug");
            final ScriptFunction addRuntimeEvent = (ScriptFunction)debug.get("addRuntimeEvent");
            ScriptRuntime.apply(addRuntimeEvent, debug, event);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:DebugLogger.java

示例7: apply

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:NativeFunction.java

示例8: callAdaptee

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private Object callAdaptee(final Object retValue, final String name, final Object... args) {
    final Object func = adaptee.get(name);
    if (func instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)func, this, args);
    }
    return retValue;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:NativeJSAdapter.java

示例9: eval

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private static Object eval(final Context cx, final String name, final String code) {
    final Source source = sourceFor(name, code);
    final ScriptObject global = Context.getGlobal();
    final ScriptFunction func = cx.compileScript(source, global);
    return func != null ? ScriptRuntime.apply(func, global) : null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:ContextTest.java

示例10: run

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    try {
        ctxOut.setDelegatee(out);
        ctxErr.setDelegatee(err);
        final ErrorManager errors = context.getErrorManager();
        final Global global = context.createGlobal();
        Context.setGlobal(global);

        // For each file on the command line.
        for (final String fileName : args) {
            if (fileName.startsWith("-")) {
                // ignore options in shared context mode (which was initialized upfront!)
                continue;
            }
            final File file = new File(fileName);
            final ScriptFunction script = context.compileScript(sourceFor(fileName, file.toURI().toURL()), global);

            if (script == null || errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            try {
                ScriptRuntime.apply(script, global);
            } catch (final NashornException e) {
                errors.error(e.toString());
                if (context.getEnv()._dump_on_error) {
                    e.printStackTrace(context.getErr());
                }

                return RUNTIME_ERROR;
            }
        }
    } finally {
        context.getOut().flush();
        context.getErr().flush();
        Context.setGlobal(oldGlobal);
    }

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

示例11: apply

import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
/**
 * Hook to ScriptFunction "apply". A performance metering shell may
 * introduce enter/exit timing here.
 *
 * @param target target function for apply
 * @param self self reference for apply
 *
 * @return result of the function apply
 */
protected Object apply(final ScriptFunction target, final Object self) {
    return ScriptRuntime.apply(target, self);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:Shell.java


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