use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class Interpreter method EvaluateCall.
/**
* 12.3.4.2 Runtime Semantics: EvaluateCall( ref, arguments, tailPosition )<br>
* 12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
*
* @param ref
* the call base reference
* @param arguments
* the function call arguments
* @param directEval
* the direct eval flag
* @param cx
* the execution context
* @return the return value after applying the call operation
*/
private Object EvaluateCall(Object ref, List<Expression> arguments, boolean directEval, ExecutionContext cx) {
/* steps 1-2 (EvaluateCall) */
Object func = GetValue(ref, cx);
/* steps 3-4 (EvaluateCall) */
Object thisValue = UNDEFINED;
if (ref instanceof Reference) {
Reference<?, ?> rref = (Reference<?, ?>) ref;
if (rref.isPropertyReference()) {
thisValue = rref.getThisValue();
} else if (!(rref instanceof Reference.BindingReference)) {
assert rref instanceof Reference.IdentifierReference;
Reference.IdentifierReference<?> idref = (Reference.IdentifierReference<?>) rref;
ScriptObject newThisValue = idref.getBase().withBaseObject();
if (newThisValue != null) {
thisValue = newThisValue;
}
}
}
/* steps 1-2 (EvaluateDirectCall) */
Object[] argList = ArgumentListEvaluation(arguments, cx);
/* steps 3-4 (EvaluateDirectCall) */
Callable f = CheckCallable(func, cx);
/* [12.3.4.1 Runtime Semantics: Evaluation - step 3] */
if (directEval && IsBuiltinEval(ref, f, cx)) {
int evalFlags = EvalFlags.Direct.getValue();
if (strict) {
evalFlags |= EvalFlags.Strict.getValue();
}
evalFlags |= EvalFlags.toFlags(parserOptions);
return Eval.directEval(argList, cx, evalFlags);
}
if (directEval && ScriptRuntime.directEvalFallbackHook(cx) != null) {
argList = ScriptRuntime.directEvalFallbackArguments(f, cx, thisValue, argList);
thisValue = ScriptRuntime.directEvalFallbackThisArgument(cx);
f = ScriptRuntime.directEvalFallbackHook(cx);
}
/* steps 6, 9 (EvaluateDirectCall) */
return f.call(cx, thisValue, argList);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class Realm method SetDefaultGlobalBindings.
/**
* 8.2.4 SetDefaultGlobalBindings ( realmRec )
* <p>
* Initializes {@code [[globalObject]]} with the default properties of the Global Object.
*
* @param cx
* the execution context
* @param realm
* the realm instance
* @return the global object
*/
public static ScriptObject SetDefaultGlobalBindings(ExecutionContext cx, Realm realm) {
/* step 1 */
ScriptObject globalObject = realm.getGlobalObject();
GlobalObject globalTemplate = realm.getGlobalObjectTemplate();
assert globalObject != null && globalTemplate != null;
/* step 2 */
for (Object key : globalTemplate.ownPropertyKeys(cx)) {
Property prop = globalTemplate.getOwnProperty(cx, key);
if (prop != null) {
PropertyDescriptor desc = prop.toPropertyDescriptor();
DefinePropertyOrThrow(cx, globalObject, key, desc);
}
}
/* step 3 */
return globalObject;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ObjectEnvironmentRecord method getBindingValue.
/**
* 8.1.1.2.6 GetBindingValue(N,S)
*/
@Override
public Object getBindingValue(String name, boolean strict) {
/* step 1 (omitted) */
/* step 2 */
ScriptObject bindings = this.bindings;
/* steps 3-4 */
boolean foundBinding = HasProperty(cx, bindings, name);
/* step 5 */
if (!foundBinding) {
if (!strict) {
return UNDEFINED;
}
throw newReferenceError(cx, Messages.Key.UnresolvableReference, name);
}
/* step 6 */
return Get(cx, bindings, name);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ObjectEnvironmentRecord method hasBinding.
/**
* 8.1.1.2.1 HasBinding(N)
*/
@Override
public boolean hasBinding(String name) {
/* step 1 (omitted) */
/* step 2 */
ScriptObject bindings = this.bindings;
/* steps 3-4 */
boolean foundBinding = HasProperty(cx, bindings, name);
/* step 5 */
if (!foundBinding) {
return false;
}
/* step 6 */
if (!withEnvironment) {
return true;
}
/* steps 7-8 */
Object unscopables = Get(cx, bindings, BuiltinSymbol.unscopables.get());
/* step 9 */
if (Type.isObject(unscopables)) {
boolean blocked = ToBoolean(Get(cx, Type.objectValue(unscopables), name));
if (blocked) {
return false;
}
}
/* step 10 */
return true;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class Properties method createExternalClass.
private static Constructor createExternalClass(ExecutionContext cx, String className, Class<?> constructorProperties, Class<?> prototypeProperties) {
ObjectLayout ctorLayout = externalClassLayouts.get(constructorProperties);
ObjectLayout protoLayout = externalClassLayouts.get(prototypeProperties);
Converter converter = new Converter(cx);
ScriptObject[] objects = ScriptRuntime.getDefaultClassProto(cx);
ScriptObject constructorParent = objects[0];
OrdinaryObject proto = (OrdinaryObject) objects[1];
assert constructorParent == cx.getIntrinsic(Intrinsics.FunctionPrototype);
OrdinaryObject constructor = createConstructor(cx, className, proto, converter, protoLayout);
assert constructor instanceof Constructor;
if (ctorLayout.functions != null) {
createExternalFunctions(cx, constructor, ctorLayout, converter);
}
if (ctorLayout.accessors != null) {
createExternalAccessors(cx, constructor, ctorLayout, converter);
}
if (protoLayout.functions != null) {
createExternalFunctions(cx, proto, protoLayout, converter);
}
if (protoLayout.accessors != null) {
createExternalAccessors(cx, proto, protoLayout, converter);
}
return (Constructor) constructor;
}
Aggregations