use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class ArrayObject method ArraySpeciesCreate.
/**
* 9.4.2.3 ArraySpeciesCreate(originalArray, length)
*
* @param cx
* the execution context
* @param orginalArray
* the source array
* @param length
* the array length
* @return the new array object
*/
public static ScriptObject ArraySpeciesCreate(ExecutionContext cx, ScriptObject orginalArray, long length) {
/* step 1 */
assert length >= 0;
/* steps 3-4 */
if (!IsArray(cx, orginalArray)) {
return ArrayCreate(cx, length);
}
/* step 5 */
Object c = Get(cx, orginalArray, "constructor");
/* step 6 */
if (IsConstructor(c)) {
Constructor constructor = (Constructor) c;
/* step 6.a */
Realm thisRealm = cx.getRealm();
/* step 6.b */
Realm realmC = GetFunctionRealm(cx, constructor);
/* step 6.c */
if (thisRealm != realmC && constructor == realmC.getIntrinsic(Intrinsics.Array)) {
c = UNDEFINED;
}
}
/* step 7 */
if (Type.isObject(c)) {
/* step 7.a.*/
c = Get(cx, Type.objectValue(c), BuiltinSymbol.species.get());
/* step 7.b */
if (Type.isNull(c)) {
c = UNDEFINED;
}
}
/* step 8 */
if (Type.isUndefined(c)) {
return ArrayCreate(cx, length);
}
/* step 9 */
if (!IsConstructor(c)) {
throw newTypeError(cx, Messages.Key.NotConstructor);
}
/* step 10 */
return ((Constructor) c).construct(cx, 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 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);
}
Aggregations