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;
/* step 2 (not applicable) */
/* step 3 */
Object c = UNDEFINED;
/* steps 4-6 */
if (IsArray(cx, orginalArray)) {
/* steps 6.a-b */
c = Get(cx, orginalArray, "constructor");
/* step 6.c */
if (IsConstructor(c)) {
Constructor constructor = (Constructor) c;
/* step 6.c.i */
Realm thisRealm = cx.getRealm();
/* steps 6.c.ii-iii */
Realm realmC = GetFunctionRealm(cx, constructor);
/* step 6.c.iv */
if (thisRealm != realmC && constructor == realmC.getIntrinsic(Intrinsics.Array)) {
c = UNDEFINED;
}
}
/* step 6.d */
if (Type.isObject(c)) {
c = Get(cx, Type.objectValue(c), BuiltinSymbol.species.get());
if (Type.isNull(c)) {
c = UNDEFINED;
}
}
}
/* step 7 */
if (Type.isUndefined(c)) {
return ArrayCreate(cx, length);
}
/* step 8 */
if (!IsConstructor(c)) {
throw newTypeError(cx, Messages.Key.NotConstructor);
}
/* step 9 */
return ((Constructor) c).construct(cx, (Constructor) c, length);
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class PropertiesTest method createEmptyClassAndConstruct.
@Test
public void createEmptyClassAndConstruct() {
Constructor emptyClass = Properties.createClass(cx, "EmptyClass", EmptyClass.ConstructorProperties.class, EmptyClass.PrototypeProperties.class);
ScriptObject object = emptyClass.construct(cx, emptyClass);
assertNotNull(object);
assertSame(emptyClass.get(cx, "prototype", emptyClass), object.getPrototypeOf(cx));
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class PropertiesTest method createEmptyClassAndCall.
@Test(expected = ScriptException.class)
public void createEmptyClassAndCall() {
Constructor emptyClass = Properties.createClass(cx, "EmptyClass", EmptyClass.ConstructorProperties.class, EmptyClass.PrototypeProperties.class);
emptyClass.call(cx, Null.NULL);
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class PropertiesTest method createCustomClassWithObject.
@Test
public void createCustomClassWithObject() {
Constructor customClass = Properties.createClass(cx, "CustomClassWithObject", CustomClassWithObject.ConstructorProperties.class, CustomClassWithObject.PrototypeProperties.class);
ScriptObject object = customClass.construct(cx, customClass);
assertNotNull(object);
}
Aggregations