javafx中使用了什么javascript引擎? [英] What javascript engine used inside javafx?

查看:125
本文介绍了javafx中使用了什么javascript引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebView内置了javascript引擎。它用的是什么引擎? openjdk和oracle jdk是一样的吗?可以与WebView分开使用,就像JSR 223引擎一样吗?

WebView has built-in javascript engine. What engine is used for it? Is it the same for openjdk and oracle jdk? May it be used separately from WebView, just as JSR 223 engine?

推荐答案

Oracle JRE中的JavaScript运行时

完整的Oracle Java Runtime 8附带两个JavaScript引擎:

The full Oracle Java Runtime 8 ships with two JavaScript engines:


  1. Nashorn :Nashorn的目标是使用本机JVM在Java中实现轻量级高性能JavaScript运行时。打算让Java开发人员通过JSR-223在Java应用程序中嵌入JavaScript,并使用jrunscript命令行工具开发独立的JavaScript应用程序。

  2. JavaScriptCore :由WebView 组件JavaFX系统。

  1. Nashorn: "Nashorn's goal is to implement a lightweight high-performance JavaScript runtime in Java with a native JVM. This Project intends to enable Java developers embedding of JavaScript in Java applications via JSR-223 and to develop free standing JavaScript applications using the jrunscript command-line tool."
  2. JavaScriptCore: The JavaScript engine built into the WebKit implementation wrapped by WebView component the JavaFX system.

WebView和JavaFX应用程序使用的JavaScript运行时

JavaFX Webkit不使用Nashorn,它使用JavaScriptCore。

您可以使用Nashorn编写JavaFX应用程序和API(作为Java编程的替代方案),您可以使用Nashorn作为JavaFX FXML文档的JavaFX脚本引擎,但是您无法使用Nashorn是WebView中的JavaScript引擎。

You can use Nashorn to program JavaFX applications and APIs (as an alternative to programming in Java) and you can use Nashorn as a JavaFX script engine for JavaFX FXML documents, but you cannot use Nashorn as the JavaScript engine within WebView.

背景源信息

有JavaFX开发人员提供的一些有关WebView中JavaScript实现的信息 JavaFX邮件列表。引用Oracle JavaFX开发人员Richard Bair(他反过来引用了WebKit开发人员Olivier Hunt):

There is some information on the JavaScript implementation in WebView provided by the JavaFX developers on the JavaFX mailing list. Quoting Richard Bair, an Oracle JavaFX developer (who in turn quotes Olivier Hunt, a WebKit Developer):


嗯....它是这样的。 WebKit默认带有JavaScriptCore,这是我们使用的JS引擎。非常好。我的理解是JavaScriptCore(又名SquirrelFish aka Nitro)是 Safari使用的相同JS引擎。当Chrome和Apple都是WebKit的一部分时,谷歌放入WebKit的一个抽象层就是能够交换JavaScript引擎。当Google将WebKit分解为Blink时,WebKit项目需要对不同的JS VM进行抽象消失。因此,WebKit的人一直在谈论删除这些抽象,以便你将无法换掉JS引擎,[进一步信息]。如果/当发生这种情况时,我们很难(或不可能)切换到Nashorn for WebView。我们不打算分叉WebKit,所以我们必须跟随WebKit的做法。

Well…. it goes like this. WebKit comes with JavaScriptCore by default, and this is the JS engine that we use. It is pretty good. My understanding is that JavaScriptCore (aka SquirrelFish aka Nitro) is the same JS engine used by Safari. When Chrome and Apple were both part of WebKit, one of the abstraction layers that Google had put into WebKit was the ability to swap out the JavaScript engine. When Google forked WebKit into Blink, the need for the WebKit project to have an abstraction for a different JS VM disappeared. As a consequence, the WebKit guys have been talking about removing those abstractions such that you won't be able to swap out the JS engine, [further info]. If/When that happens, it will be hard (or impossible) for us to switch over to Nashorn for WebView. We aren't going to fork WebKit, so we sort of have to follow along with what WebKit does.


支持V8相当可观Webkit的负担,支持多个
JS引擎所需的大量,繁琐且昂贵的抽象(参见多年前关于该主题的原始讨论)。

"Supporting V8 places a considerable burden on webkit, there are a number of large, cumbersome and expensive abstractions required for to support multiple JS engines (see the original discussions on the topic from many years ago).

此外,我们只支持WebKit2中的JSC,所以我认为任何事情都不能让b $ b让我相信至少保持对多个JS引擎的支持对项目有利。 - Oliver Hunt

Additionally we will only be supporting JSC in WebKit2, so I don't think anything could convince me at least that maintaining support for multiple JS engines is good for the project." - Oliver Hunt


免责声明

这个答案仅与Oracle Java 8版本有关;备用和未来的JavaFX和Java实现可能有不同的内部实现。

This answer is related to Oracle Java 8 releases only; alternate and future JavaFX and Java implementations may have different internal implementations.


可以使用它与WebView分开,就像JSR 223引擎一样?

May it be used separately from WebView, just as JSR 223 engine?

WebView中的JavaScriptCore不能单独用作WebView作为JSR 223引擎(目前为止)我所知)。

JavaScriptCore in WebView cannot be used separately from WebView as a JSR 223 engine (as far as I know).

我认为最好将支持WebView的JavaScriptCore实现视为WebView组件的内部实现细节,而不是将JavaScript实现视为通用JavaScript运行时在别处使用。它不是WebView中特定用途之外的官方支持组件,并且在其中使用时,公共WebView API使您免受它使用的JavaScript运行时的实现细节:这样对于JavaScript运行时的用户而言它是故意不透明的实际上用于在WebView组件中执行JavaScript。

I think it is best to treat the JavaScriptCore implementation shipped to support WebView as an internal implementation detail of the WebView component and not treat the JavaScript implementation as a general purpose JavaScript Runtime to be used elsewhere. It is not an officially supported component outside of its specific use within WebView, and, when used there, the public WebView API shields you from the implementation details of the JavaScript runtime it uses: Such that it is deliberately opaque to users which JavaScript runtime is actually used to execute JavaScript within the WebView component.

这篇关于javafx中使用了什么javascript引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