• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java V8类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.eclipsesource.v8.V8的典型用法代码示例。如果您正苦于以下问题:Java V8类的具体用法?Java V8怎么用?Java V8使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



V8类属于com.eclipsesource.v8包,在下文中一共展示了V8类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: eval

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Override
public Object eval(final String script, final ScriptContext context) throws ScriptException {
    try {
        final Object[] result = new Object[1];
        concurrentV8.run(new ConcurrentV8Runnable() {
            @Override
            public void run(V8 v8) {

                // TODO: Incorporate usage of the ScriptContext.
                result[0] = v8.executeScript(script);
            }
        });
        return result[0];
    } catch (Exception e) {

        // TODO: Add checking to throw a NoSuchMethodException.
        throw new ScriptException(e);
    }
}
 
开发者ID:alicorn-systems,项目名称:v8-adapter,代码行数:20,代码来源:V8ScriptingEngine.java


示例2: start

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public void start(V8Object worker, String... s) {
	String script = (String) s[0];
	V8Executor executor = new V8Executor(script, true, "messageHandler") {
		@Override
		protected void setup(V8 runtime) {
			configureWorker(runtime);
		}
	};
	worker.getRutime().registerV8Executor(worker, executor);
	executor.start();
}
 
开发者ID:irbull,项目名称:j2v8_examples,代码行数:12,代码来源:WebWorker.java


示例3: invokeFunction

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Override
public Object invokeFunction(final String name, final Object... args) throws ScriptException, NoSuchMethodException {
    try {
        final Object[] result = new Object[1];
        concurrentV8.run(new ConcurrentV8Runnable() {
            @Override
            public void run(V8 v8) {
                result[0] = v8.executeJSFunction(name, V8JavaObjectUtils.translateJavaArgumentsToJavascript(args, v8, V8JavaAdapter.getCacheForRuntime(v8)));
            }
        });
        return result[0];
    } catch (Exception e) {

        // TODO: Add checking to throw a NoSuchMethodException.
        throw new ScriptException(e);
    }
}
 
开发者ID:alicorn-systems,项目名称:v8-adapter,代码行数:18,代码来源:V8ScriptingEngine.java


示例4: run

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Override
public void run() {
    long start = System.currentTimeMillis();

    V8 v8Runtime = JustJsCore.getRuntime();
    mJustWindow = new JustWindow(v8Runtime, mViewGroup);
    v8Runtime.add("window", mJustWindow.getV8Object());

    JustJsCore.run(js);

    mJustWindow.drawWindow();

    JustJsCore.clean(mJustWindow);

    long end = System.currentTimeMillis();
    time = end - start;
    handler.sendEmptyMessage(0);
}
 
开发者ID:LiuHongtao,项目名称:JustDraw,代码行数:19,代码来源:V8Activity.java


示例5: run

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Override
public void run() {
    long start = System.currentTimeMillis();

    V8 runtime = V8.createV8Runtime();
    runtime.registerJavaMethod(new JavaVoidCallback() {
        public void invoke(final V8Object receiver, final V8Array parameters) {

            if (parameters.length() > 0) {
                jcdemoString(parameters);
            }

        }
    }, "call");
    runtime.add("screenWidth", JustConfig.screenWidth);
    runtime.add("screenHeight", JustConfig.screenHeight - JustConfig.navbarheight - JustConfig.statusbarheight);
    runtime.executeScript(js);

    long end = System.currentTimeMillis();
    time = end - start;
    handler.sendEmptyMessage(0);
}
 
开发者ID:LiuHongtao,项目名称:JustDraw,代码行数:23,代码来源:JCDemoActivity.java


示例6: getRuntime

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public static V8 getRuntime() {
    mRuntime = V8.createV8Runtime();
    mRuntime.registerJavaMethod(new JavaVoidCallback() {
        public void invoke(final V8Object receiver, final V8Array parameters) {
            if (parameters.length() > 0) {
                Object msg = parameters.get(0);
                Log.d(LOG_TAG, msg.toString());
                if (msg instanceof Releasable) {
                    ((Releasable) msg).release();
                }
            }
        }
    }, "log");
    mRuntime.add("screenWidth", JustConfig.screenWidth);
    mRuntime.add("screenHeight", JustConfig.screenHeight - JustConfig.navbarheight - JustConfig.statusbarheight);
    return mRuntime;
}
 
开发者ID:LiuHongtao,项目名称:JustDraw,代码行数:18,代码来源:JustJsCore.java


示例7: DetermineBasalAdapterJS

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public DetermineBasalAdapterJS(ScriptReader scriptReader, Profile profile) throws IOException {
    Log.d(TAG, "START");
    mV8rt = V8.createV8Runtime();
    mScriptReader  = scriptReader;
    realmManager = new RealmManager();

    initProfile(profile);
    initMealData();
    initGlucoseStatus();
    initIobData(profile);
    initCurrentTemp();

    initLogCallback();

    initProcessExitCallback();

    initModuleParent();

    loadScript();

    realmManager.closeRealm();
    Log.d(TAG, "DetermineBasalAdapterJS: FINISH");
}
 
