# HG changeset patch # User Jaroslav Tulach # Date 1389613023 -3600 # Node ID 6ceb7c4570739ee276834da424358719e822e470 # Parent f45b7126d21d53b2c92104a7645691eac2accdf1# Parent 08ba3c2b9eea095f4fb9c1361043e9a2c6437c8f Merge into the default line the use of stable 0.7 version of org.netbeans.html APIs diff -r f45b7126d21d -r 6ceb7c457073 ko/archetype/src/main/resources/archetype-resources/pom.xml --- a/ko/archetype/src/main/resources/archetype-resources/pom.xml Wed Dec 11 08:22:17 2013 +0100 +++ b/ko/archetype/src/main/resources/archetype-resources/pom.xml Mon Jan 13 12:37:03 2014 +0100 @@ -126,7 +126,7 @@ test - org.apidesign.html + org.netbeans.html net.java.html.json \${net.java.html.version} jar @@ -182,8 +182,8 @@ - org.apidesign.html - ko-fx + org.netbeans.html + ko4j \${net.java.html.version} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/pom.xml --- a/ko/bck2brwsr/pom.xml Wed Dec 11 08:22:17 2013 +0100 +++ b/ko/bck2brwsr/pom.xml Mon Jan 13 12:37:03 2014 +0100 @@ -62,6 +62,12 @@ ${project.version} jar test + + + json + org.json + + org.apidesign.bck2brwsr @@ -74,14 +80,20 @@ launcher.http ${project.version} test + + + asm + org.ow2.asm + + - org.apidesign.html + org.netbeans.html net.java.html.json ${net.java.html.version} - org.apidesign.html + org.netbeans.html net.java.html.json.tck ${net.java.html.version} test @@ -93,10 +105,31 @@ jar - org.apidesign.html + org.netbeans.html net.java.html.boot ${net.java.html.version} jar + + + asm + org.ow2.asm + + + + + org.netbeans.html + ko4j + ${net.java.html.version} + + + json + org.json + + + org.json-osgi + de.twentyeleven.skysail + + diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxImpl.java --- a/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxImpl.java Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.ko2brwsr; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import org.apidesign.html.json.spi.FunctionBinding; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.PropertyBinding; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; - -/** - * - * @author Jaroslav Tulach - */ -final class BrwsrCtxImpl implements Technology, Transfer, WSTransfer { - private BrwsrCtxImpl() {} - - public static final BrwsrCtxImpl DEFAULT = new BrwsrCtxImpl(); - - @Override - public void extract(Object obj, String[] props, Object[] values) { - ConvertTypes.extractJSON(obj, props, values); - } - - @Override - public void loadJSON(final JSONCall call) { - class R implements Runnable { - final boolean success; - - public R(boolean success) { - this.success = success; - } - - Object[] arr = { null }; - @Override - public void run() { - if (success) { - call.notifySuccess(arr[0]); - } else { - Throwable t; - if (arr[0] instanceof Throwable) { - t = (Throwable) arr[0]; - } else { - if (arr[0] == null) { - t = new IOException(); - } else { - t = new IOException(arr[0].toString()); - } - } - call.notifyError(t); - } - } - } - R success = new R(true); - R failure = new R(false); - if (call.isJSONP()) { - String me = ConvertTypes.createJSONP(success.arr, success); - ConvertTypes.loadJSONP(call.composeURL(me), me); - } else { - String data = null; - if (call.isDoOutput()) { - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - call.writeData(bos); - data = new String(bos.toByteArray(), "UTF-8"); - } catch (IOException ex) { - call.notifyError(ex); - } - } - ConvertTypes.loadJSON(call.composeURL(null), success.arr, success, failure, call.getMethod(), data); - } - } - - @Override - public Object wrapModel(Object model) { - return model; - } - - @Override - public void bind(PropertyBinding b, Object model, Object data) { - Knockout.bind(data, b, b.getPropertyName(), - "getValue__Ljava_lang_Object_2", - b.isReadOnly() ? null : "setValue__VLjava_lang_Object_2", - false, false - ); - } - - @Override - public void valueHasMutated(Object data, String propertyName) { - Knockout.valueHasMutated(data, propertyName); - } - - @Override - public void expose(FunctionBinding fb, Object model, Object d) { - Knockout.expose(d, fb, fb.getFunctionName(), "call__VLjava_lang_Object_2Ljava_lang_Object_2"); - } - - @Override - public void applyBindings(Object data) { - Knockout.applyBindings(data); - } - - @Override - public Object wrapArray(Object[] arr) { - return arr; - } - - @Override - public M toModel(Class modelClass, Object data) { - return modelClass.cast(data); - } - - @Override - public Object toJSON(InputStream is) throws IOException { - StringBuilder sb = new StringBuilder(); - InputStreamReader r = new InputStreamReader(is); - for (;;) { - int ch = r.read(); - if (ch == -1) { - break; - } - sb.append((char)ch); - } - return ConvertTypes.parse(sb.toString()); - } - - @Override - public void runSafe(Runnable r) { - r.run(); - } - - @Override - public LoadWS open(String url, JSONCall callback) { - return new LoadWS(callback, url); - } - - @Override - public void send(LoadWS socket, JSONCall data) { - socket.send(data); - } - - @Override - public void close(LoadWS socket) { - socket.close(); - } -} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxPrvdr.java --- a/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/BrwsrCtxPrvdr.java Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.ko2brwsr; - -import org.apidesign.bck2brwsr.core.JavaScriptBody; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.spi.WSTransfer; -import org.openide.util.lookup.ServiceProvider; - -/** This is an implementation package - just - * include its JAR on classpath and use official {@link Context} API - * to access the functionality. - *

