mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-11 08:34:01 -05:00
Add V8::set_flags_from_string() (#457)
This commit is contained in:
parent
5b0de38fe4
commit
de58267948
3 changed files with 31 additions and 0 deletions
|
@ -11,6 +11,7 @@ use crate::support::UniqueRef;
|
|||
|
||||
extern "C" {
|
||||
fn v8__V8__SetFlagsFromCommandLine(argc: *mut c_int, argv: *mut *mut c_char);
|
||||
fn v8__V8__SetFlagsFromString(flags: *const u8, length: usize);
|
||||
fn v8__V8__GetVersion() -> *const c_char;
|
||||
fn v8__V8__InitializePlatform(platform: *mut Platform);
|
||||
fn v8__V8__Initialize();
|
||||
|
@ -79,6 +80,13 @@ pub fn set_flags_from_command_line(args: Vec<String>) -> Vec<String> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Sets V8 flags from a string.
|
||||
pub fn set_flags_from_string(flags: &str) {
|
||||
unsafe {
|
||||
v8__V8__SetFlagsFromString(flags.as_ptr(), flags.len());
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the version string.
|
||||
pub fn get_version() -> &'static str {
|
||||
let version = unsafe { v8__V8__GetVersion() };
|
||||
|
|
|
@ -93,6 +93,10 @@ void v8__V8__SetFlagsFromCommandLine(int* argc, char** argv) {
|
|||
v8::V8::SetFlagsFromCommandLine(argc, argv, true);
|
||||
}
|
||||
|
||||
void v8__V8__SetFlagsFromString(const char* flags, size_t length) {
|
||||
v8::V8::SetFlagsFromString(flags, length);
|
||||
}
|
||||
|
||||
const char* v8__V8__GetVersion() { return v8::V8::GetVersion(); }
|
||||
|
||||
void v8__V8__InitializePlatform(v8::Platform* platform) {
|
||||
|
|
19
tests/test_api_flags.rs
Normal file
19
tests/test_api_flags.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Tests from the same file run in a single process. That's why this test
|
||||
// is in its own file, because changing flags affects the whole process.
|
||||
use rusty_v8 as v8;
|
||||
|
||||
#[test]
|
||||
fn set_flags_from_string() {
|
||||
v8::V8::set_flags_from_string("--use_strict");
|
||||
v8::V8::initialize_platform(v8::new_default_platform().unwrap());
|
||||
v8::V8::initialize();
|
||||
let isolate = &mut v8::Isolate::new(Default::default());
|
||||
let scope = &mut v8::HandleScope::new(isolate);
|
||||
let context = v8::Context::new(scope);
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let source = "(function() { return this })()";
|
||||
let source = v8::String::new(scope, source).unwrap();
|
||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
||||
let result = script.run(scope).unwrap();
|
||||
assert!(result.is_undefined()); // Because of --use_strict.
|
||||
}
|
Loading…
Reference in a new issue