summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/web-snapshot/web-snapshot-bigint.js
blob: 3ad17da2f0a9c30376871d889d1134bfb47c86fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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 TestBigInt() {
  function createObjects() {
    const b = 100n;
    const c = 2n ** 222n;
    globalThis.foo = { bar: b, bar1: c };
  }
  const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
  assertEquals(100n, foo.bar);
  assertEquals(2n ** 222n , foo.bar1)
})();

(function TestBigIntInArray() {
  function createObjects() {
    const b = 100n;
    const c = 2n ** 222n;
    globalThis.foo = [b, c];
  }
  const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
  assertEquals([100n, 2n ** 222n], foo)
})();

(function TestBigIntInFunctionContext() {
  function createObjects() {
    globalThis.foo = {
      key: (function () {
        const b = 100n;
        const c = 2n ** 222n;
        function inner() {
          return [b, c];
        }
        return inner;
      })()
    };
  }
  const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
  assertEquals([100n, 2n**222n], foo.key());
})();

(function TestBigIntInFunctionContextWithParentContext() {
  function createObjects() {
    globalThis.foo = {
      key: (function () {
        const b = 100n;
        function inner() {
          const c = 2n ** 222n;
          function innerinner() {
            return [b, c]
          }
          return innerinner
        }
        return inner();
      })()
    };
  }
  const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
  assertEquals([100n, 2n**222n], foo.key());
})();

(function TestBigIntInTopLevelFunctionWithContext() {
  function createObjects() {
    globalThis.foo = (function () {
      const b = 100n;
      const c = 2n ** 222n;
      function inner() { return [b, c]; }
      return inner;
    })();
  }
  const { foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
  assertEquals([100n, 2n**222n], foo());
})();


(function TestBigIntInClassStaticProperty() {
  function createObjects() {
    globalThis.foo = class Foo {
      static b = 100n;
      static c = 2n ** 222n;
    };
  }
  const { foo: Foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
  assertEquals([100n, 2n**222n], [Foo.b, Foo.c]);
})();

(function TestBigIntInClassWithConstructor() {
  function createObjects() {
    globalThis.foo = class Foo {
      constructor() {
        this.b = 100n;
        this.c = 2n ** 222n;
      }
    };
  }
  const { foo: Foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
  const foo = new Foo()
  assertEquals([100n, 2n**222n], [foo.b, foo.c]);
})();

(async function TestBigIntInClassWithMethods() {
  function createObjects() {
    globalThis.foo = class Foo {
      b() {
        return 100n;
      }
      async c() {
        return 2n ** 222n;
      }
    };
  }
  const { foo: Foo } = takeAndUseWebSnapshot(createObjects, ['foo']);
  const foo = new Foo()
  assertEquals([100n, 2n**222n], [foo.b(), await foo.c()]);
})();