use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class PluralRulesConstructor method construct.
/**
* Intl.PluralRules ([ locales [ , options ]])
*/
@Override
public PluralRulesObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object locales = argument(args, 0);
Object options = argument(args, 1);
/* step 1 (not applicable) */
/* step 2 */
PluralRulesObject pluralRules = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.Intl_PluralRulesPrototype, PluralRulesObject::new);
/* step 3 */
InitializePluralRules(calleeContext, pluralRules, locales, options);
return pluralRules;
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class SetConstructor method construct.
/**
* 23.2.1.1 Set ([ iterable ])
*/
@Override
public SetObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object iterable = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-3 */
SetObject set = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.SetPrototype, SetObject::new);
/* steps 4-5, 7 */
if (Type.isUndefinedOrNull(iterable)) {
return set;
}
/* step 6 */
Object _adder = Get(calleeContext, set, "add");
if (!IsCallable(_adder)) {
throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "add");
}
Callable adder = (Callable) _adder;
boolean isBuiltin = SetPrototype.isBuiltinAdd(adder);
if (isBuiltin && iterable instanceof SetObject) {
SetObject other = (SetObject) iterable;
if (ScriptIterators.isBuiltinSetIterator(calleeContext, other)) {
set.getSetData().setAll(other.getSetData());
return set;
}
}
ScriptIterator<?> iter = GetIterator(calleeContext, iterable);
/* step 8 */
try {
if (isBuiltin) {
iter.forEachRemaining(nextValue -> set.getSetData().set(nextValue, null));
} else {
while (iter.hasNext()) {
/* steps 8.a-c */
Object nextValue = iter.next();
/* steps 8.d-e */
adder.call(calleeContext, set, nextValue);
}
}
return set;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class DateConstructor method construct.
/**
* 20.3.2.1 Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )<br>
* 20.3.2.2 Date (value)<br>
* 20.3.2.3 Date ( )<br>
*/
@Override
public DateObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Realm realm = calleeContext.getRealm();
/* steps 1-2 */
int numberOfArgs = args.length;
/* step 3 */
final double dateValue;
if (numberOfArgs >= 2) {
// [20.3.2.1]
/* step 3.a */
double year = ToNumber(calleeContext, args[0]);
/* step 3.b */
double month = ToNumber(calleeContext, args[1]);
/* step 3.c */
double date = (args.length > 2 ? ToNumber(calleeContext, args[2]) : 1);
/* step 3.d */
double hour = (args.length > 3 ? ToNumber(calleeContext, args[3]) : 0);
/* step 3.e */
double min = (args.length > 4 ? ToNumber(calleeContext, args[4]) : 0);
/* step 3.f */
double sec = (args.length > 5 ? ToNumber(calleeContext, args[5]) : 0);
/* step 3.g */
double ms = (args.length > 6 ? ToNumber(calleeContext, args[6]) : 0);
/* step 3.h */
// ToInteger
int intYear = (int) year;
if (!Double.isNaN(year) && 0 <= intYear && intYear <= 99) {
year = 1900 + intYear;
}
/* step 3.i */
double finalDate = MakeDate(MakeDay(year, month, date), MakeTime(hour, min, sec, ms));
/* step 3.k */
dateValue = TimeClip(UTC(realm, finalDate));
} else if (numberOfArgs == 1) {
// [20.3.2.2]
double tv;
if (args[0] instanceof DateObject) {
/* step 3.a */
// TODO: spec improvement - inline thisTimeValue() call.
tv = ((DateObject) args[0]).getDateValue();
} else {
/* step 3.b */
Object v = ToPrimitive(calleeContext, args[0]);
if (Type.isString(v)) {
tv = (double) Properties.parse(calleeContext, null, v);
} else {
tv = ToNumber(calleeContext, v);
}
}
dateValue = TimeClip(tv);
} else {
// [20.3.2.3]
if (!calleeContext.getRealm().isGranted(Permission.CurrentTime)) {
throw newTypeError(calleeContext, Messages.Key.NoPermission, "Date");
}
dateValue = System.currentTimeMillis();
}
DateObject obj = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.DatePrototype, DateObject::new);
obj.setDateValue(dateValue);
return obj;
/* step 4 (not applicable) */
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class DateConstructor method call.
/**
* 20.3.2.1 Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )<br>
* 20.3.2.2 Date (value)<br>
* 20.3.2.3 Date ( )<br>
*/
@Override
public String call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* step 4 */
if (!calleeContext.getRealm().isGranted(Permission.CurrentTime)) {
throw newTypeError(calleeContext, Messages.Key.NoPermission, "Date");
}
long now = System.currentTimeMillis();
return DatePrototype.ToDateString(calleeContext.getRealm(), now);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class NumberConstructor method construct.
/**
* 20.1.1.1 Number ( [ value ] )
*/
@Override
public NumberObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* steps 1-2 */
double n;
if (args.length == 0) {
n = 0d;
} else {
// Extension: BigInt:
Number prim = ToNumeric(calleeContext, args[0]);
if (Type.isBigInt(prim)) {
n = Type.bigIntValue(prim).doubleValue();
} else {
n = prim.doubleValue();
}
}
/* steps 4-6 */
return NumberCreate(calleeContext, n, GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.NumberPrototype));
}
Aggregations