Skip to content

joeosburn/JavaScriptCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript

This package provides JavaScript APIs for several engines.

Package Targets

  • JavaScipt - common protocols
  • V8 - google's v8 engine wrapper
  • JavaScriptCoreSwift - linux version of apple's JavaScriptCore
  • СhakraCore - microsoft's chakracore engine wrapper (WIP)

Package.swift

.package(url: "https://github.com/tris-foundation/javascript.git", .branch("master"))

Requirements

V8

macOS

brew install v8

Linux

add-apt-repository -y ppa:pinepain/libv8-archived
apt update && apt install -y libv8-dev

JavaScriptCore

Linux

apt install -y libjavascriptcoregtk-1.0-dev

Usage

let context = JSContext()
try context.evaluate("40 + 2")

try context.createFunction(name: "getResult") {
    return .string("result string")
}
let result = try context.evaluate("getResult()")
assertTrue(result.isString)
assertEqual(try result.toString(), "result string")
assertEqual("\(result)", "result string")

Useful commands

macOS

swift package \
 -Xcc -I/usr/local/include \
 -Xlinker -L/usr/local/lib \
 -Xlinker /usr/local/lib/libv8.dylib \
 -Xlinker /usr/local/lib/libv8_libbase.a \
 -Xlinker /usr/local/lib/libv8_libplatform.a \
 generate-xcodeproj

swift test \
 -Xlinker /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore \
 -Xcc -I/usr/local/include \
 -Xlinker /usr/local/lib/libv8.dylib \
 -Xlinker /usr/local/lib/libv8_libbase.a \
 -Xlinker /usr/local/lib/libv8_libplatform.a \
 --generate-linuxmain

Linux

swift test -Xlinker /usr/lib/libv8_libbase.a -Xlinker /usr/lib/libv8_libplatform.a

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 99.5%
  • C 0.5%