use of com.github.anba.es6draft.runtime.types.Callable 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-4 */
SetObject set = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.SetPrototype, SetObject::new);
/* steps 5-6, 8 */
if (Type.isUndefinedOrNull(iterable)) {
return set;
}
/* step 7 */
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.isBuiltinIterator(calleeContext, other)) {
set.getSetData().setAll(other.getSetData());
return set;
}
}
ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
/* step 9 */
try {
while (iter.hasNext()) {
Object nextValue = iter.next();
if (isBuiltin) {
set.getSetData().set(nextValue, null);
} else {
adder.call(calleeContext, set, nextValue);
}
}
return set;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class ObservablePrototype method ExecuteSubscriber.
/**
* Runtime Semantics: ExecuteSubscriber ( subscriber, observer )
*
* @param cx
* the execution context
* @param subscriber
* the subscriber function
* @param observer
* the observer object
* @return the subscriber result value
*/
public static Callable ExecuteSubscriber(ExecutionContext cx, Callable subscriber, SubscriptionObserverObject observer) {
/* steps 1-2 (implicit) */
/* steps 3-4 */
Object subscriberResult = subscriber.call(cx, UNDEFINED, observer);
/* step 5 */
if (Type.isUndefinedOrNull(subscriberResult)) {
return null;
}
/* step 6 */
if (IsCallable(subscriberResult)) {
return (Callable) subscriberResult;
}
/* steps 7-8 */
Callable result = GetMethod(cx, subscriberResult, "unsubscribe");
/* step 9 */
if (result == null) {
throw newTypeError(cx, Messages.Key.PropertyNotCallable, "unsubscribe");
}
/* steps 10-11 */
SubscriptionCleanupFunction cleanupFunction = new SubscriptionCleanupFunction(cx.getRealm(), subscriberResult);
// FIXME: spec bug - typo 'cancelFunction'
return cleanupFunction;
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class PromiseConstructor method construct.
/**
* 25.4.3.1 Promise ( executor )
*/
@Override
public PromiseObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object executor = argument(args, 0);
/* step 2 */
if (!IsCallable(executor)) {
throw newTypeError(calleeContext, Messages.Key.NotCallable);
}
/* steps 3-7 */
PromiseObject promise = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.PromisePrototype, GetPromiseAllocator(calleeContext.getRealm()));
/* step 8 */
ResolvingFunctions resolvingFunctions = CreateResolvingFunctions(calleeContext, promise);
/* steps 9-10 */
try {
/* step 9 */
((Callable) executor).call(calleeContext, UNDEFINED, resolvingFunctions.getResolve(), resolvingFunctions.getReject());
} catch (ScriptException e) {
/* step 10 */
resolvingFunctions.getReject().call(calleeContext, UNDEFINED, e.getValue());
}
/* step 11 */
return promise;
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class ReflectParser method parse.
/**
* Parses the given script code and returns the matching Reflect AST nodes.
*
* @param cx
* the execution context
* @param source
* the source string
* @param options
* the options object
* @return the parsed node
*/
public static Object parse(ExecutionContext cx, String source, ScriptObject options) {
boolean location = true;
String sourceInfo = null;
int line = 1;
EnumMap<Type, Callable> builder = new EnumMap<>(Type.class);
if (options != null) {
if (HasProperty(cx, options, "loc")) {
location = ToBoolean(Get(cx, options, "loc"));
}
if (HasProperty(cx, options, "source")) {
sourceInfo = ToFlatString(cx, Get(cx, options, "source"));
}
if (HasProperty(cx, options, "line")) {
line = ToInt32(cx, Get(cx, options, "line"));
}
if (HasProperty(cx, options, "builder")) {
Object value = Get(cx, options, "builder");
if (!isUndefinedOrNull(value)) {
builder = toBuilderMap(cx, ToObject(cx, value));
}
}
}
return parse(cx, source, location, sourceInfo, line, builder);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class ArgumentsObject method CreateUnmappedArgumentsObject.
/**
* 9.4.4.6 CreateUnmappedArgumentsObject(argumentsList)
* <p>
* [Called from generated code]
*
* @param cx
* the execution context
* @param argumentsList
* the function arguments
* @return the strict mode arguments object
*/
public static ArgumentsObject CreateUnmappedArgumentsObject(ExecutionContext cx, Object[] argumentsList) {
/* step 1 */
int len = argumentsList.length;
/* steps 2-3 */
ArgumentsObject obj = new ArgumentsObject(cx.getRealm());
obj.setPrototype(cx.getIntrinsic(Intrinsics.ObjectPrototype));
/* step 4 */
obj.infallibleDefineOwnProperty("length", new Property(len, true, false, true));
/* steps 5-6 */
for (int index = 0; index < len; ++index) {
obj.setIndexed(index, argumentsList[index]);
}
Callable thrower = cx.getRealm().getThrowTypeError();
/* step 7 */
obj.infallibleDefineOwnProperty(BuiltinSymbol.iterator.get(), new Property(cx.getIntrinsic(Intrinsics.ArrayProto_values), true, false, true));
/* step 8 */
obj.infallibleDefineOwnProperty("callee", new Property(thrower, thrower, false, false));
/* step 9 */
obj.infallibleDefineOwnProperty("caller", new Property(thrower, thrower, false, false));
/* step 11 */
return obj;
}
Aggregations