Created
January 6, 2018 13:50
-
-
Save tondrej/59683331c0183b17c105a0cdf5df2bd9 to your computer and use it in GitHub Desktop.
chakracore-delphi preview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example usage... | |
procedure TDataModuleMain.DataModuleCreate(Sender: TObject); | |
begin | |
try | |
FRuntime := TChakraCoreRuntime.Create([ccroEnableExperimentalFeatures, ccroDispatchSetExceptionsToDebugger]); | |
FContext := TChakraCoreContext.Create(FRuntime); | |
FContext.Activate; | |
ChakraCoreCheck(JsCreateObject(FConsole)); | |
ChakraCoreCheck(JsAddRef(FConsole, nil)); | |
SetCallback(FConsole, 'assert', ConsoleAssertFunc, Self); | |
SetCallback(FConsole, 'log', ConsoleLogFunc, Self); | |
SetCallback(FConsole, 'info', ConsoleInfoFunc, Self); | |
SetCallback(FConsole, 'warn', ConsoleWarnFunc, Self); | |
SetCallback(FConsole, 'error', ConsoleErrorFunc, Self); | |
SetCallback(FConsole, 'exception', ConsoleErrorFunc, Self); | |
SetProperty(FContext.Global, 'console', FConsole); | |
except | |
FConsole := nil; | |
FreeAndNil(FContext); | |
FreeAndNil(FRuntime); | |
raise; | |
end; | |
end; | |
procedure TDataModuleMain.DataModuleDestroy(Sender: TObject); | |
begin | |
if Assigned(FConsole) then | |
ChakraCoreCheck(JsRelease(FConsole, nil)); | |
FConsole := nil; | |
FreeAndNil(FContext); | |
FreeAndNil(FRuntime); | |
end; | |
procedure TDataModuleMain.Execute(const ScriptFileNames: array of UnicodeString); | |
var | |
I, Cookie: Integer; | |
begin | |
Cookie := 0; | |
for I := Low(ScriptFileNames) to High(ScriptFileNames) do | |
begin | |
RunScript(LoadFile(ScriptFilenames[I]), UnicodeString(ExtractFileName(ScriptFileNames[I])), Cookie); | |
Inc(Cookie); | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment