Giter Club home page Giter Club logo

chakracore-rs's Introduction

NOTE: This project is not currently maintained, due to ChakraCore itself is no longer being actively developed.

chakracore-rs

crates.io version Documentation Language (Rust)

chakracore-rs is an iditiomatic wrapper for ChakraCore, written in Rust.

This repository contains two crates:

  • chakracore-sys - raw bindings to the JavaScript Runtime.
  • chakracore - an idiomatic wrapper, built on the chakracore-sys crate.

chakracore

This is a wrapper around the JavaScript Runtime (JSRT), used in Microsoft Edge and node-chakracore. The library is still in pre-release and is not yet stable. The tests try to cover as much functionality as possible but memory leaks and segfaults may occur. If you want a more stable library, use the underlying API directly; chakracore-sys.

Installation

Add this to your Cargo.toml:

[dependencies]
chakracore = "0.2"

... and this to your crate root:

extern crate chakracore as js;

NOTE: See additional build instructions for chakracore-sys

Examples

Hello World

extern crate chakracore as js;

fn main() {
  let runtime = js::Runtime::new().unwrap();
  let context = js::Context::new(&runtime).unwrap();
  let guard = context.make_current().unwrap();

  let result = js::script::eval(&guard, "5 + 5").unwrap();
  assert_eq!(result.to_integer(&guard), 10);
}

Function - Multiply

extern crate chakracore as js;

fn main() {
  let runtime = js::Runtime::new().unwrap();
  let context = js::Context::new(&runtime).unwrap();
  let guard = context.make_current().unwrap();

  let multiply = js::value::Function::new(&guard, Box::new(|guard, info| {
      let result = info.arguments[0].to_integer(guard)
                 * info.arguments[1].to_integer(guard);
      Ok(js::value::Number::new(guard, result).into())
  }));

  let result = multiply.call(&guard, &[
      &js::value::Number::new(&guard, 191).into(),
      &js::value::Number::new(&guard, 7).into(),
  ]).unwrap();

  assert_eq!(result.to_integer(&guard), 1337);
}

chakracore-sys

This library handles the static and dynamic linking of the JavaScript Runtime. The rust bindings are generated (on the fly) for the interface, therefore the entire API is exposed and accessable.

A Hello World example can be found in src/lib.rs.

An example of the generated bindings can be found here.

Requirements

This library builds the ChakraCore component in the source tree. It is cloned by the build script and built in test-mode (same as release, but includes more runtime checks). If custom build settings are desired, ChakraCore can be built manually, out of tree, and specified using two environment variables:

  • CHAKRA_SOURCE: The root of the ChakraCore checkout.
  • CHAKRA_BUILD: The bin directory of the build.
    • Default on Windows: %CHAKRA_SOURCE%\Build\VcBuild\bin\{BUILD_TYPE}.
    • Default on Unix: $CHAKRA_SOURCE/BuildLinux/{BUILD_TYPE}.

This script has not been tested with the --embed-icu option.

Static/Shared

