use of com.github.anba.es6draft.runtime.AbstractOperations.IsCallable 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.AbstractOperations.IsCallable 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;
}
Aggregations