use of com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor in project es6draft by anba.
the class ObjectConstructor method ObjectDefineProperties.
/**
* 19.1.2.3.1 Runtime Semantics: ObjectDefineProperties ( O, Properties )
*
* @param cx
* the execution context
* @param o
* the script object
* @param properties
* the properties object
* @return the script object
*/
public static ScriptObject ObjectDefineProperties(ExecutionContext cx, Object o, Object properties) {
/* step 1 */
if (!Type.isObject(o)) {
throw newTypeError(cx, Messages.Key.NotObjectType);
}
ScriptObject obj = Type.objectValue(o);
/* steps 2-3 */
ScriptObject props = ToObject(cx, properties);
/* steps 4-5 */
List<?> keys = props.ownPropertyKeys(cx);
/* step 6 */
int initialSize = Math.min(32, keys.size());
ArrayList<PropertyDescriptor> descriptors = new ArrayList<>(initialSize);
ArrayList<Object> names = new ArrayList<>(initialSize);
/* step 7 */
for (Object nextKey : keys) {
Property propDesc = props.getOwnProperty(cx, nextKey);
if (propDesc != null && propDesc.isEnumerable()) {
Object descObj = Get(cx, props, nextKey);
PropertyDescriptor desc = ToPropertyDescriptor(cx, descObj);
descriptors.add(desc);
names.add(nextKey);
}
}
/* step 8 */
for (int i = 0, size = names.size(); i < size; ++i) {
Object p = names.get(i);
PropertyDescriptor desc = descriptors.get(i);
DefinePropertyOrThrow(cx, obj, p, desc);
}
/* step 9 */
return obj;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor in project es6draft by anba.
the class ScriptRuntime method evaluateMethodDecorators.
private static int evaluateMethodDecorators(OrdinaryObject object, ArrayList<Object> decorators, int start, ExecutionContext cx) {
int count = 0;
for (int i = start, size = decorators.size(); i < size; ++i, ++count) {
if (!(decorators.get(i) instanceof Callable))
break;
}
assert count > 0;
Object propKey = decorators.get(start + count);
Property property = object.getOwnProperty(cx, propKey);
// Current proposal uses `undefined` instead of the initial property descriptor in, and only
// in, object literals. We don't support this distinction between decorators for object and
// decorators for class methods.
Object desc = FromPropertyDescriptor(cx, property);
for (int i = start; i < start + count; ++i) {
Callable decorator = (Callable) decorators.get(i);
Object result = decorator.call(cx, UNDEFINED, object, propKey, desc);
if (Type.isObject(result)) {
// So, this means a bad decorator can mess up all following decorators?
// Example: `({ @(()=>({})) @((o,p,d)=>{ print(JSON.stringify(d)) }) m() {} })`
desc = result;
}
}
if (Type.isObject(desc)) {
PropertyDescriptor pdesc = ToPropertyDescriptor(cx, desc);
DefinePropertyOrThrow(cx, object, propKey, pdesc);
}
return count;
}
use of com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor in project es6draft by anba.
the class ProxyObject method validateGetOwnProperty.
private Property validateGetOwnProperty(ExecutionContext cx, ScriptObject target, Object trapResultObj, Property targetDesc) {
/* step 14 */
if (Type.isUndefined(trapResultObj)) {
if (targetDesc == null) {
return null;
}
if (!targetDesc.isConfigurable()) {
throw newTypeError(cx, Messages.Key.ProxyNotConfigurable);
}
boolean extensibleTarget = IsExtensible(cx, target);
if (!extensibleTarget) {
throw newTypeError(cx, Messages.Key.ProxyNotExtensible);
}
return null;
}
if (targetDesc != null) {
// need copy because of possible side-effects in IsExtensible()
targetDesc = targetDesc.clone();
}
/* steps 15-16 */
boolean extensibleTarget = IsExtensible(cx, target);
/* steps 17-18 */
PropertyDescriptor resultDesc = ToPropertyDescriptor(cx, trapResultObj);
/* step 19 */
CompletePropertyDescriptor(resultDesc);
/* step 20 */
boolean valid = IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc);
/* step 21 */
if (!valid) {
throw newTypeError(cx, Messages.Key.ProxyIncompatibleDescriptor);
}
/* step 22 */
if (!resultDesc.isConfigurable()) {
if (targetDesc == null || targetDesc.isConfigurable()) {
throw newTypeError(cx, Messages.Key.ProxyAbsentOrConfigurable);
}
}
/* step 23 */
return resultDesc.toProperty();
}
Aggregations