1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --logfile='+' --log --log-maps --log-ic --log-code
6// Flags: --log-function-events --no-stress-opt --no-predictable
7
8import { Processor } from "../../../tools/system-analyzer/processor.mjs";
9
10// log code start
11function doWork() {
12  let array = [];
13  for (let i = 0; i < 500; i++) {
14    doWorkStep(i, array);
15  }
16  let sum = 0;
17  for (let i = 0; i < 500; i++) {
18    sum += array[i]["property" + i];
19  }
20  return sum;
21}
22
23function doWorkStep(i, array) {
24  const obj = {
25    ["property" + i]: i,
26  };
27  array.push(obj);
28  obj.custom1 = 1;
29  obj.custom2 = 2;
30}
31
32const result = doWork();
33 // log code end
34
35const logString = d8.log.getAndStop();
36const processor = new Processor();
37await processor.processChunk(logString);
38await processor.finalize();
39
40const maps = processor.mapTimeline;
41const ics = processor.icTimeline;
42const scripts = processor.scripts;
43
44(function testResults() {
45  assertEquals(result, 124750);
46  assertTrue(maps.length > 0);
47  assertTrue(ics.length > 0);
48  assertTrue(scripts.length > 0);
49})();
50
51(function testIcKeys() {
52  const keys = new Set();
53  ics.forEach(ic => keys.add(ic.key));
54  assertTrue(keys.has("custom1"));
55  assertTrue(keys.has("custom2"));
56  assertTrue(keys.has("push"));
57})();
58