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


Java ScriptObject.delete方法代码示例

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


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

示例1: captureStackTrace

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

示例2: pop

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.6 Array.prototype.pop ()
 *
 * @param self self reference
 * @return array after pop
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
    try {
        final ScriptObject sobj = (ScriptObject)self;

        if (bulkable(sobj)) {
            return sobj.getArray().pop();
        }

        final long len = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            sobj.set("length", 0, CALLSITE_STRICT);
            return ScriptRuntime.UNDEFINED;
        }

        final long   index   = len - 1;
        final Object element = sobj.get(index);

        sobj.delete(index, true);
        sobj.set("length", index, CALLSITE_STRICT);

        return element;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:NativeArray.java

示例3: reverse

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.8 Array.prototype.reverse ()
 *
 * @param self self reference
 * @return reversed array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object reverse(final Object self) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;
        final long         len    = JSType.toUint32(sobj.getLength());
        final long         middle = len / 2;

        for (long lower = 0; lower != middle; lower++) {
            final long    upper       = len - lower - 1;
            final Object  lowerValue  = sobj.get(lower);
            final Object  upperValue  = sobj.get(upper);
            final boolean lowerExists = sobj.has(lower);
            final boolean upperExists = sobj.has(upper);

            if (lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            } else if (!lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.delete(upper, true);
            } else if (lowerExists && !upperExists) {
                sobj.delete(lower, true);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            }
        }
        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:NativeArray.java

示例4: captureStackTrace

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的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 = ScriptFunction.createBuiltin("getStack", GET_STACK);
        final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", SET_STACK);
        sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    }
    return UNDEFINED;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:NativeError.java

示例5: shift

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

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

示例6: unshift

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self  self reference
 * @param items items for unshift
 * @return unshifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object unshift(final Object self, final Object... items) {
    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());

    if (items == null) {
        return ScriptRuntime.UNDEFINED;
    }

    if (bulkable(sobj)) {
        sobj.getArray().shiftRight(items.length);

        for (int j = 0; j < items.length; j++) {
            sobj.setArray(sobj.getArray().set(j, items[j], true));
        }
    } else {
        for (long k = len; k > 0; k--) {
            final long from = k - 1;
            final long to = k + items.length - 1;

            if (sobj.has(from)) {
                final Object fromValue = sobj.get(from);
                sobj.set(to, fromValue, CALLSITE_STRICT);
            } else {
                sobj.delete(to, true);
            }
        }

        for (int j = 0; j < items.length; j++) {
            sobj.set(j, items[j], CALLSITE_STRICT);
        }
    }

    final long newLength = len + items.length;
    sobj.set("length", newLength, CALLSITE_STRICT);

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

示例7: unshift

import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self  self reference
 * @param items items for unshift
 * @return unshifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object unshift(final Object self, final Object... items) {
    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());

    if (items == null) {
        return ScriptRuntime.UNDEFINED;
    }

    if (bulkable(sobj)) {
        sobj.getArray().shiftRight(items.length);

        for (int j = 0; j < items.length; j++) {
            sobj.setArray(sobj.getArray().set(j, items[j], true));
        }
    } else {
        for (long k = len; k > 0; k--) {
            final long from = k - 1;
            final long to = k + items.length - 1;

            if (sobj.has(from)) {
                final Object fromValue = sobj.get(from);
                sobj.set(to, fromValue, CALLSITE_STRICT);
            } else {
                sobj.delete(to, true);
            }
        }

        for (int j = 0; j < items.length; j++) {
            sobj.set(j, items[j], CALLSITE_STRICT);
        }
    }

    final long newLength = len + items.length;
    sobj.set("length", newLength, CALLSITE_STRICT);

    return JSType.toNarrowestNumber(newLength);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:NativeArray.java


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