- * Provides binding between models and - * Bck2Brwsr VM. - * Registers {@link ContextProvider}, so {@link ServiceLoader} can find it. - * - * @author Jaroslav Tulach - */ -@ServiceProvider(service = Contexts.Provider.class) -public final class BrwsrCtxPrvdr implements Contexts.Provider { - - @Override - public void fillContext(Contexts.Builder context, Class requestor) { - if (bck2BrwsrVM()) { - context.register(Technology.class, BrwsrCtxImpl.DEFAULT, 50). - register(Transfer.class, BrwsrCtxImpl.DEFAULT, 50). - register(WSTransfer.class, BrwsrCtxImpl.DEFAULT, 50); - } - } - - @JavaScriptBody(args = { }, body = "return true;") - private static boolean bck2BrwsrVM() { - return false; - } -} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/ConvertTypes.java --- a/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/ConvertTypes.java Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.ko2brwsr; - -import org.apidesign.bck2brwsr.core.JavaScriptBody; - -/** - * - * @author Jaroslav Tulach - */ -final class ConvertTypes { - ConvertTypes() { - } - - public static String toString(Object object, String property) { - Object ret = getProperty(object, property); - return ret == null ? null : ret.toString(); - } - - public static double toDouble(Object object, String property) { - Object ret = getProperty(object, property); - return ret instanceof Number ? ((Number)ret).doubleValue() : Double.NaN; - } - - public static int toInt(Object object, String property) { - Object ret = getProperty(object, property); - return ret instanceof Number ? ((Number)ret).intValue() : Integer.MIN_VALUE; - } - - public static T toModel(Class modelClass, Object object, String property) { - Object ret = getProperty(object, property); - if (ret == null || modelClass.isInstance(ret)) { - return modelClass.cast(ret); - } - throw new IllegalStateException("Value " + ret + " is not of type " + modelClass); - } - - public static String toJSON(Object value) { - if (value == null) { - return "null"; - } - if (value instanceof Enum) { - value = value.toString(); - } - if (value instanceof String) { - return '"' + - ((String)value). - replace("\"", "\\\""). - replace("\n", "\\n"). - replace("\r", "\\r"). - replace("\t", "\\t") - + '"'; - } - return value.toString(); - } - - @JavaScriptBody(args = { "object", "property" }, - body = - "if (property === null) return object;\n" - + "if (object === null) return null;\n" - + "var p = object[property]; return p ? p : null;" - ) - private static Object getProperty(Object object, String property) { - return null; - } - - public static String createJSONP(Object[] jsonResult, Runnable whenDone) { - int h = whenDone.hashCode(); - String name; - for (;;) { - name = "jsonp" + Integer.toHexString(h); - if (defineIfUnused(name, jsonResult, whenDone)) { - return name; - } - h++; - } - } - - @JavaScriptBody(args = { "name", "arr", "run" }, body = - "if (window[name]) return false;\n " - + "window[name] = function(data) {\n " - + " delete window[name];\n" - + " var el = window.document.getElementById(name);\n" - + " el.parentNode.removeChild(el);\n" - + " arr[0] = data;\n" - + " run.run__V();\n" - + "};\n" - + "return true;\n" - ) - private static boolean defineIfUnused(String name, Object[] arr, Runnable run) { - return true; - } - - @JavaScriptBody(args = { "s" }, body = "return eval('(' + s + ')');") - static Object parse(String s) { - return s; - } - - @JavaScriptBody(args = { "url", "arr", "callback", "onError", "method", "data" }, body = "" - + "var request = new XMLHttpRequest();\n" - + "if (!method) method = 'GET';\n" - + "request.open(method, url, true);\n" - + "request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');\n" - + "request.onreadystatechange = function() {\n" - + " if (this.readyState!==4) return;\n" - + " try {\n" - + " arr[0] = eval('(' + this.response + ')');\n" - + " } catch (error) {;\n" - + " arr[0] = this.response;\n" - + " }\n" - + " callback.run__V();\n" - + "};\n" - + "request.onerror = function (e) {\n" - + " arr[0] = e; onError.run__V();\n" - + "}\n" - + "if (data) request.send(data);" - + "else request.send();" - ) - static void loadJSON( - String url, Object[] jsonResult, Runnable whenDone, Runnable whenErr, String method, String data - ) { - } - - @JavaScriptBody(args = { "url", "jsonp" }, body = - "var scrpt = window.document.createElement('script');\n " - + "scrpt.setAttribute('src', url);\n " - + "scrpt.setAttribute('id', jsonp);\n " - + "scrpt.setAttribute('type', 'text/javascript');\n " - + "var body = document.getElementsByTagName('body')[0];\n " - + "body.appendChild(scrpt);\n" - ) - static void loadJSONP(String url, String jsonp) { - - } - - public static void extractJSON(Object jsonObject, String[] props, Object[] values) { - for (int i = 0; i < props.length; i++) { - values[i] = getProperty(jsonObject, props[i]); - } - } - -} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/Knockout.java --- a/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/Knockout.java Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.ko2brwsr; - -import java.lang.reflect.Method; -import java.util.List; -import org.apidesign.bck2brwsr.core.ExtraJavaScript; -import org.apidesign.bck2brwsr.core.JavaScriptBody; - -/** Provides binding between models and bck2brwsr VM. - * - * @author Jaroslav Tulach - */ -@ExtraJavaScript(resource = "/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js") -final class Knockout { - /** used by tests */ - static Knockout next; - private final Object model; - - Knockout(Object model) { - this.model = model == null ? this : model; - } - - public static Knockout applyBindings( - Object model, String[] propsGettersAndSetters, - String[] methodsAndSignatures - ) { - applyImpl(propsGettersAndSetters, model.getClass(), model, model, methodsAndSignatures); - return new Knockout(model); - } - public static Knockout applyBindings( - Class modelClass, M model, String[] propsGettersAndSetters, - String[] methodsAndSignatures - ) { - Knockout bindings = next; - next = null; - if (bindings == null) { - bindings = new Knockout(null); - } - applyImpl(propsGettersAndSetters, modelClass, bindings, model, methodsAndSignatures); - applyBindings(bindings); - return bindings; - } - - public void valueHasMutated(String prop) { - valueHasMutated(model, prop); - } - @JavaScriptBody(args = { "self", "prop" }, body = - "var p = self[prop]; if (p) p.valueHasMutated();" - ) - public static void valueHasMutated(Object self, String prop) { - } - - - @JavaScriptBody(args = { "id", "ev" }, body = "ko.utils.triggerEvent(window.document.getElementById(id), ev.substring(2));") - public static void triggerEvent(String id, String ev) { - } - - @JavaScriptBody(args = { "bindings", "model", "prop", "getter", "setter", "primitive", "array" }, body = - "var bnd = {\n" - + " 'read': function() {\n" - + " var v = model[getter]();\n" - + " if (array) v = v.koArray(); else if (v !== null) v = v.valueOf();\n" - + " return v;\n" - + " },\n" - + " 'owner': bindings\n" - + "};\n" - + "if (setter != null) {\n" - + " bnd['write'] = function(val) {\n" - + " var v = val === null ? null : val.valueOf();" - + " model[setter](v);\n" - + " };\n" - + "}\n" - + "bindings[prop] = ko['computed'](bnd);" - ) - static void bind( - Object bindings, Object model, String prop, String getter, String setter, boolean primitive, boolean array - ) { - } - - @JavaScriptBody(args = { "bindings", "model", "prop", "sig" }, body = - "bindings[prop] = function(data, ev) { model[sig](data, ev); };" - ) - static void expose( - Object bindings, Object model, String prop, String sig - ) { - } - - @JavaScriptBody(args = { "bindings" }, body = "ko.applyBindings(bindings);") - static void applyBindings(Object bindings) {} - - private static void applyImpl( - String[] propsGettersAndSetters, - Class modelClass, - Object bindings, - Object model, - String[] methodsAndSignatures - ) throws IllegalStateException, SecurityException { - for (int i = 0; i < propsGettersAndSetters.length; i += 4) { - try { - Method getter = modelClass.getMethod(propsGettersAndSetters[i + 3]); - bind(bindings, model, propsGettersAndSetters[i], - propsGettersAndSetters[i + 1], - propsGettersAndSetters[i + 2], - getter.getReturnType().isPrimitive(), - List.class.isAssignableFrom(getter.getReturnType())); - } catch (NoSuchMethodException ex) { - throw new IllegalStateException(ex.getMessage()); - } - } - for (int i = 0; i < methodsAndSignatures.length; i += 2) { - expose( - bindings, model, methodsAndSignatures[i], methodsAndSignatures[i + 1]); - } - } -} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/LoadWS.java --- a/ko/bck2brwsr/src/main/java/org/apidesign/bck2brwsr/ko2brwsr/LoadWS.java Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.ko2brwsr; - -import net.java.html.js.JavaScriptBody; -import org.apidesign.html.json.spi.JSONCall; - -/** Communication with WebSockets for WebView 1.8. - * - * @author Jaroslav Tulach - */ -final class LoadWS { - private static final boolean SUPPORTED = isWebSocket(); - private final Object ws; - private final JSONCall call; - LoadWS(JSONCall first, String url) { - call = first; - ws = initWebSocket(this, url); - if (ws == null) { - first.notifyError(new IllegalArgumentException("Wrong URL: " + url)); - } - } - - static boolean isSupported() { - return SUPPORTED; - } - - void send(JSONCall call) { - push(call); - } - - private synchronized void push(JSONCall call) { - send(ws, call.getMessage()); - } - - void onOpen(Object ev) { - if (!call.isDoOutput()) { - call.notifySuccess(null); - } - } - - - @JavaScriptBody(args = { "data" }, body = "try {\n" - + " return eval('(' + data + ')');\n" - + " } catch (error) {;\n" - + " return data;\n" - + " }\n" - ) - private static native Object toJSON(String data); - - void onMessage(Object ev, String data) { - Object json = toJSON(data); - call.notifySuccess(json); - } - - void onError(Object ev) { - call.notifyError(new Exception(ev.toString())); - } - - void onClose(boolean wasClean, int code, String reason) { - call.notifyError(null); - } - - @JavaScriptBody(args = {}, body = "if (window.WebSocket) return true; else return false;") - private static boolean isWebSocket() { - return false; - } - - @JavaScriptBody(args = { "back", "url" }, javacall = true, body = "" - + "if (window.WebSocket) {\n" - + " try {\n" - + " var ws = new window.WebSocket(url);\n" - + " ws.onopen = function(ev) {\n" - + " back.@org.apidesign.bck2brwsr.ko2brwsr.LoadWS::onOpen(Ljava/lang/Object;)(ev);\n" - + " };\n" - + " ws.onmessage = function(ev) {\n" - + " back.@org.apidesign.bck2brwsr.ko2brwsr.LoadWS::onMessage(Ljava/lang/Object;Ljava/lang/String;)(ev, ev.data);\n" - + " };\n" - + " ws.onerror = function(ev) {\n" - + " back.@org.apidesign.bck2brwsr.ko2brwsr.LoadWS::onError(Ljava/lang/Object;)(ev);\n" - + " };\n" - + " ws.onclose = function(ev) {\n" - + " back.@org.apidesign.bck2brwsr.ko2brwsr.LoadWS::onClose(ZILjava/lang/String;)(ev.wasClean, ev.code, ev.reason);\n" - + " };\n" - + " return ws;\n" - + " } catch (ex) {\n" - + " return null;\n" - + " }\n" - + "} else {\n" - + " return null;\n" - + "}\n" - ) - private static Object initWebSocket(Object back, String url) { - return null; - } - - - @JavaScriptBody(args = { "ws", "msg" }, body = "" - + "ws.send(msg);" - ) - private void send(Object ws, String msg) { - } - - @JavaScriptBody(args = { "ws" }, body = "ws.close();") - private static void close(Object ws) { - } - - void close() { - close(ws); - } -} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js --- a/ko/bck2brwsr/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout-2.2.1.js Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3614 +0,0 @@ -/* - * HTML via Java(tm) Language Bindings - * Copyright (C) 2013 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. apidesign.org - * designates this particular file as subject to the - * "Classpath" exception as provided by apidesign.org - * in the License file that accompanied this code. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException - */ -// Knockout JavaScript library v2.2.1 -// (c) Steven Sanderson - http://knockoutjs.com/ -// License: MIT (http://www.opensource.org/licenses/mit-license.php) - -(function(){ -var DEBUG=true; -(function(window,document,navigator,jQuery,undefined){ -!function(factory) { - // Support three module loading scenarios - if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { - // [1] CommonJS/Node.js - var target = module['exports'] || exports; // module.exports is for Node.js - factory(target); - } else if (typeof define === 'function' && define['amd']) { - // [2] AMD anonymous module - define(['exports'], factory); - } else { - // [3] No module loader (plain "); - }; - - if (jQueryTmplVersion > 0) { - jQuery['tmpl']['tag']['ko_code'] = { - open: "__.push($1 || '');" - }; - jQuery['tmpl']['tag']['ko_with'] = { - open: "with($1) {", - close: "} " - }; - } - }; - - ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine(); - - // Use this one by default *only if jquery.tmpl is referenced* - var jqueryTmplTemplateEngineInstance = new ko.jqueryTmplTemplateEngine(); - if (jqueryTmplTemplateEngineInstance.jQueryTmplVersion > 0) - ko.setTemplateEngine(jqueryTmplTemplateEngineInstance); - - ko.exportSymbol('jqueryTmplTemplateEngine', ko.jqueryTmplTemplateEngine); -})(); -}); -})(window,document,navigator,window["jQuery"]); -})(); \ No newline at end of file diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrJavaScriptBodyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrJavaScriptBodyTest.java Mon Jan 13 12:37:03 2014 +0100 @@ -0,0 +1,34 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.ko2brwsr; + +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.apidesign.html.json.tck.JavaScriptTCK; +import org.apidesign.html.json.tck.KOTest; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +public class Bck2BrwsrJavaScriptBodyTest extends JavaScriptTCK { + @Factory public static Object[] tests() { + return VMTest.newTests().withClasses(testClasses()) + .withTestAnnotation(KOTest.class).build(); + } +} diff -r f45b7126d21d -r 6ceb7c457073 ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutTest.java --- a/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutTest.java Wed Dec 11 08:22:17 2013 +0100 +++ b/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutTest.java Mon Jan 13 12:37:03 2014 +0100 @@ -31,6 +31,7 @@ import org.apidesign.html.json.spi.WSTransfer; import org.apidesign.html.json.tck.KOTest; import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.ko4j.KO4J; import org.openide.util.lookup.ServiceProvider; import org.testng.annotations.Factory; @@ -50,10 +51,11 @@ @Override public BrwsrCtx createContext() { + KO4J ko = new KO4J(null); return Contexts.newBuilder(). - register(Transfer.class, BrwsrCtxImpl.DEFAULT, 9). - register(WSTransfer.class, BrwsrCtxImpl.DEFAULT, 9). - register(Technology.class, BrwsrCtxImpl.DEFAULT, 9).build(); + register(Transfer.class, ko.transfer(), 9). + register(WSTransfer.class, ko.websockets(), 9). + register(Technology.class, ko.knockout(), 9).build(); } diff -r f45b7126d21d -r 6ceb7c457073 ko/fx/pom.xml --- a/ko/fx/pom.xml Wed Dec 11 08:22:17 2013 +0100 +++ b/ko/fx/pom.xml Mon Jan 13 12:37:03 2014 +0100 @@ -40,7 +40,7 @@ jar - org.apidesign.html + org.netbeans.html net.java.html.json ${net.java.html.version} @@ -50,7 +50,7 @@ test - org.apidesign.html + org.netbeans.html net.java.html.json.tck ${net.java.html.version} test @@ -67,14 +67,14 @@ test - org.apidesign.html + org.netbeans.html net.java.html.boot ${net.java.html.version} jar - org.apidesign.html - ko-fx + org.netbeans.html + ko4j ${net.java.html.version} jar @@ -86,7 +86,7 @@ jar - org.apidesign.html + org.netbeans.html ko-ws-tyrus ${net.java.html.version} test diff -r f45b7126d21d -r 6ceb7c457073 ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/JavaScriptBodyFXBrwsrTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/JavaScriptBodyFXBrwsrTest.java Mon Jan 13 12:37:03 2014 +0100 @@ -0,0 +1,36 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.kofx; + +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.apidesign.html.json.tck.JavaScriptTCK; +import org.apidesign.html.json.tck.KOTest; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +public class JavaScriptBodyFXBrwsrTest extends JavaScriptTCK { + @Factory public static Object[] create() { + return VMTest.newTests(). + withLaunchers("fxbrwsr"). + withClasses(testClasses()). + withTestAnnotation(KOTest.class).build(); + } +} diff -r f45b7126d21d -r 6ceb7c457073 ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/KnockoutFXTest.java --- a/ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/KnockoutFXTest.java Wed Dec 11 08:22:17 2013 +0100 +++ b/ko/fx/src/test/java/org/apidesign/bck2brwsr/kofx/KnockoutFXTest.java Mon Jan 13 12:37:03 2014 +0100 @@ -28,17 +28,17 @@ import net.java.html.BrwsrCtx; import net.java.html.js.JavaScriptBody; import org.apidesign.bck2brwsr.vmtest.VMTest; -import org.apidesign.html.boot.impl.FnUtils; +import org.apidesign.html.boot.spi.Fn; import org.apidesign.html.context.spi.Contexts; import org.apidesign.html.json.spi.Technology; import org.apidesign.html.json.spi.Transfer; import org.apidesign.html.json.spi.WSTransfer; import org.apidesign.html.json.tck.KOTest; import org.apidesign.html.json.tck.KnockoutTCK; -import org.apidesign.html.kofx.FXContext; -import org.apidesign.html.wstyrus.TyrusContext; import org.json.JSONException; import org.json.JSONObject; +import org.netbeans.html.ko4j.KO4J; +import org.netbeans.html.wstyrus.TyrusContext; import org.openide.util.lookup.ServiceProvider; import org.testng.annotations.Factory; @@ -60,34 +60,36 @@ @Override public BrwsrCtx createContext() { - FXContext fx = new FXContext(FnUtils.currentPresenter()); + KO4J ko = new KO4J(Fn.activePresenter()); TyrusContext tc = new TyrusContext(); Contexts.Builder b = Contexts.newBuilder(). - register(Technology.class, fx, 10). - register(Transfer.class, fx, 10); + register(Technology.class, ko.knockout(), 10). + register(Transfer.class, ko.transfer(), 10); try { Class.forName("java.util.function.Function"); // prefer WebView's WebSockets on JDK8 - b.register(WSTransfer.class, fx, 10); + b.register(WSTransfer.class, ko.websockets(), 10); } catch (ClassNotFoundException ex) { // ok, JDK7 needs tyrus b.register(WSTransfer.class, tc, 20); + b.register(Transfer.class, tc, 5); } return b.build(); } @Override public Object createJSON(Map values) { - JSONObject json = new JSONObject(); + Object json = createJSON(); for (Map.Entry entry : values.entrySet()) { - try { - json.put(entry.getKey(), entry.getValue()); - } catch (JSONException ex) { - throw new IllegalStateException(ex); - } + setProperty(json, entry.getKey(), entry.getValue()); } return json; } + + @JavaScriptBody(args = {}, body = "return new Object();") + private static native Object createJSON(); + @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;") + private static native void setProperty(Object json, String key, Object value); @Override @JavaScriptBody(args = { "s", "args" }, body = "" diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/pom.xml --- a/launcher/fx/pom.xml Wed Dec 11 08:22:17 2013 +0100 +++ b/launcher/fx/pom.xml Mon Jan 13 12:37:03 2014 +0100 @@ -75,7 +75,7 @@ 4.1 - org.apidesign.html + org.netbeans.html net.java.html.boot ${net.java.html.version} diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/Console.java --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/Console.java Wed Dec 11 08:22:17 2013 +0100 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/Console.java Mon Jan 13 12:37:03 2014 +0100 @@ -25,8 +25,8 @@ import java.lang.reflect.Modifier; import java.net.URL; import java.util.Enumeration; +import net.java.html.js.JavaScriptBody; import netscape.javascript.JSObject; -import org.apidesign.bck2brwsr.core.JavaScriptBody; /** * @@ -60,8 +60,7 @@ } private static void beginTest(Case c) { - Object[] arr = new Object[2]; - beginTest(c.getClassName() + "." + c.getMethodName(), c, arr); + Object[] arr = beginTest(c.getClassName() + "." + c.getMethodName(), c, new Object[2]); textArea = arr[0]; statusArea = arr[1]; } @@ -102,23 +101,23 @@ + "ul.appendChild(li);\n" + "arr[0] = pre;\n" + "arr[1] = status;\n" + + "return arr;" ) - private static native void beginTest(String test, Case c, Object[] arr); + private static native Object[] beginTest(String test, Case c, Object[] arr); - @JavaScriptBody(args = { "url", "callback", "arr" }, body = + @JavaScriptBody(args = { "url", "callback" }, javacall = true, body = "var request = new XMLHttpRequest();\n" + "request.open('GET', url, true);\n" + "request.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');\n" + "request.onreadystatechange = function() {\n" + " if (this.readyState!==4) return;\n" + " try {\n" - + " arr[0] = this.responseText;\n" - + " callback.run();\n" + + " callback.@org.apidesign.bck2brwsr.launcher.fximpl.OnMessage::onMessage(Ljava/lang/String;)(this.responseText);\n" + " } catch (e) { alert(e); }\n" + "};\n" + "request.send();\n" ) - private static native void loadText(String url, Runnable callback, String[] arr) throws IOException; + private static native void loadText(String url, OnMessage callback) throws IOException; public static void runHarness(String url) throws IOException { new Console().harness(url); @@ -129,7 +128,7 @@ Request r = new Request(url); } - private static class Request implements Runnable { + private static class Request implements Runnable, OnMessage { private final String[] arr = { null }; private final String url; private Case c; @@ -137,11 +136,17 @@ private Request(String url) throws IOException { this.url = url; - loadText(url, new Run(this), arr); + loadText(url, this); } private Request(String url, String u) throws IOException { this.url = url; - loadText(u, new Run(this), arr); + loadText(u, this); + } + + @Override + public void onMessage(String msg) { + arr[0] = msg; + run(); } @Override @@ -177,7 +182,7 @@ } catch (Exception ex) { if (ex instanceof InterruptedException) { log("Re-scheduling in 100ms"); - schedule(new Run(this), 100); + schedule(this, 100); return; } log(ex.getClass().getName() + ":" + ex.getMessage()); @@ -250,7 +255,11 @@ private static void turnAssetionStatusOn() { } - @JavaScriptBody(args = { "r", "time" }, body = "return window.setTimeout(function() { r.run(); }, time);") + @JavaScriptBody(args = { "r", "time" }, javacall = true, body = + "return window.setTimeout(function() { " + + "r.@java.lang.Runnable::run()(); " + + "}, time);" + ) private static native Object schedule(Runnable r, int time); private static final class Case { diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JVMBridge.java --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JVMBridge.java Wed Dec 11 08:22:17 2013 +0100 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/JVMBridge.java Mon Jan 13 12:37:03 2014 +0100 @@ -19,24 +19,30 @@ import java.io.BufferedReader; import java.io.Reader; -import org.apidesign.html.boot.spi.Fn; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.TooManyListenersException; +import java.util.concurrent.Executor; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.scene.web.WebEngine; import netscape.javascript.JSObject; -import org.apidesign.html.boot.impl.FindResources; -import org.apidesign.html.boot.impl.FnUtils; +import org.apidesign.html.boot.spi.Fn; +import org.netbeans.html.boot.impl.FindResources; +import org.netbeans.html.boot.impl.FnUtils; /** * * @author Jaroslav Tulach */ public final class JVMBridge { + static final Logger LOG = Logger.getLogger(JVMBridge.class.getName()); + private final WebEngine engine; private final ClassLoader cl; private final WebPresenter presenter; @@ -70,11 +76,12 @@ } public Class loadClass(String name) throws ClassNotFoundException { - FnUtils.currentPresenter(presenter); + Fn.activate(presenter); return Class.forName(name, true, cl); } - private final class WebPresenter implements FindResources, Fn.Presenter { + private final class WebPresenter + implements FindResources, Fn.Presenter, Fn.ToJavaScript, Fn.FromJavaScript, Executor { @Override public void findResources(String name, Collection results, boolean oneIsEnough) { if (ldrs != null) for (ClassLoader l : ldrs) { @@ -87,6 +94,9 @@ @Override public Fn defineFn(String code, String... names) { + return defineJSFn(code, names); + } + private JSFn defineJSFn(String code, String... names) { StringBuilder sb = new StringBuilder(); sb.append("(function() {"); sb.append(" return function("); @@ -122,6 +132,91 @@ } engine.executeScript(sb.toString()); } + + @Override + public Object toJava(Object js) { + return checkArray(js); + } + + @Override + public Object toJavaScript(Object toReturn) { + if (toReturn instanceof Object[]) { + return convertArrays((Object[]) toReturn); + } + return toReturn; + } + + @Override + public void execute(Runnable command) { + if (Platform.isFxApplicationThread()) { + command.run(); + } else { + Platform.runLater(command); + } + } + + final JSObject convertArrays(Object[] arr) { + for (int i = 0; i < arr.length; i++) { + if (arr[i] instanceof Object[]) { + arr[i] = convertArrays((Object[]) arr[i]); + } + } + final JSObject wrapArr = (JSObject) wrapArrFn().call("array", arr); // NOI18N + return wrapArr; + } + + private JSObject wrapArrImpl; + + private final JSObject wrapArrFn() { + if (wrapArrImpl == null) { + try { + wrapArrImpl = (JSObject) defineJSFn(" var k = {};" + + " k.array= function() {" + + " return Array.prototype.slice.call(arguments);" + + " };" + + " return k;" + ).invokeImpl(null, false); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + return wrapArrImpl; + } + + final Object checkArray(Object val) { + int length = ((Number) arraySizeFn().call("array", val, null)).intValue(); + if (length == -1) { + return val; + } + Object[] arr = new Object[length]; + arraySizeFn().call("array", val, arr); + return arr; + } + private JSObject arraySize; + + private final JSObject arraySizeFn() { + if (arraySize == null) { + try { + arraySize = (JSObject) defineJSFn(" var k = {};" + + " k.array = function(arr, to) {" + + " if (to === null) {" + + " if (Object.prototype.toString.call(arr) === '[object Array]') return arr.length;" + + " else return -1;" + + " } else {" + + " var l = arr.length;" + + " for (var i = 0; i < l; i++) to[i] = arr[i];" + + " return l;" + + " }" + + " };" + + " return k;" + ).invokeImpl(null, false); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + return arraySize; + } + } private static final class JSFn extends Fn { @@ -134,12 +229,29 @@ @Override public Object invoke(Object thiz, Object... args) throws Exception { + return invokeImpl(thiz, true, args); + } + + final Object invokeImpl(Object thiz, boolean arrayChecks, Object... args) throws Exception { try { List all = new ArrayList(args.length + 1); all.add(thiz == null ? fn : thiz); - all.addAll(Arrays.asList(args)); + for (int i = 0; i < args.length; i++) { + if (arrayChecks && args[i] instanceof Object[]) { + Object[] arr = (Object[]) args[i]; + Object conv = ((WebPresenter) presenter()).convertArrays(arr); + args[i] = conv; + } + all.add(args[i]); + } Object ret = fn.call("call", all.toArray()); // NOI18N - return ret == fn ? null : ret; + if (ret == fn) { + return null; + } + if (!arrayChecks) { + return ret; + } + return ((WebPresenter) presenter()).checkArray(ret); } catch (Error t) { t.printStackTrace(); throw t; diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/OnMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/OnMessage.java Mon Jan 13 12:37:03 2014 +0100 @@ -0,0 +1,26 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.launcher.fximpl; + +/** + * + * @author Jaroslav Tulach + */ +interface OnMessage { + public void onMessage(String msg); +} diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/Run.java --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/fximpl/Run.java Wed Dec 11 08:22:17 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ - -package org.apidesign.bck2brwsr.launcher.fximpl; - -/** - * - * @author Jaroslav Tulach - */ -public final class Run implements Runnable { - private final Runnable r; - Run(Runnable r) { - this.r = r; - } - - @Override - public void run() { - r.run(); - } -} diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/src/test/java/org/apidesign/bck2brwsr/launcher/fximpl/JsClassLoaderTest.java --- a/launcher/fx/src/test/java/org/apidesign/bck2brwsr/launcher/fximpl/JsClassLoaderTest.java Wed Dec 11 08:22:17 2013 +0100 +++ b/launcher/fx/src/test/java/org/apidesign/bck2brwsr/launcher/fximpl/JsClassLoaderTest.java Mon Jan 13 12:37:03 2014 +0100 @@ -31,8 +31,8 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.boot.impl.FindResources; -import org.apidesign.html.boot.impl.FnUtils; +import org.netbeans.html.boot.impl.FindResources; +import org.netbeans.html.boot.impl.FnUtils; import static org.testng.Assert.*; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -118,7 +118,7 @@ } @BeforeMethod public void registerPresenter() { - FnUtils.currentPresenter(presenter); + Fn.activate(presenter); } @Test public void noParamMethod() throws Throwable { diff -r f45b7126d21d -r 6ceb7c457073 launcher/fx/src/test/java/org/apidesign/bck2brwsr/launcher/fximpl/JsMethods.java --- a/launcher/fx/src/test/java/org/apidesign/bck2brwsr/launcher/fximpl/JsMethods.java Wed Dec 11 08:22:17 2013 +0100 +++ b/launcher/fx/src/test/java/org/apidesign/bck2brwsr/launcher/fximpl/JsMethods.java Mon Jan 13 12:37:03 2014 +0100 @@ -17,7 +17,7 @@ */ package org.apidesign.bck2brwsr.launcher.fximpl; -import org.apidesign.bck2brwsr.core.JavaScriptBody; +import net.java.html.js.JavaScriptBody; /** * diff -r f45b7126d21d -r 6ceb7c457073 pom.xml --- a/pom.xml Wed Dec 11 08:22:17 2013 +0100 +++ b/pom.xml Mon Jan 13 12:37:03 2014 +0100 @@ -15,7 +15,7 @@ UTF-8 RELEASE74 COPYING - 0.6 + 0.7 none diff -r f45b7126d21d -r 6ceb7c457073 rt/emul/mini/src/main/java/java/lang/Class.java --- a/rt/emul/mini/src/main/java/java/lang/Class.java Wed Dec 11 08:22:17 2013 +0100 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Mon Jan 13 12:37:03 2014 +0100 @@ -632,6 +632,20 @@ return getAccess(); } + /** + * If the class or interface represented by this {@code Class} object + * is a member of another class, returns the {@code Class} object + * representing the class in which it was declared. This method returns + * null if this class or interface is not a member of any other class. If + * this {@code Class} object represents an array class, a primitive + * type, or void,then this method returns null. + * + * @return the declaring class for this class + * @since JDK1.1 + */ + public Class getDeclaringClass() { + throw new SecurityException(); + } /** * Returns the simple name of the underlying class as given in the diff -r f45b7126d21d -r 6ceb7c457073 rt/emul/mini/src/main/java/java/lang/Throwable.java --- a/rt/emul/mini/src/main/java/java/lang/Throwable.java Wed Dec 11 08:22:17 2013 +0100 +++ b/rt/emul/mini/src/main/java/java/lang/Throwable.java Mon Jan 13 12:37:03 2014 +0100 @@ -638,8 +638,11 @@ * ... 2 more * */ - @JavaScriptBody(args = { }, body = "console.warn(this.toString());") - public native void printStackTrace(); + public void printStackTrace() { + warn(getClass().getName() + ": " + getMessage()); + } + @JavaScriptBody(args = { "msg" }, body = "if (console) console.warn(msg.toString());") + private native void warn(String msg); /** * Prints this throwable and its backtrace to the specified print stream. diff -r f45b7126d21d -r 6ceb7c457073 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Wed Dec 11 08:22:17 2013 +0100 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Mon Jan 13 12:37:03 2014 +0100 @@ -19,6 +19,7 @@ import java.lang.reflect.Method; import org.apidesign.bck2brwsr.core.JavaScriptBody; +import org.apidesign.bck2brwsr.core.JavaScriptOnly; /** * @@ -71,4 +72,27 @@ } @JavaScriptBody(args = { "obj" }, body="return vm.java_lang_Object(false).hashCode__I.call(obj);") public static native int identityHashCode(Object obj); + + @JavaScriptOnly(name = "toJS", value = "function(v) {\n" + + " if (v === null) return null;\n" + + " if (Object.prototype.toString.call(v) === '[object Array]') {\n" + + " return vm.org_apidesign_bck2brwsr_emul_lang_System(false).convArray__Ljava_lang_Object_2Ljava_lang_Object_2(v);\n" + + " }\n" + + " return v.valueOf();\n" + + "}\n" + ) + public static native int toJS(); + + private static Object convArray(Object o) { + if (o instanceof Object[]) { + Object[] arr = (Object[]) o; + final int l = arr.length; + Object[] ret = new Object[l]; + for (int i = 0; i < l; i++) { + ret[i] = convArray(arr[i]); + } + return ret; + } + return o; + } } diff -r f45b7126d21d -r 6ceb7c457073 rt/vm/pom.xml --- a/rt/vm/pom.xml Wed Dec 11 08:22:17 2013 +0100 +++ b/rt/vm/pom.xml Mon Jan 13 12:37:03 2014 +0100 @@ -154,7 +154,7 @@ compile - org.apidesign.html + org.netbeans.html net.java.html.boot test ${net.java.html.version} diff -r f45b7126d21d -r 6ceb7c457073 rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Dec 11 08:22:17 2013 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 13 12:37:03 2014 +0100 @@ -1623,6 +1623,7 @@ String[] args = new String[30]; String body; boolean javacall; + boolean html4j; @Override protected void visitAttr(String type, String attr, String at, String value) { @@ -1636,6 +1637,7 @@ } } if (type.equals(htmlType)) { + html4j = true; if ("body".equals(attr)) { body = value; } else if ("args".equals(attr)) { @@ -1659,12 +1661,18 @@ out.append(" = function("); String space = ""; int index = 0; + StringBuilder toValue = new StringBuilder(); for (int i = 0; i < cnt.length(); i++) { out.append(space); space = outputArg(out, p.args, index); + if (p.html4j && space.length() > 0) { + toValue.append("\n ").append(p.args[index]).append(" = vm.org_apidesign_bck2brwsr_emul_lang_System(false).toJS("). + append(p.args[index]).append(");"); + } index++; } out.append(") {").append("\n"); + out.append(toValue.toString()); if (p.javacall) { int lastSlash = jc.getClassName().lastIndexOf('/'); final String pkg = jc.getClassName().substring(0, lastSlash); @@ -1765,6 +1773,23 @@ final String fqnu = fqn.replace('.', '_'); final String rfqn = mangleClassName(fqnu); final String rm = mangleMethodName(method); + final String srp; + { + StringBuilder pb = new StringBuilder(); + int len = params.length(); + int indx = 0; + while (indx < len) { + char ch = params.charAt(indx); + if (ch == '[' || ch == 'L') { + pb.append("Ljava/lang/Object;"); + indx = params.indexOf(';', indx) + 1; + } else { + pb.append(ch); + indx++; + } + } + srp = mangleSig(pb.toString()); + } final String rp = mangleSig(params); final String mrp = mangleMethodName(rp); sb.append(rfqn).append("$").append(rm). @@ -1772,7 +1797,7 @@ if (!isStatic) { sb.append('L').append(fqnu).append("_2"); } - sb.append(rp); + sb.append(srp); return sb.toString(); }