rt/emul/mini/src/main/java/org/apidesign/vm4brwsr/api/VM.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 05 May 2014 12:58:10 +0200
branchclosure
changeset 1529 9afa6856382c
parent 1373 c4e57ec5f0df
permissions -rw-r--r--
Adopting proxy implementation to extension mode
jaroslav@1373
     1
/**
jaroslav@1373
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1373
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1373
     4
 *
jaroslav@1373
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1373
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1373
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1373
     8
 *
jaroslav@1373
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1373
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1373
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1373
    12
 * GNU General Public License for more details.
jaroslav@1373
    13
 *
jaroslav@1373
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1373
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1373
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1373
    17
 */
jaroslav@1373
    18
package org.apidesign.vm4brwsr.api;
jaroslav@1373
    19
jaroslav@1373
    20
import java.io.IOException;
jaroslav@1373
    21
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@1373
    22
jaroslav@1373
    23
/** Utility methods to talk to the Bck2Brwsr virtual machine.
jaroslav@1373
    24
 *
jaroslav@1373
    25
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1373
    26
 * @since 0.9
jaroslav@1373
    27
 */
jaroslav@1373
    28
public final class VM {
jaroslav@1373
    29
    private VM() {
jaroslav@1373
    30
    }
jaroslav@1373
    31
jaroslav@1373
    32
    /** Takes an existing class and replaces its existing byte code 
jaroslav@1373
    33
     * with new one.
jaroslav@1373
    34
     * 
jaroslav@1373
    35
     * @param clazz existing class to reload
jaroslav@1373
    36
     * @param byteCode new bytecode
jaroslav@1373
    37
     * @throws IOException an exception is something goes wrong
jaroslav@1373
    38
     */
jaroslav@1373
    39
    public static void reload(Class<?> clazz, byte[] byteCode) throws IOException {
jaroslav@1373
    40
        reloadImpl(clazz.getName(), byteCode);
jaroslav@1373
    41
    }
jaroslav@1373
    42
    
jaroslav@1529
    43
    @JavaScriptBody(args = { "name", "byteCode" }, body = 
jaroslav@1529
    44
        "var r = vm._reload;"
jaroslav@1529
    45
      + "if (!r) r = exports._reload;"
jaroslav@1529
    46
      + "r(name, byteCode);"
jaroslav@1529
    47
    )
jaroslav@1373
    48
    private static void reloadImpl(String name, byte[] byteCode) throws IOException {
jaroslav@1373
    49
        throw new IOException();
jaroslav@1373
    50
    }
jaroslav@1373
    51
}