use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class Eval method directEval.
/**
* 18.2.1 eval (x)
* <p>
* [Called from generated code]
*
* @param arguments
* the arguments
* @param cx
* the execution context
* @param flags
* the eval flags
* @return the evaluation result
*/
public static Object directEval(Object[] arguments, ExecutionContext cx, int flags) {
assert EvalFlags.Direct.isSet(flags);
Object source;
Callable translate = cx.getRealm().getDirectEvalTranslate();
if (translate != null) {
source = translate.call(cx, cx.getRealm().getRealmObject(), arguments);
} else {
source = arguments.length > 0 ? arguments[0] : UNDEFINED;
}
return PerformEval(cx, cx, source, flags);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class Eval method indirectEval.
/**
* 18.2.1 eval (x)
*
* @param cx
* the execution context
* @param caller
* the caller context
* @param arguments
* the arguments
* @return the evaluation result
*/
public static Object indirectEval(ExecutionContext cx, ExecutionContext caller, Object... arguments) {
Object source;
Callable indirectEval = cx.getRealm().getIndirectEval();
if (indirectEval != null) {
source = indirectEval.call(cx, cx.getRealm().getRealmObject(), arguments);
} else {
source = arguments.length > 0 ? arguments[0] : UNDEFINED;
}
return globalEval(cx, caller, source);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class MapConstructor method construct.
/**
* 23.1.1.1 Map ([ iterable ])
*/
@Override
public MapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object iterable = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-4 */
MapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.MapPrototype, MapObject::new);
/* steps 5-6, 8 */
if (Type.isUndefinedOrNull(iterable)) {
return map;
}
/* step 7 */
Object _adder = Get(calleeContext, map, "set");
if (!IsCallable(_adder)) {
throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
}
Callable adder = (Callable) _adder;
boolean isBuiltin = MapPrototype.isBuiltinSet(_adder);
if (isBuiltin && iterable instanceof MapObject) {
MapObject other = (MapObject) iterable;
if (ScriptIterators.isBuiltinIterator(calleeContext, other)) {
map.getMapData().setAll(other.getMapData());
return map;
}
}
ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
/* step 9 */
try {
while (iter.hasNext()) {
Object nextItem = iter.next();
if (!Type.isObject(nextItem)) {
throw newTypeError(calleeContext, Messages.Key.MapPairNotObject);
}
ScriptObject item = Type.objectValue(nextItem);
Object k = Get(calleeContext, item, 0);
Object v = Get(calleeContext, item, 1);
if (isBuiltin) {
map.getMapData().set(k, v);
} else {
adder.call(calleeContext, map, k, v);
}
}
return map;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class WeakMapConstructor method construct.
/**
* 23.3.1.1 WeakMap ([ iterable ])
*/
@Override
public WeakMapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object iterable = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-4 */
WeakMapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakMapPrototype, WeakMapObject::new);
/* steps 5-6, 8 */
if (Type.isUndefinedOrNull(iterable)) {
return map;
}
/* step 7 */
Object _adder = Get(calleeContext, map, "set");
if (!IsCallable(_adder)) {
throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
}
Callable adder = (Callable) _adder;
ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
/* step 9 */
try {
while (iter.hasNext()) {
Object nextItem = iter.next();
if (!Type.isObject(nextItem)) {
throw newTypeError(calleeContext, Messages.Key.WeakMapPairNotObject);
}
ScriptObject item = Type.objectValue(nextItem);
Object k = Get(calleeContext, item, 0);
Object v = Get(calleeContext, item, 1);
adder.call(calleeContext, map, k, v);
}
return map;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class WeakSetConstructor method construct.
/**
* 23.4.1.1 WeakSet ([ iterable ])
*/
@Override
public WeakSetObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object iterable = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-4 */
WeakSetObject set = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakSetPrototype, WeakSetObject::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;
ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
/* step 9 */
try {
while (iter.hasNext()) {
Object nextValue = iter.next();
adder.call(calleeContext, set, nextValue);
}
return set;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
Aggregations