blob: bd576854ee74d15e665fcc641cffadd294cd1a87 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let suite = InspectorTest.createSyncSuite("WeakMap");
suite.addTestCase({
name: "WeakMap.prototype.getOrInitialize.Raw",
test() {
const key = {value: "key"};
const value = "value";
const value2 = "value2";
let map = new WeakMap;
InspectorTest.expectEqual(map.get(key), undefined, "Map does not have `key`.");
InspectorTest.expectEqual(map.getOrInitialize(key, value), value, "Map should have initialized `key` with `value`.");
InspectorTest.expectEqual(map.get(key), value, "Map does have `key` => `value`.");
InspectorTest.expectEqual(map.getOrInitialize(key, value2), value, "Map should get `key` with `value` without re-initializing.");
InspectorTest.expectEqual(map.get(key), value, "Map still has `key` => `value`.");
}
});
suite.addTestCase({
name: "WeakMap.prototype.getOrInitialize.Function",
test() {
const key = {value: "key"};
const value = () => "value";
const value2 = () => InspectorTest.fail("Should not be reached.");
let map = new WeakMap;
InspectorTest.expectEqual(map.get(key), undefined, "Map does not have `key`.");
InspectorTest.expectEqual(map.getOrInitialize(key, value), value(), "Map should have initialized `key` with `value`.");
InspectorTest.expectEqual(map.get(key), value(), "Map does have `key` => `value`.");
InspectorTest.expectEqual(map.getOrInitialize(key, value2), value(), "Map should get `key` with `value` without re-initializing.");
InspectorTest.expectEqual(map.get(key), value(), "Map still has `key` => `value`.");
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onLoad="runTest()">
</body>
</html>