v8/test/mjsunit/web-snapshot/web-snapshot-3.js
Nico Hartmann f479b0163f Revert "[web snapshot] Add support for object with dictionary mode"
This reverts commit 507fa4d7f5.

Reason for revert: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux%20-%20gc%20stress/38308/overview

Original change's description:
> [web snapshot] Add support for object with dictionary mode
>
> This CL adds the serialization support for object properties
> with dictionary map. Shape id is used to distinguish between if the object has dictionary map. And add TODO to support “no map objects” which can have fast map and “objects with map” which needs to be turned to dictionary mode.
>
> Bug: v8:11525
> Change-Id: If3eb4195115a41d4a3f6cc7372924b982ca96fc1
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3621593
> Commit-Queue: 王澳 <wangao.james@bytedance.com>
> Reviewed-by: Marja Hölttä <marja@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#80366}

Bug: v8:11525
Change-Id: I0d236a9937a5942b387553a61991716321b063e6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3629541
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Nico Hartmann <nicohartmann@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Owners-Override: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80368}
2022-05-05 12:33:29 +00:00

105 lines
3.3 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-d8-web-snapshot-api --allow-natives-syntax
'use strict';
d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
(function TestObjectWithPackedElements() {
function createObjects() {
globalThis.foo = {
'0': 'zero', '1': 'one', '2': 'two', '3': 'three'
};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
// Objects always get HOLEY_ELEMENTS; no PACKED or SMI_ELEMENTS.
const elementsKindTest = {0: 0, 1: 1, 2: 2};
assertFalse(%HasPackedElements(elementsKindTest));
assertFalse(%HasSmiElements(elementsKindTest));
assertFalse(%HasPackedElements(foo));
assertFalse(%HasSmiElements(foo));
assertEquals('zeroonetwothree', foo[0] + foo[1] + foo[2] + foo[3]);
})();
(function TestObjectWithPackedSmiElements() {
function createObjects() {
globalThis.foo = {
'0': 0, '1': 1, '2': 2, '3': 3
};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertFalse(%HasPackedElements(foo));
assertFalse(%HasSmiElements(foo));
assertEquals('0123', '' + foo[0] + foo[1] + foo[2] + foo[3]);
})();
(function TestObjectWithHoleyElements() {
function createObjects() {
globalThis.foo = {
'1': 'a', '11': 'b', '111': 'c'
};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertFalse(%HasPackedElements(foo));
assertFalse(%HasSmiElements(foo));
assertEquals('abc', foo[1] + foo[11] + foo[111]);
})();
(function TestObjectWithHoleySmiElements() {
function createObjects() {
globalThis.foo = {
'1': 0, '11': 1, '111': 2
};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertFalse(%HasPackedElements(foo));
assertFalse(%HasSmiElements(foo));
assertEquals('012', '' + foo[1] + foo[11] + foo[111]);
})();
(function TestObjectWithPropertiesAndElements() {
function createObjects() {
globalThis.foo = {
'prop1': 'value1', '1': 'a', 'prop2': 'value2', '11': 'b', '111': 'c'
};
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertFalse(%HasPackedElements(foo));
assertFalse(%HasSmiElements(foo));
assertEquals('abc', foo[1] + foo[11] + foo[111]);
assertEquals('value1value2', foo.prop1 + foo.prop2);
})();
(function TestObjectsWithSamePropertiesButDifferentElementsKind() {
function createObjects() {
globalThis.foo = {
'prop1': 'value1', 'prop2': 'value2', '1': 'a', '11': 'b', '111': 'c'
};
globalThis.bar = {
'prop1': 'value1', 'prop2': 'value2', '0': 0, '1': 0
}
}
const { foo, bar } = takeAndUseWebSnapshot(createObjects, ['foo', 'bar']);
assertFalse(%HasPackedElements(foo));
assertFalse(%HasSmiElements(foo));
assertEquals('abc', foo[1] + foo[11] + foo[111]);
assertEquals('value1value2', foo.prop1 + foo.prop2);
assertFalse(%HasPackedElements(bar));
assertFalse(%HasSmiElements(bar));
assertEquals('00', '' + bar[0] + bar[1]);
assertEquals('value1value2', bar.prop1 + bar.prop2);
})();
(function TestObjectWithEmptyMap() {
function createObjects() {
globalThis.foo = [{a:1}, {}, {b: 2}];
}
const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
assertEquals(1, foo[0].a);
assertEquals(2, foo[2].b);
})();