JavaScriptCore.cr
JavaScriptCore bindings for Crystal
What is this?
JavaScriptCore is a framework that provides a JavaScript engine for WebKit implementations, and provides this type of scripting in other contexts within macOS. JavaScriptCore is originally derived from KDE's JavaScript engine (KJS) library (which is part of the KDE project) and the PCRE regular expression library. Since forking from KJS and PCRE, JavaScriptCore has been improved with many new features and greatly improved performance.
from: https://en.wikipedia.org/wiki/WebKit#JavaScriptCore
This shard provides bindings for it, allowing you to evaluate JS from Crystal!
Bindings are being generated using gi-crystal.
Dependencies
You need JavaScriptCore 5.0
. Your distro might provide it as libjavascriptcoregtk-5_0
or typelib-1_0-JavaScriptCore-5_0
. If it doesn't then try installing webkit2gtk
(the latest, -dev or -devel version if available). Doc generation will probably only be availble by installing one of the webkit2gtk
packages.
Installation
-
Add the dependency to your
shard.yml
:dependencies: javascriptcore: github: GeopJr/JavaScriptCore.cr
-
Run
shards install
-
Run
./bin/gi-crystal
to generate the bindings
Usage
There's a lot you can do with the bindings, but here's a simple evaluation:
require "javascriptcore"
context = JavaScriptCore::Context.new
script = "['Java', 'Script', 'Core'].join('')"
result = context.evaluate(script, -1)
p result.to_s #=> "JavaScriptCore"
There might be more examples on ./spec
.
Contributing
- Read the Code of Conduct
- Fork it ( https://github.com/GeopJr/JavaScriptCore.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request