use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class IntlAbstractOperations method SupportedLocales.
/**
* 9.2.9 SupportedLocales (availableLocales, requestedLocales, options)
*
* @param cx
* the execution context
* @param availableLocales
* the set of available locales
* @param requestedLocales
* the set of requested locales
* @param options
* the options object
* @return the supported locales array
*/
public static ScriptObject SupportedLocales(ExecutionContext cx, Set<String> availableLocales, Set<String> requestedLocales, Object options) {
/* step 1 */
String matcher = null;
if (!Type.isUndefined(options)) {
matcher = GetStringOption(cx, ToObject(cx, options), "localeMatcher", set("lookup", "best fit"), "best fit");
}
/* steps 2-5 */
List<String> supportedLocales;
if (matcher == null || "best fit".equals(matcher)) {
supportedLocales = BestFitSupportedLocales(availableLocales, requestedLocales);
} else {
supportedLocales = LookupSupportedLocales(availableLocales, requestedLocales);
}
/* steps 6-8 */
ArrayObject subset = ArrayCreate(cx, supportedLocales.size());
int index = 0;
for (Object value : supportedLocales) {
subset.defineOwnProperty(cx, index++, new PropertyDescriptor(value, false, true, false));
}
PropertyDescriptor nonConfigurableWritable = new PropertyDescriptor();
nonConfigurableWritable.setConfigurable(false);
nonConfigurableWritable.setWritable(false);
subset.defineOwnProperty(cx, "length", nonConfigurableWritable);
/* step 9 */
return subset;
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class ExpressionGenerator method visit.
/**
* 12.2.4.1.3 Runtime Semantics: Evaluation<br>
* 12.2.4.1.2 Runtime Semantics: Array Accumulation
*/
@Override
public ValType visit(SpreadElementMethod node, CodeVisitor mv) {
MethodName method = codegen.compile(node, mv);
boolean hasResume = node.hasResumePoint();
mv.enterVariableScope();
Variable<ArrayObject> array = mv.newVariable("array", ArrayObject.class);
Variable<Integer> nextIndex = mv.newVariable("nextIndex", int.class);
// stack: [array, nextIndex] -> [array]
mv.store(nextIndex);
mv.dup();
mv.store(array);
// stack: [array] -> [array, nextIndex']
// 0 = hint for stacktraces to omit this frame
mv.lineInfo(0);
if (hasResume) {
mv.callWithSuspend(method, array, nextIndex);
} else {
mv.call(method, array, nextIndex);
}
mv.exitVariableScope();
return ValType.Any;
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class Interpreter method visit.
@Override
public Object visit(ArrayLiteral node, ExecutionContext cx) {
ArrayObject array = ArrayCreate(cx, 0);
int nextIndex = 0;
for (Expression element : node.getElements()) {
if (element instanceof Elision) {
// Elision
} else {
Object value = GetValue(element.accept(this, cx), cx);
ScriptRuntime.defineProperty(array, nextIndex, value);
}
nextIndex += 1;
}
Set(cx, array, "length", nextIndex, false);
return array;
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class JSONParser method jsonArray.
/**
* <pre>
* JSONArray :
* [ ]
* [ JSONElementList ]
* JSONElementList :
* JSONValue
* JSONElementList , JSONValue
* </pre>
*
* @return the script object represented by the JSON array
*/
private ArrayObject jsonArray() {
ArrayObject array = ArrayCreate(cx, 0);
consume(Token.LB);
if (token() != Token.RB) {
for (long index = 0; ; ) {
Object value = jsonValue();
array.defineOwnProperty(cx, index++, new PropertyDescriptor(value, true, true, true));
if (token() == Token.RB) {
break;
}
consume(Token.COMMA);
}
}
consume(Token.RB);
return array;
}
use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject in project es6draft by anba.
the class ObjectConstructor method EnumerableOwnProperties.
/**
* EnumerableOwnProperties (O)
*
* @param cx
* the execution context
* @param object
* the script object
* @param kind
* the property kind
* @return <var>object</var>'s own enumerable properties
*/
static List<Object> EnumerableOwnProperties(ExecutionContext cx, ScriptObject object, PropertyKind kind) {
/* step 1 (not applicable) */
/* steps 2-3 */
List<?> ownKeys = object.ownPropertyKeys(cx);
/* step 4 */
int initialSize = Math.min(16, ownKeys.size());
ArrayList<Object> properties = new ArrayList<>(initialSize);
/* step 5 */
for (Object key : ownKeys) {
if (key instanceof String) {
String skey = (String) key;
Property desc = object.getOwnProperty(cx, skey);
if (desc != null && desc.isEnumerable()) {
if (kind == PropertyKind.Key) {
properties.add(skey);
} else {
Object value = Get(cx, object, skey);
if (kind == PropertyKind.Value) {
properties.add(value);
} else {
ArrayObject entry = CreateArrayFromList(cx, key, value);
properties.add(entry);
}
}
}
}
}
/* step 7 */
return properties;
}
Aggregations