mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-26 00:59:28 -05:00
bind v8::V8::Initialize and v8::V8::Dispose (#10)
This commit is contained in:
parent
3f6812ee60
commit
05ce4006c0
2 changed files with 30 additions and 1 deletions
|
@ -6,4 +6,8 @@ void v8__V8__SetFlagsFromCommandLine(int *argc, char **argv) {
|
|||
}
|
||||
|
||||
const char *v8__V8__GetVersion() { return v8::V8::GetVersion(); }
|
||||
|
||||
void v8__V8__Initialize() { v8::V8::Initialize(); }
|
||||
|
||||
bool v8__V8__Dispose() { return v8::V8::Dispose(); }
|
||||
}
|
||||
|
|
27
src/v8.rs
27
src/v8.rs
|
@ -11,8 +11,9 @@ extern "C" {
|
|||
argc: *mut c_int,
|
||||
argv: *mut *mut c_char,
|
||||
);
|
||||
|
||||
pub fn v8__V8__GetVersion() -> *const c_char;
|
||||
pub fn v8__V8__Initialize();
|
||||
pub fn v8__V8__Dispose() -> bool;
|
||||
}
|
||||
|
||||
/// Pass the command line arguments to v8.
|
||||
|
@ -68,6 +69,7 @@ fn test_set_flags_from_command_line() {
|
|||
);
|
||||
}
|
||||
|
||||
/// Get the version string.
|
||||
pub fn get_version() -> &'static str {
|
||||
let version = unsafe { v8__V8__GetVersion() };
|
||||
let c_str = unsafe { CStr::from_ptr(version) };
|
||||
|
@ -78,3 +80,26 @@ pub fn get_version() -> &'static str {
|
|||
fn test_get_version() {
|
||||
assert!(get_version().len() > 3);
|
||||
}
|
||||
|
||||
/// Initializes V8. This function needs to be called before the first Isolate
|
||||
/// is created. It always returns true.
|
||||
pub fn initialize() {
|
||||
unsafe { v8__V8__Initialize() }
|
||||
}
|
||||
|
||||
/// Releases any resources used by v8 and stops any utility threads
|
||||
/// that may be running. Note that disposing v8 is permanent, it
|
||||
/// cannot be reinitialized.
|
||||
///
|
||||
/// It should generally not be necessary to dispose v8 before exiting
|
||||
/// a process, this should happen automatically. It is only necessary
|
||||
/// to use if the process needs the resources taken up by v8.
|
||||
pub fn dispose() -> bool {
|
||||
unsafe { v8__V8__Dispose() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initialize_dispose() {
|
||||
initialize();
|
||||
dispose();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue