@@ -128,8 +128,6 @@ export const __${name}_prototype_at = (_this: ${name}, index: number) => {
128
128
129
129
export const __${ name } _prototype_slice = (_this: ${ name } , start: number, end: number) => {
130
130
const len: i32 = _this.length;
131
- if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
132
-
133
131
start |= 0;
134
132
end |= 0;
135
133
@@ -160,7 +158,6 @@ export const __${name}_prototype_slice = (_this: ${name}, start: number, end: nu
160
158
161
159
export const __${ name } _prototype_set = (_this: ${ name } , array: any, offset: number) => {
162
160
const len: i32 = _this.length;
163
- if (Porffor.type(offset) == Porffor.TYPES.undefined) offset = 0;
164
161
165
162
offset |= 0;
166
163
if (Porffor.fastOr(offset < 0, offset > len)) throw new RangeError('Offset out of bounds');
@@ -179,6 +176,32 @@ export const __${name}_prototype_set = (_this: ${name}, array: any, offset: numb
179
176
}
180
177
};
181
178
179
+ export const __${ name } _prototype_subarray = (_this: ${ name } , start: number, end: any) => {
180
+ const len: i32 = _this.length;
181
+ if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
182
+
183
+ start |= 0;
184
+ end |= 0;
185
+
186
+ if (start < 0) {
187
+ start = len + start;
188
+ if (start < 0) start = 0;
189
+ }
190
+ if (start > len) start = len;
191
+ if (end < 0) {
192
+ end = len + end;
193
+ if (end < 0) end = 0;
194
+ }
195
+ if (end > len) end = len;
196
+
197
+ const out: ${ name } = Porffor.allocateBytes(12);
198
+ Porffor.wasm.i32.store(out, end - start, 0, 0);
199
+ Porffor.wasm.i32.store(out, Porffor.wasm.i32.load(_this, 0, 4) + start * ${ name } .BYTES_PER_ELEMENT, 0, 4);
200
+ Porffor.wasm.i32.store(out, Porffor.wasm.i32.load(_this, 0, 8) + start * ${ name } .BYTES_PER_ELEMENT, 0, 8);
201
+
202
+ return out;
203
+ };
204
+
182
205
${ typedArrayFuncs . reduce ( ( acc , x ) => acc + x . replace ( '// @porf-typed-array\n' , '' ) . replaceAll ( 'Array' , name ) . replaceAll ( 'any[]' , name ) + '\n\n' , '' ) }
183
206
` ;
184
207
0 commit comments