diff options
Diffstat (limited to '')
-rw-r--r-- | js/src/jit-test/tests/fields/private-throwing-initializer.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/fields/private-throwing-initializer.js b/js/src/jit-test/tests/fields/private-throwing-initializer.js new file mode 100644 index 0000000000..ac5d94b343 --- /dev/null +++ b/js/src/jit-test/tests/fields/private-throwing-initializer.js @@ -0,0 +1,64 @@ +// |jit-test| --enable-private-fields; + +// Ensure private fields are stamped in order and that +// we can successfully partially initialize objects. + +class Base { + constructor(o) { + return o; + } +} + +let constructorThrow = false; + +function maybeThrow() { + if (constructorThrow) { + throw 'fail' + } + return 'sometimes' +} + +class A extends Base { + constructor(o) { + super(o); + constructorThrow = !constructorThrow; + } + + #x = 'always'; + #y = maybeThrow(); + + static gx(o) { + return o.#x; + } + + static gy(o) { + return o.#y; + } +}; + +var obj1 = {}; +var obj2 = {}; + +new A(obj1); + +var threw = true; +try { + new A(obj2); + threw = false; +} catch (e) { + assertEq(e, 'fail'); +} +assertEq(threw, true); + +A.gx(obj1) +A.gx(obj2); // Both objects get x; +A.gy(obj1); // obj1 gets y + +try { + A.gy(obj2); // shouldn't have x. + threw = false; +} catch (e) { + assertEq(e instanceof TypeError, true); +} + +assertEq(threw, true); |