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:
parent
558742e9b5
commit
a5dfe4b722
1 changed files with 190 additions and 37 deletions
|
@ -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,16 +3609,21 @@ 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();
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
assert_eq!(0, snapshot_creator.add_context(context));
|
assert_eq!(0, snapshot_creator.add_context(context));
|
||||||
}
|
}
|
||||||
{
|
|
||||||
let scope = &mut v8::HandleScope::new(&mut isolate);
|
|
||||||
let context = v8::Context::new(scope);
|
|
||||||
assert_eq!(1, 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.
|
||||||
snapshot_creator
|
snapshot_creator
|
||||||
|
@ -3614,36 +3631,172 @@ fn snapshot_creator_multiple_contexts() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let params = v8::Isolate::create_params().snapshot_blob(startup_data);
|
let startup_data = {
|
||||||
let isolate = &mut v8::Isolate::new(params);
|
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 scope = &mut v8::HandleScope::new(isolate);
|
let params = v8::Isolate::create_params().snapshot_blob(startup_data);
|
||||||
let context = v8::Context::new(scope);
|
let isolate = &mut v8::Isolate::new(params);
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
{
|
||||||
let source = v8::String::new(scope, "f()").unwrap();
|
let scope = &mut v8::HandleScope::new(isolate);
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
let context = v8::Context::new(scope);
|
||||||
let result = script.run(scope).unwrap();
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
let one_val = v8::Number::new(scope, 1.0).into();
|
{
|
||||||
assert!(result.same_value(one_val));
|
let source =
|
||||||
}
|
v8::String::new(scope, "globalThis.__bootstrap.context0Prop")
|
||||||
{
|
.unwrap();
|
||||||
let scope = &mut v8::HandleScope::new(isolate);
|
let script = v8::Script::compile(scope, source, None).unwrap();
|
||||||
let context = v8::Context::from_snapshot(scope, 0).unwrap();
|
let value = script.run(scope).unwrap();
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
assert!(value.is_undefined());
|
||||||
let source = v8::String::new(scope, "f()").unwrap();
|
}
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
{
|
||||||
let result = script.run(scope).unwrap();
|
let source =
|
||||||
let two_val = v8::Number::new(scope, 2.0).into();
|
v8::String::new(scope, "globalThis.__bootstrap.context0Prop2")
|
||||||
assert!(result.same_value(two_val));
|
.unwrap();
|
||||||
}
|
let script = v8::Script::compile(scope, source, None).unwrap();
|
||||||
{
|
let value = script.run(scope).unwrap();
|
||||||
let scope = &mut v8::HandleScope::new(isolate);
|
assert!(value.is_undefined());
|
||||||
let context = v8::Context::from_snapshot(scope, 1).unwrap();
|
}
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
{
|
||||||
let source = v8::String::new(scope, "this.f").unwrap();
|
let source =
|
||||||
let script = v8::Script::compile(scope, source, None).unwrap();
|
v8::String::new(scope, "globalThis.__bootstrap.defaultContextProp")
|
||||||
let result = script.run(scope).unwrap();
|
.unwrap();
|
||||||
assert!(result.is_undefined());
|
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.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 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.defaultContextProp2")
|
||||||
|
.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")
|
||||||
|
.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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue