Commit 819d3cb5 authored by Vicky Kontoura's avatar Vicky Kontoura Committed by V8 LUCI CQ

[web snapshot] Refactor mjsunit tests

This CL refactors mjsunit tests, so that the common core of all tests is
abstracted away.

Bug: v8:11525, v8:11706
Change-Id: I24a1af4298380e21a64e4d17149422c32fbf8a4d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2914882Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Vicky Kontoura <vkont@google.com>
Cr-Commit-Position: refs/heads/master@{#74853}
parent 8c9c0cf7
......@@ -5,28 +5,37 @@
// Flags: --experimental-d8-web-snapshot-api
function callString(f) {
return '(' + f.toString() + ')()';
return '(' + f.toString() + ')()';
}
(function TestMinimal() {
const r1 = Realm.create();
function initialize() {
globalThis.foo = {
'str': 'hello',
'n': 42,
};
}
Realm.eval(r1, callString(initialize));
const snapshot = Realm.takeWebSnapshot(r1, ['foo']);
function use() {
const result = Object.create(null);
Realm.shared.exports.forEach(x => result[x] = globalThis[x]);
return result;
}
const r2 = Realm.create();
function use() {
return globalThis.foo;
}
const success = Realm.useWebSnapshot(r2, snapshot);
assertTrue(success);
function takeAndUseWebSnapshot(createObjects, exports) {
// Make the exports list available across Realms.
Realm.shared = { exports };
// Take a snapshot in Realm r1.
const r1 = Realm.create();
Realm.eval(r1, callString(createObjects));
const snapshot = Realm.takeWebSnapshot(r1, exports);
// Use the snapshot in Realm r2.
const r2 = Realm.create();
const success = Realm.useWebSnapshot(r2, snapshot);
assertTrue(success);
return Realm.eval(r2, callString(use));
}
const foo = Realm.eval(r2, callString(use));
assertEquals(foo.str, 'hello');
assertEquals(foo.n, 42);
(function TestMinimal() {
function createObjects() {
globalThis.foo = {
str: 'hello',
n: 42,
};
}
const exports = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals(exports.foo.str, 'hello');
assertEquals(exports.foo.n, 42);
})();
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