porffor 0.55.17 → 0.55.19

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.
@@ -1,6 +1,6 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const Object = function (value: any): object {
3
+ export const Object = function (value: any): any {
4
4
  if (value == null) {
5
5
  // if nullish, return new empty object
6
6
  const obj: object = Porffor.allocate();
@@ -8,6 +8,7 @@ export const Object = function (value: any): object {
8
8
  }
9
9
 
10
10
  // primitives into primitive objects
11
+ if ((Porffor.rawType(value) | 0b10000000) == Porffor.TYPES.bytestring) return new String(value);
11
12
  if (Porffor.rawType(value) == Porffor.TYPES.number) return new Number(value);
12
13
  if (Porffor.rawType(value) == Porffor.TYPES.boolean) return new Boolean(value);
13
14
 
@@ -159,11 +160,11 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
159
160
  return __Array_prototype_includes(keys, p);
160
161
  };
161
162
 
162
- export const __Object_hasOwn = (obj: any, prop: any) => {
163
+ export const __Object_hasOwn = (obj: any, prop: any): boolean => {
163
164
  return __Object_prototype_hasOwnProperty(obj, prop);
164
165
  };
165
166
 
166
- export const __Porffor_object_in = (obj: any, prop: any) => {
167
+ export const __Porffor_object_in = (obj: any, prop: any): boolean => {
167
168
  if (__Object_prototype_hasOwnProperty(obj, prop)) {
168
169
  return true;
169
170
  }
@@ -180,7 +181,7 @@ export const __Porffor_object_in = (obj: any, prop: any) => {
180
181
  return false;
181
182
  };
182
183
 
183
- export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: any) => {
184
+ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: any): boolean => {
184
185
  if (Porffor.rawType(constr) != Porffor.TYPES.function) {
185
186
  throw new TypeError('instanceof right-hand side is not a function');
186
187
  }
@@ -202,7 +203,7 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
202
203
  };
203
204
 
204
205
 
205
- export const __Object_assign = (target: any, ...sources: any[]) => {
206
+ export const __Object_assign = (target: any, ...sources: any[]): any => {
206
207
  if (target == null) throw new TypeError('Argument is nullish, expected object');
207
208
 
208
209
  for (const x of sources) {
@@ -220,7 +221,7 @@ export const __Object_assign = (target: any, ...sources: any[]) => {
220
221
  };
221
222
 
222
223
  // Object.assign but also non enumerable properties and 1 source
223
- export const __Porffor_object_assignAll = (target: any, source: any) => {
224
+ export const __Porffor_object_assignAll = (target: any, source: any): any => {
224
225
  if (target == null) throw new TypeError('Argument is nullish, expected object');
225
226
 
226
227
  const keys: any[] = Reflect.ownKeys(source);
@@ -337,7 +338,7 @@ export const __Object_isSealed = (obj: any): any => {
337
338
  };
338
339
 
339
340
 
340
- export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): any => {
341
+ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|undefined => {
341
342
  const p: any = ecma262.ToPropertyKey(prop);
342
343
 
343
344
  const entryPtr: i32 = Porffor.object.lookup(obj, p);
@@ -387,7 +388,7 @@ local.set ${value+1}`;
387
388
  return out;
388
389
  };
389
390
 
390
- export const __Object_getOwnPropertyDescriptors = (obj: any): any => {
391
+ export const __Object_getOwnPropertyDescriptors = (obj: any): object => {
391
392
  const out: object = {};
392
393
 
393
394
  if (Porffor.rawType(obj) != Porffor.TYPES.object) {
@@ -515,7 +516,7 @@ local.set ${key}`;
515
516
  };
516
517
 
517
518
 
518
- export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
519
+ export const __Object_defineProperty = (target: any, prop: any, desc: any): any => {
519
520
  if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
520
521
  if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
521
522
 
@@ -593,7 +594,7 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
593
594
  return target;
594
595
  };
595
596
 
596
- export const __Object_defineProperties = (target: any, props: any) => {
597
+ export const __Object_defineProperties = (target: any, props: any): any => {
597
598
  if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
598
599
  if (!Porffor.object.isObjectOrSymbol(props)) throw new TypeError('Props needs to be an object or symbol');
599
600
 
@@ -604,7 +605,7 @@ export const __Object_defineProperties = (target: any, props: any) => {
604
605
  return target;
605
606
  };
606
607
 
607
- export const __Object_create = (proto: any, props: any) => {
608
+ export const __Object_create = (proto: any, props: any): object => {
608
609
  if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
609
610
 
610
611
  const out: object = {};
@@ -618,7 +619,7 @@ export const __Object_create = (proto: any, props: any) => {
618
619
  };
619
620
 
620
621
 
621
- export const __Object_groupBy = (items: any, callbackFn: any) => {
622
+ export const __Object_groupBy = (items: any, callbackFn: any): object => {
622
623
  const out: object = {};
623
624
 
624
625
  let i = 0;
@@ -636,13 +637,13 @@ export const __Object_groupBy = (items: any, callbackFn: any) => {
636
637
  };
637
638
 
638
639
 
639
- export const __Object_getPrototypeOf = (obj: any) => {
640
+ export const __Object_getPrototypeOf = (obj: any): any => {
640
641
  if (obj == null) throw new TypeError('Object is nullish, expected object');
641
642
 
642
643
  return obj.__proto__;
643
644
  };
644
645
 
645
- export const __Object_setPrototypeOf = (obj: any, proto: any) => {
646
+ export const __Object_setPrototypeOf = (obj: any, proto: any): any => {
646
647
  if (obj == null) throw new TypeError('Object is nullish, expected object');
647
648
  if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
648
649
 
@@ -144,7 +144,7 @@ export const __Porffor_then = (promise: any[], fulfillReaction: any[], rejectRea
144
144
  }
145
145
  };
146
146
 
147
- export const __Porffor_promise_resolve = (value: any, promise: any): any => {
147
+ export const __Porffor_promise_resolve = (value: any, promise: any): void => {
148
148
  // if value is own promise, reject with typeerror
149
149
  if (value === promise) throw new TypeError('cannot resolve promise with itself');
150
150
 
@@ -156,13 +156,10 @@ export const __Porffor_promise_resolve = (value: any, promise: any): any => {
156
156
  } else {
157
157
  __ecma262_FulfillPromise(promise, value);
158
158
  }
159
-
160
- return undefined;
161
159
  };
162
160
 
163
- export const __Porffor_promise_reject = (reason: any, promise: any): any => {
161
+ export const __Porffor_promise_reject = (reason: any, promise: any): void => {
164
162
  __ecma262_RejectPromise(promise, reason);
165
- return undefined;
166
163
  };
167
164
 
168
165
  export const __Porffor_promise_create = (): any[] => {
@@ -187,12 +184,12 @@ export const __Porffor_promise_create = (): any[] => {
187
184
  return obj;
188
185
  };
189
186
 
190
- export const __Porffor_promise_runNext = (func: Function) => {
187
+ export const __Porffor_promise_runNext = (func: Function): void => {
191
188
  const reaction: any[] = __Porffor_promise_newReaction(func, undefined, 1);
192
189
  __ecma262_HostEnqueuePromiseJob(__ecma262_NewPromiseReactionJob(reaction, undefined));
193
190
  };
194
191
 
195
- export const __Porffor_promise_runJobs = () => {
192
+ export const __Porffor_promise_runJobs = (): void => {
196
193
  while (true) {
197
194
  let x: any = jobQueue.shift();
198
195
  if (x == null) break;
@@ -225,10 +222,10 @@ export const __Porffor_promise_runJobs = () => {
225
222
 
226
223
  // hack: cannot share scope so use a global
227
224
  let activePromise: any;
228
- export const __Porffor_promise_resolveActive = (value: any) => __Porffor_promise_resolve(value, activePromise);
229
- export const __Porffor_promise_rejectActive = (reason: any) => __Porffor_promise_reject(reason, activePromise);
225
+ export const __Porffor_promise_resolveActive = (value: any): void => __Porffor_promise_resolve(value, activePromise);
226
+ export const __Porffor_promise_rejectActive = (reason: any): void => __Porffor_promise_reject(reason, activePromise);
230
227
 
231
- export const Promise = function (executor: any): void {
228
+ export const Promise = function (executor: any): Promise {
232
229
  if (!new.target) throw new TypeError("Constructor Promise requires 'new'");
233
230
  if (Porffor.rawType(executor) != Porffor.TYPES.function) throw new TypeError('Promise executor is not a function');
234
231
 
@@ -242,17 +239,15 @@ export const Promise = function (executor: any): void {
242
239
  __ecma262_RejectPromise(obj, e);
243
240
  }
244
241
 
245
- const pro: Promise = obj;
246
- return pro;
242
+ return obj as Promise;
247
243
  };
248
244
 
249
- export const __Promise_withResolvers = (): Promise => {
245
+ export const __Promise_withResolvers = (): object => {
250
246
  const obj: any[] = __Porffor_promise_create();
251
247
  activePromise = obj;
252
248
 
253
- const promise: Promise = obj;
254
249
  const out: object = Porffor.allocate();
255
- out.promise = promise;
250
+ out.promise = obj as Promise;
256
251
 
257
252
  out.resolve = __Porffor_promise_resolveActive;
258
253
  out.reject = __Porffor_promise_rejectActive;
@@ -265,8 +260,7 @@ export const __Promise_resolve = (value: any): Promise => {
265
260
 
266
261
  __Porffor_promise_resolve(value, obj);
267
262
 
268
- const pro: Promise = obj;
269
- return pro;
263
+ return obj as Promise;
270
264
  };
271
265
 
272
266
  export const __Promise_reject = (reason: any): Promise => {
@@ -274,8 +268,7 @@ export const __Promise_reject = (reason: any): Promise => {
274
268
 
275
269
  __Porffor_promise_reject(reason, obj);
276
270
 
277
- const pro: Promise = obj;
278
- return pro;
271
+ return obj as Promise;
279
272
  };
280
273
 
281
274
 
@@ -296,19 +289,18 @@ export const __Promise_prototype_then = (_this: any, onFulfilled: any, onRejecte
296
289
 
297
290
  __Porffor_then(_this, fulfillReaction, rejectReaction);
298
291
 
299
- const pro: Promise = outPromise;
300
- return pro;
292
+ return outPromise as Promise;
301
293
  };
302
294
 
303
295
  // 27.2.5.1 Promise.prototype.catch (onRejected)
304
296
  // https://tc39.es/ecma262/#sec-promise.prototype.catch
305
- export const __Promise_prototype_catch = (_this: any, onRejected: any): Promise => {
297
+ export const __Promise_prototype_catch = (_this: any, onRejected: any) => {
306
298
  // 1. Let promise be the this value.
307
299
  // 2. Return ? Invoke(promise, "then", « undefined, onRejected »).
308
300
  return __Promise_prototype_then(_this, undefined, onRejected);
309
301
  };
310
302
 
311
- export const __Promise_prototype_finally = (_this: any, onFinally: any): Promise => {
303
+ export const __Promise_prototype_finally = (_this: any, onFinally: any) => {
312
304
  // custom impl based on then but also not (sorry)
313
305
  if (!__ecma262_IsPromise(_this)) throw new TypeError('Promise.prototype.then called on non-Promise');
314
306
 
@@ -332,8 +324,7 @@ export const __Promise_prototype_finally = (_this: any, onFinally: any): Promise
332
324
  __ecma262_HostEnqueuePromiseJob(__ecma262_NewPromiseReactionJob(finallyReaction, value));
333
325
  }
334
326
 
335
- const pro: Promise = outPromise;
336
- return pro;
327
+ return outPromise as Promise;
337
328
  };
338
329
 
339
330
 
@@ -480,18 +471,16 @@ export const __Promise_prototype_toString = (_this: any) => '[object Promise]';
480
471
  export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prototype_toString(_this);
481
472
 
482
473
 
483
- export const __Porffor_promise_await = (value: any) => {
474
+ export const __Porffor_promise_await = (value: any): any => {
484
475
  if (Porffor.rawType(value) != Porffor.TYPES.promise) return value;
485
476
 
486
477
  // hack: peek value instead of awaiting
487
- const promise: any[] = value;
488
-
489
- const state: i32 = promise[1];
478
+ const state: i32 = (value as any[])[1];
490
479
 
491
480
  // pending
492
481
  if (state == 0) return value;
493
482
 
494
- const result: any = promise[0];
483
+ const result: any = (value as any[])[0];
495
484
 
496
485
  // fulfilled
497
486
  if (state == 1) return result;
@@ -28,8 +28,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
28
28
  // force bytestrings to strings
29
29
  if (Porffor.rawType(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
30
30
 
31
- const O: StringObject = s;
32
- return O;
31
+ return s as StringObject;
33
32
  };
34
33
 
35
34
  export const __String_fromCharCode = (...codes: any[]): bytestring|string => {
@@ -17,8 +17,7 @@ export const Symbol = (description: any): Symbol => {
17
17
  }
18
18
 
19
19
  // 4. Return a new Symbol whose [[Description]] is descString.
20
- const sym: Symbol = Porffor.array.fastPush(descStore, descString);
21
- return sym;
20
+ return Porffor.array.fastPush(descStore, descString) as Symbol;
22
21
  };
23
22
 
24
23
  export const __Symbol_prototype_description$get = (_this: Symbol) => {
@@ -55,7 +54,6 @@ export const __Symbol_prototype_toString = (_this: Symbol) => {
55
54
  Porffor.wasm.i32.store8(Porffor.wasm`local.get ${out}` + descLen, 41, 0, 11);
56
55
 
57
56
  out.length = 8 + descLen;
58
-
59
57
  return out;
60
58
  };
61
59
 
@@ -71,13 +71,18 @@ export const __ecma262_ToNumber = (argument: unknown): number => {
71
71
  // https://tc39.es/ecma262/#sec-tonumeric
72
72
  export const __ecma262_ToNumeric = (value: unknown): number => {
73
73
  // 1. Let primValue be ? ToPrimitive(value, number).
74
- // we do not have ToPrimitive
74
+ // only run ToPrimitive if pure object for perf
75
+ let primValue: any = value;
76
+ if (Porffor.rawType(value) == Porffor.TYPES.object && Porffor.wasm`local.get ${value}` != 0)
77
+ primValue = __ecma262_ToPrimitive_Number(value);
75
78
 
76
79
  // 2. If primValue is a BigInt, return primValue.
77
- // todo: do this when we have bigints
80
+ if (Porffor.comptime.flag`hasType.bigint`) {
81
+ if (Porffor.rawType(primValue) == Porffor.TYPES.bigint) return primValue;
82
+ }
78
83
 
79
84
  // 3. Return ? ToNumber(primValue).
80
- return __ecma262_ToNumber(value);
85
+ return __ecma262_ToNumber(primValue);
81
86
  };
82
87
 
83
88
  // 7.1.5 ToIntegerOrInfinity (argument)
@@ -154,8 +159,7 @@ export const __ecma262_ToString = (argument: unknown): any => {
154
159
 
155
160
  // hack: StringObject -> String
156
161
  if (type == Porffor.TYPES.stringobject) {
157
- const remap: string = argument;
158
- return remap;
162
+ return argument as string;
159
163
  }
160
164
 
161
165
  // 9. Assert: argument is an Object.
@@ -171,9 +175,8 @@ export const __ecma262_ToString = (argument: unknown): any => {
171
175
  // https://tc39.es/ecma262/#sec-topropertykey
172
176
  export const __ecma262_ToPropertyKey = (argument: any): any => {
173
177
  // 1. Let key be ? ToPrimitive(argument, string).
174
- let key: any = argument;
175
-
176
178
  // only run ToPrimitive if pure object for perf
179
+ let key: any = argument;
177
180
  if (Porffor.rawType(argument) == Porffor.TYPES.object && Porffor.wasm`local.get ${argument}` != 0)
178
181
  key = __ecma262_ToPrimitive_String(argument);
179
182
 
@@ -131,8 +131,7 @@ export const BuiltinFuncs = function() {
131
131
  number(TYPES.number, Valtype.i32),
132
132
  [ Opcodes.local_get, 1 ],
133
133
  number(TYPES.number, Valtype.i32),
134
- [ Opcodes.call, builtin('__Math_pow') ],
135
- [ Opcodes.drop ],
134
+ [ Opcodes.call, builtin('__Math_pow') ]
136
135
  ]
137
136
  };
138
137
 
@@ -756,6 +755,7 @@ export const BuiltinFuncs = function() {
756
755
  params: [ Valtype.i32, Valtype.i32 ],
757
756
  locals: [],
758
757
  returns: [],
758
+ returnType: TYPES.undefined,
759
759
  wasm: [
760
760
  // dst
761
761
  [ Opcodes.local_get, 1 ],
@@ -74,9 +74,7 @@ export default function({ builtinFuncs }, Prefs) {
74
74
  number(flags, Valtype.i32),
75
75
  number(TYPES.number, Valtype.i32),
76
76
 
77
- [ Opcodes.call, builtin('__Porffor_object_expr_initWithFlags') ],
78
- [ Opcodes.drop ],
79
- [ Opcodes.drop ]
77
+ [ Opcodes.call, builtin('__Porffor_object_expr_initWithFlags') ]
80
78
  );
81
79
  }
82
80