开发者ID:timomer,项目名称:HAPP,代码行数:24,代码来源:DetermineBasalAdapterJS.java


示例8: DetermineBasalAdapterJS

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public DetermineBasalAdapterJS(ScriptReader scriptReader, Profile profile) throws IOException {
    Log.d(TAG, "START");
    mV8rt = V8.createV8Runtime();
    mScriptReader  = scriptReader;
    realmManager = new RealmManager();

    Date dateVar = new Date();

    initProfile(profile);
    initGlucoseStatus();
    initIobData(profile);
    initCurrentTemp();

    initLogCallback();

    initProcessExitCallback();

    initModuleParent();

    loadScript();
    realmManager.closeRealm();
    Log.d(TAG, "DetermineBasalAdapterJS: FINISH");
}
 
开发者ID:timomer,项目名称:HAPP,代码行数:24,代码来源:DetermineBasalAdapterJS.java


示例9: exec

import com.eclipsesource.v8.V8; //导入依赖的package包/类
/**
 * Unpack and execute a nodejs library. Once unpack this method will execute one of these scripts
 * in the following order: 1) [library].js; 2) main.js; 3) index.js.
 *
 * The first file found will be executed.
 *
 * @param library Library to unpack and execute this library.
 * @throws Throwable If something goes wrong.
 */
