v8/test/mjsunit/web-snapshot/web-snapshot-externals.js
Marja Hölttä 7b49edbc39 [web snapshot] Test cleanup + remove assertEquals misuse
Some assertEquals:s should've been assertSame.

Drive-by: Coding style fixes
Drive-by: Fix the parameter order of assertEquals, it should be
(expected, found).

Bug: v8:11525
Change-Id: I4e6db32329cbbe455853d19c20abe9d251263505
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3877148
Auto-Submit: Marja Hölttä <marja@chromium.org>
Reviewed-by: Matthias Liedtke <mliedtke@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83024}
2022-09-07 12:00:45 +00:00

81 lines
3.1 KiB
JavaScript

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --experimental-web-snapshots --allow-natives-syntax --verify-heap
const external_1 = {external: 1};
const external_2 = {external: 2};
const object = {
a: [1,2],
b: external_1,
c: [external_1, external_2],
d: { d_a: external_2 }
};
(function testNoExternals() {
const snapshot = WebSnapshot.serialize(object);
const deserialized = WebSnapshot.deserialize(snapshot);
%HeapObjectVerify(deserialized);
assertEquals(object, deserialized);
assertEquals(external_1, deserialized.b);
assertNotSame(external_1, deserialized.b);
assertEquals(external_2, deserialized.d.d_a);
assertNotSame(external_2, deserialized.d.d_a);
})();
(function testOneExternals() {
const externals = [external_1];
const snapshot = WebSnapshot.serialize(object, externals);
const replaced_externals = [{replacement:1}]
const deserialized = WebSnapshot.deserialize(snapshot, replaced_externals);
%HeapObjectVerify(deserialized);
assertEquals(object.a, deserialized.a);
assertSame(replaced_externals[0], deserialized.b);
assertArrayEquals([replaced_externals[0], external_2], deserialized.c);
assertSame(replaced_externals[0], deserialized.c[0]);
assertNotSame(external_2, deserialized.c[1]);
assertEquals(external_2, deserialized.d.d_a);
assertNotSame(external_2, deserialized.d.d_a);
})();
(function testTwoExternals() {
const externals = [external_1, external_2];
const snapshot = WebSnapshot.serialize(object, externals);
const replaced_externals = [{replacement:1}, {replacement:2}]
const deserialized = WebSnapshot.deserialize(snapshot, replaced_externals);
%HeapObjectVerify(deserialized);
assertEquals(object.a, deserialized.a);
assertSame(deserialized.b, replaced_externals[0]);
assertArrayEquals(replaced_externals, deserialized.c);
assertSame(replaced_externals[0], deserialized.c[0]);
assertSame(replaced_externals[1], deserialized.c[1]);
assertSame(replaced_externals[1], deserialized.d.d_a);
})();
(function testApiObject() {
const api_object = new d8.dom.Div();
const source_1 = [{}, api_object];
assertThrows(() => WebSnapshot.serialize(source_1));
let externals = [external_1]
const source_2 = [{}, external_1, api_object, api_object];
const snapshot_2 = WebSnapshot.serialize(source_2, externals);
%HeapObjectVerify(externals);
// Check that the unhandled api object is added to the externals.
assertArrayEquals([external_1, api_object], externals);
assertThrows(() => WebSnapshot.deserialize(snapshot_2));
assertThrows(() => WebSnapshot.deserialize(snapshot_2, []));
assertThrows(() => WebSnapshot.deserialize(snapshot_2, [external_1]));
const result_2 = WebSnapshot.deserialize(snapshot_2, [external_1, api_object]);
%HeapObjectVerify(externals);
%HeapObjectVerify(result_2);
assertArrayEquals(source_2, result_2);
assertNotSame(source_2[0], result_2[0]);
assertSame(external_1, result_2[1]);
assertSame(api_object, result_2[2]);
assertSame(api_object, result_2[3]);
})();