chromium/third_party/blink/web_tests/http/tests/workers/resources/shared-worker-count-connections.js

var ports = [];
onconnect = function(event) {
  ports.push(event.ports[0]);
  for (var i = 0 ; i < ports.length ; i++) {
    ports[i].postMessage(ports.length);
  }
};