public void exec(final String library, final Throwing.Consumer<V8> callback) throws Throwable {
  Path basedir = deploy(library);
  List<String> candidates = Arrays.asList(
      basedir.getFileName().toString() + ".js",
      "main.js",
      "index.js");

  Path main = candidates.stream()
      .map(it -> basedir.resolve(it))
      .filter(it -> it.toFile().exists())
      .findFirst()
      .orElseThrow(() -> new FileNotFoundException(candidates.toString()));

  callback.accept(node.getRuntime());

  node.exec(main.toFile());

  while (node.isRunning()) {
    node.handleMessage();
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:31,代码来源:Nodejs.java


示例10: getInvocable

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Nullable
public V8 getInvocable() {
  if (Strings.isNullOrEmpty(gcsJSPath())) {
    return null;
  }

  if (mRuntime == null) {
    V8 runtime = V8.createV8Runtime();
    for (String script : getScripts()) {
      runtime.executeScript(script);
    }
    mRuntime = runtime;
  }
  return mRuntime;
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:16,代码来源:JSTransform.java


示例11: shouldNotGeneratePropertiesForGettersAndSettersWithoutAnnotations

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Test
public void shouldNotGeneratePropertiesForGettersAndSettersWithoutAnnotations() {
    final String readBooleanGetterScript = "x.fullySetUp;";
    V8JavaAdapter.injectClass(WannabeBeanNoAnnotations.class, v8);

    Assert.assertNotEquals(3344, v8.executeIntegerScript("var x = new WannabeBeanNoAnnotations(); x.i = 6688; x.i;"));
    Assert.assertEquals(V8.getUndefined(), v8.executeScript(readBooleanGetterScript));

    Assert.assertNotEquals(6688, v8.executeIntegerScript("x.j = 3344; x.j;"));
    Assert.assertEquals(V8.getUndefined(), v8.executeScript(readBooleanGetterScript));
}
 
开发者ID:alicorn-systems,项目名称:v8-adapter,代码行数:12,代码来源:V8JavaAdapterTest.java


示例12: V8VizJS

import com.eclipsesource.v8.V8; //导入依赖的package包/类
/**
 * creates and initializes V8 engine with viz.js
 * 
 * @throws IOException
 */
public V8VizJS() throws IOException {
	runtime = V8.createV8Runtime();
	runtime.executeVoidScript(JSPRINTFUNCTION);
	messages = runtime.getArray(JSMESSAGESARRAY);
	runtime.executeVoidScript(getVizCode());
	vizFunction = (V8Function) runtime.getObject("Viz");
}
 
开发者ID:plantuml,项目名称:vizjs,代码行数:13,代码来源:V8VizJS.java


示例13: JustContext

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public JustContext(V8 v8Runtime) {
    super(v8Runtime);

    mPaintFill.setStyle(Paint.Style.FILL);
    mPaintStroke.setStyle(Paint.Style.STROKE);
    mPaintFill.setFlags(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setFlags(Paint.ANTI_ALIAS_FLAG);
}
 
开发者ID:LiuHongtao,项目名称:JustDraw,代码行数:9,代码来源:JustContext.java


示例14: JustCanvas

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public JustCanvas(V8 v8Runtime, Context context) {
    super(v8Runtime);
    mJustView = new JustView(context);

    mJustContext = new JustContext(v8Runtime);
    mObject.add("context", mJustContext.getObject());
}
 
开发者ID:LiuHongtao,项目名称:JustDraw,代码行数:8,代码来源:JustCanvas.java


示例15: configureWorker

import com.eclipsesource.v8.V8; //导入依赖的package包/类
private void configureWorker(V8 runtime) {
	runtime.registerJavaMethod(this, "start", "Worker", new Class<?>[] { V8Object.class, String[].class }, true);
	V8Object worker = runtime.getObject("Worker");
	V8Object prototype = runtime.executeObjectScript("Worker.prototype");
	prototype.registerJavaMethod(this, "terminate", "terminate", new Class<?>[] { V8Object.class, Object[].class },
			true);
	prototype.registerJavaMethod(this, "postMessage", "postMessage",
			new Class<?>[] { V8Object.class, String[].class }, true);
	runtime.registerJavaMethod(WebWorker.this, "print", "print", new Class<?>[] { String.class });
	worker.setPrototype(prototype);
	worker.release();
	prototype.release();
}
 
开发者ID:irbull,项目名称:j2v8_examples,代码行数:14,代码来源:WebWorker.java


示例16: getSanitizedHtml

import com.eclipsesource.v8.V8; //导入依赖的package包/类
/**
	 * Parses the supplied markdown into html.
	 * This calls the PageDown javascript library to do the work for us.
	 */
	public static String getSanitizedHtml(String markdown){
		
//		System.out.println(new File(".").getAbsolutePath());
//		for(String f : new File(".").list()){
//			System.out.println("\t" + f);
//		}

		if(markdown == null){
			return null;
		}

		try{
			V8 runtime = V8.createV8Runtime();
			
			 runtime.executeScript( new String(Files.readAllBytes(Paths.get(PageDownUtils.class.getResource("Markdown.Converter.js").toURI()))));
	         runtime.executeScript( new String(Files.readAllBytes(Paths.get(PageDownUtils.class.getResource("Markdown.Sanitizer.js").toURI()))));
	         runtime.executeScript( new String(Files.readAllBytes(Paths.get(PageDownUtils.class.getResource("MarkdownParser.js").toURI()))));

			V8Array args = new V8Array(runtime);
			args.push(markdown);

			String html = runtime.executeStringFunction("parseMarkdown", args);
			args.release();
			runtime.release();
			return html;
		}
		catch(Exception e){
			e.printStackTrace();
			return "ERROR";
		}
	}
 
开发者ID:KevinWorkman,项目名称:StaticVoidGames,代码行数:36,代码来源:PageDownUtils.java


示例17: Nodejs

import com.eclipsesource.v8.V8; //导入依赖的package包/类
/**
 * Creates a new {@link Nodejs}.
 *
 * @param basedir Base dir where to deploy a library.
 * @param loader Class loader to use.
 */
public Nodejs(final File basedir, final ClassLoader loader) {
  this.basedir = requireNonNull(basedir, "Basedir required.");
  this.loader = requireNonNull(loader, "ClassLoader required.");
  this.node = NodeJS.createNodeJS();
  V8 v8 = node.getRuntime();
  this.scope = new MemoryManager(v8);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:14,代码来源:Nodejs.java


示例18: process

import com.eclipsesource.v8.V8; //导入依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
    throws Exception {
  return V8Context.run("window", ctx -> {
    V8 v8 = ctx.v8;

    V8Object j2v8 = ctx.hash();
    j2v8.add("createFilter", ctx.function((receiver, args) -> {
      List<PathMatcher> includes = filter(args, 0).stream()
          .map(it -> FileSystems.getDefault().getPathMatcher("glob:" + it))
          .collect(Collectors.toList());
      if (includes.isEmpty()) {
        includes.add(TRUE);
      }

      List<PathMatcher> excludes = filter(args, 1).stream()
          .map(it -> FileSystems.getDefault().getPathMatcher("glob:" + it))
          .collect(Collectors.toList());
      if (excludes.isEmpty()) {
        excludes.add(FALSE);
      }

      return ctx.function((self, arguments) -> {
        Path path = Paths.get(arguments.get(0).toString());
        if (includes.stream().filter(it -> it.matches(path)).findFirst().isPresent()) {
          return !excludes.stream().filter(it -> it.matches(path)).findFirst().isPresent();
        }
        return false;
      });
    }));

    v8.add("j2v8", j2v8);

    Map<String, Object> options = options();
    log.debug("{}", options);

    return ctx.invoke("rollup.js", source, options, filename);
  });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:40,代码来源:Rollup.java


示例19: b64

import com.eclipsesource.v8.V8; //导入依赖的package包/类
private void b64(final V8 v8) {
  v8.registerJavaMethod((JavaCallback) (receiver, args) -> {
    byte[] bytes = args.get(0).toString().getBytes(StandardCharsets.UTF_8);
    return BaseEncoding.base64().encode(bytes);
  }, "btoa");
  v8.registerJavaMethod((JavaCallback) (receiver, args) -> {
    byte[] atob = BaseEncoding.base64().decode(args.get(0).toString());
    return new String(atob, StandardCharsets.UTF_8);
  }, "atob");
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:11,代码来源:V8Context.java


示例20: ConcurrentV8

import com.eclipsesource.v8.V8; //导入依赖的package包/类
public ConcurrentV8() {
    v8 = V8.createV8Runtime();
    v8.getLocker().release();
}
 
开发者ID:alicorn-systems,项目名称:v8-adapter,代码行数:5,代码来源:ConcurrentV8.java



注:本文中的com.eclipsesource.v8.V8类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Type类代码示例发布时间:2022-05-22
下一篇:
Java Label类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap