项目作者: geokaralis

项目描述 :
A Javascript runtime through v8 for android, sharing code between web and mobile.
高级语言: C
项目地址: git://github.com/geokaralis/jscore.git
创建时间: 2019-02-13T10:03:32Z
项目社区:https://github.com/geokaralis/jscore

开源协议:Apache License 2.0

下载


JSCore


JSCore Logo


JSCore is an android library for running javascript inside java. It’s main purpose is for code sharing between web and mobile. In it’s core it uses google’s v8 javascript runtime library. One main characteristic of JSCore is the concept of javascript bindings within java/kotlin, making the js library feel more like a native one.

Usage

  1. class Underscore(private val src: String): JSObject() {
  2. // Bind Underscore.js's contains function to Kotlin for integers
  3. fun contains(list: ArrayList<Int>, index: Int): Boolean {
  4. return JSObject().bind(src).function("contains", arrayListOf(list, index))
  5. }
  6. }
  1. val list: ArrayList<Int> = ArrayList()
  2. list.add(1)
  3. list.add(2)
  4. list.add(3)
  5. val underscore = Underscore(src)
  6. val contains = underscore.contains(list, 3) // true

JSCore also evaluates scripts as per the usual way.

  1. JSContext ctx = new JSContext(); // Javascript VM context
  2. String greeting = (String) ctx.evaluate(""
  3. + "var message = 'hello world!'"
  4. + "message.toUpperCase();");
  5. Log.d("Greeting", greeting); // HELLO WORLD!

v8

v8 is used as JSCore’s javascript runtime environment.

Kotlin

JSCore is written entirely in Kotlin.

Contributing

JSCore is still at the early alpha stages of architecting and c++ support through ndk. If you ‘d like to contribute to this project feel free to pull request and provide ideas through issues.

LICENSE

  1. Copyright (c) 2019, George Karalis.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.