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


Java ScriptRuntime.EMPTY_ARRAY属性代码示例

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


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

示例1: call

/**
 * 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,代码行数:29,代码来源:NativeFunction.java

示例2: bind

/**
 * ECMA 15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, ...]])
 *
 * @param self self reference
 * @param args arguments for bind
 * @return function with bound arguments
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object bind(final Object self, final Object... args) {
    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;
    }

    return Bootstrap.bindCallable(self, thiz, arguments);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:NativeFunction.java

示例3: getStackTrace

/**
 * Nashorn extension: Error.prototype.getStackTrace()
 * "stack" property is an array typed value containing {@link StackTraceElement}
 * objects of JavaScript stack frames.
 *
 * @param self  self reference
 *
 * @return      stack trace as a script array.
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object getStackTrace(final Object self) {
    final ScriptObject sobj = Global.checkObject(self);
    final Object exception = ECMAException.getException(sobj);
    Object[] res;
    if (exception instanceof Throwable) {
        res = NashornException.getScriptFrames((Throwable)exception);
    } else {
        res = ScriptRuntime.EMPTY_ARRAY;
    }

    return new NativeArray(res);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:NativeError.java

示例4: splice

/**
 * ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self self reference
 * @param args arguments
 * @return result of splice
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
    final Object obj = Global.toObject(self);

    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final Object start = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final Object deleteCount = args.length > 1 ? args[1] : ScriptRuntime.UNDEFINED;

    Object[] items;

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

    final ScriptObject sobj                = (ScriptObject)obj;
    final long         len                 = JSType.toUint32(sobj.getLength());
    final long         relativeStart       = JSType.toLong(start);

    final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
    final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);

    NativeArray returnValue;

    if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
        try {
            returnValue =  new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));

            // Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
            int k = (int) actualStart;
            for (int i = 0; i < items.length; i++, k++) {
                sobj.defineOwnProperty(k, items[i]);
            }
        } catch (final UnsupportedOperationException uoe) {
            returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
        }
    } else {
        returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
    }

    return returnValue;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:54,代码来源:NativeArray.java

示例5: BoundCallable

BoundCallable(final Object callable, final Object boundThis, final Object[] boundArgs) {
    this.callable = callable;
    this.boundThis = boundThis;
    this.boundArgs = isEmptyArray(boundArgs) ? ScriptRuntime.EMPTY_ARRAY : boundArgs.clone();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:BoundCallable.java

示例6: asObjectArray

@Override
public Object[] asObjectArray() {
    return ScriptRuntime.EMPTY_ARRAY;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:ArrayData.java

示例7: splice

/**
 * ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self self reference
 * @param args arguments
 * @return result of splice
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
    final Object obj = Global.toObject(self);

    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final ScriptObject sobj          = (ScriptObject)obj;
    final long         len           = JSType.toUint32(sobj.getLength());
    final long         relativeStart = JSType.toLong(args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED);

    final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
    final long actualDeleteCount;
    Object[] items = ScriptRuntime.EMPTY_ARRAY;

    if (args.length == 0) {
        actualDeleteCount = 0;
    } else if (args.length == 1) {
        actualDeleteCount = len - actualStart;
    } else {
        actualDeleteCount = Math.min(Math.max(JSType.toLong(args[1]), 0), len - actualStart);
        if (args.length > 2) {
            items = new Object[args.length - 2];
            System.arraycopy(args, 2, items, 0, items.length);
        }
    }

    NativeArray returnValue;

    if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
        try {
            returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));

            // Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
            int k = (int) actualStart;
            for (int i = 0; i < items.length; i++, k++) {
                sobj.defineOwnProperty(k, items[i]);
            }
        } catch (final UnsupportedOperationException uoe) {
            returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
        }
    } else {
        returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
    }

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


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