Skip to content

Commit b158334

Browse files
committed
[Tests] add coverage from tc39/test262#4520
1 parent 8804598 commit b158334

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/tests.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,58 @@ module.exports = function (getOrInsertComputed, t) {
9696

9797
st.end();
9898
});
99+
100+
t.test('test262: test/built-ins/WeakMap/prototype/getOrInsertComputed/check-state-after-callback-fn-throws', { skip: typeof WeakMap === 'undefined' }, function (st) {
101+
var map = new WeakMap();
102+
var obj0 = {};
103+
var obj1 = {};
104+
var obj2 = {};
105+
var obj3 = {};
106+
map.set(obj0, 'zero');
107+
map.set(obj1, 'one');
108+
map.set(obj2, 'two');
109+
110+
st['throws'](
111+
function () {
112+
map.getOrInsertComputed(Symbol('3'), function () {
113+
throw new Error('throw in callback');
114+
});
115+
},
116+
Error
117+
);
118+
119+
// Check the values after throwing in callbackfn.
120+
st.equal(map.get(obj0), 'zero');
121+
st.equal(map.get(obj1), 'one');
122+
st.equal(map.get(obj2), 'two');
123+
st.equal(map.has(obj3), false);
124+
125+
st['throws'](function () {
126+
map.getOrInsertComputed(obj3, function () {
127+
map.set(obj1, 'mutated');
128+
throw new Error('throw in callback');
129+
});
130+
}, Error);
131+
132+
// Check the values after throwing in callbackfn, with mutation.
133+
st.equal(map.get(obj0), 'zero');
134+
st.equal(map.get(obj1), 'mutated');
135+
st.equal(map.get(obj2), 'two');
136+
st.equal(map.has(obj3), false);
137+
138+
st['throws'](function () {
139+
map.getOrInsertComputed(obj3, function () {
140+
map.set(obj3, 'mutated');
141+
throw new Error('throw in callback');
142+
});
143+
}, Error);
144+
145+
// Check the values after throwing in callbackfn, with mutation.
146+
st.equal(map.get(obj0), 'zero');
147+
st.equal(map.get(obj1), 'mutated');
148+
st.equal(map.get(obj2), 'two');
149+
st.equal(map.get(obj3), 'mutated');
150+
151+
st.end();
152+
});
99153
};

0 commit comments

Comments
 (0)