mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-29 19:51:22 +02:00
* Catch errors when initializing/instantiating Webassembly
This commit is contained in:
parent
8fa57daec4
commit
7f2f5f240a
@ -539,7 +539,7 @@ function TWASIHost.CreateWebAssembly(aPath: string; aImportObject: TJSObject
|
|||||||
Function ArrayOK(res2 : jsValue) : JSValue;
|
Function ArrayOK(res2 : jsValue) : JSValue;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=TJSWebAssembly.instantiate(TJSArrayBuffer(res2),aImportObject);
|
Result:=TJSWebAssembly.instantiate(TJSArrayBuffer(res2),aImportObject);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fetchOK(res : jsValue) : JSValue;
|
function fetchOK(res : jsValue) : JSValue;
|
||||||
@ -547,8 +547,15 @@ function TWASIHost.CreateWebAssembly(aPath: string; aImportObject: TJSObject
|
|||||||
Result:=TJSResponse(Res).arrayBuffer._then(@ArrayOK,Nil)
|
Result:=TJSResponse(Res).arrayBuffer._then(@ArrayOK,Nil)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function DoFail(Res : jsValue) : JSValue;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Console.Log('Failed to fetch webassembly '+aPath+' : ');
|
||||||
|
Console.Debug(res);
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=fetch(aPath)._then(@fetchOK,Nil);
|
Result:=fetch(aPath)._then(@fetchOK);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWASIHost.CreateWasiEnvironment: TPas2JSWASIEnvironment;
|
function TWASIHost.CreateWasiEnvironment: TPas2JSWASIEnvironment;
|
||||||
@ -623,6 +630,12 @@ Var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function DoFail(aValue: JSValue): JSValue;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Console.Log('Failed to create webassembly. Reason:');
|
||||||
|
Console.Debug(aValue);
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
FReadLineCount:=0;
|
FReadLineCount:=0;
|
||||||
@ -635,7 +648,7 @@ begin
|
|||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
FEnv.AddImports(ImportObj);
|
FEnv.AddImports(ImportObj);
|
||||||
CreateWebAssembly(aPath,ImportObj)._then(@initEnv)
|
CreateWebAssembly(aPath,ImportObj)._then(@initEnv,@DoFail)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TImportExtension.getModuleMemoryDataView : TJSDataView;
|
function TImportExtension.getModuleMemoryDataView : TJSDataView;
|
||||||
|
Loading…
Reference in New Issue
Block a user