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


Java Bootstrap.isCallable方法代码示例

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


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

示例1: toString

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.2 Array.prototype.toString ( )
 *
 * @param self self reference
 * @return string representation of array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toString(final Object self) {
    final Object obj = Global.toObject(self);
    if (obj instanceof ScriptObject) {
        final InvokeByName joinInvoker = getJOIN();
        final ScriptObject sobj = (ScriptObject)obj;
        try {
            final Object join = joinInvoker.getGetter().invokeExact(sobj);
            if (Bootstrap.isCallable(join)) {
                return joinInvoker.getInvoker().invokeExact(join, sobj);
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    // FIXME: should lookup Object.prototype.toString and call that?
    return ScriptRuntime.builtinObjectToString(self);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:NativeArray.java

示例2: toLocaleString

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * ECMA 15.2.4.3 Object.prototype.toLocaleString ( )
 *
 * @param self self reference
 * @return localized ToString
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toLocaleString(final Object self) {
    final Object obj = JSType.toScriptObject(self);
    if (obj instanceof ScriptObject) {
        final InvokeByName toStringInvoker = getTO_STRING();
        final ScriptObject sobj = (ScriptObject)self;
        try {
            final Object toString = toStringInvoker.getGetter().invokeExact(sobj);

            if (Bootstrap.isCallable(toString)) {
                return toStringInvoker.getInvoker().invokeExact(toString, sobj);
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }

        throw typeError("not.a.function", "toString");
    }

    return ScriptRuntime.builtinObjectToString(self);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:NativeObject.java

示例3: replace

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的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 (Bootstrap.isCallable(replacement)) {
        return nativeRegExp.replace(str, "", replacement);
    }

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

示例4: forEach

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 *
 * @param self the self reference
 * @param callbackFn the callback function
 * @param thisArg optional this-object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static void forEach(final Object self, final Object callbackFn, final Object thisArg) {
    final NativeMap map = getNativeMap(self);
    if (!Bootstrap.isCallable(callbackFn)) {
        throw typeError("not.a.function", ScriptRuntime.safeToString(callbackFn));
    }
    final MethodHandle invoker = Global.instance().getDynamicInvoker(FOREACH_INVOKER_KEY,
            () -> Bootstrap.createDynamicCallInvoker(Object.class, Object.class, Object.class, Object.class, Object.class, Object.class));

    final LinkedMap.LinkedMapIterator iterator = map.getJavaMap().getIterator();
    for (;;) {
        final LinkedMap.Node node = iterator.next();
        if (node == null) {
            break;
        }

        try {
            final Object result = invoker.invokeExact(callbackFn, thisArg, node.getValue(), node.getKey(), self);
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:NativeMap.java

示例5: forEach

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * ECMA6 23.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self the self reference
 * @param callbackFn the callback function
 * @param thisArg optional this object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static void forEach(final Object self, final Object callbackFn, final Object thisArg) {
    final NativeSet set = getNativeSet(self);
    if (!Bootstrap.isCallable(callbackFn)) {
        throw typeError("not.a.function", ScriptRuntime.safeToString(callbackFn));
    }
    final MethodHandle invoker = Global.instance().getDynamicInvoker(FOREACH_INVOKER_KEY,
            () -> Bootstrap.createDynamicCallInvoker(Object.class, Object.class, Object.class, Object.class, Object.class, Object.class));

    final LinkedMap.LinkedMapIterator iterator = set.getJavaMap().getIterator();
    for (;;) {
        final LinkedMap.Node node = iterator.next();
        if (node == null) {
            break;
        }

        try {
            final Object result = invoker.invokeExact(callbackFn, thisArg, node.getKey(), node.getKey(), self);
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:NativeSet.java

示例6: toLocaleString

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * ECMA 15.2.4.3 Object.prototype.toLocaleString ( )
 *
 * @param self self reference
 * @return localized ToString
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toLocaleString(final Object self) {
    final Object obj = JSType.toScriptObject(self);
    if (obj instanceof ScriptObject) {
        final InvokeByName toStringInvoker = getTO_STRING();
        final ScriptObject sobj = (ScriptObject)obj;
        try {
            final Object toString = toStringInvoker.getGetter().invokeExact(sobj);

            if (Bootstrap.isCallable(toString)) {
                return toStringInvoker.getInvoker().invokeExact(toString, sobj);
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }

        throw typeError("not.a.function", "toString");
    }

    return ScriptRuntime.builtinObjectToString(self);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:NativeObject.java

示例7: toJSON

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * ECMA 15.9.5.44 Date.prototype.toJSON ( key )
 *
 * Provides a string representation of this Date for use by {@link NativeJSON#stringify(Object, Object, Object, Object)}
 *
 * @param self self reference
 * @param key ignored
 * @return JSON representation of this date
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toJSON(final Object self, final Object key) {
    // NOTE: Date.prototype.toJSON is generic. Accepts other objects as well.
    final Object selfObj = Global.toObject(self);
    if (!(selfObj instanceof ScriptObject)) {
        return null;
    }
    final ScriptObject sobj  = (ScriptObject)selfObj;
    final Object       value = sobj.getDefaultValue(Number.class);
    if (value instanceof Number) {
        final double num = ((Number)value).doubleValue();
        if (isInfinite(num) || isNaN(num)) {
            return null;
        }
    }

    try {
        final InvokeByName toIsoString = getTO_ISO_STRING();
        final Object func = toIsoString.getGetter().invokeExact(sobj);
        if (Bootstrap.isCallable(func)) {
            return toIsoString.getInvoker().invokeExact(func, sobj, key);
        }
        throw typeError("not.a.function", ScriptRuntime.safeToString(func));
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:NativeDate.java

示例8: compareFunction

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static Object compareFunction(final Object comparefn) {
    if (comparefn == ScriptRuntime.UNDEFINED) {
        return null;
    }

    if (!Bootstrap.isCallable(comparefn)) {
        throw typeError("not.a.function", ScriptRuntime.safeToString(comparefn));
    }

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

示例9: getIterator

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * ES6 7.4.1 GetIterator abstract operation
 *
 * @param iterable an object
 * @param global the global object
 * @return the iterator
 */
public static Object getIterator(final Object iterable, final Global global) {
    final Object object = Global.toObject(iterable);

    if (object instanceof ScriptObject) {
        // TODO we need to implement fast property access for Symbol keys in order to use InvokeByName here.
        final Object getter = ((ScriptObject) object).get(NativeSymbol.iterator);

        if (Bootstrap.isCallable(getter)) {
            try {
                final MethodHandle invoker = getIteratorInvoker(global);

                final Object value = invoker.invokeExact(getter, iterable);
                if (JSType.isPrimitive(value)) {
                    throw typeError("not.an.object", ScriptRuntime.safeToString(value));
                }
                return value;

            } catch (final Throwable t) {
                throw new RuntimeException(t);
            }
        }
        throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
    }

    throw typeError("cannot.get.iterator", ScriptRuntime.safeToString(iterable));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:AbstractIterator.java

示例10: iterate

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * Iterate over an iterable object, passing every value to {@code consumer}.
 *
 * @param iterable an iterable object
 * @param global the current global
 * @param consumer the value consumer
 */
public static void iterate(final Object iterable, final Global global, final Consumer<Object> consumer) {

    final Object iterator = AbstractIterator.getIterator(Global.toObject(iterable), global);

    final InvokeByName nextInvoker = getNextInvoker(global);
    final MethodHandle doneInvoker = getDoneInvoker(global);
    final MethodHandle valueInvoker = getValueInvoker(global);

    try {
        do {
            final Object next = nextInvoker.getGetter().invokeExact(iterator);
            if (!Bootstrap.isCallable(next)) {
                break;
            }

            final Object result = nextInvoker.getInvoker().invokeExact(next, iterator, (Object) null);
            if (!(result instanceof ScriptObject)) {
                break;
            }

            final Object done = doneInvoker.invokeExact(result);
            if (JSType.toBoolean(done)) {
                break;
            }

            consumer.accept(valueInvoker.invokeExact(result));

        } while (true);

    } catch (final RuntimeException r) {
        throw r;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:AbstractIterator.java

示例11: applyReviver

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static Object applyReviver(final Global global, final Object unfiltered, final Object reviver) {
    if (Bootstrap.isCallable(reviver)) {
        final ScriptObject root = global.newObject();
        root.addOwnProperty("", Property.WRITABLE_ENUMERABLE_CONFIGURABLE, unfiltered);
        return walk(root, "", reviver);
    }
    return unfiltered;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:JSONFunctions.java

示例12: getFunction

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private Object getFunction(final String name) {
    final Object fn = obj.getMember(name);
    if(!(Bootstrap.isCallable(fn))) {
        throw new UnsupportedOperationException("The script object doesn't have a function named " + name);
    }
    return fn;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:ListAdapter.java

示例13: checkFunction

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static void checkFunction(final Object fn, final InvokeByName invoke) {
    if(!(Bootstrap.isCallable(fn))) {
        throw new UnsupportedOperationException("The script object doesn't have a function named " + invoke.getName());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:ListAdapter.java

示例14: isJavaFunction

import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
 * Returns true if the specified object is a java function (but not script function)
 * @param self not used
 * @param obj the object that is checked if it is a Java function or not
 * @return tells whether given object is a Java function or not
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static boolean isJavaFunction(final Object self, final Object obj) {
    return Bootstrap.isCallable(obj) && !(obj instanceof ScriptFunction);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:NativeJava.java


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