Search in sources :

Example 1 with FromPropertyDescriptor

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;
}
Also used : AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) ToPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor) FromPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor) GeneratorObject(com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject) TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) CompiledObject(com.github.anba.es6draft.compiler.CompiledObject)

Aggregations

CompiledObject (com.github.anba.es6draft.compiler.CompiledObject)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 GeneratorObject (com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject)1 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)1 FromPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.FromPropertyDescriptor)1 ToPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.ToPropertyDescriptor)1