porffor 0.18.23 → 0.18.24

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.
@@ -0,0 +1,261 @@
1
+ import type {} from './porffor.d.ts';
2
+
3
+ export const DataView = function (arg: any, byteOffset: any, length: any): DataView {
4
+ if (!new.target) throw new TypeError("Constructor DataView requires 'new'");
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
+ const type: i32 = Porffor.rawType(arg);
13
+ if (Porffor.fastOr(
14
+ type == Porffor.TYPES.arraybuffer,
15
+ type == Porffor.TYPES.sharedarraybuffer
16
+ )) {
17
+ bufferPtr = Porffor.wasm`local.get ${arg}`;
18
+
19
+ if (arg.detached) throw new TypeError('Constructed DataView with a detached ArrayBuffer');
20
+
21
+ let offset: i32 = 0;
22
+ if (Porffor.rawType(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
23
+ if (offset < 0) throw new RangeError('Invalid DataView byte offset (negative)');
24
+
25
+ Porffor.wasm.i32.store(outPtr, offset, 0, 8);
26
+ Porffor.wasm.i32.store(outPtr, bufferPtr + offset, 0, 4);
27
+
28
+ if (Porffor.rawType(length) == Porffor.TYPES.undefined) {
29
+ const bufferLen: i32 = Porffor.wasm.i32.load(bufferPtr, 0, 0);
30
+ len = bufferLen - byteOffset;
31
+ } else len = Math.trunc(length);
32
+ } else {
33
+ throw new TypeError('First argument to DataView constructor must be an ArrayBuffer');
34
+ }
35
+
36
+ if (len < 0) throw new RangeError('Invalid DataView length (negative)');
37
+ if (len > 4294967295) throw new RangeError('Invalid DataView length (over 32 bit address space)');
38
+
39
+ Porffor.wasm.i32.store(outPtr, len, 0, 0);
40
+ return out;
41
+ };
42
+
43
+ export const __DataView_prototype_buffer$get = (_this: DataView) => {
44
+ const out: ArrayBuffer = Porffor.wasm.i32.load(_this, 0, 4) - Porffor.wasm.i32.load(_this, 0, 8);
45
+ return out;
46
+ };
47
+
48
+ export const __DataView_prototype_byteLength$get = (_this: DataView) => {
49
+ return Porffor.wasm.i32.load(_this, 0, 0);
50
+ };
51
+
52
+ export const __DataView_prototype_byteOffset$get = (_this: DataView) => {
53
+ return Porffor.wasm.i32.load(_this, 0, 8);
54
+ };
55
+
56
+
57
+ export const __DataView_prototype_getUint8 = (_this: DataView, byteOffset: number) => {
58
+ const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
59
+ if (Porffor.fastOr(byteOffset < 0, byteOffset >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
60
+
61
+ Porffor.wasm`
62
+ local.get ${_this}
63
+ i32.to_u
64
+ i32.load 0 4
65
+ local.get ${byteOffset}
66
+ i32.to_u
67
+ i32.add
68
+ i32.load8_u 0 4
69
+ i32.from_u
70
+ i32.const 0
71
+ return`;
72
+ };
73
+
74
+ export const __DataView_prototype_setUint8 = (_this: DataView, byteOffset: number, value: number) => {
75
+ const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
76
+ if (Porffor.fastOr(byteOffset < 0, byteOffset >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
77
+
78
+ Porffor.wasm`
79
+ local.get ${_this}
80
+ i32.to_u
81
+ i32.load 0 4
82
+ local.get ${byteOffset}
83
+ i32.to_u
84
+ i32.add
85
+ local.get ${value}
86
+ i32.to_u
87
+ i32.store8 0 4`;
88
+
89
+ return undefined;
90
+ };
91
+
92
+ export const __DataView_prototype_getInt8 = (_this: DataView, byteOffset: number) => {
93
+ const n: i32 = __DataView_prototype_getUint8(_this, byteOffset);
94
+ return n & 0x80 ? n ^ -0x100 : n;
95
+ };
96
+
97
+ export const __DataView_prototype_setInt8 = (_this: DataView, byteOffset: number, value: number) => {
98
+ return __DataView_prototype_setUint8(_this, byteOffset, value < 0 ? value | 0x100 : value);
99
+ };
100
+
101
+
102
+ export const __DataView_prototype_getUint16 = (_this: DataView, byteOffset: number, littleEndian: any) => {
103
+ const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
104
+ if (Porffor.fastOr(byteOffset < 0, byteOffset + 1 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
105
+
106
+ let byte1: i32 = 0, byte2: i32 = 0;
107
+ Porffor.wasm`local ptr i32
108
+ local.get ${_this}
109
+ i32.to_u
110
+ i32.load 0 4
111
+ local.get ${byteOffset}
112
+ i32.to_u
113
+ i32.add
114
+ local.set ptr
115
+
116
+ local.get ptr
117
+ i32.load8_u 0 4
118
+ i32.from_u
119
+ local.set ${byte1}
120
+ local.get ptr
121
+ i32.load8_u 0 5
122
+ i32.from_u
123
+ local.set ${byte2}`;
124
+
125
+ if (Boolean(littleEndian)) return byte1 | (byte2 << 8);
126
+ return (byte1 << 8) | byte2;
127
+ };
128
+
129
+ export const __DataView_prototype_setUint16 = (_this: DataView, byteOffset: number, value: number, littleEndian: any) => {
130
+ const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
131
+ if (Porffor.fastOr(byteOffset < 0, byteOffset + 1 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
132
+
133
+ let byte1: i32 = 0, byte2: i32 = 0;
134
+ if (littleEndian) {
135
+ byte1 = value & 0xff;
136
+ byte2 = (value >>> 8) & 0xff;
137
+ } else {
138
+ byte1 = (value >>> 8) & 0xff;
139
+ byte2 = value & 0xff;
140
+ }
141
+
142
+ Porffor.wasm`local ptr i32
143
+ local.get ${_this}
144
+ i32.to_u
145
+ i32.load 0 4
146
+ local.get ${byteOffset}
147
+ i32.to_u
148
+ i32.add
149
+ local.set ptr
150
+
151
+ local.get ptr
152
+ local.get ${byte1}
153
+ i32.to_u
154
+ i32.store8 0 4
155
+ local.get ptr
156
+ local.get ${byte2}
157
+ i32.to_u
158
+ i32.store8 0 5`;
159
+
160
+ return undefined;
161
+ };
162
+
163
+ export const __DataView_prototype_getInt16 = (_this: DataView, byteOffset: number, littleEndian: any) => {
164
+ const n: i32 = __DataView_prototype_getUint16(_this, byteOffset, littleEndian);
165
+ return n & 0x8000 ? n ^ -0x10000 : n;
166
+ };
167
+
168
+ export const __DataView_prototype_setInt16 = (_this: DataView, byteOffset: number, value: number, littleEndian: any) => {
169
+ return __DataView_prototype_setUint16(_this, byteOffset, value < 0 ? value | 0x10000 : value, littleEndian);
170
+ };
171
+
172
+
173
+ export const __DataView_prototype_getUint32 = (_this: DataView, byteOffset: number, littleEndian: any) => {
174
+ const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
175
+ if (Porffor.fastOr(byteOffset < 0, byteOffset + 3 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
176
+
177
+ let byte1: i32 = 0, byte2: i32 = 0, byte3: i32 = 0, byte4: i32 = 0;
178
+ Porffor.wasm`local ptr i32
179
+ local.get ${_this}
180
+ i32.to_u
181
+ i32.load 0 4
182
+ local.get ${byteOffset}
183
+ i32.to_u
184
+ i32.add
185
+ local.set ptr
186
+
187
+ local.get ptr
188
+ i32.load8_u 0 4
189
+ i32.from_u
190
+ local.set ${byte1}
191
+ local.get ptr
192
+ i32.load8_u 0 5
193
+ i32.from_u
194
+ local.set ${byte2}
195
+ local.get ptr
196
+ i32.load8_u 0 6
197
+ i32.from_u
198
+ local.set ${byte3}
199
+ local.get ptr
200
+ i32.load8_u 0 7
201
+ i32.from_u
202
+ local.set ${byte4}`;
203
+
204
+ if (Boolean(littleEndian)) return byte1 | (byte2 << 8) | (byte3 << 16) | (byte4 << 24);
205
+ return (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
206
+ };
207
+
208
+ export const __DataView_prototype_setUint32 = (_this: DataView, byteOffset: number, value: number, littleEndian: any) => {
209
+ const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
210
+ if (Porffor.fastOr(byteOffset < 0, byteOffset + 3 >= len)) throw new RangeError('Byte offset is out of bounds of the DataView');
211
+
212
+ let byte1: i32 = 0, byte2: i32 = 0, byte3: i32 = 0, byte4: i32 = 0;
213
+ if (littleEndian) {
214
+ byte1 = value & 0xff;
215
+ byte2 = (value >>> 8) & 0xff;
216
+ byte3 = (value >>> 16) & 0xff;
217
+ byte4 = (value >>> 24) & 0xff;
218
+ } else {
219
+ byte1 = (value >>> 24) & 0xff;
220
+ byte2 = (value >>> 16) & 0xff;
221
+ byte3 = (value >>> 8) & 0xff;
222
+ byte4 = value & 0xff;
223
+ }
224
+
225
+ Porffor.wasm`local ptr i32
226
+ local.get ${_this}
227
+ i32.to_u
228
+ i32.load 0 4
229
+ local.get ${byteOffset}
230
+ i32.to_u
231
+ i32.add
232
+ local.set ptr
233
+
234
+ local.get ptr
235
+ local.get ${byte1}
236
+ i32.to_u
237
+ i32.store8 0 4
238
+ local.get ptr
239
+ local.get ${byte2}
240
+ i32.to_u
241
+ i32.store8 0 5
242
+ local.get ptr
243
+ local.get ${byte3}
244
+ i32.to_u
245
+ i32.store8 0 6
246
+ local.get ptr
247
+ local.get ${byte4}
248
+ i32.to_u
249
+ i32.store8 0 7`;
250
+
251
+ return undefined;
252
+ };
253
+
254
+ export const __DataView_prototype_getInt32 = (_this: DataView, byteOffset: number, littleEndian: any) => {
255
+ const n: i32 = __DataView_prototype_getUint32(_this, byteOffset, littleEndian);
256
+ return n & 0x80000000 ? n ^ -0x100000000 : n;
257
+ };
258
+
259
+ export const __DataView_prototype_setInt32 = (_this: DataView, byteOffset: number, value: number, littleEndian: any) => {
260
+ return __DataView_prototype_setUint32(_this, byteOffset, value < 0 ? value | 0x100000000 : value, littleEndian);
261
+ };
@@ -19,37 +19,26 @@ export default async () => {
19
19
  let bufferPtr: i32;
20
20
 
21
21
  const type: i32 = Porffor.rawType(arg);
22
- if (type == Porffor.TYPES.arraybuffer) {
22
+ if (Porffor.fastOr(
23
+ type == Porffor.TYPES.arraybuffer,
24
+ type == Porffor.TYPES.sharedarraybuffer
25
+ )) {
23
26
  bufferPtr = Porffor.wasm\`local.get \${arg}\`;
24
27
 
25
28
  if (arg.detached) throw new TypeError('Constructed ${name} with a detached ArrayBuffer');
26
29
 
27
30
  let offset: i32 = 0;
28
31
  if (Porffor.rawType(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
29
- Porffor.wasm.i32.store(outPtr, offset, 0, 8);
30
-
31
- Porffor.wasm.i32.store(outPtr, bufferPtr + offset, 0, 4);
32
+ if (offset < 0) throw new RangeError('Invalid DataView byte offset (negative)');
32
33
 
33
- if (Porffor.rawType(length) == Porffor.TYPES.undefined) {
34
- const bufferLen: i32 = Porffor.wasm.i32.load(bufferPtr, 0, 0);
35
- len = (bufferLen - byteOffset) / ${name}.BYTES_PER_ELEMENT;
36
-
37
- if (!Number.isInteger(len)) throw new RangeError('byte length of ${name} should be divisible by BYTES_PER_ELEMENT');
38
- } else len = Math.trunc(length);
39
- } else if (type == Porffor.TYPES.sharedarraybuffer) {
40
- bufferPtr = Porffor.wasm\`local.get \${arg}\`;
41
-
42
- let offset: i32 = 0;
43
- if (Porffor.rawType(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
44
34
  Porffor.wasm.i32.store(outPtr, offset, 0, 8);
45
-
46
35
  Porffor.wasm.i32.store(outPtr, bufferPtr + offset, 0, 4);
47
36
 
48
37
  if (Porffor.rawType(length) == Porffor.TYPES.undefined) {
49
38
  const bufferLen: i32 = Porffor.wasm.i32.load(bufferPtr, 0, 0);
50
39
  len = (bufferLen - byteOffset) / ${name}.BYTES_PER_ELEMENT;
51
40
 
52
- if (!Number.isInteger(len)) throw new RangeError('byte length of ${name} should be divisible by BYTES_PER_ELEMENT');
41
+ if (!Number.isInteger(len)) throw new RangeError('Byte length of ${name} should be divisible by BYTES_PER_ELEMENT');
53
42
  } else len = Math.trunc(length);
54
43
  } else {
55
44
  bufferPtr = Porffor.allocate();
@@ -117,12 +106,12 @@ export const __${name}_from = (arg: any, mapFn: any): ${name} => {
117
106
  };
118
107
 
119
108
  export const __${name}_prototype_buffer$get = (_this: ${name}) => {
120
- const out: ArrayBuffer = Porffor.wasm.i32.load(_this, 0, 4);
109
+ const out: ArrayBuffer = Porffor.wasm.i32.load(_this, 0, 4) - Porffor.wasm.i32.load(_this, 0, 8);
121
110
  return out;
122
111
  };
123
112
 
124
113
  export const __${name}_prototype_byteLength$get = (_this: ${name}) => {
125
- return _this.length * ${name}.BYTES_PER_ELEMENT;
114
+ return Porffor.wasm.i32.load(_this, 0, 0) * ${name}.BYTES_PER_ELEMENT;
126
115
  };
127
116
 
128
117
  export const __${name}_prototype_byteOffset$get = (_this: ${name}) => {