Implementation of Fn.Presenter using Truffle's PolyglotEngine Truffle
authorJaroslav Tulach <jtulach@netbeans.org>
Fri, 01 Jul 2016 23:34:06 +0200
branchTruffle
changeset 109447cd2110ed8d
parent 1093 7d3990311255
child 1095 1dbcc395b2e5
Implementation of Fn.Presenter using Truffle's PolyglotEngine
boot-truffle/pom.xml
boot-truffle/src/main/java/net/java/html/boot/truffle/JavaArray.java
boot-truffle/src/main/java/net/java/html/boot/truffle/JavaObject.java
boot-truffle/src/main/java/net/java/html/boot/truffle/JavaValue.java
boot-truffle/src/main/java/net/java/html/boot/truffle/TrufflePresenter.java
boot-truffle/src/main/java/net/java/html/boot/truffle/package.html
boot-truffle/src/test/java/net/java/html/boot/truffle/SingleCase.java
boot-truffle/src/test/java/net/java/html/boot/truffle/TruffleJavaScriptTest.java
pom.xml
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/boot-truffle/pom.xml	Fri Jul 01 23:34:06 2016 +0200
     1.3 @@ -0,0 +1,119 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     1.6 +    <modelVersion>4.0.0</modelVersion>
     1.7 +    <parent>
     1.8 +        <groupId>org.netbeans.html</groupId>
     1.9 +        <artifactId>pom</artifactId>
    1.10 +        <version>2.0-SNAPSHOT</version>
    1.11 +    </parent>
    1.12 +    <name>Presenter via Truffle</name>
    1.13 +    <artifactId>net.java.html.boot.truffle</artifactId>
    1.14 +    <version>2.0-SNAPSHOT</version>
    1.15 +    <packaging>bundle</packaging>
    1.16 +    <properties>
    1.17 +        <netbeans.compile.on.save>NONE</netbeans.compile.on.save>
    1.18 +        <publicPackages>net.java.html.boot.truffle</publicPackages>
    1.19 +    </properties>
    1.20 +    <build>
    1.21 +      <plugins>
    1.22 +          <plugin>
    1.23 +              <groupId>org.apache.felix</groupId>
    1.24 +              <artifactId>maven-bundle-plugin</artifactId>
    1.25 +              <extensions>true</extensions>
    1.26 +              <configuration>
    1.27 +                  <instructions>
    1.28 +                      <Export-Package>${publicPackages}</Export-Package>
    1.29 +                      <Bundle-SymbolicName>net.java.html.boot.truffle</Bundle-SymbolicName>
    1.30 +                  </instructions>
    1.31 +              </configuration>
    1.32 +          </plugin>
    1.33 +          <plugin>
    1.34 +              <groupId>org.netbeans.html</groupId>
    1.35 +              <artifactId>html4j-maven-plugin</artifactId>
    1.36 +          </plugin>
    1.37 +         <plugin>
    1.38 +            <groupId>org.apache.maven.plugins</groupId>
    1.39 +            <artifactId>maven-compiler-plugin</artifactId>
    1.40 +            <version>2.3.2</version>
    1.41 +            <configuration>
    1.42 +               <source>1.7</source>
    1.43 +               <target>1.7</target>
    1.44 +            </configuration>
    1.45 +         </plugin>
    1.46 +      </plugins>
    1.47 +    </build>
    1.48 +    <dependencies>
    1.49 +        <dependency>
    1.50 +            <groupId>org.netbeans.api</groupId>
    1.51 +            <artifactId>org-openide-util-lookup</artifactId>
    1.52 +            <scope>provided</scope>
    1.53 +        </dependency>
    1.54 +        <dependency>
    1.55 +            <groupId>com.oracle.truffle</groupId>
    1.56 +            <artifactId>truffle-api</artifactId>
    1.57 +            <version>0.14</version>
    1.58 +        </dependency>
    1.59 +        <dependency>
    1.60 +            <groupId>com.oracle.truffle</groupId>
    1.61 +            <artifactId>truffle-dsl-processor</artifactId>
    1.62 +            <version>0.14</version>
    1.63 +            <scope>provided</scope>
    1.64 +        </dependency>
    1.65 +        <dependency>
    1.66 +            <groupId>org.netbeans.html</groupId>
    1.67 +            <artifactId>net.java.html.boot</artifactId>
    1.68 +            <version>${project.version}</version>
    1.69 +            <type>jar</type>
    1.70 +        </dependency>
    1.71 +        <dependency>
    1.72 +            <groupId>org.testng</groupId>
    1.73 +            <artifactId>testng</artifactId>
    1.74 +            <scope>test</scope>
    1.75 +        </dependency>
    1.76 +        <dependency>
    1.77 +            <groupId>${project.groupId}</groupId>
    1.78 +            <artifactId>net.java.html.json.tck</artifactId>
    1.79 +            <version>${project.version}</version>
    1.80 +            <scope>test</scope>
    1.81 +        </dependency>
    1.82 +        <dependency>
    1.83 +            <groupId>org.glassfish.grizzly</groupId>
    1.84 +            <artifactId>grizzly-http-server</artifactId>
    1.85 +            <version>${grizzly.version}</version>
    1.86 +            <scope>test</scope>
    1.87 +        </dependency>
    1.88 +        <dependency>
    1.89 +            <groupId>org.glassfish.grizzly</groupId>
    1.90 +            <artifactId>grizzly-websockets-server</artifactId>
    1.91 +            <version>${grizzly.version}</version>
    1.92 +            <scope>test</scope>
    1.93 +            <type>jar</type>
    1.94 +        </dependency>
    1.95 +        <dependency>
    1.96 +            <groupId>org.glassfish.grizzly</groupId>
    1.97 +            <artifactId>grizzly-http-servlet</artifactId>
    1.98 +            <version>${grizzly.version}</version>
    1.99 +            <scope>test</scope>
   1.100 +        </dependency>    
   1.101 +        <dependency>
   1.102 +            <groupId>javax.servlet</groupId>
   1.103 +            <artifactId>javax.servlet-api</artifactId>
   1.104 +            <scope>test</scope>
   1.105 +            <version>3.1.0</version>
   1.106 +        </dependency>
   1.107 +        <dependency>
   1.108 +            <groupId>org.netbeans.html</groupId>
   1.109 +            <artifactId>ko4j</artifactId>
   1.110 +            <version>${project.version}</version>
   1.111 +            <scope>test</scope>
   1.112 +            <type>jar</type>
   1.113 +        </dependency>
   1.114 +        <dependency>
   1.115 +            <groupId>${project.groupId}</groupId>
   1.116 +            <artifactId>ko-ws-tyrus</artifactId>
   1.117 +            <version>${project.version}</version>
   1.118 +            <scope>test</scope>
   1.119 +            <type>jar</type>
   1.120 +        </dependency>
   1.121 +    </dependencies>
   1.122 +</project>
   1.123 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/boot-truffle/src/main/java/net/java/html/boot/truffle/JavaArray.java	Fri Jul 01 23:34:06 2016 +0200
     2.3 @@ -0,0 +1,102 @@
     2.4 +/**
     2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 + *
     2.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     2.8 + *
     2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    2.10 + * Other names may be trademarks of their respective owners.
    2.11 + *
    2.12 + * The contents of this file are subject to the terms of either the GNU
    2.13 + * General Public License Version 2 only ("GPL") or the Common
    2.14 + * Development and Distribution License("CDDL") (collectively, the
    2.15 + * "License"). You may not use this file except in compliance with the
    2.16 + * License. You can obtain a copy of the License at
    2.17 + * http://www.netbeans.org/cddl-gplv2.html
    2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    2.19 + * specific language governing permissions and limitations under the
    2.20 + * License.  When distributing the software, include this License Header
    2.21 + * Notice in each file and include the License file at
    2.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    2.23 + * particular file as subject to the "Classpath" exception as provided
    2.24 + * by Oracle in the GPL Version 2 section of the License file that
    2.25 + * accompanied this code. If applicable, add the following below the
    2.26 + * License Header, with the fields enclosed by brackets [] replaced by
    2.27 + * your own identifying information:
    2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    2.29 + *
    2.30 + * Contributor(s):
    2.31 + *
    2.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    2.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    2.34 + *
    2.35 + * If you wish your version of this file to be governed by only the CDDL
    2.36 + * or only the GPL Version 2, indicate your decision by adding
    2.37 + * "[Contributor] elects to include this software in this distribution
    2.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    2.39 + * single choice of license, a recipient has the option to distribute
    2.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    2.41 + * to extend the choice of license to its licensees as provided above.
    2.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    2.43 + * Version 2 license, then the option applies only if the new code is
    2.44 + * made subject to such option by the copyright holder.
    2.45 + */
    2.46 +package net.java.html.boot.truffle;
    2.47 +
    2.48 +import com.oracle.truffle.api.interop.ForeignAccess;
    2.49 +import com.oracle.truffle.api.interop.MessageResolution;
    2.50 +import com.oracle.truffle.api.interop.Resolve;
    2.51 +import com.oracle.truffle.api.interop.TruffleObject;
    2.52 +import com.oracle.truffle.api.nodes.Node;
    2.53 +import java.lang.reflect.Array;
    2.54 +
    2.55 +@MessageResolution(receiverType = JavaArray.class, language = TrufflePresenter.JavaLang.class)
    2.56 +final class JavaArray extends JavaValue implements TruffleObject {
    2.57 +    final TrufflePresenter.WrapArray wrap;
    2.58 +    final Object arr;
    2.59 +
    2.60 +    public JavaArray(TrufflePresenter.WrapArray wrap, Object arr) {
    2.61 +        this.arr = arr;
    2.62 +        this.wrap = wrap;
    2.63 +    }
    2.64 +
    2.65 +    @Override
    2.66 +    public ForeignAccess getForeignAccess() {
    2.67 +        return JavaArrayForeign.ACCESS;
    2.68 +    }
    2.69 +
    2.70 +    @Override
    2.71 +    public Object get() {
    2.72 +        return arr;
    2.73 +    }
    2.74 +
    2.75 +    static boolean isInstance(TruffleObject obj) {
    2.76 +        return obj instanceof JavaArray;
    2.77 +    }
    2.78 +
    2.79 +    static boolean isArray(Object obj) {
    2.80 +        return obj != null && obj.getClass().getComponentType() != null;
    2.81 +    }
    2.82 +
    2.83 +    @Resolve(message = "READ")
    2.84 +    static abstract class ReadNode extends Node {
    2.85 +        protected Object access(JavaArray arr, int index) {
    2.86 +            Object obj = Array.get(arr.arr, index);
    2.87 +            return toJavaScript(obj, arr.wrap);
    2.88 +        }
    2.89 +    }
    2.90 +
    2.91 +    @Resolve(message = "HAS_SIZE")
    2.92 +    static abstract class HasSizeNode extends Node {
    2.93 +        protected boolean access(JavaArray arr) {
    2.94 +            return true;
    2.95 +        }
    2.96 +    }
    2.97 +
    2.98 +    @Resolve(message = "GET_SIZE")
    2.99 +    static abstract class GetSizeNode extends Node {
   2.100 +        protected int access(JavaArray arr) {
   2.101 +            return Array.getLength(arr.arr);
   2.102 +        }
   2.103 +    }
   2.104 +
   2.105 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/boot-truffle/src/main/java/net/java/html/boot/truffle/JavaObject.java	Fri Jul 01 23:34:06 2016 +0200
     3.3 @@ -0,0 +1,82 @@
     3.4 +/**
     3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 + *
     3.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     3.8 + *
     3.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    3.10 + * Other names may be trademarks of their respective owners.
    3.11 + *
    3.12 + * The contents of this file are subject to the terms of either the GNU
    3.13 + * General Public License Version 2 only ("GPL") or the Common
    3.14 + * Development and Distribution License("CDDL") (collectively, the
    3.15 + * "License"). You may not use this file except in compliance with the
    3.16 + * License. You can obtain a copy of the License at
    3.17 + * http://www.netbeans.org/cddl-gplv2.html
    3.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    3.19 + * specific language governing permissions and limitations under the
    3.20 + * License.  When distributing the software, include this License Header
    3.21 + * Notice in each file and include the License file at
    3.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    3.23 + * particular file as subject to the "Classpath" exception as provided
    3.24 + * by Oracle in the GPL Version 2 section of the License file that
    3.25 + * accompanied this code. If applicable, add the following below the
    3.26 + * License Header, with the fields enclosed by brackets [] replaced by
    3.27 + * your own identifying information:
    3.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    3.29 + *
    3.30 + * Contributor(s):
    3.31 + *
    3.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    3.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    3.34 + *
    3.35 + * If you wish your version of this file to be governed by only the CDDL
    3.36 + * or only the GPL Version 2, indicate your decision by adding
    3.37 + * "[Contributor] elects to include this software in this distribution
    3.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    3.39 + * single choice of license, a recipient has the option to distribute
    3.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    3.41 + * to extend the choice of license to its licensees as provided above.
    3.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    3.43 + * Version 2 license, then the option applies only if the new code is
    3.44 + * made subject to such option by the copyright holder.
    3.45 + */
    3.46 +package net.java.html.boot.truffle;
    3.47 +
    3.48 +import com.oracle.truffle.api.interop.ForeignAccess;
    3.49 +import com.oracle.truffle.api.interop.MessageResolution;
    3.50 +import com.oracle.truffle.api.interop.Resolve;
    3.51 +import com.oracle.truffle.api.interop.TruffleObject;
    3.52 +import com.oracle.truffle.api.nodes.Node;
    3.53 +
    3.54 +@MessageResolution(receiverType = JavaObject.class, language = TrufflePresenter.JavaLang.class)
    3.55 +final class JavaObject extends JavaValue implements TruffleObject {
    3.56 +    final Object obj;
    3.57 +
    3.58 +    JavaObject(Object obj) {
    3.59 +        this.obj = obj;
    3.60 +    }
    3.61 +
    3.62 +
    3.63 +    @Override
    3.64 +    public ForeignAccess getForeignAccess() {
    3.65 +        return JavaObjectForeign.ACCESS;
    3.66 +    }
    3.67 +
    3.68 +    public static boolean isInstance(TruffleObject obj) {
    3.69 +        return obj instanceof JavaObject;
    3.70 +    }
    3.71 +
    3.72 +    @Override
    3.73 +    public Object get() {
    3.74 +        return obj;
    3.75 +    }
    3.76 +
    3.77 +    @Resolve(message = "HAS_SIZE")
    3.78 +    static abstract class NoSizeNode extends Node {
    3.79 +
    3.80 +        protected boolean access(JavaObject obj) {
    3.81 +            return false;
    3.82 +        }
    3.83 +    }
    3.84 +
    3.85 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/boot-truffle/src/main/java/net/java/html/boot/truffle/JavaValue.java	Fri Jul 01 23:34:06 2016 +0200
     4.3 @@ -0,0 +1,91 @@
     4.4 +/**
     4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 + *
     4.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     4.8 + *
     4.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    4.10 + * Other names may be trademarks of their respective owners.
    4.11 + *
    4.12 + * The contents of this file are subject to the terms of either the GNU
    4.13 + * General Public License Version 2 only ("GPL") or the Common
    4.14 + * Development and Distribution License("CDDL") (collectively, the
    4.15 + * "License"). You may not use this file except in compliance with the
    4.16 + * License. You can obtain a copy of the License at
    4.17 + * http://www.netbeans.org/cddl-gplv2.html
    4.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    4.19 + * specific language governing permissions and limitations under the
    4.20 + * License.  When distributing the software, include this License Header
    4.21 + * Notice in each file and include the License file at
    4.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    4.23 + * particular file as subject to the "Classpath" exception as provided
    4.24 + * by Oracle in the GPL Version 2 section of the License file that
    4.25 + * accompanied this code. If applicable, add the following below the
    4.26 + * License Header, with the fields enclosed by brackets [] replaced by
    4.27 + * your own identifying information:
    4.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    4.29 + *
    4.30 + * Contributor(s):
    4.31 + *
    4.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    4.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    4.34 + *
    4.35 + * If you wish your version of this file to be governed by only the CDDL
    4.36 + * or only the GPL Version 2, indicate your decision by adding
    4.37 + * "[Contributor] elects to include this software in this distribution
    4.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.39 + * single choice of license, a recipient has the option to distribute
    4.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    4.41 + * to extend the choice of license to its licensees as provided above.
    4.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    4.43 + * Version 2 license, then the option applies only if the new code is
    4.44 + * made subject to such option by the copyright holder.
    4.45 + */
    4.46 +package net.java.html.boot.truffle;
    4.47 +
    4.48 +import com.oracle.truffle.api.interop.TruffleObject;
    4.49 +import com.oracle.truffle.api.interop.java.JavaInterop;
    4.50 +
    4.51 +abstract class JavaValue {
    4.52 +    public abstract Object get();
    4.53 +
    4.54 +    static Object toJavaScript(Object conv, TrufflePresenter.WrapArray wrap) {
    4.55 +        if (conv instanceof TruffleObject) {
    4.56 +            return conv;
    4.57 +        }
    4.58 +        if (JavaArray.isArray(conv)) {
    4.59 +            conv = wrap.copy(new JavaArray(wrap, conv));
    4.60 +        }
    4.61 +        if (conv instanceof Character) {
    4.62 +            conv = (int) (Character) conv;
    4.63 +        }
    4.64 +        if (conv == null || conv.getClass().getSimpleName().equals("$JsCallbacks$")) { // NOI18N
    4.65 +            conv = JavaInterop.asTruffleObject(conv);
    4.66 +        } else if (!isJSReady(conv)) {
    4.67 +            conv = new JavaObject(conv);
    4.68 +        }
    4.69 +        return conv;
    4.70 +    }
    4.71 +
    4.72 +    private static boolean isJSReady(Object obj) {
    4.73 +        if (obj == null) {
    4.74 +            return true;
    4.75 +        }
    4.76 +        if (obj instanceof String) {
    4.77 +            return true;
    4.78 +        }
    4.79 +        if (obj instanceof Number) {
    4.80 +            return true;
    4.81 +        }
    4.82 +        if (obj instanceof Character) {
    4.83 +            return true;
    4.84 +        }
    4.85 +        if (obj instanceof Boolean) {
    4.86 +            return true;
    4.87 +        }
    4.88 +        if (obj instanceof TruffleObject) {
    4.89 +            return true;
    4.90 +        }
    4.91 +        return false;
    4.92 +    }
    4.93 +
    4.94 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/boot-truffle/src/main/java/net/java/html/boot/truffle/TrufflePresenter.java	Fri Jul 01 23:34:06 2016 +0200
     5.3 @@ -0,0 +1,272 @@
     5.4 +/**
     5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 + *
     5.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     5.8 + *
     5.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    5.10 + * Other names may be trademarks of their respective owners.
    5.11 + *
    5.12 + * The contents of this file are subject to the terms of either the GNU
    5.13 + * General Public License Version 2 only ("GPL") or the Common
    5.14 + * Development and Distribution License("CDDL") (collectively, the
    5.15 + * "License"). You may not use this file except in compliance with the
    5.16 + * License. You can obtain a copy of the License at
    5.17 + * http://www.netbeans.org/cddl-gplv2.html
    5.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.19 + * specific language governing permissions and limitations under the
    5.20 + * License.  When distributing the software, include this License Header
    5.21 + * Notice in each file and include the License file at
    5.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    5.23 + * particular file as subject to the "Classpath" exception as provided
    5.24 + * by Oracle in the GPL Version 2 section of the License file that
    5.25 + * accompanied this code. If applicable, add the following below the
    5.26 + * License Header, with the fields enclosed by brackets [] replaced by
    5.27 + * your own identifying information:
    5.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    5.29 + *
    5.30 + * Contributor(s):
    5.31 + *
    5.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    5.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    5.34 + *
    5.35 + * If you wish your version of this file to be governed by only the CDDL
    5.36 + * or only the GPL Version 2, indicate your decision by adding
    5.37 + * "[Contributor] elects to include this software in this distribution
    5.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.39 + * single choice of license, a recipient has the option to distribute
    5.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    5.41 + * to extend the choice of license to its licensees as provided above.
    5.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    5.43 + * Version 2 license, then the option applies only if the new code is
    5.44 + * made subject to such option by the copyright holder.
    5.45 + */
    5.46 +package net.java.html.boot.truffle;
    5.47 +
    5.48 +import com.oracle.truffle.api.CallTarget;
    5.49 +import com.oracle.truffle.api.TruffleLanguage;
    5.50 +import com.oracle.truffle.api.interop.TruffleObject;
    5.51 +import com.oracle.truffle.api.interop.java.JavaInterop;
    5.52 +import com.oracle.truffle.api.interop.java.MethodMessage;
    5.53 +import com.oracle.truffle.api.source.Source;
    5.54 +import com.oracle.truffle.api.vm.PolyglotEngine;
    5.55 +import java.io.Closeable;
    5.56 +import java.io.IOException;
    5.57 +import java.io.Reader;
    5.58 +import java.net.URL;
    5.59 +import java.util.ArrayList;
    5.60 +import java.util.List;
    5.61 +import java.util.concurrent.Executor;
    5.62 +import org.netbeans.html.boot.spi.Fn;
    5.63 +import org.netbeans.html.boot.spi.Fn.Presenter;
    5.64 +
    5.65 +/**
    5.66 + * Implementation of {@link Presenter} that delegates to Truffle.
    5.67 + *
    5.68 + * @author Jaroslav Tulach
    5.69 + */
    5.70 +final class TrufflePresenter implements Fn.KeepAlive,
    5.71 +    Presenter, Fn.FromJavaScript, Fn.ToJavaScript, Executor {
    5.72 +
    5.73 +    private Eval eval;
    5.74 +    private WrapArray copy;
    5.75 +    private final Executor exc;
    5.76 +
    5.77 +    TrufflePresenter(Executor exc, TruffleObject eval) {
    5.78 +        this.exc = exc;
    5.79 +        this.eval = eval == null ? null : JavaInterop.asJavaFunction(Eval.class, eval);
    5.80 +    }
    5.81 +
    5.82 +    @Override
    5.83 +    public Fn defineFn(String code, String... names) {
    5.84 +        return defineImpl(code, names, null);
    5.85 +    }
    5.86 +
    5.87 +    @Override
    5.88 +    public Fn defineFn(String code, String[] names, boolean[] keepAlive) {
    5.89 +        return defineImpl(code, names, keepAlive);
    5.90 +    }
    5.91 +
    5.92 +    private FnImpl defineImpl(String code, String[] names, boolean[] keepAlive) {
    5.93 +        StringBuilder sb = new StringBuilder();
    5.94 +        sb.append("(function() {\n");
    5.95 +        sb.append("  return function(");
    5.96 +        String sep = "";
    5.97 +        if (names != null) {
    5.98 +            for (String n : names) {
    5.99 +                sb.append(sep).append(n);
   5.100 +                sep = ",";
   5.101 +            }
   5.102 +        }
   5.103 +        sb.append(") {\n");
   5.104 +        sb.append(code);
   5.105 +        sb.append("\n  };\n");
   5.106 +        sb.append("})()\n");
   5.107 +
   5.108 +        TruffleObject fn = (TruffleObject) getEval().eval(sb.toString());
   5.109 +        return new FnImpl(this, fn, keepAlive);
   5.110 +    }
   5.111 +
   5.112 +    @Override
   5.113 +    public void displayPage(URL page, Runnable onPageLoad) {
   5.114 +        if (onPageLoad != null) {
   5.115 +            onPageLoad.run();
   5.116 +        }
   5.117 +    }
   5.118 +
   5.119 +    @Override
   5.120 +    public void loadScript(Reader code) throws Exception {
   5.121 +        Source src = Source.fromReader(code, "unknown.js");
   5.122 +        getEval().eval(src.getCode());
   5.123 +    }
   5.124 +
   5.125 +    interface IsArray {
   5.126 +        @MethodMessage(message = "HAS_SIZE")
   5.127 +        public boolean hasSize();
   5.128 +    }
   5.129 +
   5.130 +    interface IsNull {
   5.131 +        @MethodMessage(message = "IS_NULL")
   5.132 +        public boolean isNull();
   5.133 +    }
   5.134 +
   5.135 +    interface WrapArray {
   5.136 +        public Object copy(Object arr);
   5.137 +    }
   5.138 +
   5.139 +    interface Eval {
   5.140 +        public Object eval(String code);
   5.141 +    }
   5.142 +
   5.143 +    final Object checkArray(Object val) throws Exception {
   5.144 +        if (val instanceof TruffleObject) {
   5.145 +            final TruffleObject truffleObj = (TruffleObject)val;
   5.146 +            IsArray arrayTest = JavaInterop.asJavaObject(IsArray.class, truffleObj);
   5.147 +            try {
   5.148 +                if (arrayTest.hasSize()) {
   5.149 +                    List<?> list = JavaInterop.asJavaObject(List.class, truffleObj);
   5.150 +                    return list.toArray();
   5.151 +                }
   5.152 +            } catch (NegativeArraySizeException ex) {
   5.153 +                // swallow
   5.154 +            }
   5.155 +        }
   5.156 +        return val;
   5.157 +    }
   5.158 +
   5.159 +    @Override
   5.160 +    public Object toJava(Object jsArray) {
   5.161 +        if (jsArray instanceof JavaValue) {
   5.162 +            jsArray = ((JavaValue) jsArray).get();
   5.163 +        }
   5.164 +        if (jsArray instanceof TruffleObject) {
   5.165 +            IsNull checkNull = JavaInterop.asJavaFunction(IsNull.class, (TruffleObject)jsArray);
   5.166 +            try {
   5.167 +                if (checkNull.isNull()) {
   5.168 +                    return null;
   5.169 +                }
   5.170 +            } catch (NegativeArraySizeException ex) {
   5.171 +                System.err.println("negative size for " + jsArray);
   5.172 +                ex.printStackTrace();
   5.173 +            }
   5.174 +        }
   5.175 +        try {
   5.176 +            return checkArray(jsArray);
   5.177 +        } catch (Exception ex) {
   5.178 +            throw new IllegalStateException(ex);
   5.179 +        }
   5.180 +    }
   5.181 +
   5.182 +    @Override
   5.183 +    public Object toJavaScript(Object conv) {
   5.184 +        return JavaValue.toJavaScript(conv, getWrap());
   5.185 +    }
   5.186 +
   5.187 +    @Override
   5.188 +    public void execute(final Runnable command) {
   5.189 +        if (Fn.activePresenter() == this) {
   5.190 +            command.run();
   5.191 +            return;
   5.192 +        }
   5.193 +
   5.194 +        class Wrap implements Runnable {
   5.195 +
   5.196 +            public void run() {
   5.197 +                try (Closeable c = Fn.activate(TrufflePresenter.this)) {
   5.198 +                    command.run();
   5.199 +                } catch (IOException ex) {
   5.200 +                    throw new IllegalStateException(ex);
   5.201 +                }
   5.202 +            }
   5.203 +        }
   5.204 +        final Runnable wrap = new Wrap();
   5.205 +        if (exc == null) {
   5.206 +            wrap.run();
   5.207 +        } else {
   5.208 +            exc.execute(wrap);
   5.209 +        }
   5.210 +    }
   5.211 +
   5.212 +    private Eval getEval() {
   5.213 +        if (eval == null) {
   5.214 +            try {
   5.215 +                PolyglotEngine engine = PolyglotEngine.newBuilder().build();
   5.216 +                TruffleObject fn = (TruffleObject) engine.eval(
   5.217 +                    Source.fromText("eval.bind(this)", "eval.js").withMimeType("text/javascript")
   5.218 +                ).get();
   5.219 +                eval = JavaInterop.asJavaFunction(Eval.class, fn);
   5.220 +            } catch (IOException ex) {
   5.221 +                throw new IllegalStateException(ex);
   5.222 +            }
   5.223 +        }
   5.224 +        return eval;
   5.225 +    }
   5.226 +
   5.227 +    private WrapArray getWrap() {
   5.228 +        if (copy == null) {
   5.229 +            TruffleObject fn = (TruffleObject) getEval().eval("(function(arr) {\n"
   5.230 +                + "  var n = [];\n"
   5.231 +                + "  for (var i = 0; i < arr.length; i++) {\n"
   5.232 +                + "    n[i] = arr[i];\n"
   5.233 +                + "  }\n"
   5.234 +                + "  return n;\n"
   5.235 +                + "}).bind(this)"
   5.236 +            );
   5.237 +            copy = JavaInterop.asJavaFunction(WrapArray.class, fn);
   5.238 +        }
   5.239 +        return copy;
   5.240 +    }
   5.241 +
   5.242 +    private class FnImpl extends Fn {
   5.243 +
   5.244 +        private final CallTarget fn;
   5.245 +        private final boolean[] keepAlive;
   5.246 +
   5.247 +        public FnImpl(Presenter presenter, TruffleObject fn, boolean[] keepAlive) {
   5.248 +            super(presenter);
   5.249 +            this.fn = JavaInterop.asJavaFunction(CallTarget.class, fn);
   5.250 +            this.keepAlive = keepAlive;
   5.251 +        }
   5.252 +
   5.253 +        @Override
   5.254 +        public Object invoke(Object thiz, Object... args) throws Exception {
   5.255 +            List<Object> all = new ArrayList<>(args.length + 1);
   5.256 +            all.add(thiz == null ? fn : toJavaScript(thiz));
   5.257 +            for (int i = 0; i < args.length; i++) {
   5.258 +                Object conv = args[i];
   5.259 +                conv = toJavaScript(conv);
   5.260 +                all.add(conv);
   5.261 +            }
   5.262 +            Object ret = fn.call(all.toArray());
   5.263 +            if (ret instanceof JavaValue) {
   5.264 +                ret = ((JavaValue)ret).get();
   5.265 +            }
   5.266 +            if (ret == fn) {
   5.267 +                return null;
   5.268 +            }
   5.269 +            return toJava(ret);
   5.270 +        }
   5.271 +    }
   5.272 +
   5.273 +    static abstract class JavaLang extends TruffleLanguage<Object> {
   5.274 +    }
   5.275 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/boot-truffle/src/main/java/net/java/html/boot/truffle/package.html	Fri Jul 01 23:34:06 2016 +0200
     6.3 @@ -0,0 +1,51 @@
     6.4 +<!--
     6.5 +
     6.6 +    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.7 +
     6.8 +    Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     6.9 +
    6.10 +    Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    6.11 +    Other names may be trademarks of their respective owners.
    6.12 +
    6.13 +    The contents of this file are subject to the terms of either the GNU
    6.14 +    General Public License Version 2 only ("GPL") or the Common
    6.15 +    Development and Distribution License("CDDL") (collectively, the
    6.16 +    "License"). You may not use this file except in compliance with the
    6.17 +    License. You can obtain a copy of the License at
    6.18 +    http://www.netbeans.org/cddl-gplv2.html
    6.19 +    or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    6.20 +    specific language governing permissions and limitations under the
    6.21 +    License.  When distributing the software, include this License Header
    6.22 +    Notice in each file and include the License file at
    6.23 +    nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    6.24 +    particular file as subject to the "Classpath" exception as provided
    6.25 +    by Oracle in the GPL Version 2 section of the License file that
    6.26 +    accompanied this code. If applicable, add the following below the
    6.27 +    License Header, with the fields enclosed by brackets [] replaced by
    6.28 +    your own identifying information:
    6.29 +    "Portions Copyrighted [year] [name of copyright owner]"
    6.30 +
    6.31 +    Contributor(s):
    6.32 +
    6.33 +    The Original Software is NetBeans. The Initial Developer of the Original
    6.34 +    Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    6.35 +
    6.36 +    If you wish your version of this file to be governed by only the CDDL
    6.37 +    or only the GPL Version 2, indicate your decision by adding
    6.38 +    "[Contributor] elects to include this software in this distribution
    6.39 +    under the [CDDL or GPL Version 2] license." If you do not indicate a
    6.40 +    single choice of license, a recipient has the option to distribute
    6.41 +    your version of this file under either the CDDL, the GPL Version 2 or
    6.42 +    to extend the choice of license to its licensees as provided above.
    6.43 +    However, if you add GPL Version 2 code and therefore, elected the GPL
    6.44 +    Version 2 license, then the option applies only if the new code is
    6.45 +    made subject to such option by the copyright holder.
    6.46 +
    6.47 +-->
    6.48 +<body>
    6.49 +    <p>
    6.50 +        Integration with <a href="http://github.com/graalvm/truffle">Truffle</a>
    6.51 +        useful to execute against <b>node.js</b> running on top of
    6.52 +        the <a href="http://www.oracle.com/technetwork/oracle-labs/program-languages/overview/">GraalVM</a>.
    6.53 +    </p>
    6.54 +</body>
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/boot-truffle/src/test/java/net/java/html/boot/truffle/SingleCase.java	Fri Jul 01 23:34:06 2016 +0200
     7.3 @@ -0,0 +1,127 @@
     7.4 +/**
     7.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.6 + *
     7.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     7.8 + *
     7.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    7.10 + * Other names may be trademarks of their respective owners.
    7.11 + *
    7.12 + * The contents of this file are subject to the terms of either the GNU
    7.13 + * General Public License Version 2 only ("GPL") or the Common
    7.14 + * Development and Distribution License("CDDL") (collectively, the
    7.15 + * "License"). You may not use this file except in compliance with the
    7.16 + * License. You can obtain a copy of the License at
    7.17 + * http://www.netbeans.org/cddl-gplv2.html
    7.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    7.19 + * specific language governing permissions and limitations under the
    7.20 + * License.  When distributing the software, include this License Header
    7.21 + * Notice in each file and include the License file at
    7.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    7.23 + * particular file as subject to the "Classpath" exception as provided
    7.24 + * by Oracle in the GPL Version 2 section of the License file that
    7.25 + * accompanied this code. If applicable, add the following below the
    7.26 + * License Header, with the fields enclosed by brackets [] replaced by
    7.27 + * your own identifying information:
    7.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    7.29 + *
    7.30 + * Contributor(s):
    7.31 + *
    7.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    7.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    7.34 + *
    7.35 + * If you wish your version of this file to be governed by only the CDDL
    7.36 + * or only the GPL Version 2, indicate your decision by adding
    7.37 + * "[Contributor] elects to include this software in this distribution
    7.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    7.39 + * single choice of license, a recipient has the option to distribute
    7.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    7.41 + * to extend the choice of license to its licensees as provided above.
    7.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    7.43 + * Version 2 license, then the option applies only if the new code is
    7.44 + * made subject to such option by the copyright holder.
    7.45 + */
    7.46 +package net.java.html.boot.truffle;
    7.47 +
    7.48 +import java.lang.reflect.InvocationTargetException;
    7.49 +import java.lang.reflect.Method;
    7.50 +import java.util.concurrent.Executor;
    7.51 +import java.util.concurrent.Executors;
    7.52 +import org.netbeans.html.boot.spi.Fn;
    7.53 +import org.netbeans.html.boot.impl.FnContext;
    7.54 +import org.testng.IHookCallBack;
    7.55 +import org.testng.IHookable;
    7.56 +import org.testng.ITest;
    7.57 +import org.testng.ITestResult;
    7.58 +import org.testng.annotations.Test;
    7.59 +
    7.60 +/**
    7.61 + *
    7.62 + * @author Jaroslav Tulach
    7.63 + */
    7.64 +public final class SingleCase implements ITest, IHookable, Runnable {
    7.65 +    static final Executor JS = Executors.newSingleThreadExecutor();
    7.66 +    private final Fn.Presenter p;
    7.67 +    private final Method m;
    7.68 +    private Object result;
    7.69 +    private Object inst;
    7.70 +
    7.71 +    SingleCase(Fn.Presenter p, Method m) {
    7.72 +        this.p = p;
    7.73 +        this.m = m;
    7.74 +    }
    7.75 +
    7.76 +    @Override
    7.77 +    public String getTestName() {
    7.78 +        return m.getName();
    7.79 +    }
    7.80 +
    7.81 +    @Test
    7.82 +    public synchronized void executeTest() throws Exception {
    7.83 +        if (result == null) {
    7.84 +            JS.execute(this);
    7.85 +            wait();
    7.86 +        }
    7.87 +        if (result instanceof Exception) {
    7.88 +            throw (Exception)result;
    7.89 +        }
    7.90 +        if (result instanceof Error) {
    7.91 +            throw (Error)result;
    7.92 +        }
    7.93 +    }
    7.94 +
    7.95 +    @Override
    7.96 +    public synchronized void run() {
    7.97 +        boolean notify = true;
    7.98 +        try {
    7.99 +            FnContext.currentPresenter(p);
   7.100 +            if (inst == null) {
   7.101 +                inst = m.getDeclaringClass().newInstance();
   7.102 +            }
   7.103 +            result = m.invoke(inst);
   7.104 +            if (result == null) {
   7.105 +                result = this;
   7.106 +            }
   7.107 +        } catch (InvocationTargetException ex) {
   7.108 +            Throwable r = ex.getTargetException();
   7.109 +            if (r instanceof InterruptedException) {
   7.110 +                notify = false;
   7.111 +                JS.execute(this);
   7.112 +                return;
   7.113 +            }
   7.114 +            result = r;
   7.115 +        } catch (Exception ex) {
   7.116 +            result = ex;
   7.117 +        } finally {
   7.118 +            if (notify) {
   7.119 +                notifyAll();
   7.120 +            }
   7.121 +            FnContext.currentPresenter(null);
   7.122 +        }
   7.123 +    }
   7.124 +
   7.125 +    @Override
   7.126 +    public void run(IHookCallBack ihcb, ITestResult itr) {
   7.127 +        ihcb.runTestMethod(itr);
   7.128 +    }
   7.129 +    
   7.130 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/boot-truffle/src/test/java/net/java/html/boot/truffle/TruffleJavaScriptTest.java	Fri Jul 01 23:34:06 2016 +0200
     8.3 @@ -0,0 +1,156 @@
     8.4 +/**
     8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 + *
     8.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
     8.8 + *
     8.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    8.10 + * Other names may be trademarks of their respective owners.
    8.11 + *
    8.12 + * The contents of this file are subject to the terms of either the GNU
    8.13 + * General Public License Version 2 only ("GPL") or the Common
    8.14 + * Development and Distribution License("CDDL") (collectively, the
    8.15 + * "License"). You may not use this file except in compliance with the
    8.16 + * License. You can obtain a copy of the License at
    8.17 + * http://www.netbeans.org/cddl-gplv2.html
    8.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    8.19 + * specific language governing permissions and limitations under the
    8.20 + * License.  When distributing the software, include this License Header
    8.21 + * Notice in each file and include the License file at
    8.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    8.23 + * particular file as subject to the "Classpath" exception as provided
    8.24 + * by Oracle in the GPL Version 2 section of the License file that
    8.25 + * accompanied this code. If applicable, add the following below the
    8.26 + * License Header, with the fields enclosed by brackets [] replaced by
    8.27 + * your own identifying information:
    8.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    8.29 + *
    8.30 + * Contributor(s):
    8.31 + *
    8.32 + * The Original Software is NetBeans. The Initial Developer of the Original
    8.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
    8.34 + *
    8.35 + * If you wish your version of this file to be governed by only the CDDL
    8.36 + * or only the GPL Version 2, indicate your decision by adding
    8.37 + * "[Contributor] elects to include this software in this distribution
    8.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    8.39 + * single choice of license, a recipient has the option to distribute
    8.40 + * your version of this file under either the CDDL, the GPL Version 2 or
    8.41 + * to extend the choice of license to its licensees as provided above.
    8.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    8.43 + * Version 2 license, then the option applies only if the new code is
    8.44 + * made subject to such option by the copyright holder.
    8.45 + */
    8.46 +package net.java.html.boot.truffle;
    8.47 +
    8.48 +import com.oracle.truffle.api.source.Source;
    8.49 +import com.oracle.truffle.api.vm.PolyglotEngine;
    8.50 +import java.lang.annotation.Annotation;
    8.51 +import java.lang.reflect.Method;
    8.52 +import java.util.ArrayList;
    8.53 +import java.util.List;
    8.54 +import java.util.concurrent.Executors;
    8.55 +import net.java.html.boot.BrowserBuilder;
    8.56 +import org.netbeans.html.boot.spi.Fn;
    8.57 +import org.netbeans.html.json.tck.JavaScriptTCK;
    8.58 +import org.netbeans.html.json.tck.KOTest;
    8.59 +import org.testng.Assert;
    8.60 +import static org.testng.Assert.assertEquals;
    8.61 +import org.testng.SkipException;
    8.62 +import org.testng.annotations.Factory;
    8.63 +import org.testng.annotations.Test;
    8.64 +
    8.65 +/**
    8.66 + *
    8.67 + * @author Jaroslav Tulach
    8.68 + */
    8.69 +public class TruffleJavaScriptTest {
    8.70 +    private static Class<?> browserClass;
    8.71 +    private static Fn.Presenter browserPresenter;
    8.72 +    
    8.73 +    public TruffleJavaScriptTest() {
    8.74 +    }
    8.75 +
    8.76 +    @Factory public static Object[] compatibilityTests() throws Exception {
    8.77 +        PolyglotEngine engine = PolyglotEngine.newBuilder().build();
    8.78 +        PolyglotEngine.Value result = null;
    8.79 +        try {
    8.80 +            result = engine.eval(Source.fromText("6 * 7", "test.js").withMimeType("text/javascript"));
    8.81 +        } catch (Exception notSupported) {
    8.82 +            if (notSupported.getMessage().contains("text/javascript")) {
    8.83 +                return new Object[] { new SkipTest(notSupported.getMessage()) };
    8.84 +            }
    8.85 +        }
    8.86 +        assertEquals(42, result.as(Number.class).intValue(), "Executed OK");
    8.87 +
    8.88 +        final BrowserBuilder bb = BrowserBuilder.newBrowser(new TrufflePresenter(SingleCase.JS, null)).
    8.89 +            loadClass(TruffleJavaScriptTest.class).
    8.90 +            loadPage("empty.html").
    8.91 +            invoke("initialized");
    8.92 +
    8.93 +        Executors.newSingleThreadExecutor().submit(new Runnable() {
    8.94 +            @Override
    8.95 +            public void run() {
    8.96 +                bb.showAndWait();
    8.97 +            }
    8.98 +        });
    8.99 +
   8.100 +        List<Object> res = new ArrayList<>();
   8.101 +        Class<? extends Annotation> test = 
   8.102 +            loadClass().getClassLoader().loadClass(KOTest.class.getName()).
   8.103 +            asSubclass(Annotation.class);
   8.104 +
   8.105 +        Class[] arr = (Class[]) loadClass().getDeclaredMethod("tests").invoke(null);
   8.106 +        for (Class c : arr) {
   8.107 +            if (c.getSimpleName().contains("GC")) {
   8.108 +                continue;
   8.109 +            }
   8.110 +            for (Method m : c.getMethods()) {
   8.111 +                if (m.getAnnotation(test) != null) {
   8.112 +                    res.add(new SingleCase(browserPresenter, m));
   8.113 +                }
   8.114 +            }
   8.115 +        }
   8.116 +        return res.toArray();
   8.117 +    }
   8.118 +
   8.119 +    static synchronized Class<?> loadClass() throws InterruptedException {
   8.120 +        while (browserClass == null) {
   8.121 +            TruffleJavaScriptTest.class.wait();
   8.122 +        }
   8.123 +        return browserClass;
   8.124 +    }
   8.125 +    
   8.126 +    public static synchronized void ready(Class<?> browserCls) throws Exception {
   8.127 +        browserClass = browserCls;
   8.128 +        browserPresenter = Fn.activePresenter();
   8.129 +        TruffleJavaScriptTest.class.notifyAll();
   8.130 +    }
   8.131 +    
   8.132 +    public static void initialized() throws Exception {
   8.133 +        Assert.assertSame(TruffleJavaScriptTest.class.getClassLoader(),
   8.134 +            ClassLoader.getSystemClassLoader(),
   8.135 +            "No special classloaders"
   8.136 +        );
   8.137 +        TruffleJavaScriptTest.ready(Tck.class);
   8.138 +    }
   8.139 +
   8.140 +    public static final class Tck extends JavaScriptTCK {
   8.141 +
   8.142 +        public static Class[] tests() {
   8.143 +            return testClasses();
   8.144 +        }
   8.145 +    }
   8.146 +
   8.147 +    public static class SkipTest {
   8.148 +        private final String message;
   8.149 +
   8.150 +        public SkipTest(String message) {
   8.151 +            this.message = message;
   8.152 +        }
   8.153 +
   8.154 +        @Test
   8.155 +        public void needsGraalVMToExecuteTheTests() {
   8.156 +            throw new SkipException(message);
   8.157 +        }
   8.158 +    }
   8.159 +}
     9.1 --- a/pom.xml	Wed May 11 07:18:59 2016 +0200
     9.2 +++ b/pom.xml	Fri Jul 01 23:34:06 2016 +0200
     9.3 @@ -35,6 +35,7 @@
     9.4      <module>ko-osgi-test</module>
     9.5      <module>equinox-agentclass-hook</module>
     9.6      <module>boot-script</module>
     9.7 +    <module>boot-truffle</module>
     9.8      <module>boot-agent-test</module>
     9.9      <module>xhr4j</module>
    9.10    </modules>