By default, this library links ChakraCore dynamically. There is a feature called static that builds it by linking to the generated archive instead. On windows, only shared library builds are available as of this time (see #279).

Prerequisites

The library naturally shares all of ChakraCore's dependencies. Beyond this, rust-bindgen is used in the build script, which requires clang-3.8 or later. On Unix pkg-config is required as well.

Windows
  • Visual Studio 2013/2015/2017 with:
    • Windows SDK 8.1
    • C++ support
  • clang-3.8 or later. Downloads can be found here.
    Remember to add LLVM directories to PATH during installation.
  • Rust MSVC toolchain (i.e rustup install stable-msvc).
    This is required since ChakraCore uses the MSVC ABI.
  • If building for ARM: Windows 10 SDK (July 2015)
macOS
$ brew install cmake icu4c llvm38 pkg-config
Debian-based linuxes
# apt-get install -y build-essential cmake clang libunwind8-dev \
#     libicu-dev llvm-3.8-dev libclang-3.8-dev pkg-config liblzma-dev

Building

  • Windows

    Ensure that you are running in a Visual Studio command line environment, either by sourcing vcvarsall.bat, or by building from the Visual Studio Command Prompt.

    $ cargo test -vv
    
  • Unix
    $ cargo test -vv [--features static]
    

In case you find yourself stuck in the build process, open an issue.

Status

This library has been built on macOS 10.12 x86_64, Ubuntu 16.10 x86_64 and Windows 10 x86_x64.

chakracore-rs's People

Contributors

darfink avatar rosshadden avatar srijs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chakracore-rs's Issues

Expose JsGetAndClearException API

Quoting the JSRT docs:

When a JavaScript exception occurs during script execution, the containing runtime is put into an exception state. While in an exception state, no code can run and all API calls will fail with the error code JsErrorInExceptionState until the host retrieves and clears the exception using the JsGetAndClearException API.

It would be useful to expose the JsGetAndClearException API on the context so the runtime can continue to be used after an exception occurred.

EDIT: Reading through the source code I noticed that most places use util::handle_exception to do just that. I might've run into an edge-case where it doesn't do that. Let me try to narrow down the problem.

lib directory does not exist on Windows custom

C:\Users\camer\rs\chakracore-rs\chakracore-sys>echo %CHAKRA_SOURCE%
C:\Users\camer\rs\ChakraCore

C:\Users\camer\rs\chakracore-rs\chakracore-sys>echo %CHAKRA_BUILD%
C:\Users\camer\rs\ChakraCore\Build\VcBuild\bin\x64_release

C:\Users\camer\rs\chakracore-rs\chakracore-sys>cargo test -vv
       Fresh unicode-width v0.1.4
       Fresh utf8-ranges v1.0.0
       Fresh rustc-serialize v0.3.24
       Fresh unicode-segmentation v1.2.0
       Fresh log v0.3.8
       Fresh glob v0.2.11
       Fresh bitflags v0.8.2
       Fresh cfg-if v0.1.2
       Fresh unicode-xid v0.0.4
       Fresh regex-syntax v0.4.1
       Fresh void v1.0.2
       Fresh bitflags v0.9.1
       Fresh winapi-build v0.1.1
       Fresh ansi_term v0.9.0
       Fresh winapi v0.2.8
       Fresh peeking_take_while v0.1.2
       Fresh lazy_static v0.2.8
       Fresh libc v0.2.29
       Fresh strsim v0.6.0
       Fresh pkg-config v0.3.9
       Fresh vec_map v0.8.0
       Fresh syntex_pos v0.58.1
       Fresh unreachable v1.0.0
       Fresh memchr v1.0.1
       Fresh thread_local v0.3.4
       Fresh nom v3.2.0
       Fresh aho-corasick v0.6.3
       Fresh kernel32-sys v0.2.2
       Fresh cexpr v0.2.2
       Fresh regex v0.2.2
       Fresh term v0.4.6
       Fresh atty v0.2.2
       Fresh term_size v0.3.0
       Fresh libloading v0.4.0
       Fresh env_logger v0.4.3
       Fresh syntex_errors v0.58.1
       Fresh textwrap v0.7.0
       Fresh clang-sys v0.18.0
       Fresh syntex_syntax v0.58.1
       Fresh clap v2.26.0
       Fresh aster v0.41.0
       Fresh quasi v0.32.0
       Fresh syntex v0.58.1
       Fresh quasi_codegen v0.32.0
       Fresh bindgen v0.25.5
   Compiling chakracore-sys v0.2.2 (file:///C:/Users/camer/rs/chakracore-rs/chakracore-sys)
     Running `C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\build\chakracore-sys-386c670e5139aed9\build-script-build`
cargo:rerun-if-env-changed=CHAKRA_SOURCE
cargo:rerun-if-env-changed=CHAKRA_BUILD
chakracore-sys/build.rs:48: Using custom ChakraCore build
thread 'main' panicked at 'Library search path '"C:\\Users\\camer\\rs\\ChakraCore\\Build\\VcBuild\\bin\\x64_release\\lib"' does not exist', build.rs:234
stack backtrace:
   0: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:71
   1: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:354
   2: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:371
   3: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:549
   4: std::panicking::begin_panic<collections::string::String>
             at C:\projects\rust\src\libstd\panicking.rs:511
   5: build_script_build::linking::add_path<&std::path::PathBuf>
             at .\build.rs:234
   6: build_script_build::linking::setup
             at .\build.rs:194
   7: build_script_build::main
             at .\build.rs:56
   8: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:98
   9: std::rt::lang_start
             at C:\projects\rust\src\libstd\rt.rs:52
  10: main
  11: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
  12: BaseThreadInitThunk
error: failed to run custom build command for `chakracore-sys v0.2.2 (file:///C:/Users/camer/rs/chakracore-rs/chakracore-sys)`
process didn't exit successfully: `C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\build\chakracore-sys-386c670e5139aed9\build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=CHAKRA_SOURCE
cargo:rerun-if-env-changed=CHAKRA_BUILD
chakracore-sys/build.rs:48: Using custom ChakraCore build

--- stderr
thread 'main' panicked at 'Library search path '"C:\\Users\\camer\\rs\\ChakraCore\\Build\\VcBuild\\bin\\x64_release\\lib"' does not exist', build.rs:234
stack backtrace:
   0: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:71
   1: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:354
   2: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:371
   3: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:549
   4: std::panicking::begin_panic<collections::string::String>
             at C:\projects\rust\src\libstd\panicking.rs:511
   5: build_script_build::linking::add_path<&std::path::PathBuf>
             at .\build.rs:234
   6: build_script_build::linking::setup
             at .\build.rs:194
   7: build_script_build::main
             at .\build.rs:56
   8: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:98
   9: std::rt::lang_start
             at C:\projects\rust\src\libstd\rt.rs:52
  10: main
  11: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283

To get past this error, I did mkdir %CHAKRA_BUILD%\lib.

Value::to_json should return Result

While testing out the current master I ran into this gotcha. JSON.stringify can throw, for instance when the toJSON method on the value throws, or when passed a circular object graph. It would be useful for Value::to_json to return a Result in order to allow the user to catch this exception.

JsCopyString expected 5 parameters

Looks like there may be a breaking change in JsCopyString.
chakra-core/ChakraCore#3433

C:\Users\camer\rs\chakracore-rs\chakracore-sys>cargo test -vv
       Fresh bitflags v0.9.1
       Fresh cfg-if v0.1.2
       Fresh void v1.0.2
       Fresh vec_map v0.8.0
       Fresh bitflags v0.8.2
       Fresh winapi-build v0.1.1
       Fresh rustc-serialize v0.3.24
       Fresh glob v0.2.11
       Fresh unicode-xid v0.0.4
       Fresh lazy_static v0.2.8
       Fresh strsim v0.6.0
       Fresh pkg-config v0.3.9
       Fresh utf8-ranges v1.0.0
       Fresh unicode-width v0.1.4
       Fresh peeking_take_while v0.1.2
       Fresh winapi v0.2.8
       Fresh log v0.3.8
       Fresh regex-syntax v0.4.1
       Fresh libc v0.2.29
       Fresh unicode-segmentation v1.2.0
       Fresh ansi_term v0.9.0
       Fresh unreachable v1.0.0
       Fresh syntex_pos v0.58.1
       Fresh memchr v1.0.1
       Fresh thread_local v0.3.4
       Fresh aho-corasick v0.6.3
       Fresh nom v3.2.0
       Fresh kernel32-sys v0.2.2
       Fresh regex v0.2.2
       Fresh cexpr v0.2.2
       Fresh term_size v0.3.0
       Fresh atty v0.2.2
       Fresh libloading v0.4.0
       Fresh term v0.4.6
       Fresh env_logger v0.4.3
       Fresh textwrap v0.7.0
       Fresh clang-sys v0.18.0
       Fresh syntex_errors v0.58.1
       Fresh clap v2.26.0
       Fresh syntex_syntax v0.58.1
       Fresh aster v0.41.0
       Fresh quasi v0.32.0
       Fresh syntex v0.58.1
       Fresh quasi_codegen v0.32.0
       Fresh bindgen v0.25.5
   Compiling chakracore-sys v0.2.2 (file:///C:/Users/camer/rs/chakracore-rs/chakracore-sys)
     Running `rustc --crate-name chakracore_sys src\lib.rs --emit=dep-info,link -C debuginfo=2 --test -C metadata=7017975e9837d42b -C extra-filename=-7017975e9837d42b --out-dir C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\deps -L dependency=C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\deps --extern libc=C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\deps\liblibc-275c4a96a27a8a7e.rlib -L native=C:\Users\camer\rs\ChakraCore\Build\VcBuild\bin\x64_release\lib -l dylib=ChakraCore`
error[E0061]: this function takes 5 parameters but 4 parameters were supplied
    --> src\lib.rs:70:30
     |
70   |               js!(JsCopyString(result_as_string,
     |                                ^^^^^^^^^^^^^^^^ expected 5 parameters
     |
    ::: C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\build\chakracore-sys-60176a7cbd0e748e\out/ffi.rs
     |
3607 | /     pub fn JsCopyString(value: JsValueRef, buffer: *mut libc::c_char,
3608 | |                         bufferSize: usize, writtenLength: *mut usize,
3609 | |                         actualLength: *mut usize) -> JsErrorCode;
     | |_________________________________________________________________- defined here

error: aborting due to previous error(s)

error: Could not compile `chakracore-sys`.

Caused by:
  process didn't exit successfully: `rustc --crate-name chakracore_sys src\lib.rs --emit=dep-info,link -C debuginfo=2 --test -C metadata=7017975e9837d42b -C extra-filename=-7017975e9837d42b --out-dir C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\deps -L dependency=C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\deps --extern libc=C:\Users\camer\rs\chakracore-rs\chakracore-sys\target\debug\deps\liblibc-275c4a96a27a8a7e.rlib -L native=C:\Users\camer\rs\ChakraCore\Build\VcBuild\bin\x64_release\lib -l dylib=ChakraCore` (exit code: 101)

C:\Users\camer\rs\chakracore-rs\chakracore-sys>rustup show
Default host: x86_64-pc-windows-msvc

installed toolchains
--------------------

stable-i686-pc-windows-gnu
stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc (default)
beta-x86_64-pc-windows-gnu
nightly-x86_64-pc-windows-gnu
nightly-x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.19.0 (0ade33941 2017-07-17)

How to pass function callbacks?

I am trying to figure out how to use function callbacks. In this example, I'm simply creating a numeric array and trying to filter for just the even numbers. Unfortunately, the returned array is always empty. Any idea how to make this work? Here is what I last tried:

extern crate chakracore as js;

use std::io::prelude::*;
use std::fs::File;
use js::Property;

fn main() {
    let runtime = js::Runtime::new().unwrap();
    let context = js::Context::new(&runtime).unwrap();
    let guard = context.make_current().unwrap();


    // create a JavaScript Array
    let length = 10;
    let array = js::value::Array::new(&guard, length);
    for i in 0..length {
        array.set_index(&guard, i, &js::value::Number::new(&guard, i as i32));
    }
    println!("array: {:?}", array.len(&guard));


    // try filtering it
    let is_even = js::value::Function::new(&guard, Box::new(|guard, info| {
        //        let i = info.arguments[0].to_integer(guard);
        //        println!("i: {:?}", i);
        //        Ok(js::value::Boolean::new(guard, i % 2 == 0).into())
        println!("is_even");
        Ok(js::value::Boolean::new(guard, true).into())
    }));

    let fn_filter = array.get(&guard, &Property::new(&guard, "filter")).into_function().unwrap();

    let filtered_array = fn_filter.call(&guard, &[&is_even]).unwrap(); //.into_array().unwrap();
    println!("filtered_array: {:?}", filtered_array);

    //    for v in filtered_array.iter(&guard){
    //        println!("filtered v: {:?}", v);
    //    }

}

Runtime is not Send

Hi!

According to the Chakracore JSRT docs, runtimes "[...] are rental threaded, so a runtime that is not currently active on a thread (i.e. isn’t running any JavaScript code or responding to any calls from the host) can be used on any thread that doesn’t already have an active runtime on it.".

The way I understand it is that Runtime should implement Send, so it can be sent between threads. However, trying to send a runtime between threads results in the following errors:

error[E0277]: the trait bound `*mut libc::c_void: std::marker::Send` is not satisfied in `js::Runtime`
   = help: within `js::Runtime`, the trait `std::marker::Send` is not implemented for `*mut libc::c_void`
   = note: required because it appears within the type `chakracore_sys::JsRuntimeHandle`
   = note: required because it appears within the type `js::Runtime`
error[E0277]: the trait bound `std::ops::Fn() + 'static: std::marker::Send` is not satisfied
   = help: the trait `std::marker::Send` is not implemented for `std::ops::Fn() + 'static`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<std::ops::Fn() + 'static>`
   = note: required because it appears within the type `std::boxed::Box<std::ops::Fn() + 'static>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<std::boxed::Box<std::ops::Fn() + 'static>>`
   = note: required because it appears within the type `std::boxed::Box<std::boxed::Box<std::ops::Fn() + 'static>>`
   = note: required because it appears within the type `std::option::Option<std::boxed::Box<std::boxed::Box<std::ops::Fn() + 'static>>>`
   = note: required because it appears within the type `js::Runtime`

0.2.0 does not build

Perhaps it worked in the past, but nowadays the following occurs:

Compiling syntex_syntax v0.58.1
error[E0423]: expected function, tuple struct or tuple variant, found struct `ast::Name`
   --> C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_syntax-0.58.1\src\symbol.rs:146:27
    |
146 |                       name: ast::Name($index),
    |                             ^^^^^^^^^
...
165 | / declare_keywords! {
166 | |     // Invalid identifier
167 | |     (0,  Invalid,        "")
168 | |
...   |
231 | |     (56, CrateRoot, "{{root}}")
232 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Crate is not published

It doesn't seem that chakracore is published, though chakracore-sys is.

Btw thanks for this project, I'm hoping to use it in a thing. It's not immediately clear what works or what doesn't, but if I run into something I know I can just use chakracore-sys like you mentioned.

Segfault when dropping Context

I made a simple program (uses ChakraCore 0.11, current master) which segfaults when releasing a Context:

Process 29099 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x907f32000)
    frame #0: 0x000000010021a07c libChakraCore.dylib`VirtualTableInfoBase::GetVirtualTable(ptr=0x0000000907f32000) at vtinfo.h:89
   86  	class VirtualTableInfoBase
   87  	{
   88  	public:
-> 89  	    static INT_PTR GetVirtualTable(void * ptr) { return (*(INT_PTR*)ptr); }
   90  	protected:
   91  	    static void SetVirtualTable(void * ptr, INT_PTR vt) { *(INT_PTR*)ptr = vt; }
   92  	};
Target 0: (rustproxy) stopped.
(lldb) fr v
(void *) ptr = 0x0000000907f32000
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x907f32000)
  * frame #0: 0x000000010021a07c libChakraCore.dylib`VirtualTableInfoBase::GetVirtualTable(ptr=0x0000000907f32000) at vtinfo.h:89
    frame #1: 0x00000001003a2545 libChakraCore.dylib`VirtualTableInfo<JsrtContextCore>::HasVirtualTable(ptr=0x0000000907f32000) at vtinfo.h:101
    frame #2: 0x00000001003a2525 libChakraCore.dylib`JsrtContext::Is(ref=0x0000000907f32000) at JsrtContextCore.cpp:17
    frame #3: 0x00000001002ee3ac libChakraCore.dylib`::JsRelease(ref=0x0000000907f32000, count=0x00007ffeefbfe948) at Jsrt.cpp:682
    frame #4: 0x000000010002bb4b rustproxy`chakracore::util::release_reference::hb73d2b9d781d679f(reference=JsRef @ 0x00007ffeefbfe938) at util.rs:34
    frame #5: 0x000000010002613a rustproxy`_$LT$chakracore..context..Context$u20$as$u20$core..ops..drop..Drop$GT$::drop::hd59efd86683630b5(self=0x00007ffeefbfeae8) at macros.rs:75
    frame #6: 0x0000000100001af5 rustproxy`core::ptr::drop_in_place::h161661c845e43bd1((null)=0x00007ffeefbfeae8) at ptr.rs:59
    frame #7: 0x0000000100001a8a rustproxy`core::ptr::drop_in_place::h1072f79302fb8014((null)=0x00007ffeefbfeab0) at ptr.rs:59
    frame #8: 0x0000000100002bb4 rustproxy`rustproxy::main::h0a8ee1b9fd89ba26 at main.rs:210
<snip>

This is likely due to the latest ChakraCore, but I thought I'd still bring it up.

This isn't the first segfault I've seen related to the "Virtual Table"

Cloning Context/Value fails w/o ContextGuard

Problem:

The JsAddRef and JsRelease APIs require a current context to be set in order to work. However, they are being exposed through the Clone and Drop traits that don't require a ContextGuard to be present when clone is called, or the value is dropped.

This results in the following panics, when a value is cloned and/or dropped w/o a current context:

thread '<unnamed>' panicked at 'Call to 'JsAddRef(value, ::std::ptr::null_mut())' failed with: NoCurrentContext', /
Users/sam/.cargo/git/checkouts/chakracore-rs-259abda0f25cff98/cbe5ca1/src/value/function.rs:158
thread '<unnamed>' panicked at 'Call to 'unsafe { JsRelease(self.as_raw(), &mut count) }' failed with: NoCurrentContext', /Users/sam/.cargo/git/checkouts/chakracore-rs-259abda0f25cff98/cbe5ca1/src/value/function.rs:158

I'm struggling to think of a way to expose a safe API through clone/drop, tbh. Especially drop seems to be problematic, because Rust offers no way to control under which circumstances a value might be dropped.

A possible way to fix it could be to tie the lifetime of a Context or Value to the lifetime of the ContextGuard, which would require the value to be dropped before the context guard is dropped, i.e. before the current context is unset, and would require the context guard to be alive in order to clone a value.

The downside is that this complicates storing contexts or values in Rust data structures, but it's the only possible solution I can think of at this point.

Having trouble building on macOS

Having some trouble build on macOS 10.12

I followed the brew install instructions and force linked but perhaps I am just missing something simple

chakracore-sys-2d117dd71bab5fd5/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=CHAKRA_SOURCE
cargo:rerun-if-env-changed=CHAKRA_BUILD
/usr/local/bin/pkg-config
chakracore-sys/build.rs:51: Using default ChakraCore build (version: 1.5.1)
chakracore-sys/build.rs:103: Binaries already built, using existing...
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCommon.h:79:9: error: unknown type name 'uintptr_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCommon.h:84:9: error: unknown type name 'uint32_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCommon.h:85:9: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:932:18: error: unknown type name 'uint32_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:933:17: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:934:15: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:935:19: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:948:14: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:949:15: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:950:15: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:962:14: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:963:15: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:978:14: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:979:14: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:981:15: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:997:18: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:998:18: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:1014:19: error: unknown type name 'int64_t', err: true
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCore.h:248:20: error: unknown type name 'uint16_t', err: true
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true

--- stderr
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCommon.h:79:9: error: unknown type name 'uintptr_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCommon.h:84:9: error: unknown type name 'uint32_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCommon.h:85:9: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:932:18: error: unknown type name 'uint32_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:933:17: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:934:15: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:935:19: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:948:14: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:949:15: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:950:15: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:962:14: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:963:15: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:978:14: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:979:14: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:981:15: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:997:18: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:998:18: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraDebug.h:1014:19: error: unknown type name 'int64_t'
/Users/corbinu/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.2/target/source-1.5.1/lib/Jsrt/ChakraCore.h:248:20: error: unknown type name 'uint16_t'
fatal error: too many errors emitted, stopping now [-ferror-limit=]
thread 'main' panicked at 'Failed to generate binding: ()', src/libcore/result.rs:860
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Compilation problem

Hi! Thanks for making this! ❤️

I'm running into the following compilation problem:

/home/saghul/.cargo/registry/src/github.com-1ecc6299db9ec823/chakracore-sys-0.2.3/target/source-1.7.6/lib/Backend/IRBuilderAsmJs.cpp:1063:14: error: comparison of two values with different enumeration types in switch statement ('Js::AsmJsRetType::Which' and 'Js::AsmJsVarType::Which') [-Werror,-Wenum-compare-switch]
        case Js::AsmJsVarType::Which::Int64:
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

In case it matters, I'm using Rust 1.127.0. Cheers!

Only one thread can access the same context at a given time

This was non-obvious to me since I have experience with V8 which takes care of synchronization for you.

Before setting a context, you might need to unset the current one. Which is what your ContextGuard does as it is dropped. Except it doesn't prevent another thread from trying to set the same context concurrently.

I was thinking an Arc<Mutex<()>> might work for entering a context.

I'm not sure what's the logic with setting the "previous" context as the current context from the Context#exit method. I'm assuming people won't be using more than 1 context per runtime, so inner guards are probably infrequent.

Any ideas?

Audit context guard soundness

How is the soundness of Context::make_current guaranteed? For example, what happens if user calls it for two different contexts and then drops the guard in reverse order?

Can't build to target musl on Ubuntu

Sorry I feel like I am going to be that annoying guy who doesn't ever know whats going on but I was trying to build on Ubuntu now and the normal target works.

However I wanted to build targeting musl so libc is build into the binary (lets it run on any linux system and a FROM scratch docker container)

I then get this

cargo run --target=x86_64-unknown-linux-musl
   Compiling rocket_contrib v0.2.8
   Compiling chakracore-sys v0.2.2
error: failed to run custom build command for `chakracore-sys v0.2.2`
process didn't exit successfully: `/home/corbinu/Developer/corbinu/rocket-challenge/target/debug/build/chakracore-sys-795c32afd2d7755e/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=CHAKRA_SOURCE
cargo:rerun-if-env-changed=CHAKRA_BUILD
/usr/bin/pkg-config
chakracore-sys/build.rs:51: Using default ChakraCore build (version: 1.5.1)
chakracore-sys/build.rs:103: Binaries already built, using existing...
cargo:rustc-link-search=native=/home/corbinu/Developer/corbinu/rocket-challenge/target/x86_64-unknown-linux-musl/debug/build/chakracore-sys-201a0b8ad8cf6a2f/out/lib-1.5.1
cargo:rustc-link-lib=static=ChakraCoreStatic

--- stderr
thread 'main' panicked at 'No package configuration for 'libunwind-ptrace' found', /checkout/src/libcore/option.rs:823
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I tried installing libunwind-dev and that din't help any thoughts?

How to load a js file?

How can you load a JavaScript module and then call properties or functions in that module? For example, how would I load C:\Users\camer\ts\TsAst\node_modules\typescript\lib\typescript.js and then access ts.version which should return 2.4.2 JsString?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.