MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / createBigInt64Array

Function createBigInt64Array

src/polyfill/bigint64array.js:26–105  ·  view source on GitHub ↗
(array)

Source from the content-addressed store, hash-verified

24
25 function createBigIntArrayShim(partsToBigInt) {
26 function createBigInt64Array(array) {
27 if (typeof array === "number") {
28 array = new Uint32Array(2 * array);
29 }
30 var orig_array;
31 if (!ArrayBuffer.isView(array)) {
32 if (array.constructor?.name === "ArrayBuffer") {
33 array = new Uint32Array(array);
34 } else {
35 orig_array = array;
36 array = new Uint32Array(array.length * 2);
37 }
38 }
39 var proxy = new Proxy(
40 {
41 slice(min, max) {
42 max ??= array.length;
43 var new_buf = array.slice(min * 2, max * 2);
44 return createBigInt64Array(new_buf);
45 },
46 subarray(min, max) {
47 var new_buf = array.subarray(min * 2, max * 2);
48 return createBigInt64Array(new_buf);
49 },
50 [Symbol.iterator]: function* () {
51 for (var i = 0; i < array.length / 2; i++) {
52 yield partsToBigInt(array[2 * i], array[2 * i + 1]);
53 }
54 },
55 BYTES_PER_ELEMENT: 2 * array.BYTES_PER_ELEMENT,
56 buffer: array.buffer,
57 byteLength: array.byteLength,
58 byteOffset: array.byteOffset,
59 length: array.length / 2,
60 copyWithin: function (target, start, end) {
61 array.copyWithin(target * 2, start * 2, end * 2);
62 return proxy;
63 },
64 set(source, targetOffset) {
65 targetOffset ??= 0;
66 if (2 * (source.length + targetOffset) > array.length) {
67 // This is the Chrome error message
68 // Firefox: "invalid or out-of-range index"
69 throw new RangeError("offset is out of bounds");
70 }
71 for (var i = 0; i < source.length; i++) {
72 var value = source[i];
73 var pair = bigIntToParts(value);
74 array.set(pair, 2 * (targetOffset + i));
75 }
76 },
77 },
78 {
79 get(target, idx, receiver) {
80 if (typeof idx !== "string" || !/^\d+$/.test(idx)) {
81 return Reflect.get(target, idx, receiver);
82 }
83 var lower = array[idx * 2];

Callers 2

sliceFunction · 0.85
subarrayFunction · 0.85

Calls 1

setMethod · 0.65

Tested by

no test coverage detected