use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class Properties method createAccessor.
private static void createAccessor(Realm realm, OrdinaryObject target, AccessorLayout layout) {
int arity = accessorArity(layout.type);
NativeFunction fun = new NativeFunction(realm, layout.accessorName, arity, layout.nativeId, layout.methodHandle);
Property accessorProperty = lookupOwnProperty(target, layout);
if (accessorProperty == null) {
defineProperty(target, layout, accessorProperty(layout, fun));
} else {
assert accessorProperty.isAccessorDescriptor();
assert accessorProperty.isConfigurable() == layout.configurable();
assert accessorProperty.isEnumerable() == layout.enumerable();
assert (layout.type == Accessor.Type.Getter ? accessorProperty.getGetter() : accessorProperty.getSetter()) == null;
accessorProperty.apply(accessorPropertyDescriptor(layout, fun));
}
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class ClassOperations method DefineField.
public static void DefineField(Object fieldName, Object initValue, ExecutionContext cx) {
EnvironmentRecord envRec = cx.getThisEnvironment();
assert envRec instanceof FunctionEnvironmentRecord;
FunctionEnvironmentRecord fEnvRec = (FunctionEnvironmentRecord) envRec;
assert fEnvRec.getThisBindingStatus() == FunctionEnvironmentRecord.ThisBindingStatus.Initialized;
assert fEnvRec.getThisValue() instanceof ScriptObject;
ScriptObject receiver = (ScriptObject) fEnvRec.getThisValue();
if (fieldName instanceof PrivateName) {
PrivateName name = (PrivateName) fieldName;
Property desc = new Property(initValue, true, false, false);
privateFieldDefine(cx, receiver, name, desc);
} else {
assert IsPropertyKey(fieldName);
CreateDataPropertyOrThrow(cx, receiver, fieldName, initValue);
}
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class ClassOperations method InitializeInstanceFields.
public static void InitializeInstanceFields(ScriptObject thisValue, OrdinaryConstructorFunction constructor, ExecutionContext cx) {
Property initializerDesc = constructor.get(CLASS_INSTANCE_INITIALIZER);
if (initializerDesc != null) {
assert initializerDesc.isDataDescriptor();
Object initializer = initializerDesc.getValue();
assert initializer instanceof OrdinaryFunction;
OrdinaryFunction initializerFn = (OrdinaryFunction) initializer;
Property instanceMethods = initializerFn.get(INSTANCE_METHODS);
assert instanceMethods != null && instanceMethods.isDataDescriptor();
if (instanceMethods.getValue() != null) {
initializeInstanceMethods(thisValue, arrayValue(instanceMethods, InstanceMethod[].class), cx);
}
// Call the instance fields initializer.
Property classFields = initializerFn.get(CLASS_FIELDS);
assert classFields != null && classFields.isDataDescriptor();
if (classFields.getValue() != null) {
initializerFn.call(cx, thisValue);
}
}
}
use of com.github.anba.es6draft.runtime.types.Property 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();
OrdinaryObject globalProperties = realm.getGlobalPropertiesObject();
assert globalObject != null && globalProperties != null;
/* step 2 */
for (Object key : globalProperties.ownPropertyKeys(cx)) {
Property prop = globalProperties.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.Property in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, Symbol propertyKey, Object value, Object receiver) {
Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
if (ownDesc == null) {
ScriptObject parent = getPrototypeOf(cx);
if (parent != null) {
return parent.set(cx, propertyKey, value, receiver);
} else {
ownDesc = new Property(UNDEFINED, true, true, true);
}
}
if (ownDesc.isDataDescriptor()) {
if (!ownDesc.isWritable()) {
return false;
}
if (!Type.isObject(receiver)) {
return false;
}
ScriptObject _receiver = Type.objectValue(receiver);
Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
if (existingDescriptor != null) {
PropertyDescriptor valueDesc = new PropertyDescriptor(value);
return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
} else {
return CreateDataProperty(cx, _receiver, propertyKey, value);
}
}
assert ownDesc.isAccessorDescriptor();
Callable setter = ownDesc.getSetter();
if (setter == null) {
return false;
}
setter.call(cx, receiver, value);
return true;
}
Aggregations