Search in sources :

Example 36 with ScriptObject

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

the class ArrayBufferConstructor method AllocateArrayBuffer.

/**
     * 24.1.1.1 AllocateArrayBuffer( constructor, byteLength )
     * 
     * @param cx
     *            the execution context
     * @param constructor
     *            the constructor function
     * @param byteLength
     *            the buffer byte length
     * @return the new array buffer object
     */
public static ArrayBufferObject AllocateArrayBuffer(ExecutionContext cx, Constructor constructor, long byteLength) {
    /* steps 1-2 */
    ScriptObject proto = GetPrototypeFromConstructor(cx, constructor, Intrinsics.ArrayBufferPrototype);
    /* step 3 */
    assert byteLength >= 0;
    /* steps 4-5 */
    ByteBuffer block = CreateByteDataBlock(cx, byteLength);
    /* steps 1-2, 6-8 */
    return new ArrayBufferObject(cx.getRealm(), block, byteLength, proto);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ByteBuffer(java.nio.ByteBuffer)

Example 37 with ScriptObject

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

the class ModuleSemantics method GetModuleNamespace.

/**
     * 15.2.1.18 Runtime Semantics: GetModuleNamespace( module )
     * 
     * @param cx
     *            the execution context
     * @param module
     *            the module record
     * @return the module namespace object
     * @throws IOException
     *             if there was any I/O error
     * @throws MalformedNameException
     *             if any imported module request cannot be normalized
     * @throws ResolutionException
     *             if any export binding cannot be resolved
     */
public static ScriptObject GetModuleNamespace(ExecutionContext cx, ModuleRecord module) throws IOException, MalformedNameException, ResolutionException {
    /* step 1 (not applicable) */
    /* step 2 */
    ScriptObject namespace = module.getNamespace();
    /* step 3 */
    if (namespace == null) {
        /* steps 3.a-b */
        Set<String> exportedNames = module.getExportedNames(new HashSet<>());
        /* step 3.c */
        Set<String> unambiguousNames = new HashSet<>();
        /* step 3.d */
        for (String name : exportedNames) {
            ModuleExport resolution = module.resolveExport(name, new HashMap<>(), new HashSet<>());
            if (resolution == null) {
                throw new ResolutionException(Messages.Key.ModulesUnresolvedExport, name);
            }
            if (!resolution.isAmbiguous()) {
                unambiguousNames.add(name);
            }
        }
        /* step 3.e */
        namespace = ModuleNamespaceCreate(cx, module, unambiguousNames);
    }
    /* step 4 */
    return namespace;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) HashSet(java.util.HashSet)

Example 38 with ScriptObject

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

the class PropertiesTest method createCustomClassNoArgs.

@Test
public void createCustomClassNoArgs() {
    Constructor customClass = Properties.createClass(cx, "CustomClassNoArgs", CustomClassNoArgs.ConstructorProperties.class, CustomClassNoArgs.PrototypeProperties.class);
    ScriptObject object = customClass.construct(cx, customClass);
    assertNotNull(object);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) OrdinaryCreateFromConstructor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor) Test(org.junit.Test)

Example 39 with ScriptObject

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

the class PropertiesTest method createCustomClassWithSubclass.

@Test
public void createCustomClassWithSubclass() {
    Constructor customClass = Properties.createClass(cx, "CustomClassWithSubclass", CustomClassWithSubclass.ConstructorProperties.class, CustomClassWithSubclass.PrototypeProperties.class);
    ScriptObject object = customClass.construct(cx, customClass);
    assertNotNull(object);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) OrdinaryCreateFromConstructor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor) Test(org.junit.Test)

Example 40 with ScriptObject

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

the class ScriptEngineImpl method invoke.

private Object invoke(ScriptObject thisValue, String name, Object... args) throws javax.script.ScriptException, NoSuchMethodException {
    Realm realm = getEvalRealm(context);
    RuntimeContext runtimeContext = realm.getWorld().getContext();
    Console console = runtimeContext.getConsole();
    runtimeContext.setConsole(new ScriptingConsole(context));
    try {
        Object[] arguments = TypeConverter.fromJava(args);
        if (thisValue == null) {
            thisValue = realm.getGlobalThis();
        }
        ExecutionContext cx = realm.defaultContext();
        Object func = thisValue.get(cx, name, thisValue);
        if (!IsCallable(func)) {
            throw new NoSuchMethodException(name);
        }
        Object result = ((Callable) func).call(cx, thisValue, arguments);
        realm.getWorld().runEventLoop();
        return TypeConverter.toJava(result);
    } catch (ScriptException e) {
        throw new javax.script.ScriptException(e);
    } finally {
        runtimeContext.setConsole(console);
    }
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newScriptingExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext) Console(com.github.anba.es6draft.runtime.internal.Console) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) Realm(com.github.anba.es6draft.runtime.Realm) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) 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