porffor 0.59.6 → 0.59.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,45 +3,34 @@ import type {} from './porffor.d.ts';
3
3
  export const DataView = function (arg: any, byteOffset: any, length: any): DataView {
4
4
  if (!new.target) throw new TypeError("Constructor DataView requires 'new'");
5
5
 
6
- const out: DataView = Porffor.allocateBytes(12);
7
- const outPtr: i32 = Porffor.wasm`local.get ${out}`;
8
-
9
- let len: i32 = 0;
10
- let bufferPtr: i32;
11
-
12
- if (Porffor.fastOr(
13
- Porffor.type(arg) == Porffor.TYPES.arraybuffer,
14
- Porffor.type(arg) == Porffor.TYPES.sharedarraybuffer
15
- )) {
16
- bufferPtr = Porffor.wasm`local.get ${arg}`;
17
-
18
- if (arg.detached) throw new TypeError('Constructed DataView with a detached ArrayBuffer');
6
+ if (Porffor.fastAnd(
7
+ Porffor.type(arg) != Porffor.TYPES.arraybuffer,
8
+ Porffor.type(arg) != Porffor.TYPES.sharedarraybuffer
9
+ )) throw new TypeError('First argument to DataView constructor must be an ArrayBuffer');
10
+ if ((arg as ArrayBuffer).detached) throw new TypeError('Constructed DataView with a detached ArrayBuffer');
19
11
 
20
- let offset: i32 = 0;
21
- if (Porffor.type(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
22
- if (offset < 0) throw new RangeError('Invalid DataView byte offset (negative)');
12
+ let offset: i32 = 0;
13
+ if (Porffor.type(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
14
+ if (offset < 0) throw new RangeError('Invalid DataView byte offset (negative)');
23
15
 
24
- Porffor.wasm.i32.store(outPtr, offset, 0, 8);
25
- Porffor.wasm.i32.store(outPtr, bufferPtr + offset, 0, 4);
26
-
27
- if (Porffor.type(length) == Porffor.TYPES.undefined) {
28
- const bufferLen: i32 = Porffor.wasm.i32.load(bufferPtr, 0, 0);
29
- len = bufferLen - byteOffset;
30
- } else len = Math.trunc(length);
31
- } else {
32
- throw new TypeError('First argument to DataView constructor must be an ArrayBuffer');
33
- }
16
+ let len: i32 = 0;
17
+ if (Porffor.type(length) == Porffor.TYPES.undefined) {
18
+ const bufferLen: i32 = Porffor.wasm.i32.load(Porffor.wasm`local.get ${arg}`, 0, 0);
19
+ len = bufferLen - offset;
20
+ } else len = Math.trunc(length);
34
21
 
35
22
  if (len < 0) throw new RangeError('Invalid DataView length (negative)');
36
23
  if (len > 4294967295) throw new RangeError('Invalid DataView length (over 32 bit address space)');
37
24
 
38
- Porffor.wasm.i32.store(outPtr, len, 0, 0);
25
+ const out: DataView = Porffor.allocateBytes(12);
26
+ Porffor.wasm.i32.store(out, Porffor.wasm`local.get ${arg}` + offset, 0, 4);
27
+ Porffor.wasm.i32.store(out, offset, 0, 8);
28
+ Porffor.wasm.i32.store(out, len, 0, 0);
39
29
  return out;
40
30
  };
41
31
 
42
32
  export const __DataView_prototype_buffer$get = (_this: DataView) => {
43
- const out: ArrayBuffer = Porffor.wasm.i32.load(_this, 0, 4) - Porffor.wasm.i32.load(_this, 0, 8);
44
- return out;
33
+ return (Porffor.wasm.i32.load(_this, 0, 4) - Porffor.wasm.i32.load(_this, 0, 8)) as ArrayBuffer;
45
34
  };
46
35
 
47
36
  export const __DataView_prototype_byteLength$get = (_this: DataView) => {
@@ -54,6 +43,8 @@ export const __DataView_prototype_byteOffset$get = (_this: DataView) => {
54
43
 
55
44
 
56
45
  export const __DataView_prototype_getUint8 = (_this: DataView, byteOffset: number) => {
46
+ if (__DataView_prototype_buffer$get(_this).detached) throw new TypeError('Cannot operate on a detached ArrayBuffer');
47
+
57
48
  const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
58
49
  if (Porffor.fastOr(byteOffset < 0, byteOffset >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
59
50
 
@@ -71,6 +62,8 @@ return`;
71
62
  };
72
63
 
73
64
  export const __DataView_prototype_setUint8 = (_this: DataView, byteOffset: number, value: number) => {
65
+ if (__DataView_prototype_buffer$get(_this).detached) throw new TypeError('Cannot operate on a detached ArrayBuffer');
66
+
74
67
  const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
75
68
  if (Porffor.fastOr(byteOffset < 0, byteOffset >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
76
69
 
@@ -99,6 +92,8 @@ export const __DataView_prototype_setInt8 = (_this: DataView, byteOffset: number
99
92
 
100
93
 
101
94
  export const __DataView_prototype_getUint16 = (_this: DataView, byteOffset: number, littleEndian: any) => {
95
+ if (__DataView_prototype_buffer$get(_this).detached) throw new TypeError('Cannot operate on a detached ArrayBuffer');
96
+
102
97
  const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
103
98
  if (Porffor.fastOr(byteOffset < 0, byteOffset + 1 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
104
99
 
@@ -120,6 +115,8 @@ local.set ${int}`;
120
115
  };
121
116
 
122
117
  export const __DataView_prototype_setUint16 = (_this: DataView, byteOffset: number, value: number, littleEndian: any) => {
118
+ if (__DataView_prototype_buffer$get(_this).detached) throw new TypeError('Cannot operate on a detached ArrayBuffer');
119
+
123
120
  const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
124
121
  if (Porffor.fastOr(byteOffset < 0, byteOffset + 1 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
125
122
 
@@ -156,6 +153,8 @@ export const __DataView_prototype_setInt16 = (_this: DataView, byteOffset: numbe
156
153
 
157
154
 
158
155
  export const __DataView_prototype_getUint32 = (_this: DataView, byteOffset: number, littleEndian: any) => {
156
+ if (__DataView_prototype_buffer$get(_this).detached) throw new TypeError('Cannot operate on a detached ArrayBuffer');
157
+
159
158
  const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
160
159
  if (Porffor.fastOr(byteOffset < 0, byteOffset + 3 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
161
160
 
@@ -180,6 +179,8 @@ local.set ${int}`;
180
179
  };
181
180
 
182
181
  export const __DataView_prototype_setUint32 = (_this: DataView, byteOffset: number, value: number, littleEndian: any) => {
182
+ if (__DataView_prototype_buffer$get(_this).detached) throw new TypeError('Cannot operate on a detached ArrayBuffer');
183
+
183
184
  const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
184
185
  if (Porffor.fastOr(byteOffset < 0, byteOffset + 3 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
185
186
 
@@ -101,9 +101,9 @@ export const __Set_prototype_union = (_this: Set, other: any) => {
101
101
  export const __Set_prototype_intersection = (_this: Set, other: any) => {
102
102
  if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
103
103
 
104
- const out: Set = new Set(_this);
105
- for (const x of other) {
106
- out.add(x);
104
+ const out: Set = new Set();
105
+ for (const x of _this) {
106
+ if (other.has(x)) out.add(x);
107
107
  }
108
108
 
109
109
  return out;