0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-28 16:21:04 -05:00

use test from Joyee

This commit is contained in:
Bartek Iwańczuk 2022-06-06 15:11:42 +02:00 committed by Bert Belder
parent 558742e9b5
commit a5dfe4b722
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -3586,10 +3586,22 @@ 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 = let source = v8::String::new(
v8::String::new(scope, "var f = function() { return 1; }").unwrap(); scope,
"globalThis.__bootstrap = { defaultContextProp: 1};",
)
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap(); let script = v8::Script::compile(scope, source, None).unwrap();
script.run(scope).unwrap(); script.run(scope).unwrap();
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
.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();
assert!(value.same_value(one_val));
}
snapshot_creator.set_default_context(context); snapshot_creator.set_default_context(context);
} }
{ {
@ -3597,15 +3609,20 @@ 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 source =
v8::String::new(scope, "var f = function() { return 2; }").unwrap(); v8::String::new(scope, "globalThis.__bootstrap = { context0Prop: 2 };")
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap(); let script = v8::Script::compile(scope, source, None).unwrap();
script.run(scope).unwrap(); script.run(scope).unwrap();
assert_eq!(0, snapshot_creator.add_context(context));
}
{ {
let scope = &mut v8::HandleScope::new(&mut isolate); let source =
let context = v8::Context::new(scope); v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
assert_eq!(1, snapshot_creator.add_context(context)); .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();
assert!(value.same_value(two_val));
}
assert_eq!(0, snapshot_creator.add_context(context));
} }
std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary. std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary.
@ -3614,36 +3631,172 @@ fn snapshot_creator_multiple_contexts() {
.unwrap() .unwrap()
}; };
let startup_data = {
let mut snapshot_creator =
v8::SnapshotCreator::new(None, Some(&startup_data));
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
{
let scope = &mut v8::HandleScope::new(&mut isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
.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();
assert!(value.same_value(one_val));
}
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
let value = script.run(scope).unwrap();
assert!(value.is_undefined());
}
{
let source = v8::String::new(
scope,
"globalThis.__bootstrap.defaultContextProp2 = 3;",
)
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
script.run(scope).unwrap();
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp2")
.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();
assert!(value.same_value(three_val));
}
snapshot_creator.set_default_context(context);
}
{
let scope = &mut v8::HandleScope::new(&mut isolate);
let context = v8::Context::from_snapshot(scope, 0).unwrap();
let scope = &mut v8::ContextScope::new(scope, context);
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
let value = script.run(scope).unwrap();
assert!(value.is_undefined());
}
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
.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();
assert!(value.same_value(two_val));
}
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.context0Prop2 = 4;")
.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();
assert!(value.same_value(four_val));
}
assert_eq!(snapshot_creator.add_context(context), 0);
}
std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary.
snapshot_creator
.create_blob(v8::FunctionCodeHandling::Clear)
.unwrap()
};
{
let params = v8::Isolate::create_params().snapshot_blob(startup_data); let params = v8::Isolate::create_params().snapshot_blob(startup_data);
let isolate = &mut v8::Isolate::new(params); let isolate = &mut v8::Isolate::new(params);
{ {
let scope = &mut v8::HandleScope::new(isolate); let scope = &mut v8::HandleScope::new(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 = v8::String::new(scope, "f()").unwrap(); {
let source =
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap(); let script = v8::Script::compile(scope, source, None).unwrap();
let result = script.run(scope).unwrap(); let value = script.run(scope).unwrap();
assert!(value.is_undefined());
}
{
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();
assert!(value.is_undefined());
}
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
.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!(result.same_value(one_val)); assert!(value.same_value(one_val));
}
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp2")
.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();
assert!(value.same_value(three_val));
}
} }
{ {
let scope = &mut v8::HandleScope::new(isolate); let scope = &mut v8::HandleScope::new(isolate);
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 = v8::String::new(scope, "f()").unwrap(); {
let source =
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
.unwrap();
let script = v8::Script::compile(scope, source, None).unwrap(); let script = v8::Script::compile(scope, source, None).unwrap();
let result = script.run(scope).unwrap(); let value = script.run(scope).unwrap();
let two_val = v8::Number::new(scope, 2.0).into(); assert!(value.is_undefined());
assert!(result.same_value(two_val));
} }
{ {
let scope = &mut v8::HandleScope::new(isolate); let source =
let context = v8::Context::from_snapshot(scope, 1).unwrap(); v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp2")
let scope = &mut v8::ContextScope::new(scope, context); .unwrap();
let source = v8::String::new(scope, "this.f").unwrap();
let script = v8::Script::compile(scope, source, None).unwrap(); let script = v8::Script::compile(scope, source, None).unwrap();
let result = script.run(scope).unwrap(); let value = script.run(scope).unwrap();
assert!(result.is_undefined()); assert!(value.is_undefined());
}
{
let source =
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
.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();
assert!(value.same_value(two_val));
}
{
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();
assert!(value.same_value(four_val));
}
}
} }
} }