0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-25 08:39:15 -05:00

bind v8::V8::Initialize and v8::V8::Dispose (#10)

This commit is contained in:
Ry Dahl 2019-11-15 14:29:19 -05:00 committed by GitHub
parent 3f6812ee60
commit 05ce4006c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View file

@ -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(); }
}

View file

@ -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();
}