porffor 0.34.2 → 0.34.4
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.
@@ -412,4 +412,26 @@ export const __Promise_prototype_toString = (_this: any) => {
|
|
412
412
|
return str;
|
413
413
|
};
|
414
414
|
|
415
|
-
export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prototype_toString(_this);
|
415
|
+
export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prototype_toString(_this);
|
416
|
+
|
417
|
+
|
418
|
+
export const __Porffor_promise_await = (value: any) => {
|
419
|
+
if (Porffor.rawType(value) != Porffor.TYPES.promise) return value;
|
420
|
+
|
421
|
+
// hack: peek value instead of awaiting
|
422
|
+
const promise: any[] = value;
|
423
|
+
|
424
|
+
const state: i32 = promise[1];
|
425
|
+
|
426
|
+
// pending
|
427
|
+
if (state == 0) return value;
|
428
|
+
|
429
|
+
const result: any = promise[0];
|
430
|
+
|
431
|
+
// fulfilled
|
432
|
+
if (state == 1) return result;
|
433
|
+
|
434
|
+
// rejected
|
435
|
+
// todo: throw result instead of fixed error here
|
436
|
+
throw Error('Uncaught await promise rejection');
|
437
|
+
};
|
@@ -1843,6 +1843,11 @@ wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__Promise_prototype_toString')],
|
|
1843
1843
|
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1844
1844
|
locals:[127],localNames:["_this","_this#type","#last_type"],
|
1845
1845
|
};
|
1846
|
+
this.__Porffor_promise_await = {
|
1847
|
+
wasm:(_,{internalThrow})=>[[32,1],[184],[68,36],[98],[4,64],[32,0],[32,1],[15],[11],[32,0],[34,2],[33,4],[68,1],[34,5],[252,3],[65,9],[108],[32,4],[252,3],[106],[34,6],[43,0,4],[32,6],[45,0,12],[26],[34,3],[68,0],[97],[4,64],[32,0],[32,1],[15],[11],[32,2],[33,4],[68,0],[34,5],[252,3],[65,9],[108],[32,4],[252,3],[106],[34,6],[43,0,4],[32,6],[45,0,12],[33,11],[33,10],[32,3],[68,1],[97],[4,64],[32,10],[32,11],[15],[11],...internalThrow(_,'Error',`Uncaught await promise rejection`),[68,0],[65,128,1],[15]],
|
1848
|
+
params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
1849
|
+
locals:[124,124,124,124,127,127,127,127,124,127],localNames:["value","value#type","promise","state","#member_obj","#member_prop","#loadArray_offset","#last_type","#member_allocd","#swap","result","result#type"],
|
1850
|
+
};
|
1846
1851
|
this.__Reflect_get = {
|
1847
1852
|
wasm:(_,{builtin,internalThrow})=>[[32,0],[252,2],[32,1],[16,builtin('__Porffor_object_isObject')],[33,4],[183],[33,5],[32,4],[33,6],[2,124],[32,6],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,5],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,6],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,5],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,5],[68,0],[97],[184],[11,"TYPESWITCH_end"],[252,3],[4,64],...internalThrow(_,'TypeError',`Target is a non-object`),[11],[32,0],[33,7],[32,2],[33,8],[32,1],[33,6],[2,124],[32,6],[65,6],[70],[4,64,"TYPESWITCH|Function"],[32,7],[252,3],[32,1],[32,8],[32,3],[16,builtin('__ecma262_ToPropertyKey')],[33,11],[252,3],[32,11],[16,builtin('__Porffor_object_get')],[33,4],[12,1],[11],[32,6],[65,7],[70],[4,64,"TYPESWITCH|Object"],[32,7],[252,3],[32,1],[32,8],[32,3],[16,builtin('__ecma262_ToPropertyKey')],[33,11],[252,3],[32,11],[16,builtin('__Porffor_object_get')],[33,4],[12,1],[11],[32,6],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[16,builtin('__Porffor_allocate')],[34,10],[65,1],[54,0,0],[32,10],[32,8],[252,3],[65,2],[108],[32,7],[252,3],[106],[47,0,4],[59,0,4],[32,10],[184],[65,195,0],[33,4],[12,1],[11],[32,6],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,8],[252,3],[65,9],[108],[32,7],[252,3],[106],[34,9],[43,0,4],[32,9],[45,0,12],[33,4],[12,1],[11],[32,6],[65,216,0],[70],[4,64,"TYPESWITCH|Uint8Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[106],[45,0,4],[184],[65,1],[33,4],[12,1],[11],[32,6],[65,217,0],[70],[4,64,"TYPESWITCH|Int8Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[106],[44,0,4],[183],[65,1],[33,4],[12,1],[11],[32,6],[65,218,0],[70],[4,64,"TYPESWITCH|Uint8ClampedArray"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[106],[45,0,4],[184],[65,1],[33,4],[12,1],[11],[32,6],[65,219,0],[70],[4,64,"TYPESWITCH|Uint16Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[65,2],[108],[106],[47,0,4],[184],[65,1],[33,4],[12,1],[11],[32,6],[65,220,0],[70],[4,64,"TYPESWITCH|Int16Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[65,2],[108],[106],[46,0,4],[183],[65,1],[33,4],[12,1],[11],[32,6],[65,221,0],[70],[4,64,"TYPESWITCH|Uint32Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[65,4],[108],[106],[40,0,4],[184],[65,1],[33,4],[12,1],[11],[32,6],[65,222,0],[70],[4,64,"TYPESWITCH|Int32Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[65,4],[108],[106],[40,0,4],[183],[65,1],[33,4],[12,1],[11],[32,6],[65,223,0],[70],[4,64,"TYPESWITCH|Float32Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[65,4],[108],[106],[42,0,4],[187],[65,1],[33,4],[12,1],[11],[32,6],[65,224,0],[70],[4,64,"TYPESWITCH|Float64Array"],[32,7],[252,3],[40,0,4],[32,8],[252,3],[65,8],[108],[106],[43,0,4],[65,1],[33,4],[12,1],[11],[32,6],[65,128,1],[70],[4,64,"TYPESWITCH|undefined"],...internalThrow(_,'TypeError',`Cannot read property of undefined`),[68,0],[12,1],[11],[32,6],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[16,builtin('__Porffor_allocate')],[34,10],[65,1],[54,0,0],[32,10],[32,8],[252,3],[32,7],[252,3],[106],[45,0,4],[58,0,4],[32,10],[184],[65,195,1],[33,4],[12,1],[11],[68,0],[65,128,1],[33,4],[11,"TYPESWITCH_end"],[32,4],[15]],
|
1848
1853
|
params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
|
package/compiler/codegen.js
CHANGED
@@ -174,6 +174,9 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
174
174
|
case 'ClassDeclaration':
|
175
175
|
return cacheAst(decl, generateClass(scope, decl));
|
176
176
|
|
177
|
+
case 'AwaitExpression':
|
178
|
+
return cacheAst(decl, generateAwait(scope, decl));
|
179
|
+
|
177
180
|
case 'ExportNamedDeclaration':
|
178
181
|
if (!decl.declaration) return todo(scope, 'unsupported export declaration');
|
179
182
|
|
@@ -5770,6 +5773,23 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
5770
5773
|
return out;
|
5771
5774
|
};
|
5772
5775
|
|
5776
|
+
const generateAwait = (scope, decl) => {
|
5777
|
+
// hack: implement as ~peeking value `await foo` -> `Porffor.promise.await(foo)`
|
5778
|
+
|
5779
|
+
// todo: warn here if -d?
|
5780
|
+
|
5781
|
+
return generateCall(scope, {
|
5782
|
+
type: 'CallExpression',
|
5783
|
+
callee: {
|
5784
|
+
type: 'Identifier',
|
5785
|
+
name: '__Porffor_promise_await'
|
5786
|
+
},
|
5787
|
+
arguments: [
|
5788
|
+
decl.argument
|
5789
|
+
]
|
5790
|
+
});
|
5791
|
+
};
|
5792
|
+
|
5773
5793
|
const generateClass = (scope, decl) => {
|
5774
5794
|
const expr = decl.type === 'ClassExpression';
|
5775
5795
|
|
package/package.json
CHANGED