porffor 0.48.4 → 0.48.5

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.
@@ -91,8 +91,6 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
91
91
  f.asmIndex = f.index - importDelta;
92
92
  }
93
93
 
94
- time('treeshake import funcs');
95
-
96
94
  if (Prefs.optLog) log('assemble', `treeshake: using ${importFuncs.length}/${importedFuncs.length} imports`);
97
95
 
98
96
  const importSection = importFuncs.length === 0 ? [] : createSection(
@@ -380,13 +378,11 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
380
378
  dataSection.unshift(Section.data, ...unsignedLEB128(dataSection.length));
381
379
  }
382
380
 
383
- time('data section');
384
-
385
381
  const dataCountSection = data.length === 0 ? [] : createSection(
386
382
  Section.data_count,
387
383
  unsignedLEB128(data.length)
388
384
  );
389
- time('datacount section');
385
+ time('data section');
390
386
 
391
387
  return Uint8Array.from([
392
388
  ...Magic,
@@ -6,17 +6,14 @@ export const __Porffor_object_underlying = (obj: any): any => {
6
6
 
7
7
  if (Porffor.fastAnd(
8
8
  t >= Porffor.TYPES.error,
9
- t <= Porffor.TYPES.__porffor_todoerror
9
+ t <= Porffor.TYPES.todoerror
10
10
  )) {
11
11
  const remap: object = obj;
12
12
  return remap;
13
13
  }
14
14
 
15
15
  if (Porffor.fastAnd(t > 0x05, t != Porffor.TYPES.undefined)) {
16
- // this causes memory corruption things in some situations in test262?
17
- // let idx: i32 = Porffor.array.fastIndexOf(underlyingKeys, obj);
18
-
19
- let idx: i32 = underlyingKeys.indexOf(obj);
16
+ let idx: i32 = Porffor.array.fastIndexOf(underlyingKeys, obj);
20
17
  if (idx == -1) {
21
18
  const underlying: object = {};
22
19
 
@@ -892,10 +892,10 @@ export const __Porffor_array_fastPush = (arr: any[], el: any): i32 => {
892
892
  return len;
893
893
  };
894
894
 
895
- export const __Porffor_array_fastIndexOf = (arr: any[], el: any): i32 => {
895
+ export const __Porffor_array_fastIndexOf = (arr: any[], el: number): i32 => {
896
896
  const len: i32 = arr.length;
897
897
  for (let i: i32 = 0; i < len; i++) {
898
- if (arr[i] === el) return i;
898
+ if (arr[i] == el) return i;
899
899
  }
900
900
 
901
901
  return -1;
@@ -1744,8 +1744,7 @@ export const __ecma262_DateString = (tv: number): bytestring => {
1744
1744
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-timezonestring
1745
1745
  export const __ecma262_TimeZoneString = (tv: number) => {
1746
1746
  // todo: time zone support
1747
- let out: bytestring = '+0000 (UTC)';
1748
- return out;
1747
+ return '+0000 (UTC)';
1749
1748
  };
1750
1749
 
1751
1750
  // 21.4.4.41.4 ToDateString (tv)
@@ -2,15 +2,12 @@ export default () => {
2
2
  let out = '';
3
3
 
4
4
  const error = name => out += `export const ${name} = function (message: any) {
5
- const _empty: bytestring = '';
6
- if (message === undefined) message = _empty;
7
- else message = ecma262.ToString(message);
5
+ if (message === undefined) message = '';
6
+ // else message = ecma262.ToString(message);
8
7
 
9
- const obj: object = Porffor.allocate();
8
+ const obj: object = Porffor.allocateBytes(128);
10
9
 
11
- const _name: bytestring = '${name.split('_').pop()}';
12
-
13
- obj.name = _name;
10
+ obj.name = '${name}';
14
11
  obj.message = message;
15
12
  obj.constructor = ${name};
16
13
 
@@ -18,7 +15,7 @@ export default () => {
18
15
  return out;
19
16
  };
20
17
 
21
- export const __${name.startsWith('__') ? name.slice(2) : name}_prototype_toString = (_this: ${name}) => {
18
+ export const __${name}_prototype_toString = (_this: ${name}) => {
22
19
  const obj: object = _this;
23
20
 
24
21
  const message: any = obj.message;
@@ -26,8 +23,7 @@ export const __${name.startsWith('__') ? name.slice(2) : name}_prototype_toStrin
26
23
  return obj.name;
27
24
  }
28
25
 
29
- const bridge: bytestring = ': ';
30
- return obj.name + bridge + message;
26
+ return obj.name + ': ' + message;
31
27
  };`;
32
28
 
33
29
  error('Error');
@@ -40,7 +36,7 @@ export const __${name.startsWith('__') ? name.slice(2) : name}_prototype_toStrin
40
36
  error('URIError');
41
37
 
42
38
  error('Test262Error');
43
- error('__Porffor_TodoError');
39
+ error('TodoError');
44
40
 
45
41
  out += `\nexport const __Test262Error_thrower = message => { throw new Test262Error(message); };`;
46
42
 
@@ -3,13 +3,9 @@ import type {} from './porffor.d.ts';
3
3
  export const __Function_prototype_toString = (_this: Function) => {
4
4
  const out: bytestring = Porffor.allocate();
5
5
 
6
- const prefix: bytestring = 'function ';
7
- Porffor.bytestring.appendStr(out, prefix);
8
-
6
+ Porffor.bytestring.appendStr(out, 'function ');
9
7
  Porffor.bytestring.appendStr(out, _this.name);
10
-
11
- const postfix: bytestring = '() { [native code] }';
12
- Porffor.bytestring.appendStr(out, postfix);
8
+ Porffor.bytestring.appendStr(out, '() { [native code] }');
13
9
  return out;
14
10
  };
15
11
 
@@ -2,19 +2,16 @@ import type {} from './porffor.d.ts';
2
2
 
3
3
  export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestring|undefined): bytestring|undefined => {
4
4
  // somewhat modelled after 25.5.2.2 SerializeJSONProperty: https://tc39.es/ecma262/#sec-serializejsonproperty
5
- let out: bytestring = Porffor.allocate();
6
-
7
- const nullString: bytestring = 'null';
8
-
9
- if (value === null) return nullString;
10
- if (value === true) return out = 'true';
11
- if (value === false) return out = 'false';
5
+ if (value === null) return 'null';
6
+ if (value === true) return 'true';
7
+ if (value === false) return 'false';
12
8
 
13
9
  const t: i32 = Porffor.rawType(value);
14
10
  if (Porffor.fastOr(
15
11
  (t | 0b10000000) == Porffor.TYPES.bytestring,
16
12
  t == Porffor.TYPES.stringobject
17
13
  )) { // string
14
+ const out: bytestring = Porffor.allocate();
18
15
  Porffor.bytestring.appendChar(out, 34); // start "
19
16
 
20
17
  const len: i32 = value.length;
@@ -77,11 +74,12 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
77
74
  t == Porffor.TYPES.number,
78
75
  t == Porffor.TYPES.numberobject
79
76
  )) { // number
80
- if (Number.isFinite(value)) return out = __Number_prototype_toString(value, 10);
81
- return nullString;
77
+ if (Number.isFinite(value)) return __Number_prototype_toString(value, 10);
78
+ return 'null';
82
79
  }
83
80
 
84
81
  if (t == Porffor.TYPES.array) {
82
+ const out: bytestring = Porffor.allocate();
85
83
  Porffor.bytestring.appendChar(out, 91); // [
86
84
 
87
85
  const hasSpace: boolean = space !== undefined;
@@ -94,7 +92,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
94
92
  for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space);
95
93
  }
96
94
 
97
- Porffor.bytestring.appendStr(out, __Porffor_json_serialize(x, depth, space) ?? nullString);
95
+ Porffor.bytestring.appendStr(out, __Porffor_json_serialize(x, depth, space) ?? 'null');
98
96
 
99
97
  Porffor.bytestring.appendChar(out, 44); // ,
100
98
  }
@@ -120,7 +118,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
120
118
 
121
119
  if (t > 0x06) {
122
120
  // non-function object
123
- // hack: just return empty object for now
121
+ const out: bytestring = Porffor.allocate();
124
122
  Porffor.bytestring.appendChar(out, 123); // {
125
123
 
126
124
  const hasSpace: boolean = space !== undefined;
@@ -188,10 +186,9 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
188
186
  if (space < 1) {
189
187
  space = undefined;
190
188
  } else {
191
- const spaceStr: bytestring = '';
192
- spaceStr.length = 0;
193
-
189
+ const spaceStr: bytestring = Porffor.allocate();
194
190
  for (let i: i32 = 0; i < space; i++) Porffor.bytestring.appendChar(spaceStr, 32);
191
+
195
192
  space = spaceStr;
196
193
  }
197
194
  } else if (Porffor.fastOr(
@@ -520,9 +520,7 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
520
520
  if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
521
521
 
522
522
  if (Porffor.rawType(target) == Porffor.TYPES.array) {
523
- const tmp1: bytestring = 'length';
524
- const tmp2: bytestring = 'value';
525
- if (prop === tmp1 && __Object_hasOwn(desc, tmp2)) {
523
+ if (prop === 'length' && __Object_hasOwn(desc, 'value')) {
526
524
  const v: any = desc.value;
527
525
  const n: number = ecma262.ToNumber(v);
528
526
  if (Porffor.fastOr(
@@ -566,33 +564,20 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
566
564
  accessor = true;
567
565
  } else if (existingDesc && value === undefined && writable === undefined) {
568
566
  // all undefined, check if past accessor
569
- const _get: bytestring = 'get';
570
- const _set: bytestring = 'set';
571
- if (_get in existingDesc || _set in existingDesc) accessor = true;
567
+ if ('get' in existingDesc || 'set' in existingDesc) accessor = true;
572
568
  }
573
569
 
574
570
  if (existingDesc) {
575
- let inKey: bytestring = '';
576
-
577
571
  // probably slow due to excessive in's but needs to have them to be spec compliant handling explicit undefined vs non-existent
578
- inKey = 'configurable';
579
- if (configurable == null && !(inKey in desc)) configurable = existingDesc.configurable;
580
-
581
- inKey = 'enumerable';
582
- if (enumerable == null && !(inKey in desc)) enumerable = existingDesc.enumerable;
572
+ if (configurable == null && !('configurable' in desc)) configurable = existingDesc.configurable;
573
+ if (enumerable == null && !('enumerable' in desc)) enumerable = existingDesc.enumerable;
583
574
 
584
575
  if (accessor) {
585
- inKey = 'get';
586
- if (get == null && !(inKey in desc)) get = existingDesc.get;
587
-
588
- inKey = 'set';
589
- if (set == null && !(inKey in desc)) set = existingDesc.set;
576
+ if (get == null && !('get' in desc)) get = existingDesc.get;
577
+ if (set == null && !('set' in desc)) set = existingDesc.set;
590
578
  } else {
591
- inKey = 'value';
592
- if (value == null && !(inKey in desc)) value = existingDesc.value;
593
-
594
- inKey = 'writable';
595
- if (writable == null && !(inKey in desc)) writable = existingDesc.writable;
579
+ if (value == null && !('value' in desc)) value = existingDesc.value;
580
+ if (writable == null && !('writable' in desc)) writable = existingDesc.writable;
596
581
  }
597
582
  }
598
583
 
@@ -688,8 +673,7 @@ export const __Object_prototype_toString = (_this: any) => {
688
673
  let ovr: any = obj.toString;
689
674
  if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_toString) return ovr.call(_this);
690
675
 
691
- const key: bytestring = 'toString';
692
- const entryPtr: i32 = Porffor.object.lookup(obj, key);
676
+ const entryPtr: i32 = Porffor.object.lookup(obj, 'toString');
693
677
  if (entryPtr != -1) {
694
678
  ovr = Porffor.object.readValue(entryPtr);
695
679
  if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
@@ -736,8 +720,7 @@ export const __Object_prototype_valueOf = (_this: any) => {
736
720
  let ovr: any = obj.valueOf;
737
721
  if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_valueOf) return ovr.call(_this);
738
722
 
739
- const key: bytestring = 'valueOf';
740
- const entryPtr: i32 = Porffor.object.lookup(obj, key);
723
+ const entryPtr: i32 = Porffor.object.lookup(obj, 'valueOf');
741
724
  if (entryPtr != -1) {
742
725
  ovr = Porffor.object.readValue(entryPtr);
743
726
  if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
@@ -393,27 +393,18 @@ export const __Promise_allSettled = (promises: any): Promise => {
393
393
  if (__ecma262_IsPromise(x)) {
394
394
  x.then(r => {
395
395
  const o = {};
396
- let status: bytestring = '';
397
- status = 'fulfilled';
398
- o.status = status;
399
-
396
+ o.status = 'fulfilled';
400
397
  o.value = r;
401
398
  if (Porffor.array.fastPush(_allOut, o) == _allLen) _allRes(_allOut);
402
399
  }, r => {
403
400
  const o = {};
404
- let status: bytestring = '';
405
- status = 'rejected';
406
- o.status = status;
407
-
401
+ o.status = 'rejected';
408
402
  o.reason = r;
409
403
  if (Porffor.array.fastPush(_allOut, o) == _allLen) _allRes(_allOut);
410
404
  });
411
405
  } else {
412
406
  const o = {};
413
- let status: bytestring = '';
414
- status = 'fulfilled';
415
- o.status = status;
416
-
407
+ o.status = 'fulfilled';
417
408
  o.value = x;
418
409
  Porffor.array.fastPush(_allOut, o);
419
410
  }
@@ -483,11 +474,7 @@ export const __Promise_race = (promises: any): Promise => {
483
474
  };
484
475
 
485
476
 
486
- export const __Promise_prototype_toString = (_this: any) => {
487
- const str: bytestring = '[object Promise]';
488
- return str;
489
- };
490
-
477
+ export const __Promise_prototype_toString = (_this: any) => '[object Promise]';
491
478
  export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prototype_toString(_this);
492
479
 
493
480
 
@@ -246,9 +246,5 @@ export const __Set_prototype_isDisjointFrom = (_this: Set, other: any) => {
246
246
  return true;
247
247
  };
248
248
 
249
- export const __Set_prototype_toString = (_this: Set) => {
250
- const out: bytestring = '[object Set]';
251
- return out;
252
- };
253
-
249
+ export const __Set_prototype_toString = (_this: Set) => '[object Set]';
254
250
  export const __Set_prototype_toLocaleString = (_this: Set) => __Set_prototype_toString(_this);
@@ -31,9 +31,5 @@ i32.load8_u 0 8
31
31
  return`;
32
32
  };
33
33
 
34
- export const __WeakRef_prototype_toString = (_this: WeakRef) => {
35
- const out: bytestring = '[object WeakRef]';
36
- return out;
37
- };
38
-
34
+ export const __WeakRef_prototype_toString = (_this: WeakRef) => '[object WeakRef]';
39
35
  export const __WeakRef_prototype_toLocaleString = (_this: WeakRef) => __WeakRef_prototype_toString(_this);
@@ -128,9 +128,5 @@ export const __Map_prototype_values = (_this: Map) => {
128
128
  return out;
129
129
  };
130
130
 
131
- export const __Map_prototype_toString = (_this: Map) => {
132
- const str: bytestring = '[object Map]';
133
- return str;
134
- }
135
-
131
+ export const __Map_prototype_toString = (_this: Map) => '[object Map]';
136
132
  export const __Map_prototype_toLocaleString = (_this: Map) => __Map_prototype_toString(_this);
@@ -37,9 +37,5 @@ export const WeakMap = function (iterable: any): WeakMap {
37
37
  return out;
38
38
  };
39
39
 
40
- export const __WeakMap_prototype_toString = (_this: WeakMap) => {
41
- const out: bytestring = '[object WeakMap]';
42
- return out;
43
- };
44
-
40
+ export const __WeakMap_prototype_toString = (_this: WeakMap) => '[object WeakMap]';
45
41
  export const __WeakMap_prototype_toLocaleString = (_this: WeakMap) => __WeakMap_prototype_toString(_this);
@@ -30,9 +30,5 @@ export const WeakSet = function (iterable: any): WeakSet {
30
30
  return out;
31
31
  };
32
32
 
33
- export const __WeakSet_prototype_toString = (_this: WeakSet) => {
34
- const out: bytestring = '[object WeakSet]';
35
- return out;
36
- };
37
-
33
+ export const __WeakSet_prototype_toString = (_this: WeakSet) => '[object WeakSet]';
38
34
  export const __WeakSet_prototype_toLocaleString = (_this: WeakSet) => __WeakSet_prototype_toString(_this);