xref: /third_party/node/test/parallel/test-buffer-sharedarraybuffer.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst sab = new SharedArrayBuffer(24);
71cb0ef41Sopenharmony_ciconst arr1 = new Uint16Array(sab);
81cb0ef41Sopenharmony_ciconst arr2 = new Uint16Array(12);
91cb0ef41Sopenharmony_ciarr2[0] = 5000;
101cb0ef41Sopenharmony_ciarr1[0] = 5000;
111cb0ef41Sopenharmony_ciarr1[1] = 4000;
121cb0ef41Sopenharmony_ciarr2[1] = 4000;
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst arr_buf = Buffer.from(arr1.buffer);
151cb0ef41Sopenharmony_ciconst ar_buf = Buffer.from(arr2.buffer);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciassert.deepStrictEqual(arr_buf, ar_buf);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciarr1[1] = 6000;
201cb0ef41Sopenharmony_ciarr2[1] = 6000;
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciassert.deepStrictEqual(arr_buf, ar_buf);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// Checks for calling Buffer.byteLength on a SharedArrayBuffer.
251cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciBuffer.from({ buffer: sab }); // Should not throw.
28

Indexes created Thu Nov 07 10:32:03 CST 2024