Merging post 0.7.5 bugfix
authorJaroslav Tulach <jaroslav.tulach@netbeans.org>
Sun, 09 Feb 2014 23:27:05 +0100
changeset 556b676a5f9d3a6
parent 554 3e851e849090
parent 555 cdae29ad68ec
child 557 2911034fe047
Merging post 0.7.5 bugfix
     1.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Fri Feb 07 07:55:14 2014 +0100
     1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Sun Feb 09 23:27:05 2014 +0100
     1.3 @@ -134,7 +134,7 @@
     1.4       * @since 0.7
     1.5       */
     1.6      public static Fn preload(final Fn fn, final Class<?> caller, final String resource) {
     1.7 -        return new Fn() {
     1.8 +        return new Fn(fn.presenter()) {
     1.9              @Override
    1.10              public Object invoke(Object thiz, Object... args) throws Exception {
    1.11                  final Presenter p = FnContext.currentPresenter(false);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/CountFnCreationTest.java	Sun Feb 09 23:27:05 2014 +0100
     2.3 @@ -0,0 +1,125 @@
     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 org.netbeans.html.boot.impl;
    2.47 +
    2.48 +import java.io.Closeable;
    2.49 +import java.io.IOException;
    2.50 +import java.io.Reader;
    2.51 +import java.lang.reflect.Method;
    2.52 +import java.net.URL;
    2.53 +import java.util.Collection;
    2.54 +import java.util.Enumeration;
    2.55 +import java.util.logging.Level;
    2.56 +import java.util.logging.Logger;
    2.57 +import net.java.html.js.JavaScriptBody;
    2.58 +import net.java.html.js.JavaScriptResource;
    2.59 +import org.apidesign.html.boot.spi.Fn;
    2.60 +import static org.testng.Assert.assertEquals;
    2.61 +import org.testng.annotations.Test;
    2.62 +
    2.63 +/**
    2.64 + *
    2.65 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.66 + */
    2.67 +@JavaScriptResource("empty.js")
    2.68 +public class CountFnCreationTest implements Fn.Presenter {
    2.69 +    private int cnt;
    2.70 +    
    2.71 +    @JavaScriptBody(args = {}, body = "return;")
    2.72 +    public static native void body();
    2.73 +    
    2.74 +    @Test public void countManyTimes() throws Exception {
    2.75 +        class Res implements FindResources {
    2.76 +            @Override
    2.77 +            public void findResources(String path, Collection<? super URL> results, boolean oneIsEnough) {
    2.78 +                try {
    2.79 +                    ClassLoader l = CountFnCreationTest.class.getClassLoader();
    2.80 +                    Enumeration<URL> en = l.getResources(path);
    2.81 +                    while (en.hasMoreElements()) {
    2.82 +                        results.add(en.nextElement());
    2.83 +                    }
    2.84 +                } catch (IOException ex) {
    2.85 +                    throw new IllegalStateException(ex);
    2.86 +                }
    2.87 +            }
    2.88 +        }
    2.89 +        ClassLoader l = FnUtils.newLoader(new Res(), this, CountFnCreationTest.class.getClassLoader().getParent());
    2.90 +        Method m = l.loadClass(CountFnCreationTest.class.getName()).getMethod("body");
    2.91 +        Closeable c = Fn.activate(this);
    2.92 +        try {
    2.93 +            assertEquals(cnt, 0, "No functions yet");
    2.94 +            m.invoke(null);
    2.95 +            assertEquals(cnt, 1, "One function defined");
    2.96 +            m.invoke(null);
    2.97 +            assertEquals(cnt, 1, "Still one function");
    2.98 +        } finally {
    2.99 +            c.close();
   2.100 +        }
   2.101 +    }
   2.102 +
   2.103 +    @Override
   2.104 +    public Fn defineFn(String code, String... names) {
   2.105 +        cnt++;
   2.106 +        return new MyFn(this);
   2.107 +    }
   2.108 +
   2.109 +    @Override
   2.110 +    public void displayPage(URL page, Runnable onPageLoad) {
   2.111 +    }
   2.112 +
   2.113 +    @Override
   2.114 +    public void loadScript(Reader code) throws Exception {
   2.115 +    }
   2.116 +    
   2.117 +    private static final class MyFn extends Fn {
   2.118 +
   2.119 +        public MyFn(Presenter presenter) {
   2.120 +            super(presenter);
   2.121 +        }
   2.122 +
   2.123 +        @Override
   2.124 +        public Object invoke(Object thiz, Object... args) throws Exception {
   2.125 +            return null;
   2.126 +        }
   2.127 +    }
   2.128 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/boot/src/test/resources/org/netbeans/html/boot/impl/empty.js	Sun Feb 09 23:27:05 2014 +0100
     3.3 @@ -0,0 +1,43 @@
     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 +