porffor 0.39.1 โ 0.39.3
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/__internal_object.ts +1 -1
- package/compiler/builtins/array.ts +37 -3
- package/compiler/builtins/error.js +3 -1
- package/compiler/builtins/promise.ts +14 -9
- package/compiler/builtins/reflect.ts +1 -19
- package/compiler/builtins/string.ts +1 -1
- package/compiler/builtins_precompiled.js +155 -95
- package/compiler/codegen.js +102 -50
- package/compiler/precompile.js +10 -7
- package/compiler/prototype.js +1 -1
- package/compiler/types.js +2 -0
- package/compiler/wrap.js +5 -3
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/runner/repl.js +1 -1
@@ -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
|
-
|
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
|
};
|
@@ -94,7 +94,7 @@ export const __ecma262_RejectPromise = (promise: any[], reason: any): void => {
|
|
94
94
|
|
95
95
|
export const __Porffor_promise_noop = () => {};
|
96
96
|
|
97
|
-
export const __Porffor_promise_resolve = (
|
97
|
+
export const __Porffor_promise_resolve = (value: any, promise: any): any => {
|
98
98
|
// todo: if value is own promise, reject with typeerror
|
99
99
|
|
100
100
|
if (__ecma262_IsPromise(value)) {
|
@@ -106,7 +106,7 @@ export const __Porffor_promise_resolve = (promise: any, value: any): any => {
|
|
106
106
|
return undefined;
|
107
107
|
};
|
108
108
|
|
109
|
-
export const __Porffor_promise_reject = (
|
109
|
+
export const __Porffor_promise_reject = (reason: any, promise: any): any => {
|
110
110
|
if (__ecma262_IsPromise(reason)) {
|
111
111
|
// todo
|
112
112
|
} else {
|
@@ -181,8 +181,8 @@ export const __Porffor_promise_runJobs = () => {
|
|
181
181
|
|
182
182
|
// hack: cannot share scope so use a global
|
183
183
|
let activePromise: any;
|
184
|
-
export const __Porffor_promise_resolveActive = (value: any) => __Porffor_promise_resolve(
|
185
|
-
export const __Porffor_promise_rejectActive = (reason: any) => __Porffor_promise_reject(
|
184
|
+
export const __Porffor_promise_resolveActive = (value: any) => __Porffor_promise_resolve(value, activePromise);
|
185
|
+
export const __Porffor_promise_rejectActive = (reason: any) => __Porffor_promise_reject(reason, activePromise);
|
186
186
|
|
187
187
|
export const Promise = function (executor: any): void {
|
188
188
|
if (!new.target) throw new TypeError("Constructor Promise requires 'new'");
|
@@ -191,7 +191,13 @@ export const Promise = function (executor: any): void {
|
|
191
191
|
const obj: any[] = __Porffor_promise_create();
|
192
192
|
|
193
193
|
activePromise = obj;
|
194
|
-
|
194
|
+
|
195
|
+
try {
|
196
|
+
executor(__Porffor_promise_resolveActive, __Porffor_promise_rejectActive);
|
197
|
+
} catch (e) {
|
198
|
+
// executor threw, reject promise
|
199
|
+
__ecma262_RejectPromise(obj, e);
|
200
|
+
}
|
195
201
|
|
196
202
|
const pro: Promise = obj;
|
197
203
|
return pro;
|
@@ -200,7 +206,7 @@ export const Promise = function (executor: any): void {
|
|
200
206
|
export const __Promise_resolve = (value: any): Promise => {
|
201
207
|
const obj: any[] = __Porffor_promise_create();
|
202
208
|
|
203
|
-
__Porffor_promise_resolve(
|
209
|
+
__Porffor_promise_resolve(value, obj);
|
204
210
|
|
205
211
|
const pro: Promise = obj;
|
206
212
|
return pro;
|
@@ -209,7 +215,7 @@ export const __Promise_resolve = (value: any): Promise => {
|
|
209
215
|
export const __Promise_reject = (reason: any): Promise => {
|
210
216
|
const obj: any[] = __Porffor_promise_create();
|
211
217
|
|
212
|
-
__Porffor_promise_reject(
|
218
|
+
__Porffor_promise_reject(reason, obj);
|
213
219
|
|
214
220
|
const pro: Promise = obj;
|
215
221
|
return pro;
|
@@ -431,6 +437,5 @@ export const __Porffor_promise_await = (value: any) => {
|
|
431
437
|
if (state == 1) return result;
|
432
438
|
|
433
439
|
// rejected
|
434
|
-
|
435
|
-
throw Error('Uncaught await promise rejection');
|
440
|
+
throw result;
|
436
441
|
};
|
@@ -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;
|