porffor 0.37.23 → 0.37.25
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.
- package/compiler/builtins/boolean.ts +10 -4
- package/compiler/builtins/number.ts +3 -3
- package/compiler/builtins/object.ts +10 -3
- package/compiler/builtins/porffor.d.ts +6 -0
- package/compiler/builtins_precompiled.js +117 -115
- package/compiler/codegen.js +105 -44
- package/compiler/types.js +3 -0
- package/compiler/wrap.js +5 -0
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -1,10 +1,16 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
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):
|
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
|
-
|
29
|
-
return
|
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
|
-
//
|
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
|
};
|
@@ -674,8 +677,12 @@ export const __Object_prototype_toString = (_this: any) => {
|
|
674
677
|
const t: i32 = Porffor.rawType(_this);
|
675
678
|
if (t == Porffor.TYPES.array) return out = '[object Array]';
|
676
679
|
if (t == Porffor.TYPES.function) return out = '[object Function]';
|
677
|
-
if (
|
678
|
-
|
680
|
+
if (Porffor.fastOr(
|
681
|
+
t == Porffor.TYPES.boolean,
|
682
|
+
t == Porffor.TYPES.booleanobject)) return out = '[object Boolean]';
|
683
|
+
if (Porffor.fastOr(
|
684
|
+
t == Porffor.TYPES.number,
|
685
|
+
t == Porffor.TYPES.numberobject)) return out = '[object Number]';
|
679
686
|
if (Porffor.fastOr(
|
680
687
|
t == Porffor.TYPES.string,
|
681
688
|
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
|
}
|