mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
add compile_and_run helper fn
This commit is contained in:
parent
a5dfe4b722
commit
4cc07a5d5d
1 changed files with 50 additions and 83 deletions
|
@ -3578,27 +3578,32 @@ fn snapshot_creator() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn snapshot_creator_multiple_contexts() {
|
fn snapshot_creator_multiple_contexts() {
|
||||||
|
fn compile_and_run<'s>(
|
||||||
|
scope: &mut v8::HandleScope<'s>,
|
||||||
|
source: &str,
|
||||||
|
) -> Option<v8::Local<'s, v8::Value>> {
|
||||||
|
let source = v8::String::new(scope, source).unwrap();
|
||||||
|
let script = v8::Script::compile(scope, source, None).unwrap();
|
||||||
|
script.run(scope)
|
||||||
|
}
|
||||||
|
|
||||||
let _setup_guard = setup();
|
let _setup_guard = setup();
|
||||||
let startup_data = {
|
let startup_data = {
|
||||||
let mut snapshot_creator = v8::SnapshotCreator::new(None, None);
|
let mut snapshot_creator = v8::SnapshotCreator::new(None, None);
|
||||||
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
|
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
|
||||||
{
|
{
|
||||||
let scope = &mut v8::HandleScope::new(&mut isolate);
|
let mut scope = v8::HandleScope::new(&mut isolate);
|
||||||
let context = v8::Context::new(scope);
|
let context = v8::Context::new(&mut scope);
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
let scope = &mut v8::ContextScope::new(&mut scope, context);
|
||||||
let source = v8::String::new(
|
compile_and_run(
|
||||||
scope,
|
scope,
|
||||||
"globalThis.__bootstrap = { defaultContextProp: 1};",
|
"globalThis.__bootstrap = { defaultContextProp: 1};",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
script.run(scope).unwrap();
|
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let one_val = v8::Number::new(scope, 1.0).into();
|
let one_val = v8::Number::new(scope, 1.0).into();
|
||||||
assert!(value.same_value(one_val));
|
assert!(value.same_value(one_val));
|
||||||
}
|
}
|
||||||
|
@ -3608,17 +3613,12 @@ fn snapshot_creator_multiple_contexts() {
|
||||||
let scope = &mut v8::HandleScope::new(&mut isolate);
|
let scope = &mut v8::HandleScope::new(&mut isolate);
|
||||||
let context = v8::Context::new(scope);
|
let context = v8::Context::new(scope);
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
let source =
|
compile_and_run(scope, "globalThis.__bootstrap = { context0Prop: 2 };")
|
||||||
v8::String::new(scope, "globalThis.__bootstrap = { context0Prop: 2 };")
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
script.run(scope).unwrap();
|
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let two_val = v8::Number::new(scope, 2.0).into();
|
let two_val = v8::Number::new(scope, 2.0).into();
|
||||||
assert!(value.same_value(two_val));
|
assert!(value.same_value(two_val));
|
||||||
}
|
}
|
||||||
|
@ -3640,35 +3640,27 @@ fn snapshot_creator_multiple_contexts() {
|
||||||
let context = v8::Context::new(scope);
|
let context = v8::Context::new(scope);
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let one_val = v8::Number::new(scope, 1.0).into();
|
let one_val = v8::Number::new(scope, 1.0).into();
|
||||||
assert!(value.same_value(one_val));
|
assert!(value.same_value(one_val));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
assert!(value.is_undefined());
|
assert!(value.is_undefined());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source = v8::String::new(
|
compile_and_run(
|
||||||
scope,
|
scope,
|
||||||
"globalThis.__bootstrap.defaultContextProp2 = 3;",
|
"globalThis.__bootstrap.defaultContextProp2 = 3;",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
let value =
|
||||||
script.run(scope).unwrap();
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp2")
|
||||||
let source =
|
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp2")
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let three_val = v8::Number::new(scope, 3.0).into();
|
let three_val = v8::Number::new(scope, 3.0).into();
|
||||||
assert!(value.same_value(three_val));
|
assert!(value.same_value(three_val));
|
||||||
}
|
}
|
||||||
|
@ -3679,33 +3671,24 @@ fn snapshot_creator_multiple_contexts() {
|
||||||
let context = v8::Context::from_snapshot(scope, 0).unwrap();
|
let context = v8::Context::from_snapshot(scope, 0).unwrap();
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
assert!(value.is_undefined());
|
assert!(value.is_undefined());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let two_val = v8::Number::new(scope, 2.0).into();
|
let two_val = v8::Number::new(scope, 2.0).into();
|
||||||
assert!(value.same_value(two_val));
|
assert!(value.same_value(two_val));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2 = 4;")
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop2 = 4;")
|
.unwrap();
|
||||||
|
let value =
|
||||||
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
script.run(scope).unwrap();
|
|
||||||
let source =
|
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop2")
|
|
||||||
.unwrap();
|
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let four_val = v8::Number::new(scope, 4.0).into();
|
let four_val = v8::Number::new(scope, 4.0).into();
|
||||||
assert!(value.same_value(four_val));
|
assert!(value.same_value(four_val));
|
||||||
}
|
}
|
||||||
|
@ -3724,36 +3707,28 @@ fn snapshot_creator_multiple_contexts() {
|
||||||
let context = v8::Context::new(scope);
|
let context = v8::Context::new(scope);
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
assert!(value.is_undefined());
|
assert!(value.is_undefined());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop2")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
assert!(value.is_undefined());
|
assert!(value.is_undefined());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let one_val = v8::Number::new(scope, 1.0).into();
|
let one_val = v8::Number::new(scope, 1.0).into();
|
||||||
assert!(value.same_value(one_val));
|
assert!(value.same_value(one_val));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp2")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let three_val = v8::Number::new(scope, 3.0).into();
|
let three_val = v8::Number::new(scope, 3.0).into();
|
||||||
assert!(value.same_value(three_val));
|
assert!(value.same_value(three_val));
|
||||||
}
|
}
|
||||||
|
@ -3763,36 +3738,28 @@ fn snapshot_creator_multiple_contexts() {
|
||||||
let context = v8::Context::from_snapshot(scope, 0).unwrap();
|
let context = v8::Context::from_snapshot(scope, 0).unwrap();
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
assert!(value.is_undefined());
|
assert!(value.is_undefined());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp2")
|
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
assert!(value.is_undefined());
|
assert!(value.is_undefined());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let two_val = v8::Number::new(scope, 2.0).into();
|
let two_val = v8::Number::new(scope, 2.0).into();
|
||||||
assert!(value.same_value(two_val));
|
assert!(value.same_value(two_val));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let source =
|
let value =
|
||||||
v8::String::new(scope, "globalThis.__bootstrap.context0Prop2")
|
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
|
||||||
let value = script.run(scope).unwrap();
|
|
||||||
let four_val = v8::Number::new(scope, 4.0).into();
|
let four_val = v8::Number::new(scope, 4.0).into();
|
||||||
assert!(value.same_value(four_val));
|
assert!(value.same_value(four_val));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue