Search in sources :

Example 31 with Callable

use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.

the class ProxyObject method enumerate.

/**
     * 9.5.11 [[Enumerate]] ()
     */
@Override
public ScriptObject enumerate(ExecutionContext cx) {
    /* steps 1-3 */
    ScriptObject handler = getProxyHandler(cx);
    /* step 4 */
    ScriptObject target = getProxyTarget();
    /* steps 5-6 */
    Callable trap = GetMethod(cx, handler, "enumerate");
    /* step 7 */
    if (trap == null) {
        return target.enumerate(cx);
    }
    /* steps 8-9 */
    Object trapResult = trap.call(cx, handler, target);
    /* step 10 */
    if (!Type.isObject(trapResult)) {
        throw newTypeError(cx, Messages.Key.ProxyNotObject);
    }
    /* step 11 */
    return Type.objectValue(trapResult);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 32 with Callable

use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.

the class WrapperProxy method get.

@Override
public Object get(ExecutionContext cx, Symbol 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);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 33 with Callable

use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.

the class WrapperProxy method set.

@Override
public boolean set(ExecutionContext cx, String 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;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 34 with Callable

use of com.github.anba.es6draft.runtime.types.Callable 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);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Property(com.github.anba.es6draft.runtime.types.Property) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 35 with Callable

use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.

the class ConsoleObject method createConsole.

/**
     * Creates a new {@code console} object.
     * 
     * @param realm
     *            the realm instance
     * @return the console object
     * @throws IOException
     *             if there was any I/O error
     * @throws URISyntaxException
     *             the URL is not a valid URI
     * @throws MalformedNameException
     *             if any imported module request cannot be normalized
     * @throws ResolutionException
     *             if any export binding cannot be resolved
     */
public static ScriptObject createConsole(Realm realm) throws IOException, URISyntaxException, MalformedNameException, ResolutionException {
    ExecutionContext cx = realm.defaultContext();
    ModuleRecord module = NativeCode.loadModule(realm, "console.jsm");
    ScriptObject console = NativeCode.getModuleExport(module, "default", ScriptObject.class);
    Callable inspectFn = Properties.createFunction(cx, new InspectFunction(), InspectFunction.class);
    CreateMethodProperty(cx, console, "_inspect", inspectFn);
    return console;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

Callable (com.github.anba.es6draft.runtime.types.Callable)59 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)49 Property (com.github.anba.es6draft.runtime.types.Property)26 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)10 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)7 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)7 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)6 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 ArrayList (java.util.ArrayList)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)2 Realm (com.github.anba.es6draft.runtime.Realm)2 PromiseObject (com.github.anba.es6draft.runtime.objects.promise.PromiseObject)2 com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 Abrupt (com.github.anba.es6draft.ast.AbruptNode.Abrupt)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 ModuleScope (com.github.anba.es6draft.ast.scope.ModuleScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 ScriptScope (com.github.anba.es6draft.ast.scope.ScriptScope)1