Commit 7b49edbc authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[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: 's avatarMatthias 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}
parent 8a281f52
......@@ -26,8 +26,8 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
}
}
const { growableArrayBuffer, arrayBuffer } = takeAndUseWebSnapshot(createObjects, ['growableArrayBuffer', 'arrayBuffer']);
assertEquals(growableArrayBuffer.byteLength, 5);
assertEquals(growableArrayBuffer.maxByteLength, 10);
assertEquals(5, growableArrayBuffer.byteLength);
assertEquals(10, growableArrayBuffer.maxByteLength);
assertTrue(growableArrayBuffer.growable);
const array1 = new Uint8Array(growableArrayBuffer);
for (let i = 0; i < 5; i++) {
......@@ -64,22 +64,22 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
globalThis.detachedArrayBuffer = detachedArrayBuffer;
}
const { resizableArrayBuffer, arrayBuffer, detachedArrayBuffer } = takeAndUseWebSnapshot(createObjects, ['resizableArrayBuffer', 'arrayBuffer', 'detachedArrayBuffer']);
assertEquals(resizableArrayBuffer.byteLength, 5);
assertEquals(resizableArrayBuffer.maxByteLength, 10);
assertEquals(5, resizableArrayBuffer.byteLength);
assertEquals(10, resizableArrayBuffer.maxByteLength);
assertTrue(resizableArrayBuffer.resizable)
const array1 = new Uint8Array(resizableArrayBuffer);
for (let i = 0; i < 5; i++) {
assertEquals(array1[i], i);
}
assertEquals(arrayBuffer.byteLength, 5);
assertEquals(arrayBuffer.maxByteLength, 5);
assertEquals(5, arrayBuffer.byteLength);
assertEquals(5, arrayBuffer.maxByteLength);
assertFalse(arrayBuffer.resizable)
const array2 = new Uint8Array(arrayBuffer);
for (let i = 0; i < 5; i++) {
assertEquals(array2[i], i);
}
assertEquals(detachedArrayBuffer.byteLength, 0);
assertEquals(detachedArrayBuffer.maxByteLength, 0);
assertEquals(0, detachedArrayBuffer.byteLength);
assertEquals(0, detachedArrayBuffer.maxByteLength);
})()
......@@ -16,8 +16,8 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
const realm = Realm.create();
const {obj1, obj2} = takeAndUseWebSnapshot(
createObjects, ['obj1', 'obj2'], realm);
assertTrue(obj1.a === Realm.eval(realm, "Error"));
assertTrue(obj2.b === Realm.eval(realm, "Error.prototype"));
assertSame(Realm.eval(realm, 'Error'), obj1.a);
assertSame(Realm.eval(realm, 'Error.prototype'), obj2.b);
})();
(function TestInheritFromBuiltin() {
......@@ -35,5 +35,5 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
const realm = Realm.create();
const {MyError} = takeAndUseWebSnapshot(createObjects, ['MyError'], realm);
const obj = new MyError();
assertTrue(obj.__proto__.__proto__ === Realm.eval(realm, "Error.prototype"));
assertSame(Realm.eval(realm, 'Error.prototype'), obj.__proto__.__proto__);
})();
......@@ -116,7 +116,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(1, Foo.key2);
assertEquals(2.2, Foo.key3);
assertEquals([1, 2], Foo.key4);
assertEquals({ 'key': 'value' }, Foo.key5 );
assertEquals({'key': 'value'}, Foo.key5);
})();
(function TestClassWithStaticMethods() {
......
......@@ -27,16 +27,16 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
'array2',
'array3'
]);
assertEquals(array1.byteLength, 5);
assertEquals(array1.byteOffset, 0);
assertEquals(array2.byteLength, 5);
assertEquals(array2.byteOffset, 5);
assertEquals(array3.byteLength, 5);
assertEquals(array3.byteOffset, 2);
assertEquals(5, array1.byteLength);
assertEquals(0, array1.byteOffset);
assertEquals(5, array2.byteLength);
assertEquals(5, array2.byteOffset);
assertEquals(5, array3.byteLength);
assertEquals(2, array3.byteOffset);
for (let i = 0; i < 5; i++) {
assertEquals(array1.getUint8(i), i);
assertEquals(array2.getUint8(i), i);
assertEquals(i, array1.getUint8(i));
assertEquals(i, array2.getUint8(i));
}
assertSame(array1.buffer, array2.buffer);
assertSame(array1.buffer, array3.buffer);
......@@ -69,18 +69,18 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
'array3',
]);
assertTrue(array1.buffer.resizable);
assertEquals(array1.buffer.maxByteLength, 2048);
assertEquals(array1.byteLength, 1024);
assertEquals(array1.byteOffset, 0);
assertEquals(array2.byteLength, 768); // 1024 - 256
assertEquals(array2.byteOffset, 256);
assertEquals(array3.byteLength, 4);
assertEquals(array3.byteOffset, 128);
assertEquals(2048, array1.buffer.maxByteLength);
assertEquals(1024, array1.byteLength);
assertEquals(0, array1.byteOffset, 0);
assertEquals(768, array2.byteLength); // 1024 - 256
assertEquals(256, array2.byteOffset);
assertEquals(4, array3.byteLength);
assertEquals(128, array3.byteOffset);
array1.buffer.resize(1024 * 2);
assertEquals(array1.byteLength, 2048);
assertEquals(array2.byteLength, 1792); // 2048 - 256
assertEquals(array3.byteLength, 4);
assertEquals(2048, array1.byteLength);
assertEquals(1792, array2.byteLength); // 2048 - 256
assertEquals(4, array3.byteLength);
assertSame(array1.buffer, array2.buffer);
assertSame(array1.buffer, array3.buffer);
......@@ -109,18 +109,18 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
'array3',
]);
assertTrue(array1.buffer.growable);
assertEquals(array1.buffer.maxByteLength, 2048);
assertEquals(array1.byteLength, 1024);
assertEquals(array1.byteOffset, 0);
assertEquals(array2.byteLength, 768); // 1024 - 256
assertEquals(array2.byteOffset, 256);
assertEquals(array3.byteLength, 4);
assertEquals(array3.byteOffset, 128);
assertEquals(2048, array1.buffer.maxByteLength);
assertEquals(1024, array1.byteLength);
assertEquals(0, array1.byteOffset);
assertEquals(768, array2.byteLength); // 1024 - 256
assertEquals(256, array2.byteOffset);
assertEquals(4, array3.byteLength);
assertEquals(128, array3.byteOffset);
array1.buffer.grow(1024 * 2);
assertEquals(array1.byteLength, 2048);
assertEquals(array2.byteLength, 1792); // 2048 - 256
assertEquals(array3.byteLength, 4);
assertEquals(2048, array1.byteLength);
assertEquals(1792, array2.byteLength); // 2048 - 256
assertEquals(4, array3.byteLength);
assertSame(array1.buffer, array2.buffer);
assertSame(array1.buffer, array3.buffer);
......
......@@ -17,26 +17,26 @@ const object = {
const snapshot = WebSnapshot.serialize(object);
const deserialized = WebSnapshot.deserialize(snapshot);
%HeapObjectVerify(deserialized);
assertEquals(deserialized, object);
assertEquals(deserialized.b, external_1);
assertNotSame(deserialized.b, external_1);
assertEquals(deserialized.d.d_a, external_2);
assertNotSame(deserialized.d.d_a, external_2);
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 externals = [external_1];
const snapshot = WebSnapshot.serialize(object, externals);
const replaced_externals = [{replacement:1}]
const deserialized = WebSnapshot.deserialize(snapshot, replaced_externals);
%HeapObjectVerify(deserialized);
assertEquals(deserialized.a, object.a);
assertSame(deserialized.b, replaced_externals[0]);
assertArrayEquals(deserialized.c, [replaced_externals[0], external_2]);
assertSame(deserialized.c[0], replaced_externals[0]);
assertNotSame(deserialized.c[1], external_2);
assertEquals(deserialized.d.d_a, external_2);
assertNotSame(deserialized.d.d_a, external_2);
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() {
......@@ -45,12 +45,12 @@ const object = {
const replaced_externals = [{replacement:1}, {replacement:2}]
const deserialized = WebSnapshot.deserialize(snapshot, replaced_externals);
%HeapObjectVerify(deserialized);
assertEquals(deserialized.a, object.a);
assertEquals(object.a, deserialized.a);
assertSame(deserialized.b, replaced_externals[0]);
assertArrayEquals(deserialized.c, replaced_externals);
assertSame(deserialized.c[0], replaced_externals[0]);
assertSame(deserialized.c[1], replaced_externals[1]);
assertSame(deserialized.d.d_a, replaced_externals[1]);
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() {
......@@ -63,7 +63,7 @@ const object = {
const snapshot_2 = WebSnapshot.serialize(source_2, externals);
%HeapObjectVerify(externals);
// Check that the unhandled api object is added to the externals.
assertArrayEquals(externals, [external_1, api_object]);
assertArrayEquals([external_1, api_object], externals);
assertThrows(() => WebSnapshot.deserialize(snapshot_2));
assertThrows(() => WebSnapshot.deserialize(snapshot_2, []));
......@@ -72,9 +72,9 @@ const object = {
const result_2 = WebSnapshot.deserialize(snapshot_2, [external_1, api_object]);
%HeapObjectVerify(externals);
%HeapObjectVerify(result_2);
assertArrayEquals(result_2, source_2);
assertNotSame(result_2[0], source_2[0]);
assertSame(result_2[1], external_1);
assertSame(result_2[2], api_object);
assertSame(result_2[3], api_object);
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]);
})();
......@@ -392,7 +392,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
})()
}
const {bar} = takeAndUseWebSnapshot(createObjects, ['bar']);
assertEquals(bar(), 1);
assertEquals(1, bar());
})();
(function TestMoreThanOneScopeLocalInContext() {
......
......@@ -86,10 +86,11 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
function createObjects() {
globalThis.F = function() {}
}
const { F } = takeAndUseWebSnapshot(createObjects, ['F']);
const realm = Realm.create();
const { F } = takeAndUseWebSnapshot(createObjects, ['F'], realm);
const o = new F();
assertEquals(Object.prototype,
Object.getPrototypeOf(Object.getPrototypeOf(o)));
assertSame(Realm.eval(realm, 'Object.prototype'),
Object.getPrototypeOf(Object.getPrototypeOf(o)));
})();
(function TestFunctionInheritance() {
......@@ -151,14 +152,14 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
(function TestFunctionWithProperties() {
function createObjects() {
function bar() { return 'bar'; };
bar.key1 = "value1";
bar.key1 = 'value1';
bar.key2 = 1;
bar.key3 = 2.2;
bar.key4 = function key4() {
return "key4";
return 'key4';
}
bar.key5 = [1, 2];
bar.key6 = {"key":"value"}
bar.key6 = {'key':'value'}
globalThis.foo = {
bar: bar,
};
......@@ -170,20 +171,20 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(2.2, foo.bar.key3);
assertEquals('key4', foo.bar.key4());
assertEquals([1, 2], foo.bar.key5);
assertEquals({ "key": "value" }, foo.bar.key6 );
assertEquals({ 'key': 'value' }, foo.bar.key6 );
})();
(function TestAsyncFunctionWithProperties() {
function createObjects() {
async function bar() { return 'bar'; };
bar.key1 = "value1";
bar.key1 = 'value1';
bar.key2 = 1;
bar.key3 = 2.2;
bar.key4 = function key4() {
return "key4";
return 'key4';
}
bar.key5 = [1, 2];
bar.key6 = {"key":"value"}
bar.key6 = {'key':'value'}
globalThis.foo = {
bar: bar,
};
......@@ -194,20 +195,20 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(2.2, foo.bar.key3);
assertEquals('key4', foo.bar.key4());
assertEquals([1, 2], foo.bar.key5);
assertEquals({ "key": "value" }, foo.bar.key6 );
assertEquals({'key': 'value'}, foo.bar.key6 );
})();
(function TestGeneratorFunctionWithProperties() {
function createObjects() {
function *bar() { return 'bar'; };
bar.key1 = "value1";
bar.key1 = 'value1';
bar.key2 = 1;
bar.key3 = 2.2;
bar.key4 = function key4() {
return "key4";
}
return 'key4';
};
bar.key5 = [1, 2];
bar.key6 = {"key":"value"}
bar.key6 = {'key':'value'};
globalThis.foo = {
bar: bar,
};
......@@ -218,20 +219,20 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(2.2, foo.bar.key3);
assertEquals('key4', foo.bar.key4());
assertEquals([1, 2], foo.bar.key5);
assertEquals({ "key": "value" }, foo.bar.key6 );
assertEquals({'key': 'value'}, foo.bar.key6 );
})();
(function TestAsyncGeneratorFunctionWithProperties() {
function createObjects() {
async function *bar() { return 'bar'; };
bar.key1 = "value1";
bar.key1 = 'value1';
bar.key2 = 1;
bar.key3 = 2.2;
bar.key4 = function key4() {
return "key4";
return 'key4';
}
bar.key5 = [1, 2];
bar.key6 = {"key":"value"}
bar.key6 = {'key':'value'}
globalThis.foo = {
bar: bar,
};
......@@ -242,18 +243,18 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(2.2, foo.bar.key3);
assertEquals('key4', foo.bar.key4());
assertEquals([1, 2], foo.bar.key5);
assertEquals({ "key": "value" }, foo.bar.key6 );
assertEquals({'key': 'value'}, foo.bar.key6);
})();
(function TestFunctionsWithSameMap() {
function createObjects() {
function bar1() { return 'bar1'; };
bar1.key = "value";
bar1.key = 'value';
function bar2() {
return "bar2";
return 'bar2';
}
bar2.key = "value";
bar2.key = 'value';
globalThis.foo = {
bar1: bar1,
......
......@@ -18,10 +18,10 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
(function TestHoleyElementsArray() {
function createObjects() {
globalThis.foo = [1,,"123"];
globalThis.foo = [1,,'123'];
}
const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals([1,,"123"], foo);
assertEquals([1,,'123'], foo);
})();
(function TestHoleyArrayContainingDoubleAndSmi() {
......
......@@ -65,16 +65,18 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
n: 42,
};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals(Object.prototype, Object.getPrototypeOf(foo));
const realm = Realm.create();
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo'], realm);
assertSame(Realm.eval(realm, 'Object.prototype'), Object.getPrototypeOf(foo));
})();
(function TestEmptyObjectProto() {
function createObjects() {
globalThis.foo = {};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals(Object.prototype, Object.getPrototypeOf(foo));
const realm = Realm.create();
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo'], realm);
assertSame(Realm.eval(realm, 'Object.prototype'), Object.getPrototypeOf(foo));
})();
(function TestObjectProto() {
......@@ -96,7 +98,8 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
y: 11
};
}
const { o1, o2 } = takeAndUseWebSnapshot(createObjects, ['o1', 'o2']);
assertEquals(o1, Object.getPrototypeOf(o2));
assertEquals(Object.prototype, Object.getPrototypeOf(o1));
const realm = Realm.create();
const { o1, o2 } = takeAndUseWebSnapshot(createObjects, ['o1', 'o2'], realm);
assertSame(o1, Object.getPrototypeOf(o2));
assertSame(Realm.eval(realm, 'Object.prototype'), Object.getPrototypeOf(o1));
})();
......@@ -22,7 +22,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertTrue(%HasDictionaryElements(foo));
assertEquals(2 ** 30 + 1, foo.length);
for (let i = 0; i < 10; i++) {
assertEquals(i,foo[i * 101]);
assertEquals(i, foo[i * 101]);
}
})();
......@@ -40,7 +40,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertTrue(%HasDictionaryElements(foo));
assertEquals(2 ** 30 + 1, foo.length);
for (let i = 0; i < 10; i++) {
assertEquals([i],foo[i * 101]);
assertEquals([i], foo[i * 101]);
}
})();
......@@ -50,7 +50,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
// Add a large index to force dictionary elements.
array[2 ** 30] = 10;
for (let i = 0; i < 10; i++) {
array[i * 101] = {i:i};
array[i * 101] = {i: i};
}
globalThis.foo = array;
}
......@@ -58,7 +58,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertTrue(%HasDictionaryElements(foo));
assertEquals(2 ** 30 + 1, foo.length);
for (let i = 0; i < 10; i++) {
assertEquals({i:i}, foo[i * 101]);
assertEquals({i: i}, foo[i * 101]);
}
})();
......
......@@ -14,7 +14,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
globalThis.foo = {mySymbol: s, innerObject: { symbolHereToo: s}};
}
const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals(foo.mySymbol, foo.innerObject.symbolHereToo);
assertSame(foo.mySymbol, foo.innerObject.symbolHereToo);
assertEquals('description', foo.mySymbol.description);
assertNotEquals(foo.mySymbol, Symbol('description'));
assertNotEquals(foo.mySymbol, Symbol.for('description'));
......@@ -26,7 +26,7 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
globalThis.foo = {mySymbol: s, innerObject: { symbolHereToo: s}};
}
const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals(foo.mySymbol, foo.innerObject.symbolHereToo);
assertSame(foo.mySymbol, foo.innerObject.symbolHereToo);
assertEquals('this is global', foo.mySymbol.description);
assertEquals(Symbol.for('this is global'), foo.mySymbol);
})();
......
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