use of com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor 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;
}
Aggregations