Search in sources :

Example 11 with ScriptObject

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

the class Properties method createExternalValues.

private static <OWNER> void createExternalValues(ExecutionContext cx, ScriptObject target, OWNER owner, ObjectLayout layout, Converter converter) {
    for (Entry<Value, Object> entry : layout.values.entrySet()) {
        Value val = entry.getKey();
        assert entry.getValue() instanceof MethodHandle;
        Object value = resolveValue(cx, converter, (MethodHandle) entry.getValue(), owner);
        defineProperty(cx, target, val.name(), val.symbol(), val.attributes(), value);
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 12 with ScriptObject

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

the class WrapperProxy method hasProperty.

@Override
public boolean hasProperty(ExecutionContext cx, Symbol propertyKey) {
    /* modified 9.1.7 [[HasProperty]](P) */
    boolean hasOwn = HasOwnProperty(cx, proxyTarget, propertyKey);
    if (hasOwn) {
        return true;
    }
    // modified
    ScriptObject parent = getPrototype();
    if (parent != null) {
        return parent.hasProperty(cx, propertyKey);
    }
    return false;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject)

Example 13 with ScriptObject

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

the class NodeModuleRecord method instantiate.

@Override
public void instantiate() {
    assert realm != null : "module is not linked";
    if (environment == null) {
        ScriptObject exports = getModuleExportsOrEmpty();
        environment = newObjectEnvironment(exports, realm.getGlobalEnv());
        // Compile the module.
        ExecutionContext cx = realm.defaultContext();
        Object compile = Get(cx, moduleObject, "compile");
        Callable moduleFn = CreateDynamicFunction(cx, source, function.getFunction());
        Callable requireFn = NodeFunctions.createRequireFunction(this);
        Call(cx, compile, moduleObject, moduleFn, requireFn);
        // Create the module bindings.
        ScriptObject currentExports = getModuleExportsOrEmpty();
        if (currentExports != exports) {
            // Module exports property has changed, update environment with new bindings.
            environment = newObjectEnvironment(currentExports, realm.getGlobalEnv());
        }
        exportedNames = ownNames(currentExports);
        instantiated = true;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 14 with ScriptObject

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

the class ShellFunctions method evalScript.

/**
     * shell-function: {@code evalScript(sourceString, [options])}
     * 
     * @param cx
     *            the execution context
     * @param sourceString
     *            the source string
     * @param options
     *            the options object (optional)
     * @return the evaluation result
     */
@Function(name = "evalScript", arity = 1)
public Object evalScript(ExecutionContext cx, String sourceString, Object options) {
    String name = "";
    int line = 1;
    Realm realm = cx.getRealm();
    if (Type.isObject(options)) {
        ScriptObject opts = Type.objectValue(options);
        Object fileName = Get(cx, opts, "fileName");
        if (!Type.isUndefined(fileName)) {
            name = ToFlatString(cx, fileName);
        }
        Object lineNumber = Get(cx, opts, "lineNumber");
        if (!Type.isUndefined(lineNumber)) {
            line = ToInt32(cx, lineNumber);
        }
        Object g = Get(cx, opts, "global");
        if (!Type.isUndefined(g)) {
            if (!(g instanceof GlobalObject)) {
                throw Errors.newError(cx, "invalid global argument");
            }
            realm = ((GlobalObject) g).getRealm();
        }
        Object r = Get(cx, opts, "realm");
        if (!Type.isUndefined(r)) {
            if (!(r instanceof RealmObject)) {
                throw Errors.newError(cx, "invalid realm argument");
            }
            realm = ((RealmObject) r).getRealm();
        }
    }
    Source source = new Source(name, line);
    Script script = realm.getScriptLoader().script(source, sourceString);
    return script.evaluate(realm);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) GlobalObject(com.github.anba.es6draft.runtime.objects.GlobalObject) SharedFunctions.relativePathToScript(com.github.anba.es6draft.repl.global.SharedFunctions.relativePathToScript) SharedFunctions.loadScript(com.github.anba.es6draft.repl.global.SharedFunctions.loadScript) Script(com.github.anba.es6draft.Script) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) WeakMapObject(com.github.anba.es6draft.runtime.objects.collection.WeakMapObject) ErrorObject(com.github.anba.es6draft.runtime.objects.ErrorObject) GlobalObject(com.github.anba.es6draft.runtime.objects.GlobalObject) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) ArrayBufferObject(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferObject) RealmObject(com.github.anba.es6draft.runtime.objects.reflect.RealmObject) RealmObject(com.github.anba.es6draft.runtime.objects.reflect.RealmObject) ToFlatString(com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString) Realm(com.github.anba.es6draft.runtime.Realm) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource) Source(com.github.anba.es6draft.runtime.internal.Source) Function(com.github.anba.es6draft.runtime.internal.Properties.Function)

Example 15 with ScriptObject

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

the class WrapperProxy method get.

@Override
public Object get(ExecutionContext cx, long 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)

Aggregations

ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)129 Callable (com.github.anba.es6draft.runtime.types.Callable)43 Property (com.github.anba.es6draft.runtime.types.Property)32 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)26 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)21 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)16 Constructor (com.github.anba.es6draft.runtime.types.Constructor)11 Realm (com.github.anba.es6draft.runtime.Realm)9 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)9 ParserException (com.github.anba.es6draft.parser.ParserException)8 CompilationException (com.github.anba.es6draft.compiler.CompilationException)7 Source (com.github.anba.es6draft.runtime.internal.Source)7 ArrayList (java.util.ArrayList)7 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)6 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)6 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)6 Test (org.junit.Test)6 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)5 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)4 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)4