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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations