porffor 0.34.6 → 0.34.7
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/crypto.ts +12 -1
- package/compiler/builtins/promise.ts +5 -5
- package/compiler/builtins_precompiled.js +8 -3
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/runner/repl.js +1 -1
- package/r.js +0 -113
@@ -118,4 +118,15 @@ export const __crypto_randomUUID = (): bytestring => {
|
|
118
118
|
|
119
119
|
|
120
120
|
return output;
|
121
|
-
};
|
121
|
+
};
|
122
|
+
|
123
|
+
export const __crypto_getRandomValues = (buffer: Uint8Array): Uint8Array => {
|
124
|
+
let i: i32 = 0;
|
125
|
+
let endPtr: i32 = buffer.length;
|
126
|
+
while (i < endPtr) {
|
127
|
+
buffer[i] = Porffor.randomByte();
|
128
|
+
i++;
|
129
|
+
}
|
130
|
+
|
131
|
+
return buffer;
|
132
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
export const __ecma262_NewPromiseReactionJob = (reaction: any[], argument: any): any[] => {
|
4
|
-
const job: any[] = Porffor.allocateBytes(
|
4
|
+
const job: any[] = Porffor.allocateBytes(32);
|
5
5
|
job[0] = reaction;
|
6
6
|
job[1] = argument;
|
7
7
|
|
@@ -118,7 +118,7 @@ export const __Porffor_promise_reject = (promise: any, reason: any): any => {
|
|
118
118
|
|
119
119
|
export const __Porffor_promise_create = (): any[] => {
|
120
120
|
// Promise [ result, state, fulfillReactions, rejectReactions ]
|
121
|
-
const obj: any[] = Porffor.allocateBytes(
|
121
|
+
const obj: any[] = Porffor.allocateBytes(64);
|
122
122
|
|
123
123
|
// result = undefined
|
124
124
|
obj[0] = undefined;
|
@@ -128,11 +128,11 @@ export const __Porffor_promise_create = (): any[] => {
|
|
128
128
|
obj[1] = 0;
|
129
129
|
|
130
130
|
// fulfillReactions = []
|
131
|
-
const fulfillReactions: any[] = Porffor.allocateBytes(
|
131
|
+
const fulfillReactions: any[] = Porffor.allocateBytes(512);
|
132
132
|
obj[2] = fulfillReactions;
|
133
133
|
|
134
134
|
// rejectReactions = []
|
135
|
-
const rejectReactions: any[] = Porffor.allocateBytes(
|
135
|
+
const rejectReactions: any[] = Porffor.allocateBytes(512);
|
136
136
|
obj[3] = rejectReactions;
|
137
137
|
|
138
138
|
return obj;
|
@@ -140,7 +140,7 @@ export const __Porffor_promise_create = (): any[] => {
|
|
140
140
|
|
141
141
|
export const __Porffor_promise_newReaction = (handler: Function, promise: any, type: i32): any[] => {
|
142
142
|
// enum ReactionType { then = 0, finally = 1 }
|
143
|
-
const out: any[] = Porffor.allocateBytes(
|
143
|
+
const out: any[] = Porffor.allocateBytes(32);
|
144
144
|
out[0] = handler;
|
145
145
|
out[1] = promise;
|
146
146
|
out[2] = type;
|
@@ -743,6 +743,11 @@ params:[],typedParams:1,returns:[127,127],typedReturns:1,
|
|
743
743
|
locals:[127,127,127,127,127,127,127,127,127,127,127],localNames:["bytes","bytesPtr","a","aEndPtr","output","i","j","endPtr","byte","lower","upper"],
|
744
744
|
data:{"bytestring: __crypto_randomUUID/bytes":[16,0,0,0,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46]},
|
745
745
|
};
|
746
|
+
this.__crypto_getRandomValues = {
|
747
|
+
wasm:(_,{builtin})=>[[65,0],[33,2],[32,0],[40,1,0],[33,3],[3,64],[32,2],[32,3],[72],[4,64],[32,0],[33,6],[32,2],[33,7],[32,6],[40,0,4],[32,7],[106],[16,builtin('__Porffor_randomByte')],[34,4],[58,0,4],[32,2],[65,1],[106],[33,2],[12,1],[11],[11],[32,0],[65,216,0],[15]],
|
748
|
+
params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
|
749
|
+
locals:[127,127,127,127,127,127,127],localNames:["buffer","buffer#type","i","endPtr","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#swap"],
|
750
|
+
};
|
746
751
|
this.DataView = {
|
747
752
|
wasm:(_,{builtin,internalThrow})=>[[32,0],[33,10],[32,1],[33,11],[2,124],[32,11],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,10],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,11],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,10],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,10],[68,0],[97],[184],[11,"TYPESWITCH_end"],[252,3],[4,64],...internalThrow(_,'TypeError',`Constructor DataView requires 'new'`),[11],[65,12],[16,builtin('__Porffor_allocateBytes')],[183],[34,12],[33,13],[68,0],[33,14],[32,5],[184],[34,16],[68,21],[97],[32,16],[68,22],[97],[114],[4,64],[32,4],[33,15],[32,4],[33,17],[32,5],[33,18],[65,16],[34,24],[65,8],[54,1,0],[32,24],[65,228,0],[58,0,4],[32,24],[65,229,0],[58,0,5],[32,24],[65,244,0],[58,0,6],[32,24],[65,225,0],[58,0,7],[32,24],[65,227,0],[58,0,8],[32,24],[65,232,0],[58,0,9],[32,24],[65,229,0],[58,0,10],[32,24],[65,228,0],[58,0,11],[32,24],[184],[33,20],[32,5],[33,11],[2,124],[32,11],[65,6],[70],[4,64,"TYPESWITCH|Function"],[32,17],[252,3],[32,5],[32,20],[65,195,1],[16,builtin('__ecma262_ToPropertyKey')],[33,23],[252,3],[32,23],[16,builtin('__Porffor_object_get')],[33,19],[12,1],[11],[32,11],[65,7],[70],[4,64,"TYPESWITCH|Object"],[32,17],[252,3],[32,5],[32,20],[65,195,1],[16,builtin('__ecma262_ToPropertyKey')],[33,23],[252,3],[32,23],[16,builtin('__Porffor_object_get')],[33,19],[12,1],[11],[32,11],[65,21],[70],[4,64,"TYPESWITCH|ArrayBuffer"],[32,17],[32,18],[16,builtin('__ArrayBuffer_prototype_detached$get')],[33,19],[12,1],[11],[32,11],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[16,builtin('__Porffor_allocate')],[34,22],[65,1],[54,0,0],[32,22],[32,20],[252,3],[65,2],[108],[32,17],[252,3],[106],[47,0,4],[59,0,4],[32,22],[184],[65,195,0],[33,19],[12,1],[11],[32,11],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,20],[252,3],[65,9],[108],[32,17],[252,3],[106],[34,21],[43,0,4],[32,21],[45,0,12],[33,19],[12,1],[11],[32,11],[65,216,0],[70],[4,64,"TYPESWITCH|Uint8Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[106],[45,0,4],[184],[65,1],[33,19],[12,1],[11],[32,11],[65,217,0],[70],[4,64,"TYPESWITCH|Int8Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[106],[44,0,4],[183],[65,1],[33,19],[12,1],[11],[32,11],[65,218,0],[70],[4,64,"TYPESWITCH|Uint8ClampedArray"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[106],[45,0,4],[184],[65,1],[33,19],[12,1],[11],[32,11],[65,219,0],[70],[4,64,"TYPESWITCH|Uint16Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[65,2],[108],[106],[47,0,4],[184],[65,1],[33,19],[12,1],[11],[32,11],[65,220,0],[70],[4,64,"TYPESWITCH|Int16Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[65,2],[108],[106],[46,0,4],[183],[65,1],[33,19],[12,1],[11],[32,11],[65,221,0],[70],[4,64,"TYPESWITCH|Uint32Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[65,4],[108],[106],[40,0,4],[184],[65,1],[33,19],[12,1],[11],[32,11],[65,222,0],[70],[4,64,"TYPESWITCH|Int32Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[65,4],[108],[106],[40,0,4],[183],[65,1],[33,19],[12,1],[11],[32,11],[65,223,0],[70],[4,64,"TYPESWITCH|Float32Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[65,4],[108],[106],[42,0,4],[187],[65,1],[33,19],[12,1],[11],[32,11],[65,224,0],[70],[4,64,"TYPESWITCH|Float64Array"],[32,17],[252,3],[40,0,4],[32,20],[252,3],[65,8],[108],[106],[43,0,4],[65,1],[33,19],[12,1],[11],[32,11],[65,128,1],[70],[4,64,"TYPESWITCH|undefined"],...internalThrow(_,'TypeError',`Cannot read property of undefined`),[68,0],[12,1],[11],[32,11],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[16,builtin('__Porffor_allocate')],[34,22],[65,1],[54,0,0],[32,22],[32,20],[252,3],[32,17],[252,3],[106],[45,0,4],[58,0,4],[32,22],[184],[65,195,1],[33,19],[12,1],[11],[68,0],[65,128,1],[33,19],[11,"TYPESWITCH_end"],[33,10],[32,19],[33,11],[2,127],[32,11],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,10],[252,3],[40,1,0],[12,1],[11],[32,11],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,10],[252,3],[40,1,0],[12,1],[11],[32,10],[252,3],[11,"TYPESWITCH_end"],[4,64],...internalThrow(_,'TypeError',`Constructed DataView with a detached ArrayBuffer`),[11],[68,0],[33,25],[32,7],[184],[68,128],[98],[4,64],[32,6],[16,builtin('__Math_trunc')],[33,25],[11],[32,25],[68,0],[99],[4,64],...internalThrow(_,'RangeError',`Invalid DataView byte offset (negative)`),[11],[32,13],[252,2],[32,25],[252,2],[54,0,8],[32,13],[252,2],[32,15],[32,25],[160],[252,2],[54,0,4],[32,9],[184],[68,128],[97],[4,64],[32,15],[252,2],[40,0,0],[183],[34,26],[32,6],[161],[33,14],[5],[32,8],[16,builtin('__Math_trunc')],[33,14],[11],[5],...internalThrow(_,'TypeError',`First argument to DataView constructor must be an ArrayBuffer`),[11],[32,14],[68,0],[99],[4,64],...internalThrow(_,'RangeError',`Invalid DataView length (negative)`),[11],[32,14],[68,4294967295],[100],[4,64],...internalThrow(_,'RangeError',`Invalid DataView length (over 32 bit address space)`),[11],[32,13],[252,2],[32,14],[252,2],[54,0,0],[32,12],[65,23],[15]],
|
748
753
|
params:[124,127,124,127,124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
@@ -1668,7 +1673,7 @@ locals:[124,127,124,127,124,124,124,124,127,124,124,127,127,127,124,127],localNa
|
|
1668
1673
|
hasRestArgument:1,
|
1669
1674
|
};
|
1670
1675
|
this.__ecma262_NewPromiseReactionJob = {
|
1671
|
-
wasm:(_,{builtin})=>[[65,
|
1676
|
+
wasm:(_,{builtin})=>[[65,32],[16,builtin('__Porffor_allocateBytes')],[183],[34,4],[33,7],[68,0],[33,8],[32,7],[252,3],[32,8],[252,3],[65,9],[108],[106],[34,6],[32,0],[34,5],[57,0,4],[32,6],[65,208,0],[58,0,12],[32,4],[33,7],[68,1],[33,8],[32,7],[252,3],[32,8],[252,3],[65,9],[108],[106],[34,6],[32,2],[34,5],[57,0,4],[32,6],[32,3],[58,0,12],[32,4],[65,208,0],[15]],
|
1672
1677
|
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1673
1678
|
locals:[124,124,127,124,124,127],localNames:["reaction","reaction#type","argument","argument#type","job","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#swap"],
|
1674
1679
|
};
|
@@ -1714,12 +1719,12 @@ params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
|
1714
1719
|
locals:[127,124,127],localNames:["promise","promise#type","reason","reason#type","#last_type","#logicinner_tmp","#typeswitch_tmp1"],
|
1715
1720
|
};
|
1716
1721
|
this.__Porffor_promise_create = {
|
1717
|
-
wasm:(_,{builtin})=>[[65,
|
1722
|
+
wasm:(_,{builtin})=>[[65,192,0],[16,builtin('__Porffor_allocateBytes')],[183],[34,0],[33,3],[68,0],[33,4],[32,3],[252,3],[32,4],[252,3],[65,9],[108],[106],[34,2],[68,0],[34,1],[57,0,4],[32,2],[65,128,1],[58,0,12],[32,0],[33,3],[68,1],[33,4],[32,3],[252,3],[32,4],[252,3],[65,9],[108],[106],[34,2],[68,0],[34,1],[57,0,4],[32,2],[65,1],[58,0,12],[65,128,4],[16,builtin('__Porffor_allocateBytes')],[183],[33,6],[32,0],[33,3],[68,2],[33,4],[32,3],[252,3],[32,4],[252,3],[65,9],[108],[106],[34,2],[32,6],[34,1],[57,0,4],[32,2],[65,208,0],[58,0,12],[65,128,4],[16,builtin('__Porffor_allocateBytes')],[183],[33,7],[32,0],[33,3],[68,3],[33,4],[32,3],[252,3],[32,4],[252,3],[65,9],[108],[106],[34,2],[32,7],[34,1],[57,0,4],[32,2],[65,208,0],[58,0,12],[32,0],[65,208,0],[15]],
|
1718
1723
|
params:[],typedParams:1,returns:[124,127],typedReturns:1,
|
1719
1724
|
locals:[124,124,127,124,124,127,124,124],localNames:["obj","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#swap","fulfillReactions","rejectReactions"],
|
1720
1725
|
};
|
1721
1726
|
this.__Porffor_promise_newReaction = {
|
1722
|
-
wasm:(_,{builtin})=>[[65,
|
1727
|
+
wasm:(_,{builtin})=>[[65,32],[16,builtin('__Porffor_allocateBytes')],[183],[34,6],[33,9],[68,0],[33,10],[32,9],[252,3],[32,10],[252,3],[65,9],[108],[106],[34,8],[32,0],[34,7],[57,0,4],[32,8],[65,6],[58,0,12],[32,6],[33,9],[68,1],[33,10],[32,9],[252,3],[32,10],[252,3],[65,9],[108],[106],[34,8],[32,2],[34,7],[57,0,4],[32,8],[32,3],[58,0,12],[32,6],[33,9],[68,2],[33,10],[32,9],[252,3],[32,10],[252,3],[65,9],[108],[106],[34,8],[32,4],[34,7],[57,0,4],[32,8],[65,1],[58,0,12],[32,6],[65,208,0],[15]],
|
1723
1728
|
params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1724
1729
|
locals:[124,124,127,124,124,127],localNames:["handler","handler#type","promise","promise#type","type","type#type","out","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#swap"],
|
1725
1730
|
};
|
package/package.json
CHANGED
package/runner/index.js
CHANGED
package/runner/repl.js
CHANGED
@@ -85,7 +85,7 @@ const run = (source, _context, _filename, callback, run = true) => {
|
|
85
85
|
let toRun = (prev ? (prev + `;\nprint(-0x1337);\n`) : '') + source;
|
86
86
|
|
87
87
|
let shouldPrint = !prev;
|
88
|
-
const { exports, pages } = compile(toRun, [], {}, str => {
|
88
|
+
const { exports, pages } = compile(toRun, process.argv.includes('--module') ? [ 'module' ] : [], {}, str => {
|
89
89
|
if (shouldPrint) process.stdout.write(str);
|
90
90
|
if (str === '-4919') shouldPrint = true;
|
91
91
|
});
|
package/r.js
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
function $DONE(error) {
|
2
|
-
if (error) {
|
3
|
-
Porffor.printStatic('Test262:AsyncTestFailure:Error: unknown');
|
4
|
-
} else {
|
5
|
-
Porffor.printStatic('Test262:AsyncTestComplete');
|
6
|
-
}
|
7
|
-
}
|
8
|
-
function assert(mustBeTrue) {
|
9
|
-
if (mustBeTrue === true) {
|
10
|
-
return;
|
11
|
-
}
|
12
|
-
|
13
|
-
throw new Test262Error('assert failed');
|
14
|
-
}
|
15
|
-
|
16
|
-
assert.throws = function (expectedErrorConstructor, func) {
|
17
|
-
if (typeof func !== 'function') {
|
18
|
-
throw new Test262Error('assert.throws invoked with a non-function value');
|
19
|
-
}
|
20
|
-
|
21
|
-
try {
|
22
|
-
func();
|
23
|
-
} catch {
|
24
|
-
return;
|
25
|
-
}
|
26
|
-
|
27
|
-
throw new Test262Error('assert.throws failed');
|
28
|
-
};
|
29
|
-
|
30
|
-
assert._isSameValue = function (a, b) {
|
31
|
-
if (a === b) {
|
32
|
-
// Handle +/-0 vs. -/+0
|
33
|
-
return a !== 0 || 1 / a === 1 / b;
|
34
|
-
}
|
35
|
-
|
36
|
-
// Handle NaN vs. NaN
|
37
|
-
return a !== a && b !== b;
|
38
|
-
};
|
39
|
-
|
40
|
-
assert.sameValue = function (actual, expected) {
|
41
|
-
if (assert._isSameValue(actual, expected)) {
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
|
45
|
-
throw new Test262Error('assert.sameValue failed');
|
46
|
-
};
|
47
|
-
|
48
|
-
assert.notSameValue = function (actual, unexpected) {
|
49
|
-
if (!assert._isSameValue(actual, unexpected)) {
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
|
53
|
-
throw new Test262Error('assert.notSameValue failed');
|
54
|
-
};
|
55
|
-
// define our $262 here too
|
56
|
-
var $262 = {
|
57
|
-
global: globalThis,
|
58
|
-
gc() { /* noop */ },
|
59
|
-
detachArrayBuffer(buffer) {
|
60
|
-
return Porffor.arraybuffer.detach(buffer);
|
61
|
-
},
|
62
|
-
getGlobal(name) {
|
63
|
-
return globalThis[name];
|
64
|
-
},
|
65
|
-
// todo: setGlobal
|
66
|
-
destroy() { /* noop */ },
|
67
|
-
agent: {}
|
68
|
-
};
|
69
|
-
|
70
|
-
function Test262Error() {}
|
71
|
-
|
72
|
-
Test262Error.thrower = function (message) {
|
73
|
-
throw new Test262Error(message);
|
74
|
-
};
|
75
|
-
|
76
|
-
function $DONOTEVALUATE() {
|
77
|
-
throw 'Test262: This statement should not be evaluated.';
|
78
|
-
}
|
79
|
-
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
80
|
-
// This code is governed by the BSD license found in the LICENSE file.
|
81
|
-
/*---
|
82
|
-
es6id: 25.4.5.3
|
83
|
-
description: PerformPromiseThen on a rejected promise
|
84
|
-
info: |
|
85
|
-
7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
|
86
|
-
resultCapability).
|
87
|
-
|
88
|
-
25.4.5.3.1 PerformPromiseThen
|
89
|
-
|
90
|
-
[...]
|
91
|
-
9. Else if the value of promise's [[PromiseState]] internal slot is
|
92
|
-
"rejected",
|
93
|
-
a. Let reason be the value of promise's [[PromiseResult]] internal slot.
|
94
|
-
b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
|
95
|
-
«rejectReaction, reason»).
|
96
|
-
[...]
|
97
|
-
flags: [async]
|
98
|
-
---*/
|
99
|
-
|
100
|
-
var value = {};
|
101
|
-
var p = new Promise(function(_, reject) {
|
102
|
-
reject(value);
|
103
|
-
});
|
104
|
-
|
105
|
-
p.then(function() {
|
106
|
-
$DONE('The `onFulfilled` handler should not be invoked.');
|
107
|
-
}, function(x) {
|
108
|
-
if (x !== value) {
|
109
|
-
$DONE('The `onRejected` handler should be invoked with the promise result.');
|
110
|
-
return;
|
111
|
-
}
|
112
|
-
$DONE();
|
113
|
-
});
|