1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19

content / test / data / gpu / webcodecs / buffer-read-and-reply-worker.js [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function readWholeBuffer(buffer) {
  let bytes = new Uint8Array(buffer);
  return bytes.reduce((acc, byte) => {
    return byte ? acc + 1 : acc;
  }, 0);
}

self.onmessage = function(e) {
  const buf = e.data;
  readWholeBuffer(buf);
  if (buf instanceof SharedArrayBuffer)
    postMessage(buf, []);
  else
    postMessage(buf, [buf]);
}