use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class ReflectParser method visit.
@Override
public Object visit(TryStatement node, Void value) {
Object block = node.getTryBlock().accept(this, value);
Object handler = acceptOrNull(node.getCatchNode(), value);
ArrayObject guardedHandlers = createList(node.getGuardedCatchNodes(), value);
Object finalizer = acceptOrNull(node.getFinallyBlock(), value);
if (hasBuilder(Type.TryStatement)) {
return call(Type.TryStatement, node, block, guardedHandlers, handler, finalizer);
}
OrdinaryObject statement = createStatement(node, Type.TryStatement);
addProperty(statement, "block", block);
addProperty(statement, "handler", handler);
addProperty(statement, "guardedHandlers", guardedHandlers);
addProperty(statement, "finalizer", finalizer);
return statement;
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class SourceBuilder method source.
private String source(ExecutionContext cx, HashSet<ScriptObject> stack, Object value) {
switch(Type.of(value)) {
case Null:
return "null";
case Boolean:
return Type.booleanValue(value) ? "true" : "false";
case String:
return Strings.quote(Type.stringValue(value).toString());
case Symbol:
return Type.symbolValue(value).toString();
case Number:
return ToFlatString(cx, value);
case SIMD:
return Type.simdValue(value).toString();
case Object:
ScriptObject objValue = Type.objectValue(value);
if (IsCallable(objValue)) {
return ((Callable) objValue).toSource(cx);
}
if (stack.contains(objValue) || stack.size() > maxStackDepth) {
return "« ... »";
}
stack.add(objValue);
try {
if (objValue instanceof DateObject) {
return DatePrototype.Properties.toString(cx, value).toString();
} else if (objValue instanceof RegExpObject) {
return RegExpPrototype.Properties.toString(cx, value).toString();
} else if (objValue instanceof ArrayObject) {
return arrayToSource(cx, stack, objValue);
} else {
return objectToSource(cx, stack, objValue);
}
} finally {
stack.remove(objValue);
}
case Undefined:
default:
return "(void 0)";
}
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class ObjectConstructor method GetOwnPropertyNames.
/**
* 19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type ), with Type = String
*
* @param cx
* the execution context
* @param o
* the script object
* @return the own string-valued property keys of <var>o</var>
*/
public static ArrayObject GetOwnPropertyNames(ExecutionContext cx, Object o) {
/* steps 1-2 */
ScriptObject obj = ToObject(cx, o);
/* steps 3-4 */
List<?> keys = obj.ownPropertyKeys(cx);
/* step 5 */
int initialSize = Math.min(32, keys.size());
ArrayList<String> nameList = new ArrayList<>(initialSize);
/* step 6 */
for (Object key : keys) {
if (key instanceof String) {
nameList.add((String) key);
}
}
/* step 7 */
return CreateArrayFromList(cx, nameList);
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class DateTimeFormatConstructor method FormatToPartDateTime.
/**
* FormatToPartDateTime(dateTimeFormat, x)
*
* @param cx
* the execution context
* @param dateTimeFormat
* the date format object
* @param x
* the number value
* @return the formatted date-time object
*/
public static ArrayObject FormatToPartDateTime(ExecutionContext cx, DateTimeFormatObject dateTimeFormat, double x) {
if (Double.isInfinite(x) || Double.isNaN(x)) {
throw newRangeError(cx, Messages.Key.InvalidDateValue);
}
/* step 1 */
List<Map.Entry<String, String>> parts = CreateDateTimeParts(dateTimeFormat, new Date((long) x));
/* step 2 */
ArrayObject result = ArrayCreate(cx, 0);
/* step 3 */
int n = 0;
/* step 4 */
for (Map.Entry<String, String> part : parts) {
/* step 4.a */
OrdinaryObject o = ObjectCreate(cx, Intrinsics.ObjectPrototype);
/* steps 4.b-c */
CreateDataProperty(cx, o, "type", part.getKey());
/* steps 4.d-e */
CreateDataProperty(cx, o, "value", part.getValue());
/* steps 4.f-g */
CreateDataProperty(cx, result, n++, o);
}
/* step 5 */
return result;
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class ArrayConstructor method construct.
/**
* 22.1.1.1 Array ( )<br>
* 22.1.1.2 Array (len)<br>
* 22.1.1.3 Array (...items )
*/
@Override
public ArrayObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* step 1 */
int numberOfArgs = args.length;
/* steps 2-3 (not applicable) */
/* steps 4-5 */
ScriptObject proto = GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.ArrayPrototype);
if (numberOfArgs == 0) {
/* step 6 */
return ArrayCreate(calleeContext, 0, proto);
} else if (numberOfArgs == 1) {
// [22.1.1.2]
Object len = args[0];
/* steps 6-11 */
if (!Type.isNumber(len)) {
return DenseArrayCreate(calleeContext, proto, len);
} else {
double llen = Type.numberValue(len);
long intLen = ToUint32(llen);
if (intLen != llen) {
throw newRangeError(calleeContext, Messages.Key.InvalidArrayLength);
}
return ArrayCreate(calleeContext, intLen, proto);
}
} else {
/* steps 6-12 */
return DenseArrayCreate(calleeContext, proto, args);
}
}
Aggregations