mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 18:29:13 +02:00
pastojs: add rtl.run() on platform module
This commit is contained in:
parent
fe39f9ca21
commit
c0c6ce5422
@ -2103,7 +2103,7 @@ type
|
|||||||
Function CreateImplementationSection(El: TPasModule; IntfContext: TInterfaceSectionContext): TJSFunctionDeclarationStatement; virtual;
|
Function CreateImplementationSection(El: TPasModule; IntfContext: TInterfaceSectionContext): TJSFunctionDeclarationStatement; virtual;
|
||||||
Procedure CreateInitSection(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
Procedure CreateInitSection(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
||||||
Procedure CreateExportsSection(El: TPasLibrary; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
Procedure CreateExportsSection(El: TPasLibrary; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
||||||
Function AddLibraryRun(El: TPasLibrary; ModuleName: string; Src: TJSSourceElements; AContext: TConvertContext): TJSCallExpression; virtual;
|
Function AddRTLRun(El: TPasModule; ModuleName: string; Src: TJSSourceElements; AContext: TConvertContext): TJSCallExpression; virtual;
|
||||||
Procedure AddHeaderStatement(JS: TJSElement; PosEl: TPasElement; aContext: TConvertContext); virtual;
|
Procedure AddHeaderStatement(JS: TJSElement; PosEl: TPasElement; aContext: TConvertContext); virtual;
|
||||||
Procedure AddImplHeaderStatement(JS: TJSElement; PosEl: TPasElement; aContext: TConvertContext); virtual;
|
Procedure AddImplHeaderStatement(JS: TJSElement; PosEl: TPasElement; aContext: TConvertContext); virtual;
|
||||||
function AddDelayedInits(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext): boolean; virtual;
|
function AddDelayedInits(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext): boolean; virtual;
|
||||||
@ -8431,11 +8431,15 @@ begin
|
|||||||
StoreImplJSLocals(ModScope,IntfContext);
|
StoreImplJSLocals(ModScope,IntfContext);
|
||||||
|
|
||||||
if El is TPasLibrary then
|
if El is TPasLibrary then
|
||||||
begin // library
|
begin
|
||||||
|
// library: rtl.run('library');
|
||||||
Lib:=TPasLibrary(El);
|
Lib:=TPasLibrary(El);
|
||||||
AddLibraryRun(Lib,ModuleName,OuterSrc,AContext);
|
AddRTLRun(Lib,ModuleName,OuterSrc,AContext);
|
||||||
CreateExportsSection(Lib,OuterSrc,AContext);
|
CreateExportsSection(Lib,OuterSrc,AContext);
|
||||||
end;
|
end
|
||||||
|
else if (El is TPasProgram) and (Globals.TargetPlatform in [PlatformNodeJS,PlatformModule]) then
|
||||||
|
// program: rtl.run();
|
||||||
|
AddRTLRun(El,'',OuterSrc,AContext);
|
||||||
|
|
||||||
ok:=true;
|
ok:=true;
|
||||||
finally
|
finally
|
||||||
@ -18224,7 +18228,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPasToJSConverter.AddLibraryRun(El: TPasLibrary; ModuleName: string;
|
function TPasToJSConverter.AddRTLRun(El: TPasModule; ModuleName: string;
|
||||||
Src: TJSSourceElements; AContext: TConvertContext): TJSCallExpression;
|
Src: TJSSourceElements; AContext: TConvertContext): TJSCallExpression;
|
||||||
var
|
var
|
||||||
Call: TJSCallExpression;
|
Call: TJSCallExpression;
|
||||||
@ -18236,6 +18240,7 @@ begin
|
|||||||
AddToSourceElements(Src,Call);
|
AddToSourceElements(Src,Call);
|
||||||
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),'run']);
|
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),'run']);
|
||||||
|
|
||||||
|
if ModuleName<>'' then
|
||||||
// add module name parameter
|
// add module name parameter
|
||||||
Call.AddArg(CreateLiteralString(El,ModuleName));
|
Call.AddArg(CreateLiteralString(El,ModuleName));
|
||||||
|
|
||||||
|
@ -2805,9 +2805,6 @@ begin
|
|||||||
FResources.DoneUnit(aFile.isMainFile);
|
FResources.DoneUnit(aFile.isMainFile);
|
||||||
EmitJavaScript(aFile,aFileWriter);
|
EmitJavaScript(aFile,aFileWriter);
|
||||||
|
|
||||||
if aFile.IsMainFile and (TargetPlatform=PlatformNodeJS) then
|
|
||||||
aFileWriter.WriteFile('rtl.run();'+LineEnding,aFile.UnitFilename);
|
|
||||||
|
|
||||||
if isSingleFile or aFile.isMainFile then
|
if isSingleFile or aFile.isMainFile then
|
||||||
begin
|
begin
|
||||||
if aFile.IsMainFile then
|
if aFile.IsMainFile then
|
||||||
|
@ -137,6 +137,7 @@ type
|
|||||||
TTestCLI_UnitSearch = class(TCustomTestCLI)
|
TTestCLI_UnitSearch = class(TCustomTestCLI)
|
||||||
protected
|
protected
|
||||||
procedure CheckLinklibProgramSrc(Msg,Header: string);
|
procedure CheckLinklibProgramSrc(Msg,Header: string);
|
||||||
|
procedure CheckFullSource(Msg, Filename, ExpectedSrc: string);
|
||||||
published
|
published
|
||||||
procedure TestUS_CreateRelativePath;
|
procedure TestUS_CreateRelativePath;
|
||||||
|
|
||||||
@ -146,6 +147,7 @@ type
|
|||||||
procedure TestUS_Program_FU;
|
procedure TestUS_Program_FU;
|
||||||
procedure TestUS_Program_FU_o;
|
procedure TestUS_Program_FU_o;
|
||||||
procedure TestUS_Program_FE_o;
|
procedure TestUS_Program_FE_o;
|
||||||
|
procedure TestUS_PlatformModule_Program;
|
||||||
|
|
||||||
// include files
|
// include files
|
||||||
procedure TestUS_IncludeSameDir;
|
procedure TestUS_IncludeSameDir;
|
||||||
@ -625,6 +627,8 @@ var
|
|||||||
aFile: TCLIFile;
|
aFile: TCLIFile;
|
||||||
begin
|
begin
|
||||||
aFile:=FindFile('test1.js');
|
aFile:=FindFile('test1.js');
|
||||||
|
if aFile=nil then
|
||||||
|
Fail(Msg+' file not found test1.js');
|
||||||
CheckDiff(Msg,
|
CheckDiff(Msg,
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
#$EF#$BB#$BF+Header,
|
#$EF#$BB#$BF+Header,
|
||||||
@ -640,6 +644,17 @@ begin
|
|||||||
aFile.Source);
|
aFile.Source);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestCLI_UnitSearch.CheckFullSource(Msg, Filename, ExpectedSrc: string
|
||||||
|
);
|
||||||
|
var
|
||||||
|
aFile: TCLIFile;
|
||||||
|
begin
|
||||||
|
aFile:=FindFile(Filename);
|
||||||
|
if aFile=nil then
|
||||||
|
Fail(Msg+' file not found "'+Filename+'"');
|
||||||
|
CheckDiff(Msg,ExpectedSrc,aFile.Source);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestCLI_UnitSearch.TestUS_CreateRelativePath;
|
procedure TTestCLI_UnitSearch.TestUS_CreateRelativePath;
|
||||||
|
|
||||||
procedure DoTest(Filename, BaseDirectory, Expected: string;
|
procedure DoTest(Filename, BaseDirectory, Expected: string;
|
||||||
@ -748,6 +763,25 @@ begin
|
|||||||
AssertNotNull('foo.js not found',FindFile('foo.js'));
|
AssertNotNull('foo.js not found',FindFile('foo.js'));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestCLI_UnitSearch.TestUS_PlatformModule_Program;
|
||||||
|
begin
|
||||||
|
AddUnit('system.pp',[''],['']);
|
||||||
|
AddFile('test1.pas',[
|
||||||
|
'begin',
|
||||||
|
'end.']);
|
||||||
|
Compile(['-Tmodule','-va','test1.pas']);
|
||||||
|
CheckFullSource('TestUS_PlatformModule_Library','test1.js',
|
||||||
|
LinesToStr([
|
||||||
|
#$EF#$BB#$BF+'rtl.module("program",["system"],function () {',
|
||||||
|
' "use strict";',
|
||||||
|
' var $mod = this;',
|
||||||
|
' $mod.$main = function () {',
|
||||||
|
' };',
|
||||||
|
'});',
|
||||||
|
'rtl.run();',
|
||||||
|
'']));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestCLI_UnitSearch.TestUS_IncludeSameDir;
|
procedure TTestCLI_UnitSearch.TestUS_IncludeSameDir;
|
||||||
begin
|
begin
|
||||||
AddUnit('system.pp',[''],['']);
|
AddUnit('system.pp',[''],['']);
|
||||||
|
Loading…
Reference in New Issue
Block a user