• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java IteratorAction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: map

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:NativeArray.java


示例2: filter

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:NativeArray.java


示例3: map

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:NativeArray.java


示例4: filter

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:NativeArray.java


示例5: map

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:29,代码来源:NativeArray.java


示例6: filter

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:24,代码来源:NativeArray.java


示例7: applyEvery

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:NativeArray.java


示例8: some

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:NativeArray.java


示例9: forEach

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:NativeArray.java


示例10: reduceInner

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:NativeArray.java


示例11: applyEvery

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:NativeArray.java


示例12: some

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:NativeArray.java


示例13: forEach

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:NativeArray.java


示例14: reduceInner

import jdk.nashorn.internal.runtime.arrays.IteratorAction; //导入依赖的package包/类
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:NativeArray.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HttpMessageConverterExtractor类代码示例发布时间:2022-05-22
下一篇:
Java BalanceType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap