porffor 0.39.1 โ†’ 0.39.2

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.
@@ -6,7 +6,7 @@ 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.urierror
9
+ t <= Porffor.TYPES.__porffor_todoerror
10
10
  )) {
11
11
  const remap: object = obj;
12
12
  return remap;
@@ -557,9 +557,44 @@ export const __Array_prototype_reduceRight = (_this: any[], callbackFn: any, ini
557
557
  return acc;
558
558
  };
559
559
 
560
+ // string less than <
561
+ export const __Porffor_strlt = (a: string|bytestring, b: string|bytestring) => {
562
+ const maxLength: i32 = Math.max(a.length, b.length);
563
+ for (let i: i32 = 0; i < maxLength; i++) {
564
+ const ac: i32 = a.charCodeAt(i);
565
+ const bc: i32 = b.charCodeAt(i);
566
+
567
+ if (ac < bc) return true;
568
+ }
569
+
570
+ return false;
571
+ };
572
+
560
573
  // @porf-typed-array
561
574
  export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
562
- // todo: default callbackFn
575
+ if (callbackFn === undefined) {
576
+ // default callbackFn, convert to strings and sort by char code
577
+ callbackFn = (x: any, y: any) => {
578
+ // 23.1.3.30.2 CompareArrayElements (x, y, comparefn)
579
+ // https://tc39.es/ecma262/#sec-comparearrayelements
580
+ // 5. Let xString be ? ToString(x).
581
+ const xString: any = ecma262.ToString(x);
582
+
583
+ // 6. Let yString be ? ToString(y).
584
+ const yString: any = ecma262.ToString(y);
585
+
586
+ // 7. Let xSmaller be ! IsLessThan(xString, yString, true).
587
+ // 8. If xSmaller is true, return -1๐”ฝ.
588
+ if (__Porffor_strlt(xString, yString)) return -1;
589
+
590
+ // 9. Let ySmaller be ! IsLessThan(yString, xString, true).
591
+ // 10. If ySmaller is true, return 1๐”ฝ.
592
+ if (__Porffor_strlt(yString, xString)) return 1;
593
+
594
+ // 11. Return +0๐”ฝ.
595
+ return 0;
596
+ };
597
+ }
563
598
 
564
599
  // insertion sort, i guess
565
600
  const len: i32 = _this.length;
@@ -584,8 +619,7 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
584
619
  else {
585
620
  // 4. If comparefn is not undefined, then
586
621
  // a. Let v be ? ToNumber(? Call(comparefn, undefined, ยซ x, y ยป)).
587
- // perf: unneeded as we just check >= 0
588
- // v = Number(callbackFn(x, y));
622
+ // perf: ToNumber unneeded as we just check >= 0
589
623
  v = callbackFn(x, y);
590
624
 
591
625
  // b. If v is NaN, return +0๐”ฝ.
@@ -41,8 +41,10 @@ export const __${name.startsWith('__') ? name.slice(2) : name}_prototype_toStrin
41
41
  error('EvalError');
42
42
  error('URIError');
43
43
 
44
- error('__Porffor_TodoError');
45
44
  error('Test262Error');
45
+ error('__Porffor_TodoError');
46
+
47
+ out += `\nexport const __Test262Error_thrower = message => { throw new Test262Error(message); };`;
46
48
 
47
49
  return out;
48
50
  };
@@ -88,6 +88,7 @@ export const __Reflect_ownKeys = (target: any) => {
88
88
 
89
89
  const out: any[] = Porffor.allocate();
90
90
 
91
+ target = __Porffor_object_underlying(target);
91
92
  const t: i32 = Porffor.rawType(target);
92
93
  if (t == Porffor.TYPES.object) {
93
94
  let ptr: i32 = Porffor.wasm`local.get ${target}` + 5;
@@ -132,25 +133,6 @@ local.set ${key}`;
132
133
  }
133
134
 
134
135
  out.length = i;
135
- } else {
136
- if (Porffor.fastOr(
137
- t == Porffor.TYPES.array,
138
- t == Porffor.TYPES.bytestring,
139
- t == Porffor.TYPES.string
140
- )) {
141
- const len: i32 = obj.length;
142
- out.length = len;
143
-
144
- for (let i: i32 = 0; i < len; i++) {
145
- out[i] = __Number_prototype_toString(i);
146
- }
147
- }
148
-
149
- target = __Porffor_object_underlying(target);
150
- if (Porffor.rawType(target) == Porffor.TYPES.object) {
151
- const objKeys: any[] = __Reflect_ownKeys(target);
152
- for (const x of objKeys) Porffor.array.fastPush(out, x);
153
- }
154
136
  }
155
137
 
156
138
  return out;
@@ -1609,4 +1609,4 @@ export const __String_prototype_valueOf = (_this: string) => {
1609
1609
  export const __ByteString_prototype_valueOf = (_this: bytestring) => {
1610
1610
  // 1. Return ? ThisStringValue(this value).
1611
1611
  return _this;
1612
- };
1612
+ };