UNPKG

twing

Version:

First-class Twig engine for Node.js

46 lines (45 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCheckToStringNodeSynchronously = exports.executeCheckToStringNode = void 0; const traceable_method_1 = require("../helpers/traceable-method"); const executeCheckToStringNode = (node, executionContext) => { const { template, environment, nodeExecutor: execute, sandboxed } = executionContext; const { value: valueNode } = node.children; const { sandboxPolicy } = environment; return execute(valueNode, executionContext) .then((value) => { if (sandboxed) { const assertToStringAllowed = (0, traceable_method_1.getTraceableMethod)((value) => { if ((value !== null) && (typeof value === 'object')) { try { sandboxPolicy.checkMethodAllowed(value, 'toString'); } catch (error) { return Promise.reject(error); } } return Promise.resolve(value); }, valueNode, template.source); return assertToStringAllowed(value); } return value; }); }; exports.executeCheckToStringNode = executeCheckToStringNode; const executeCheckToStringNodeSynchronously = (node, executionContext) => { const { template, environment, nodeExecutor: execute, sandboxed } = executionContext; const { value: valueNode } = node.children; const { sandboxPolicy } = environment; const value = execute(valueNode, executionContext); if (sandboxed) { const assertToStringAllowed = (0, traceable_method_1.getSynchronousTraceableMethod)((value) => { if ((value !== null) && (typeof value === 'object')) { sandboxPolicy.checkMethodAllowed(value, 'toString'); } return value; }, valueNode, template.source); return assertToStringAllowed(value); } return value; }; exports.executeCheckToStringNodeSynchronously = executeCheckToStringNodeSynchronously;