use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ObjectConstructor method call.
/**
* 19.1.1.1 Object ( [ value ] )
*/
@Override
public ScriptObject call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object value = argument(args, 0);
/* step 2 */
if (Type.isUndefinedOrNull(value)) {
// (= `this`) is not the intrinsic %Object% constructor function.
return OrdinaryCreateFromConstructor(calleeContext, this, Intrinsics.ObjectPrototype);
}
/* step 3 */
return ToObject(calleeContext, value);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject 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;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ObjectConstructor method GetOwnPropertySymbols.
/**
* 19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type ), with Type = Symbol
*
* @param cx
* the execution context
* @param o
* the script object
* @return the own symbol-valued property keys of <var>o</var>
*/
public static ArrayObject GetOwnPropertySymbols(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(8, keys.size());
ArrayList<Symbol> nameList = new ArrayList<>(initialSize);
/* step 6 */
for (Object key : keys) {
if (key instanceof Symbol) {
nameList.add((Symbol) key);
}
}
/* step 7 */
return CreateArrayFromList(cx, nameList);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class AsyncFunctionConstructor method CreateDynamicFunction.
/**
* 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
*
* @param callerContext
* the caller execution context
* @param cx
* the execution context
* @param newTarget
* the newTarget constructor function
* @param args
* the function arguments
* @return the new generator function object
*/
private static OrdinaryAsyncFunction CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.AsyncFunction;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.AsyncFunction, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.asyncFunction(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryAsyncFunction f = FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* steps 27-28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class AsyncGeneratorAbstractOperations method GetAsyncIterator.
/**
* GetIterator ( obj [ , hint ] )
*
* @param cx
* the execution context
* @param obj
* the script object
* @return the script iterator object
*/
public static ScriptObject GetAsyncIterator(ExecutionContext cx, Object obj) {
/* steps 1-2 (not applicable) */
/* step 3 */
Callable method = GetMethod(cx, obj, BuiltinSymbol.asyncIterator.get());
/* step 5 (inlined Call operation) */
if (method == null) {
throw newTypeError(cx, Messages.Key.PropertyNotCallable, BuiltinSymbol.asyncIterator.toString());
}
Object iterator = method.call(cx, obj);
/* step 6 */
if (!Type.isObject(iterator)) {
throw newTypeError(cx, Messages.Key.NotObjectTypeReturned, "[Symbol.asyncIterator]");
}
/* step 7 */
return Type.objectValue(iterator);
}
Aggregations