porffor 0.37.24 → 0.37.26

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,10 +1,16 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const Boolean = function (value: any): boolean {
4
- // hack: allow to be called via new but we do not have prim objects yet
5
- new.target;
3
+ // 20.3.1.1 Boolean (value)
4
+ // https://tc39.es/ecma262/#sec-boolean-constructor-boolean-value
5
+ export const Boolean = function (value: any): boolean|BooleanObject {
6
+ // 1. Let b be ToBoolean(value).
7
+ const b: boolean = !!value;
6
8
 
7
- return !!value;
9
+ // 2. If NewTarget is undefined, return b.
10
+ if (!new.target) return b;
11
+
12
+ const O: BooleanObject = b;
13
+ return O;
8
14
  };
9
15
 
10
16
  // 20.3.3.2 Boolean.prototype.toString ()
@@ -2,7 +2,7 @@ import type {} from './porffor.d.ts';
2
2
 
3
3
  // 21.1.1.1 Number (value)
4
4
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number-constructor-number-value
5
- export const Number = function (value: any): any {
5
+ export const Number = function (value: any): number|NumberObject {
6
6
  let n: number = 0;
7
7
 
8
8
  // 1. If value is present, then
@@ -25,8 +25,8 @@ export const Number = function (value: any): any {
25
25
  // 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] »).
26
26
  // 5. Set O.[[NumberData]] to n.
27
27
  // 6. Return O.
28
- // todo: actual prim objects
29
- return n;
28
+ const O: NumberObject = n;
29
+ return O;
30
30
  };
31
31
 
32
32
  // radix: number|any for rawType check
@@ -9,7 +9,10 @@ export const Object = function (value: any): object {
9
9
  return obj;
10
10
  }
11
11
 
12
- // todo: turn primitive args into objects
12
+ // primitives into primitive objects
13
+ if (Porffor.rawType(value) == Porffor.TYPES.number) return new Number(value);
14
+ if (Porffor.rawType(value) == Porffor.TYPES.boolean) return new Boolean(value);
15
+
13
16
  // return input
14
17
  return value;
15
18
  };
@@ -529,6 +532,24 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any) => {
529
532
  if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
530
533
  if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
531
534
 
535
+ if (Porffor.rawType(target) == Porffor.TYPES.array) {
536
+ const tmp1: bytestring = 'length';
537
+ const tmp2: bytestring = 'value';
538
+ if (prop === tmp1 && __Object_hasOwn(desc, tmp2)) {
539
+ const v: any = desc.value;
540
+ const n: number = ecma262.ToNumber(v);
541
+ if (Porffor.fastOr(
542
+ Number.isNaN(n), // NaN
543
+ Math.floor(n) != n, // non integer
544
+ n < 0, // negative
545
+ n >= 4294967296, // > 2**32 - 1
546
+ )) throw new RangeError('Invalid array length');
547
+
548
+ // set real array length
549
+ Porffor.wasm.i32.store(target, n, 0, 0);
550
+ }
551
+ }
552
+
532
553
  const p: any = ecma262.ToPropertyKey(prop);
533
554
 
534
555
  // base keys
@@ -674,8 +695,12 @@ export const __Object_prototype_toString = (_this: any) => {
674
695
  const t: i32 = Porffor.rawType(_this);
675
696
  if (t == Porffor.TYPES.array) return out = '[object Array]';
676
697
  if (t == Porffor.TYPES.function) return out = '[object Function]';
677
- if (t == Porffor.TYPES.boolean) return out = '[object Boolean]';
678
- if (t == Porffor.TYPES.number) return out = '[object Number]';
698
+ if (Porffor.fastOr(
699
+ t == Porffor.TYPES.boolean,
700
+ t == Porffor.TYPES.booleanobject)) return out = '[object Boolean]';
701
+ if (Porffor.fastOr(
702
+ t == Porffor.TYPES.number,
703
+ t == Porffor.TYPES.numberobject)) return out = '[object Number]';
679
704
  if (Porffor.fastOr(
680
705
  t == Porffor.TYPES.string,
681
706
  t == Porffor.TYPES.bytestring)) return out = '[object String]';
@@ -3,6 +3,9 @@ export type i64 = number;
3
3
  export type f64 = number;
4
4
  export type bytestring = string;
5
5
 
6
+ export type BooleanObject = Boolean;
7
+ export type NumberObject = Boolean;
8
+
6
9
  type PorfforGlobal = {
7
10
  wasm: {
8
11
  (...args: any[]): any;
@@ -140,4 +143,7 @@ declare global {
140
143
  type i64 = number;
141
144
  type f64 = number;
142
145
  type bytestring = string;
146
+
147
+ type BooleanObject = Boolean;
148
+ type NumberObject = Boolean;
143
149
  }