Loading

GUARD

stack

The GUARD function executes a macro, like EVAL, while ensuring sensitive information is protected. This is achieved by clearing part or all the stack, symbols and registers.

GUARD is available since version 2.9.0.

See also

Signatures

Examples

<% SAVE '.context' STORE <% 'should_fail' STORE // Parameter of the functon 'this is secret' 'secret' STORE 'this is also secret' POPR0 'this is another secret' $should_fail <% FAIL %> IFT // May fail leaving the above secret DROP // Drop the secret left on the stack 'result of the macro' %> $.context // Context to restore -1 // Hide all but 1 level. This is because this macro accepts one parameter. GUARD %> 'macro' STORE // Object left on the stack, should be left untouched. 'should stay visible' // Macro is failing, no result should be on the stack <% T @macro %> <% %> <% %> TRY // Check internal symbols and regs are undefined PUSHR0 ISNULL 'Register is protected after a failure' STORE 'secret' DEFINED F == 'Internal variable is protected after a failure' STORE // Macro is not failing F @macro // The result should be on the stack 'result of the macro' == 'Result is on the stack after a success' STORE // Check internal symbols and regs are still undefined PUSHR0 ISNULL 'Register is protected after a success' STORE 'secret' DEFINED F == 'Internal variable is protected after a success' STORE // Because of the -1, GUARD leaves what's on the stack alone. 'should stay visible' == 'Initial object on the stack is left untouched after a failure and a success' STORE // Check the stack is empty DEPTH 0 == 'Nothing is left on the stack after a failure and a success' STORE // Output checks {} SYMBOLS <% DUP LOAD SWAP PUT %> FOREACH