porffor 0.61.7 → 0.61.9

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.
@@ -64,8 +64,9 @@ export const __Array_from = (arg: any, mapFn: any, thisArg: any = undefined): an
64
64
  return out;
65
65
  }
66
66
 
67
- if (Porffor.type(arg) == Porffor.TYPES.object) {
68
- let len: i32 = ecma262.ToIntegerOrInfinity((arg as object)['length']);
67
+ if (__Porffor_object_isObject(arg)) {
68
+ const obj: object = Porffor.type(arg) == Porffor.TYPES.object ? arg : __Porffor_object_underlying(arg);
69
+ let len: i32 = ecma262.ToIntegerOrInfinity(obj['length']);
69
70
  if (len > 4294967295) throw new RangeError('Invalid array length');
70
71
  if (len < 0) len = 0;
71
72
 
@@ -73,11 +74,11 @@ export const __Array_from = (arg: any, mapFn: any, thisArg: any = undefined): an
73
74
  if (Porffor.type(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
74
75
 
75
76
  for (let i: i32 = 0; i < len; i++) {
76
- out[i] = mapFn.call(thisArg, (arg as object)[i], i);
77
+ out[i] = mapFn.call(thisArg, obj[i], i);
77
78
  }
78
79
  } else {
79
80
  for (let i: i32 = 0; i < len; i++) {
80
- out[i] = (arg as object)[i];
81
+ out[i] = obj[i];
81
82
  }
82
83
  }
83
84
 
@@ -447,7 +448,7 @@ export const __Array_prototype_with = (_this: any[], _index: any, value: any) =>
447
448
  }
448
449
  }
449
450
 
450
- if (index > len) {
451
+ if (index >= len) {
451
452
  throw new RangeError('Invalid index');
452
453
  }
453
454
 
@@ -528,7 +529,7 @@ export const __Array_prototype_reverse = (_this: any[]) => {
528
529
  let end: i32 = len - 1;
529
530
 
530
531
  while (start < end) {
531
- const tmp: i32 = _this[start];
532
+ const tmp: any = _this[start];
532
533
  _this[start++] = _this[end];
533
534
  _this[end--] = tmp;
534
535
  }
@@ -739,6 +740,8 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
739
740
  };
740
741
  }
741
742
 
743
+ if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
744
+
742
745
  // insertion sort, i guess
743
746
  const len: i32 = _this.length;
744
747
  for (let i: i32 = 0; i < len; i++) {
@@ -27,4 +27,28 @@ export const __Function_prototype_apply = (_this: Function, thisArg: any, argsAr
27
27
  export const __Function_prototype_bind = (_this: Function, thisArg: any, argsArray: any) => {
28
28
  // todo: no good way to bind without dynamic functions or closure yet, just return function
29
29
  return _this;
30
+ };
31
+
32
+
33
+ export const __Porffor_generateArgumentsObject = (argc: i32, hasRest: boolean, ...args: any[]) => {
34
+ let obj: object = {}, i: i32 = 0, limit: i32 = args.length;
35
+ if (hasRest) limit--;
36
+ limit = Math.min(argc, limit);
37
+
38
+ while (i < limit) {
39
+ obj[i] = args[i];
40
+ i++;
41
+ }
42
+
43
+ if (hasRest) {
44
+ const rest: any[] = args[limit];
45
+ const len: i32 = rest.length;
46
+ for (let j: i32 = 0; j < len; j++) {
47
+ obj[i] = rest[j];
48
+ i++;
49
+ }
50
+ }
51
+
52
+ obj.length = i;
53
+ return obj;
30
54
  };