mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-08 05:48:05 +02:00
* Demo for JOB object factory
This commit is contained in:
parent
de5144b9cf
commit
35f32843ca
95
demo/wasienv/job/Makefile
Normal file
95
demo/wasienv/job/Makefile
Normal file
@ -0,0 +1,95 @@
|
||||
#
|
||||
# This software has been developed by TIXEO.
|
||||
#
|
||||
# Copyright (c) 2004-2024 TIXEO - All Rights Reserved.
|
||||
#
|
||||
# COPYRIGHT:
|
||||
# This file is the property of TIXEO.
|
||||
# It can not be used, modified, copied without the explicit written
|
||||
# authorization from a mandated member of TIXEO.
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# WARRANTY:
|
||||
# This software is provided "AS IS" and any express or implied warranties,
|
||||
# including, but not limited to, the implied warranties of merchantability and
|
||||
# fitness for a particular purpose are disclaimed. In no no event shall copyright
|
||||
# holders be liable for any direct, indirect, incidental, special, exemplary
|
||||
# or consequential damages (including, but not limited to, procurement of
|
||||
# substitute goods or services; loss of use, data, or profits; or business
|
||||
# interruption) however caused and on any theory of liability, whether in
|
||||
# contract, strict liability, or tort (including negligence or otherwise)
|
||||
# arising in any way out of the use of this software, even if advised or the
|
||||
# possibility of such damage.
|
||||
#
|
||||
|
||||
# Default's path for the current free pascal compiler,
|
||||
# but can be overridden by an environment variable
|
||||
FPC_PATH?=/tbt/fpc/fpc-3.3.1
|
||||
#
|
||||
# Allow to specify the webidl2pas to be used.
|
||||
#
|
||||
WEBIDL2PAS?=$(FPC_PATH)/bin/webidl2pas
|
||||
#
|
||||
# Allow to specify pas2js installation dir
|
||||
#
|
||||
PAS2JSDIR?=/home/$(USER)/tixeo/pas2js/
|
||||
#
|
||||
# Allow to specify pas2js installation dir
|
||||
#
|
||||
WEBASSEMBLY_UTILS?=/home/$(USER)/tixeo/webassembly-utils
|
||||
#
|
||||
# Allow to skip generation of job_web.webidl
|
||||
#
|
||||
JOB_WEB_DEPS=job_webalias.txt job_webglobals.txt
|
||||
ifndef SKIP_WEBIDL
|
||||
JOB_WEB_DEPS:=$(JOB_WEB_DEPS) job_web.webidl
|
||||
endif
|
||||
|
||||
all: wasisimpletest.wasm index.html webserver
|
||||
|
||||
index.html: hostsimpletest.js
|
||||
|
||||
hostsimpletest.js: hostsimpletest.lpr job_browser.pp
|
||||
@echo "-------------------------------------------------------"
|
||||
@echo " - Generating hostsimpletest.js"
|
||||
@echo "-------------------------------------------------------"
|
||||
$(FPC_PATH)/bin/pas2js hostsimpletest.lpr -Jc -Jirtl.js
|
||||
|
||||
wasisimpletest.wasm: wasmsimpletest.lpr Wasm.Job.Js.pas Wasm.Job.Shared.pas job.js.pas job.shared.pas
|
||||
@echo "-------------------------------------------------------"
|
||||
@echo " - Generating wasmsimpletest.wasm "
|
||||
@echo "-------------------------------------------------------"
|
||||
$(FPC_PATH)/bin/fpc -tunicodertl-browser -dFPC_DOTTEDUNITS -Twasi -Pwasm32 wasmsimpletest.lpr -owasmsimpletest.wasm
|
||||
|
||||
webserver: index.html wasmsimpletest.wasm index.html bulma.min.css
|
||||
@echo "-------------------------------------------------------"
|
||||
@echo " - Running webserver ..."
|
||||
@echo "-------------------------------------------------------"
|
||||
python3 -m http.server
|
||||
|
||||
check:
|
||||
@echo "-------------------------------------------------------"
|
||||
@echo " - Checking if mandatory tools are installed ... "
|
||||
@echo "-------------------------------------------------------"
|
||||
@which fpc > /dev/null || (echo "Error: fpc compiler is not installed or not available in PATH"; exit 1)
|
||||
@which pas2js > /dev/null || (echo "Error: pas2js is not installed or not available in PATH"; exit 1)
|
||||
@which webidl2pas > /dev/null || (echo "Error: webidl2pas is not installed or not available in PATH"; exit 1)
|
||||
|
||||
clean:
|
||||
@echo "-------------------------------------------------------"
|
||||
@echo " - Cleaning old files "
|
||||
@echo "-------------------------------------------------------"
|
||||
@rm -f *.o
|
||||
@rm -f *.ppu
|
||||
#@rm -f *.js
|
||||
#@rm -f job_web
|
||||
#@rm -f job_web.pas
|
||||
#@rm -f *.wasm
|
||||
#@rm -f job_shared.pp
|
||||
#@rm -f job_browser.pp
|
||||
@rm -f BrowserTixeoDom.js
|
||||
@rm -f WasiTixeoDom.wasm
|
||||
|
||||
.PHONY: all clean check
|
1
demo/wasienv/job/bulma.min.css
vendored
Normal file
1
demo/wasienv/job/bulma.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
demo/wasienv/job/favicon.ico
Normal file
BIN
demo/wasienv/job/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
104
demo/wasienv/job/hostsimpletest.lpi
Normal file
104
demo/wasienv/job/hostsimpletest.lpi
Normal file
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
<Runnable Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="BrowserDomTest1"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<CustomData Count="4">
|
||||
<Item0 Name="MaintainHTML" Value="1"/>
|
||||
<Item1 Name="Pas2JSProject" Value="1"/>
|
||||
<Item2 Name="PasJSLocation" Value="BrowserTixeoDom"/>
|
||||
<Item3 Name="PasJSWebBrowserProject" Value="1"/>
|
||||
</CustomData>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="index.html"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<CustomData Count="1">
|
||||
<Item0 Name="PasJSIsProjectHTMLFile" Value="1"/>
|
||||
</CustomData>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../packages/job/job_browser.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="JOB_Browser"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../packages/job/job_shared.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="JOB_Shared"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target FileExt=".js">
|
||||
<Filename Value="hostsimpletest"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="../../../packages/job"/>
|
||||
<UnitOutputDirectory Value="js"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<AllowLabel Value="False"/>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
<CPPInline Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<TargetOS Value="browser"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
<UseLineInfoUnit Value="False"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-Jeutf-8
|
||||
-Jirtl.js
|
||||
-Jc
|
||||
-Jminclude"/>
|
||||
<CompilerPath Value="$(pas2js)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
87
demo/wasienv/job/hostsimpletest.lpr
Normal file
87
demo/wasienv/job/hostsimpletest.lpr
Normal file
@ -0,0 +1,87 @@
|
||||
program hostsimpletest;
|
||||
|
||||
{$mode objfpc}
|
||||
|
||||
uses
|
||||
BrowserConsole, JS, Types, Classes, SysUtils, Web, WasiEnv, WasiHostApp, JOB_Browser, JOB_Shared;
|
||||
|
||||
Type
|
||||
|
||||
{ TMyObject }
|
||||
|
||||
TMyObject = Class(TObject)
|
||||
private
|
||||
fa: String;
|
||||
public
|
||||
Constructor Create(aValue : string);
|
||||
Property a : String Read fa write fa;
|
||||
end;
|
||||
|
||||
{ TMyApplication }
|
||||
|
||||
TMyApplication = class(TBrowserWASIHostApplication)
|
||||
Private
|
||||
FWADomBridge : TJSObjectBridge;
|
||||
function CreateMyObject(const aName: String; aArgs: TJSValueDynArray): TObject;
|
||||
function CreateBrowserObject(const aName: String; aArgs: TJSValueDynArray): TJSObject;
|
||||
function OnBeforeStart(Sender: TObject;
|
||||
aDescriptor: TWebAssemblyStartDescriptor): Boolean;
|
||||
Public
|
||||
constructor Create(aOwner : TComponent); override;
|
||||
procedure DoRun; override;
|
||||
end;
|
||||
|
||||
{ TMyObject }
|
||||
|
||||
constructor TMyObject.Create(aValue: string);
|
||||
begin
|
||||
fa:=aValue;
|
||||
end;
|
||||
|
||||
{ TMyApplication }
|
||||
|
||||
function TMyApplication.OnBeforeStart(Sender: TObject;
|
||||
aDescriptor: TWebAssemblyStartDescriptor): Boolean;
|
||||
begin
|
||||
FWADomBridge.WasiExports:=aDescriptor.Exported;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TMyApplication.CreateMyObject(const aName: String; aArgs: TJSValueDynArray): TObject;
|
||||
begin
|
||||
Writeln('Host: Creating TMyObject with argument "',aArgs[0],'"');
|
||||
Result:=TMyObject.Create(String(aArgs[0]));
|
||||
end;
|
||||
|
||||
function TMyApplication.CreateBrowserObject(const aName: String; aArgs: TJSValueDynArray): TJSObject;
|
||||
begin
|
||||
Writeln('Host: Creating browserobject with argument "',aArgs[0],'"');
|
||||
Result:=TJSObject.New;
|
||||
Result['Aloha']:=String(aArgs[0]);
|
||||
end;
|
||||
|
||||
constructor TMyApplication.Create(aOwner: TComponent);
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
FWADomBridge:=TJSObjectBridge.Create(WasiEnvironment);
|
||||
RunEntryFunction:='_initialize';
|
||||
FWADomBridge.RegisterObjectFactory('MyObject',@CreateMyObject);
|
||||
FWADomBridge.RegisterJSObjectFactory('MyBrowserObject',@CreateBrowserObject);
|
||||
end;
|
||||
|
||||
procedure TMyApplication.DoRun;
|
||||
begin
|
||||
// Your code here
|
||||
Terminate;
|
||||
StartWebAssembly('wasmsimpletest.wasm',true,@OnBeforeStart);
|
||||
end;
|
||||
|
||||
var
|
||||
Application : TMyApplication;
|
||||
begin
|
||||
ConsoleStyle:=DefaultCRTConsoleStyle;
|
||||
HookConsole;
|
||||
Application:=TMyApplication.Create(nil);
|
||||
Application.Initialize;
|
||||
Application.Run;
|
||||
end.
|
231
demo/wasienv/job/hostsimpletest.lps
Normal file
231
demo/wasienv/job/hostsimpletest.lps
Normal file
@ -0,0 +1,231 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectSession>
|
||||
<Version Value="12"/>
|
||||
<BuildModes Active="Default"/>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<TopLine Value="38"/>
|
||||
<CursorPos X="18" Y="53"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="index.html"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<CustomData Count="1">
|
||||
<Item0 Name="PasJSIsProjectHTMLFile" Value="1"/>
|
||||
</CustomData>
|
||||
<EditorIndex Value="4"/>
|
||||
<CursorPos X="19" Y="16"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
<DefaultSyntaxHighlighter Value="HTML"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../packages/job/job_browser.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="JOB_Browser"/>
|
||||
<UsageCount Value="31"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../packages/job/job_shared.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="JOB_Shared"/>
|
||||
<UsageCount Value="31"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/job/src/job_shared.pp"/>
|
||||
<UnitName Value="JOB_Shared"/>
|
||||
<EditorIndex Value="7"/>
|
||||
<TopLine Value="5"/>
|
||||
<CursorPos X="3" Y="36"/>
|
||||
<UsageCount Value="16"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<UnitName Value="JOB_Browser"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<TopLine Value="976"/>
|
||||
<CursorPos X="20" Y="988"/>
|
||||
<UsageCount Value="16"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/wasi/src/wasihostapp.pas"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<TopLine Value="38"/>
|
||||
<CursorPos X="5" Y="50"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/rtl/src/browserconsole.pas"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<TopLine Value="150"/>
|
||||
<CursorPos Y="178"/>
|
||||
<UsageCount Value="11"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/rtl/src/web.pas"/>
|
||||
<UnitName Value="Web"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="2726"/>
|
||||
<CursorPos X="3" Y="2726"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/rtl/src/js.pas"/>
|
||||
<UnitName Value="JS"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="408"/>
|
||||
<CursorPos X="18" Y="403"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<EditorIndex Value="5"/>
|
||||
<TopLine Value="16"/>
|
||||
<CursorPos X="20" Y="19"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<CursorPos Y="5"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
<JumpHistory HistoryIndex="29">
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="51" Column="57" TopLine="35"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="25" Column="74" TopLine="5"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="26" Column="33"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="56" Column="95" TopLine="42"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="26" Column="84" TopLine="26"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="59" Column="18" TopLine="39"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="60" Column="37" TopLine="39"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="69" Column="63" TopLine="45"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="242" Column="25" TopLine="223"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="91" Column="15" TopLine="73"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="184" Column="16" TopLine="168"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="84" Column="19" TopLine="72"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="506" TopLine="495"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="703" Column="22" TopLine="678"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="772" Column="42" TopLine="764"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="691" Column="22" TopLine="659"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="701" Column="24" TopLine="669"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="796" Column="25" TopLine="764"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="26" Column="9"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="51" Column="8" TopLine="11"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="672" Column="22" TopLine="672"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="3" Column="46"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="55"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/rtl/src/browserconsole.pas"/>
|
||||
<Caret Line="59" Column="3" TopLine="37"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/rtl/src/browserconsole.pas"/>
|
||||
<Caret Line="132" Column="22" TopLine="132"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="../../../FPC/Pas2JS/packages/rtl/src/browserconsole.pas"/>
|
||||
<Caret Line="48" Column="3" TopLine="19"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="82" Column="17" TopLine="45"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="55" Column="50" TopLine="37"/>
|
||||
</Position>
|
||||
</JumpHistory>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes ActiveMode=""/>
|
||||
</RunParams>
|
||||
</ProjectSession>
|
||||
</CONFIG>
|
25
demo/wasienv/job/index.html
Normal file
25
demo/wasienv/job/index.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Wasm Javascript Object Bindings - Test bed</title>
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> <!-- Prevents caching -->
|
||||
<meta http-equiv="Pragma" content="no-cache"> <!-- Legacy HTTP 1.0 backward compatibility -->
|
||||
<meta http-equiv="Expires" content="0"> <!-- Proxies -->
|
||||
<link href="bulma.min.css" rel="stylesheet">
|
||||
<link type="stylesheet" src="bulma.min.css">
|
||||
<script src="hostsimpletest.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<p class="title is-3">Webassembly JSON test bed</p>
|
||||
<p class="subtitle is-5">Console output:</p>
|
||||
<div id="pasjsconsole">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
rtl.showUncaughtExceptions=true;
|
||||
rtl.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
12
demo/wasienv/job/simpletest.lpg
Normal file
12
demo/wasienv/job/simpletest.lpg
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectGroup FileVersion="2">
|
||||
<Targets>
|
||||
<Target FileName="hostsimpletest.lpi">
|
||||
<BuildModes>
|
||||
<Mode Name="Default"/>
|
||||
</BuildModes>
|
||||
</Target>
|
||||
</Targets>
|
||||
</ProjectGroup>
|
||||
</CONFIG>
|
77
demo/wasienv/job/wasmsimpletest.lpi
Normal file
77
demo/wasienv/job/wasmsimpletest.lpi
Normal file
@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="WasiDomTest1"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="wasmsimpletest.wasm" ApplyConventions="False"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="../../../packages/job"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<TargetCPU Value="wasm32"/>
|
||||
<TargetOS Value="wasi"/>
|
||||
<Subtarget Value="unicodertl-browser"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<ExecutableType Value="Library"/>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-dFPC_DOTTEDUNITS"/>
|
||||
<OtherDefines Count="1">
|
||||
<Define0 Value="FPC_DOTTEDUNITS"/>
|
||||
</OtherDefines>
|
||||
<CompilerPath Value="/home/tixeo/bin/ppcrosswasm32"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
243
demo/wasienv/job/wasmsimpletest.lpr
Normal file
243
demo/wasienv/job/wasmsimpletest.lpr
Normal file
@ -0,0 +1,243 @@
|
||||
library wasmsimpletest;
|
||||
|
||||
{$mode objfpc}
|
||||
{$h+}
|
||||
{$codepage UTF8}
|
||||
{$WARN 5028 off : Local $1 "$2" is not used}
|
||||
|
||||
{off $DEFINE UseDucet}
|
||||
|
||||
{off $DEFINE UseDucet}
|
||||
{$IFDEF FPC_DOTTEDUNITS}
|
||||
uses
|
||||
{$IFDEF UseDucet}
|
||||
System.Unicode.Unicodeducet, // first support for unicode ?
|
||||
System.CodePages.unicodedata, // second support for unicode
|
||||
System.FPWideString, // support for WideString
|
||||
{$ENDIF}
|
||||
System.Math, // math support
|
||||
System.SysUtils,
|
||||
System.Variants,
|
||||
Wasm.Job.Shared, // free pascal unit
|
||||
Wasm.Job.Js // free pascal unit
|
||||
;
|
||||
{$ELSE}
|
||||
uses
|
||||
{$IFDEF UseDucet}
|
||||
unicodeducet, // first support for unicode ?
|
||||
unicodedata, // second support for unicode
|
||||
fpwidestring, // support for WideString
|
||||
{$ENDIF}
|
||||
Math, // math support
|
||||
SysUtils,
|
||||
Variants,
|
||||
Job.Shared, // free pascal unit
|
||||
Job.Js, // free pascal unit
|
||||
JOB_Web // generated from the BrowerTixeoDom.lpr + job_shared.pp + job_browser.pp
|
||||
;
|
||||
{$ENDIF}
|
||||
|
||||
type
|
||||
EWasiTest = class(Exception);
|
||||
|
||||
IJSTestObj = Interface (IJSObject) ['{DE03E9A4-3960-4090-A3FA-387B61E8AEA9}']
|
||||
function GetStringAttr : UnicodeString;
|
||||
procedure SetStringAttr(const aValue : UnicodeString);
|
||||
property StringAttr : Unicodestring Read GetStringAttr Write SetStringAttr;
|
||||
end;
|
||||
|
||||
{ TTestObj }
|
||||
// Creates directly a TJSObject
|
||||
TTestObj = Class(TJSObject,IJSTestObj)
|
||||
constructor Create;
|
||||
function GetStringAttr : UnicodeString;
|
||||
procedure SetStringAttr(const aValue : UnicodeString);
|
||||
property StringAttr : Unicodestring Read GetStringAttr Write SetStringAttr;
|
||||
end;
|
||||
|
||||
{ TMyTestObj }
|
||||
|
||||
// Creates a MyObject, using a factory
|
||||
TMyTestObj = Class(TJSObject,IJSTestObj)
|
||||
constructor Create(a: String);
|
||||
class function JSClassName: UnicodeString; override;
|
||||
function GetStringAttr : UnicodeString;
|
||||
procedure SetStringAttr(const aValue : UnicodeString);
|
||||
property StringAttr : Unicodestring Read GetStringAttr Write SetStringAttr;
|
||||
end;
|
||||
|
||||
// Creates a BrowserObject, using a factory
|
||||
|
||||
{ TBrowserObj }
|
||||
|
||||
TBrowserObj = Class(TJSObject,IJSTestObj)
|
||||
constructor Create(a: String);
|
||||
class function JSClassName: UnicodeString; override;
|
||||
function GetStringAttr : UnicodeString;
|
||||
procedure SetStringAttr(const aValue : UnicodeString);
|
||||
property StringAttr : Unicodestring Read GetStringAttr Write SetStringAttr;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
// TWASMAPP CLASS DEFINITION
|
||||
TWasmApp = class
|
||||
private
|
||||
procedure DoTest;
|
||||
procedure DoTest2;
|
||||
procedure DoTest3;
|
||||
procedure Header(const aHeader : String);
|
||||
public
|
||||
procedure Run;
|
||||
procedure Fail(const Msg: string);
|
||||
public
|
||||
|
||||
end;
|
||||
|
||||
{ TBrowserObj }
|
||||
|
||||
constructor TBrowserObj.Create(a: String);
|
||||
begin
|
||||
Inherited JOBCreate([a]);
|
||||
end;
|
||||
|
||||
class function TBrowserObj.JSClassName: UnicodeString;
|
||||
begin
|
||||
Result:='MyBrowserObject';
|
||||
end;
|
||||
|
||||
function TBrowserObj.GetStringAttr: UnicodeString;
|
||||
begin
|
||||
Result:=ReadJSPropertyUnicodeString('Aloha');
|
||||
end;
|
||||
|
||||
procedure TBrowserObj.SetStringAttr(const aValue: UnicodeString);
|
||||
begin
|
||||
WriteJSPropertyUnicodeString('Aloha',aValue);
|
||||
end;
|
||||
|
||||
constructor TMyTestObj.Create(a: String);
|
||||
begin
|
||||
Inherited JobCreate([a]);
|
||||
end;
|
||||
|
||||
Class function TMyTestObj.JSClassName: UnicodeString;
|
||||
begin
|
||||
Result:='MyObject';
|
||||
end;
|
||||
|
||||
function TMyTestObj.GetStringAttr: UnicodeString;
|
||||
begin
|
||||
Result:=ReadJSPropertyUnicodeString('fa');
|
||||
end;
|
||||
|
||||
procedure TMyTestObj.SetStringAttr(const aValue: UnicodeString);
|
||||
begin
|
||||
WriteJSPropertyUnicodeString('fa',aValue);
|
||||
end;
|
||||
|
||||
{ TTestObj }
|
||||
|
||||
constructor TTestObj.Create;
|
||||
|
||||
begin
|
||||
Inherited JOBCreate([]);
|
||||
StringAttr:='Created';
|
||||
end;
|
||||
|
||||
function TTestObj.GetStringAttr: UnicodeString;
|
||||
begin
|
||||
Result:=ReadJSPropertyUnicodeString('Aloha')
|
||||
end;
|
||||
|
||||
procedure TTestObj.SetStringAttr(const aValue: UnicodeString);
|
||||
begin
|
||||
WriteJSPropertyUnicodeString('Aloha',aValue);
|
||||
end;
|
||||
|
||||
{ TApplication }
|
||||
|
||||
procedure TWasmApp.Fail(const Msg: string);
|
||||
begin
|
||||
writeln('TWasmApp.Fail ',Msg);
|
||||
raise EWasiTest.Create(Msg);
|
||||
end;
|
||||
|
||||
procedure TWasmApp.Header(const aHeader : String);
|
||||
|
||||
var
|
||||
Len : Integer;
|
||||
|
||||
begin
|
||||
Len:=50;
|
||||
If Length(aHeader)>Len then
|
||||
Len:=Length(aHeader);
|
||||
Writeln(StringOfChar('-',Len));
|
||||
Writeln(aHeader);
|
||||
Writeln(StringOfChar('-',Len));
|
||||
end;
|
||||
|
||||
procedure TWasmApp.DoTest;
|
||||
|
||||
var
|
||||
T : IJSTestObj;
|
||||
|
||||
begin
|
||||
Header('Test 1');
|
||||
Writeln('Creating TTestObj object');
|
||||
T:=TTestObj.Create;
|
||||
Writeln('Property Aloha: ',T.StringAttr);
|
||||
end;
|
||||
|
||||
procedure TWasmApp.DoTest2;
|
||||
|
||||
var
|
||||
T : IJSTestObj;
|
||||
|
||||
begin
|
||||
Header('Test 2');
|
||||
Writeln('Creating TMyTestObj object');
|
||||
T:=TMyTestObj.Create('solo');
|
||||
Writeln('Property : ',T.StringAttr);
|
||||
end;
|
||||
|
||||
procedure TWasmApp.DoTest3;
|
||||
|
||||
var
|
||||
T : IJSTestObj;
|
||||
|
||||
begin
|
||||
Header('Test 3');
|
||||
Writeln('Creating TBrowserObj object');
|
||||
T:=TBrowserObj.Create('Nice one!');
|
||||
Writeln('Property : ',T.StringAttr);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TWasmApp.Run;
|
||||
|
||||
begin
|
||||
DoTest;
|
||||
DoTest2;
|
||||
DoTest3;
|
||||
end;
|
||||
|
||||
// workaround: fpc wasm does not yet support exporting functions from units
|
||||
function JOBCallback(const Func: TJOBCallback; Data, Code: Pointer; Args: pbyte) : pbyte;
|
||||
begin
|
||||
Result := {$IFDEF FPC_DOTTEDUNITS}Wasm.{$ENDIF}Job.Js.JOBCallback(Func, Data, Code, Args);
|
||||
end;
|
||||
|
||||
exports
|
||||
JOBCallback;
|
||||
|
||||
var
|
||||
Application: TWasmApp;
|
||||
begin
|
||||
{$IFDEF UseDucet}
|
||||
SetActiveCollation('DUCET');
|
||||
{$ENDIF}
|
||||
Application:=TWasmApp.Create;
|
||||
Application.Run;
|
||||
end.
|
208
demo/wasienv/job/wasmsimpletest.lps
Normal file
208
demo/wasienv/job/wasmsimpletest.lps
Normal file
@ -0,0 +1,208 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectSession>
|
||||
<Version Value="12"/>
|
||||
<BuildModes Active="Default"/>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<TopLine Value="179"/>
|
||||
<CursorPos X="21" Y="90"/>
|
||||
<UsageCount Value="54"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job_web.pas"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="2226"/>
|
||||
<CursorPos X="3" Y="2246"/>
|
||||
<UsageCount Value="52"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job_js.pas"/>
|
||||
<UnitName Value="JOB_JS"/>
|
||||
<UsageCount Value="52"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../packages/job/job_shared.pp"/>
|
||||
<UnitName Value="JOB_Shared"/>
|
||||
<UsageCount Value="52"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<UnitName Value="JOB.Js"/>
|
||||
<EditorIndex Value="4"/>
|
||||
<CursorPos X="6" Y="16"/>
|
||||
<UsageCount Value="25"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<UnitName Value="JOB_Browser"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<CursorPos X="38" Y="12"/>
|
||||
<UsageCount Value="25"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/FPC/src/rtl/wasi/wasiapi.pp"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<CursorPos X="5" Y="22"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="Wasm.Job.Js.pas"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<CursorPos X="51" Y="3"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="../../../FPC/FPC/src/rtl/wasi/system.pp"/>
|
||||
<EditorIndex Value="5"/>
|
||||
<TopLine Value="42"/>
|
||||
<CursorPos X="66" Y="62"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<TopLine Value="7"/>
|
||||
<CursorPos X="9" Y="38"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
<OtherDefines Count="1">
|
||||
<Define0 Value="FPC_DOTTEDUNITS"/>
|
||||
</OtherDefines>
|
||||
<JumpHistory HistoryIndex="29">
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="159" Column="5" TopLine="150"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="75" Column="23" TopLine="41"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="115" Column="46" TopLine="86"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="322" Column="21" TopLine="302"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="193" Column="25" TopLine="174"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="62" Column="24" TopLine="54"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="210" Column="32" TopLine="181"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="165" Column="20" TopLine="145"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="wasmsimpletest.lpr"/>
|
||||
<Caret Line="163" TopLine="145"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="2944" TopLine="2930"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="8"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1334" TopLine="1309"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="3348" TopLine="3308"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1083" Column="10" TopLine="1050"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1096" Column="14" TopLine="1063"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1845" Column="12" TopLine="1812"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1849" Column="12" TopLine="1816"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1872" Column="12" TopLine="1839"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="1876" Column="12" TopLine="1843"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="2111" Column="12" TopLine="2078"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="2614" Column="14" TopLine="2582"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="2727" Column="12" TopLine="2695"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="153" Column="43" TopLine="127"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="214" TopLine="181"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="72" TopLine="62"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job_browser.pp"/>
|
||||
<Caret Line="701" Column="5" TopLine="694"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="job.js.pas"/>
|
||||
<Caret Line="3020" Column="74" TopLine="3009"/>
|
||||
</Position>
|
||||
<Position>
|
||||
<Filename Value="hostsimpletest.lpr"/>
|
||||
<Caret Line="16" Column="12" TopLine="7"/>
|
||||
</Position>
|
||||
</JumpHistory>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes ActiveMode=""/>
|
||||
</RunParams>
|
||||
</ProjectSession>
|
||||
</CONFIG>
|
Loading…
Reference in New Issue
Block a user