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


Java ArrayData类代码示例

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


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

示例1: set

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
@Override
public void set(final int key, final int value, final int callSiteFlags) {
    final int index = getArrayIndex(key);
    if (isValidArrayIndex(index)) {
        if (getArray().has(index)) {
            final ArrayData data = getArray();
            setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
        } else {
            doesNotHave(index, value, callSiteFlags);
        }
        return;
    }

    final String propName = JSType.toString(key);
    setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ScriptObject.java

示例2: NativeArray

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
NativeArray(final long[] array) {
    this(ArrayData.allocate(array.length));

    ArrayData arrayData = this.getArray();
    Class<?> widest = int.class;

    for (int index = 0; index < array.length; index++) {
        final long value = array[index];

        if (widest == int.class && JSType.isRepresentableAsInt(value)) {
            arrayData = arrayData.set(index, (int) value, false);
        } else if (widest != Object.class && JSType.isRepresentableAsDouble(value)) {
            arrayData = arrayData.set(index, (double) value, false);
            widest = double.class;
        } else {
            arrayData = arrayData.set(index, (Object) value, false);
            widest = Object.class;
        }
    }

    this.setArray(arrayData);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:NativeArray.java

示例3: push

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
 *
 * @param self self reference
 * @param arg argument to push
 * @return array after pushes
 */
@SpecializedFunction
public static double push(final Object self, final Object arg) {
    try {
        final ScriptObject sobj = (ScriptObject)self;
        final ArrayData arrayData = sobj.getArray();
        final long length = arrayData.length();
        if (bulkable(sobj) && length < JSType.MAX_UINT) {
            sobj.setArray(arrayData.push(true, arg));
            return length + 1;
        }

        long len = JSType.toUint32(sobj.getLength());
        sobj.set(len++, arg, CALLSITE_STRICT);
        sobj.set("length", len, CALLSITE_STRICT);
        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:NativeArray.java

示例4: delete

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
@Override
public boolean delete(final Object key, final boolean strict) {
    final Object    primitiveKey = JSType.toPrimitive(key, String.class);
    final int       index        = getArrayIndex(primitiveKey);
    final ArrayData array        = getArray();

    if (array.has(index)) {
        if (array.canDelete(index, strict)) {
            setArray(array.delete(index));
            return true;
        }
        return false;
    }

    return deleteObject(primitiveKey, strict);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:ScriptObject.java

示例5: push

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
 *
 * @param self self reference
 * @param arg argument to push
 * @return array after pushes
 */
@SpecializedFunction
public static long push(final Object self, final Object arg) {
    try {
        final ScriptObject sobj = (ScriptObject)self;
        final ArrayData arrayData = sobj.getArray();
        final long length = arrayData.length();
        if (bulkable(sobj) && length < JSType.MAX_UINT) {
            sobj.setArray(arrayData.push(true, arg));
            return length + 1;
        }

        long len = JSType.toUint32(sobj.getLength());
        sobj.set(len++, arg, CALLSITE_STRICT);
        sobj.set("length", len, CALLSITE_STRICT);
        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:NativeArray.java

示例6: loadConstant

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
private void loadConstant(final Object object, final CompileUnit compileUnit, final MethodEmitter methodEmitter) {
    final String       unitClassName = compileUnit.getUnitClassName();
    final ClassEmitter classEmitter  = compileUnit.getClassEmitter();
    final int          index         = compiler.getConstantData().add(object);
    final Class<?>     cls           = object.getClass();

    if (cls == PropertyMap.class) {
        methodEmitter.load(index);
        methodEmitter.invokestatic(unitClassName, GET_MAP.symbolName(), methodDescriptor(PropertyMap.class, int.class));
        classEmitter.needGetConstantMethod(PropertyMap.class);
    } else if (cls.isArray()) {
        methodEmitter.load(index);
        final String methodName = ClassEmitter.getArrayMethodName(cls);
        methodEmitter.invokestatic(unitClassName, methodName, methodDescriptor(cls, int.class));
        classEmitter.needGetConstantMethod(cls);
    } else {
        methodEmitter.loadConstants().load(index).arrayload();
        if (object instanceof ArrayData) {
            // avoid cast to non-public ArrayData subclass
            methodEmitter.checkcast(ArrayData.class);
            methodEmitter.invoke(virtualCallNoLookup(ArrayData.class, "copy", ArrayData.class));
        } else if (cls != Object.class) {
            methodEmitter.checkcast(cls);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:CodeGenerator.java

示例7: NativeStrictArguments

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
NativeStrictArguments(final Object[] values, final int numParams,final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    setIsArguments();

    final ScriptFunction func = Global.instance().getTypeErrorThrower();
    // We have to fill user accessor functions late as these are stored
    // in this object rather than in the PropertyMap of this object.
    final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
    initUserAccessors("caller", flags, func, func);
    initUserAccessors("callee", flags, func, func);

    setArray(ArrayData.allocate(values));
    this.length = values.length;

    // extend/truncate named arg array as needed and copy values
    this.namedArgs = new Object[numParams];
    if (numParams > values.length) {
        Arrays.fill(namedArgs, UNDEFINED);
    }
    System.arraycopy(values, 0, namedArgs, 0, Math.min(namedArgs.length, values.length));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:NativeStrictArguments.java

示例8: set

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
@Override
public void set(final Object key, final int value, final int callSiteFlags) {
    final Object primitiveKey = JSType.toPrimitive(key, String.class);
    final int    index        = getArrayIndex(primitiveKey);

    if (isValidArrayIndex(index)) {
        final ArrayData data = getArray();
        if (data.has(index)) {
            setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
        } else {
            doesNotHave(index, value, callSiteFlags);
        }

        return;
    }

    final String propName = JSType.toString(primitiveKey);
    setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ScriptObject.java

示例9: setIndexedPropertiesToExternalArrayData

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
/**
 * Nashorn extension: setIndexedPropertiesToExternalArrayData.
 * set indexed properties be exposed from a given nio ByteBuffer.
 *
 * @param buf external buffer - should be a nio ByteBuffer
 */
public void setIndexedPropertiesToExternalArrayData(final ByteBuffer buf) {
    inGlobal(new Callable<Void>() {
        @Override public Void call() {
            sobj.setArray(ArrayData.allocate(buf));
            return null;
        }
    });
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:ScriptObjectMirror.java

示例10: allocate

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
/**
 * Allocate a new object array.
 *
 * @param initial object values.
 * @return the new array
 */
public static NativeArray allocate(final Object[] initial) {
    ArrayData arrayData = ArrayData.allocate(initial);

    for (int index = 0; index < initial.length; index++) {
        final Object value = initial[index];

        if (value == ScriptRuntime.EMPTY) {
            arrayData = arrayData.delete(index);
        }
    }

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

示例11: checkIntegerKey

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
private void checkIntegerKey(final Object key) {
    final int index = getArrayIndex(key);

    if (isValidArrayIndex(index)) {
        final ArrayData data = getArray();

        if (data.has(index)) {
            setArray(data.delete(index));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ScriptObject.java

示例12: get

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
@Override
public Object get(final Object key) {
    final Object    primitiveKey = JSType.toPrimitive(key, String.class);
    final int       index        = getArrayIndex(primitiveKey);
    final ArrayData array        = getArray();

    if (array.has(index)) {
        return array.getObject(index);
    }

    return get(index, JSType.toPropertyKey(primitiveKey));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ScriptObject.java

示例13: seal

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
/**
 * ECMAScript 15.2.3.8 - seal implementation
 * @return the sealed ScriptObject
 */
public ScriptObject seal() {
    PropertyMap oldMap = getMap();

    while (true) {
        final PropertyMap newMap = getMap().seal();

        if (!compareAndSetMap(oldMap, newMap)) {
            oldMap = getMap();
        } else {
            setArray(ArrayData.seal(getArray()));
            return this;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ScriptObject.java

示例14: NativeArguments

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
NativeArguments(final Object[] arguments, final Object callee, final int numParams, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    setIsArguments();
    setArray(ArrayData.allocate(arguments));
    this.length = arguments.length;
    this.callee = callee;
    this.numMapped = Math.min(numParams, arguments.length);
    this.numParams = numParams;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:NativeArguments.java

示例15: setIndexedPropertiesToExternalArrayData

import jdk.nashorn.internal.runtime.arrays.ArrayData; //导入依赖的package包/类
/**
 * Nashorn extension: setIndexedPropertiesToExternalArrayData
 *
 * @param self self reference
 * @param obj object whose index properties are backed by buffer
 * @param buf external buffer - should be a nio ByteBuffer
 * @return the 'obj' object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject setIndexedPropertiesToExternalArrayData(final Object self, final Object obj, final Object buf) {
    Global.checkObject(obj);
    final ScriptObject sobj = (ScriptObject)obj;
    if (buf instanceof ByteBuffer) {
        sobj.setArray(ArrayData.allocate((ByteBuffer)buf));
    } else {
        throw typeError("not.a.bytebuffer", "setIndexedPropertiesToExternalArrayData's buf argument");
    }
    return sobj;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:NativeObject.java


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