use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class WrapperProxy method get.
@Override
public Object get(ExecutionContext cx, String propertyKey, Object receiver) {
/* modified 9.1.8 [[Get]] (P, Receiver) */
Property desc = proxyTarget.getOwnProperty(cx, propertyKey);
if (desc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent == null) {
return UNDEFINED;
}
return parent.get(cx, propertyKey, receiver);
}
if (desc.isDataDescriptor()) {
return desc.getValue();
}
assert desc.isAccessorDescriptor();
Callable getter = desc.getGetter();
if (getter == null) {
return UNDEFINED;
}
return getter.call(cx, receiver);
}
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, long propertyKey, Object value, Object receiver) {
/* modified 9.1.9 [[Set] (P, V, Receiver) */
Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
if (ownDesc == null) {
// modified
ScriptObject parent = getPrototype();
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;
}
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();
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.Property in project es6draft by anba.
the class Properties method createAliasFunction.
private static void createAliasFunction(Realm realm, OrdinaryObject target, AliasFunctionLayout layout) {
Object propertyKey = layout.propertyKey;
Property fun;
if (propertyKey instanceof String) {
fun = target.lookupOwnProperty((String) propertyKey);
} else {
fun = target.lookupOwnProperty(((BuiltinSymbol) propertyKey).get());
}
assert fun != null : "property not found: " + propertyKey;
defineProperty(target, layout, valueProperty(layout, fun.getValue()));
}
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));
}
}
Aggregations