mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-29 23:20:13 +02:00
* Do not try to instantiate webassembly if fetch did not result in status 200.
This commit is contained in:
parent
4eebcb7f5f
commit
63a8c9c137
@ -569,20 +569,32 @@ function TWASIHost.CreateWebAssembly(aPath: string; aImportObject: TJSObject
|
|||||||
Result:=TJSWebAssembly.instantiate(TJSArrayBuffer(res2),aImportObject)._then(@InstantiateOK,@InstantiateFail);
|
Result:=TJSWebAssembly.instantiate(TJSArrayBuffer(res2),aImportObject)._then(@InstantiateOK,@InstantiateFail);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fetchOK(res : jsValue) : JSValue;
|
|
||||||
begin
|
|
||||||
Result:=TJSResponse(Res).arrayBuffer._then(@ArrayOK,Nil);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function DoFail(res : jsValue) : JSValue;
|
function DoFail(res : jsValue) : JSValue;
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
Result:=False;
|
||||||
console.Log('Loading of WebAssembly from '+aPath+' failed '+ValueToMessage(Res));
|
console.Log('Loading of WebAssembly from URL "'+aPath+'" failed: '+ValueToMessage(Res));
|
||||||
DoLoadFail(res);
|
DoLoadFail(res);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function fetchOK(res : jsValue) : JSValue;
|
||||||
|
|
||||||
|
var
|
||||||
|
Resp : TJSResponse absolute res;
|
||||||
|
err : TJSError;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (Resp.status div 100)<>2 then
|
||||||
|
begin
|
||||||
|
DoLoadFail(res);
|
||||||
|
Raise TJSError.new('Loading of WebAssembly from URL "'+aPath+'" failed: status: '+IntToStr(Resp.status)+' '+Resp.statusText);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result:=TJSResponse(Res).arrayBuffer._then(@ArrayOK,Nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=fetch(aPath)._then(@fetchOK,@DoFail).Catch(@DoFail);
|
Result:=fetch(aPath)._then(@fetchOK,@DoFail);//.Catch(@DoFail);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWASIHost.CreateWasiEnvironment: TPas2JSWASIEnvironment;
|
function TWASIHost.CreateWasiEnvironment: TPas2JSWASIEnvironment;
|
||||||
@ -679,6 +691,8 @@ Var
|
|||||||
Result:=True;
|
Result:=True;
|
||||||
Console.Log('Failed to create webassembly. Reason:');
|
Console.Log('Failed to create webassembly. Reason:');
|
||||||
Console.Debug(aValue);
|
Console.Debug(aValue);
|
||||||
|
if isObject(aValue) then
|
||||||
|
Raise TJSError(aValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -686,7 +700,7 @@ begin
|
|||||||
// Clear current descriptor.
|
// Clear current descriptor.
|
||||||
FPreparedStartDescriptor:=Default(TWebAssemblyStartDescriptor);
|
FPreparedStartDescriptor:=Default(TWebAssemblyStartDescriptor);
|
||||||
WASD:=InitStartDescriptor(GetMemory,GetTable,Nil);
|
WASD:=InitStartDescriptor(GetMemory,GetTable,Nil);
|
||||||
Result:=CreateWebAssembly(aPath,WASD.Imports)._then(@initEnv,@DoFail).catch(@DoFail);
|
Result:=CreateWebAssembly(aPath,WASD.Imports)._then(@initEnv,@DoFail);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWASIHost.RunPreparedDescriptor;
|
procedure TWASIHost.RunPreparedDescriptor;
|
||||||
|
Loading…
Reference in New Issue
Block a user