0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-24 15:19:31 -05:00

compile_and_run is not needed because we have eval()

This commit is contained in:
Bartek Iwańczuk 2022-06-07 17:33:09 +02:00 committed by Bert Belder
parent 4cc07a5d5d
commit a8a747a5e7
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -3578,15 +3578,6 @@ 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);
@ -3595,15 +3586,11 @@ fn snapshot_creator_multiple_contexts() {
let mut scope = v8::HandleScope::new(&mut isolate); let mut scope = v8::HandleScope::new(&mut isolate);
let context = v8::Context::new(&mut scope); let context = v8::Context::new(&mut scope);
let scope = &mut v8::ContextScope::new(&mut scope, context); let scope = &mut v8::ContextScope::new(&mut scope, context);
compile_and_run( eval(scope, "globalThis.__bootstrap = { defaultContextProp: 1};")
scope, .unwrap();
"globalThis.__bootstrap = { defaultContextProp: 1};",
)
.unwrap();
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp") eval(scope, "globalThis.__bootstrap.defaultContextProp").unwrap();
.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));
} }
@ -3613,12 +3600,9 @@ 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);
compile_and_run(scope, "globalThis.__bootstrap = { context0Prop: 2 };") eval(scope, "globalThis.__bootstrap = { context0Prop: 2 };").unwrap();
.unwrap();
{ {
let value = let value = eval(scope, "globalThis.__bootstrap.context0Prop").unwrap();
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
.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));
} }
@ -3641,26 +3625,18 @@ fn snapshot_creator_multiple_contexts() {
let scope = &mut v8::ContextScope::new(scope, context); let scope = &mut v8::ContextScope::new(scope, context);
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp") eval(scope, "globalThis.__bootstrap.defaultContextProp").unwrap();
.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 value = let value = eval(scope, "globalThis.__bootstrap.context0Prop").unwrap();
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
.unwrap();
assert!(value.is_undefined()); assert!(value.is_undefined());
} }
{ {
compile_and_run( eval(scope, "globalThis.__bootstrap.defaultContextProp2 = 3;").unwrap();
scope,
"globalThis.__bootstrap.defaultContextProp2 = 3;",
)
.unwrap();
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp2") eval(scope, "globalThis.__bootstrap.defaultContextProp2").unwrap();
.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));
} }
@ -3672,23 +3648,18 @@ fn snapshot_creator_multiple_contexts() {
let scope = &mut v8::ContextScope::new(scope, context); let scope = &mut v8::ContextScope::new(scope, context);
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp") eval(scope, "globalThis.__bootstrap.defaultContextProp").unwrap();
.unwrap();
assert!(value.is_undefined()); assert!(value.is_undefined());
} }
{ {
let value = let value = eval(scope, "globalThis.__bootstrap.context0Prop").unwrap();
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
.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));
} }
{ {
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2 = 4;") eval(scope, "globalThis.__bootstrap.context0Prop2 = 4;").unwrap();
.unwrap();
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2") eval(scope, "globalThis.__bootstrap.context0Prop2").unwrap();
.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));
} }
@ -3707,28 +3678,23 @@ 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 value = let value = eval(scope, "globalThis.__bootstrap.context0Prop").unwrap();
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
.unwrap();
assert!(value.is_undefined()); assert!(value.is_undefined());
} }
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2") eval(scope, "globalThis.__bootstrap.context0Prop2").unwrap();
.unwrap();
assert!(value.is_undefined()); assert!(value.is_undefined());
} }
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp") eval(scope, "globalThis.__bootstrap.defaultContextProp").unwrap();
.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 value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp2") eval(scope, "globalThis.__bootstrap.defaultContextProp2").unwrap();
.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));
} }
@ -3739,27 +3705,22 @@ fn snapshot_creator_multiple_contexts() {
let scope = &mut v8::ContextScope::new(scope, context); let scope = &mut v8::ContextScope::new(scope, context);
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp") eval(scope, "globalThis.__bootstrap.defaultContextProp").unwrap();
.unwrap();
assert!(value.is_undefined()); assert!(value.is_undefined());
} }
{ {
let value = let value =
compile_and_run(scope, "globalThis.__bootstrap.defaultContextProp2") eval(scope, "globalThis.__bootstrap.defaultContextProp2").unwrap();
.unwrap();
assert!(value.is_undefined()); assert!(value.is_undefined());
} }
{ {
let value = let value = eval(scope, "globalThis.__bootstrap.context0Prop").unwrap();
compile_and_run(scope, "globalThis.__bootstrap.context0Prop")
.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 value = let value =
compile_and_run(scope, "globalThis.__bootstrap.context0Prop2") eval(scope, "globalThis.__bootstrap.context0Prop2").unwrap();
.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));
} }