Search in sources :

Example 11 with Constructor

use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.

the class Properties method createExternalClass.

private static Constructor createExternalClass(ExecutionContext cx, String className, Class<?> constructorProperties, Class<?> prototypeProperties) {
    ObjectLayout ctorLayout = externalClassLayouts.get(constructorProperties);
    ObjectLayout protoLayout = externalClassLayouts.get(prototypeProperties);
    Converter converter = new Converter(cx);
    ScriptObject[] objects = ScriptRuntime.getDefaultClassProto(cx);
    ScriptObject constructorParent = objects[0];
    OrdinaryObject proto = (OrdinaryObject) objects[1];
    assert constructorParent == cx.getIntrinsic(Intrinsics.FunctionPrototype);
    OrdinaryObject constructor = createConstructor(cx, className, proto, converter, protoLayout);
    assert constructor instanceof Constructor;
    if (ctorLayout.functions != null) {
        createExternalFunctions(cx, constructor, ctorLayout, converter);
    }
    if (ctorLayout.accessors != null) {
        createExternalAccessors(cx, constructor, ctorLayout, converter);
    }
    if (protoLayout.functions != null) {
        createExternalFunctions(cx, proto, protoLayout, converter);
    }
    if (protoLayout.accessors != null) {
        createExternalAccessors(cx, proto, protoLayout, converter);
    }
    return (Constructor) constructor;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) NativeConstructor(com.github.anba.es6draft.runtime.types.builtins.NativeConstructor) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Example 12 with Constructor

use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.

the class TypedArrayConstructor method TypedArraySpeciesCreate.

/**
     * TypedArraySpeciesCreate( exemplar, argumentList )
     * 
     * @param cx
     *            the execution context
     * @param exemplar
     *            the typed array object
     * @param length
     *            the new typed array length
     * @return the new typed array object
     */
public static TypedArrayObject TypedArraySpeciesCreate(ExecutionContext cx, TypedArrayObject exemplar, long length) {
    /* step 1 (implicit) */
    /* step 2 */
    Intrinsics defaultConstructor = exemplar.getElementType().getConstructor();
    /* step 3 */
    Constructor constructor = SpeciesConstructor(cx, exemplar, defaultConstructor);
    /* step 4 */
    return TypedArrayCreate(cx, constructor, length);
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Example 13 with Constructor

use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.

the class TypedArrayConstructor method TypedArraySpeciesCreate.

/**
     * TypedArraySpeciesCreate( exemplar, argumentList )
     * 
     * @param cx
     *            the execution context
     * @param exemplar
     *            the typed array object
     * @param args
     *            the constructor function arguments
     * @return the new typed array object
     */
public static TypedArrayObject TypedArraySpeciesCreate(ExecutionContext cx, TypedArrayObject exemplar, Object... args) {
    /* step 1 (implicit) */
    /* step 2 */
    Intrinsics defaultConstructor = exemplar.getElementType().getConstructor();
    /* step 3 */
    Constructor constructor = SpeciesConstructor(cx, exemplar, defaultConstructor);
    /* step 4 */
    return TypedArrayCreate(cx, constructor, args);
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Example 14 with Constructor

use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.

the class TypedArrayConstructor method constructWithTypedArray.

/**
     * 22.2.4.3 TypedArray ( typedArray )
     * 
     * @param cx
     *            the execution context
     * @param newTarget
     *            the NewTarget constructor object
     * @param typedArray
     *            the source typed array object
     * @return the typed array object
     */
private TypedArrayObject constructWithTypedArray(ExecutionContext cx, Constructor newTarget, TypedArrayObject typedArray) {
    /* step 1 (implicit) */
    /* step 2 (not applicable) */
    /* steps 3-4 (TypedArray allocation deferred) */
    ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, prototypeForType(elementType));
    /* step 5 */
    TypedArrayObject srcArray = typedArray;
    /* step 6 */
    ArrayBuffer srcData = srcArray.getBuffer();
    /* step 7 */
    if (IsDetachedBuffer(srcData)) {
        throw newTypeError(cx, Messages.Key.BufferDetached);
    }
    /* steps 8-9 */
    ElementType elementType = this.elementType;
    /* step 10 */
    long elementLength = srcArray.getArrayLength();
    /* steps 11-12 */
    ElementType srcType = srcArray.getElementType();
    /* step 13 */
    int srcElementSize = srcType.size();
    /* step 14 */
    long srcByteOffset = srcArray.getByteOffset();
    /* step 15 */
    int elementSize = elementType.size();
    /* step 16 */
    long byteLength = elementSize * elementLength;
    /* steps 17-18 */
    ArrayBufferObject data;
    if (elementType == srcType) {
        /* step 17 */
        data = CloneArrayBuffer(cx, srcData, srcByteOffset);
    } else {
        /* step 18 */
        /* step 18.a */
        // FIXME: spec bug - SharedArrayBuffers not handled correctly!
        Constructor bufferConstructor = SpeciesConstructor(cx, srcData, Intrinsics.ArrayBuffer);
        /* step 18.b */
        data = AllocateArrayBuffer(cx, bufferConstructor, byteLength);
        /* step 18.c */
        if (IsDetachedBuffer(srcData)) {
            throw newTypeError(cx, Messages.Key.BufferDetached);
        }
        /* step 18.d */
        long srcByteIndex = srcByteOffset;
        /* step 18.e */
        long targetByteIndex = 0;
        /* steps 18.f-g */
        for (long count = elementLength; count > 0; --count) {
            double value = GetValueFromBuffer(srcData, srcByteIndex, srcType);
            SetValueInBuffer(data, targetByteIndex, elementType, value);
            srcByteIndex += srcElementSize;
            targetByteIndex += elementSize;
        }
    }
    /* steps 4, 19-23 */
    return new TypedArrayObject(cx.getRealm(), elementType, data, byteLength, 0, elementLength, proto);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Example 15 with Constructor

use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.

the class PropertiesTest method createCustomClassWithCallerContext.

@Test
public void createCustomClassWithCallerContext() {
    Constructor customClass = Properties.createClass(cx, "CustomClassWithCallerContext", CustomClassWithCallerContext.ConstructorProperties.class, CustomClassWithCallerContext.PrototypeProperties.class);
    ScriptObject object = customClass.construct(cx, customClass);
    assertNotNull(object);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) OrdinaryCreateFromConstructor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor) Test(org.junit.Test)

Aggregations

Constructor (com.github.anba.es6draft.runtime.types.Constructor)19 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)11 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)8 Test (org.junit.Test)8 BuiltinConstructor (com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor)7 SpeciesConstructor (com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor)4 ArrayBufferConstructor (com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)3 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 CheckConstructor (com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckConstructor)2 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)2 MethodHandle (java.lang.invoke.MethodHandle)2 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)1 IsConstructor (com.github.anba.es6draft.runtime.AbstractOperations.IsConstructor)1 Realm (com.github.anba.es6draft.runtime.Realm)1 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 LegacyConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.LegacyConstructorFunction)1 NativeConstructor (com.github.anba.es6draft.runtime.types.builtins.NativeConstructor)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1