Commit 26902dbc authored by Gus Caplan's avatar Gus Caplan Committed by Commit Bot

[test] add module serialization test

Bug: v8:10855
Change-Id: I0f28603421ba36176d177bfcc25f18a26a097c29
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2716062Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Gus Caplan <snek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73004}
parent e708bf69
......@@ -3348,6 +3348,13 @@ UNINITIALIZED_TEST(SnapshotCreatorTemplates) {
FreeCurrentEmbeddedBlob();
}
MaybeLocal<v8::Module> ResolveCallback(Local<v8::Context> context,
Local<v8::String> specifier,
Local<v8::FixedArray> import_assertions,
Local<v8::Module> referrer) {
return {};
}
UNINITIALIZED_TEST(SnapshotCreatorAddData) {
DisableAlwaysOpt();
DisableEmbeddedBlobRefcounting();
......@@ -3397,11 +3404,23 @@ UNINITIALIZED_TEST(SnapshotCreatorAddData) {
v8::AccessorSignature::New(isolate,
v8::FunctionTemplate::New(isolate));
v8::ScriptOrigin origin(isolate, v8_str(""), {}, {}, {}, {}, {}, {}, {},
true);
v8::ScriptCompiler::Source source(
v8::String::NewFromUtf8Literal(
isolate, "export let a = 42; globalThis.a = {};"),
origin);
v8::Local<v8::Module> module =
v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
module->InstantiateModule(context, ResolveCallback).ToChecked();
module->Evaluate(context).ToLocalChecked();
CHECK_EQ(0u, creator.AddData(context, object));
CHECK_EQ(1u, creator.AddData(context, v8_str("context-dependent")));
CHECK_EQ(2u, creator.AddData(context, persistent_number_1.Get(isolate)));
CHECK_EQ(3u, creator.AddData(context, object_template));
CHECK_EQ(4u, creator.AddData(context, persistent_context.Get(isolate)));
CHECK_EQ(5u, creator.AddData(context, module));
creator.AddContext(context);
CHECK_EQ(0u, creator.AddData(v8_str("context-independent")));
......@@ -3460,7 +3479,19 @@ UNINITIALIZED_TEST(SnapshotCreatorAddData) {
CHECK_EQ(*v8::Utils::OpenHandle(*serialized_context),
*v8::Utils::OpenHandle(*context));
CHECK(context->GetDataFromSnapshotOnce<v8::Value>(5).IsEmpty());
v8::Local<v8::Module> serialized_module =
context->GetDataFromSnapshotOnce<v8::Module>(5).ToLocalChecked();
CHECK(context->GetDataFromSnapshotOnce<v8::Context>(5).IsEmpty());
{
v8::Context::Scope context_scope(context);
v8::Local<v8::Object> mod_ns =
serialized_module->GetModuleNamespace().As<v8::Object>();
CHECK(mod_ns->Get(context, v8_str("a"))
.ToLocalChecked()
->StrictEquals(v8_num(42.0)));
}
CHECK(context->GetDataFromSnapshotOnce<v8::Value>(6).IsEmpty());
// Check serialized data on the isolate.
string = isolate->GetDataFromSnapshotOnce<v8::String>(0).ToLocalChecked();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment