11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Tests that vm.createScript and runInThisContext correctly handle errors 31cb0ef41Sopenharmony_ci// thrown by option property getters. 41cb0ef41Sopenharmony_ci// See https://github.com/nodejs/node/issues/12369. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst execFile = require('child_process').execFile; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst scripts = []; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci['filename', 'cachedData', 'produceCachedData', 'lineOffset', 'columnOffset'] 131cb0ef41Sopenharmony_ci .forEach((prop) => { 141cb0ef41Sopenharmony_ci scripts.push(`vm.createScript('', { 151cb0ef41Sopenharmony_ci get ${prop} () { 161cb0ef41Sopenharmony_ci throw new Error('xyz'); 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci })`); 191cb0ef41Sopenharmony_ci }); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci['breakOnSigint', 'timeout', 'displayErrors'] 221cb0ef41Sopenharmony_ci .forEach((prop) => { 231cb0ef41Sopenharmony_ci scripts.push(`vm.createScript('').runInThisContext({ 241cb0ef41Sopenharmony_ci get ${prop} () { 251cb0ef41Sopenharmony_ci throw new Error('xyz'); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci })`); 281cb0ef41Sopenharmony_ci }); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciscripts.forEach((script) => { 311cb0ef41Sopenharmony_ci const node = process.execPath; 321cb0ef41Sopenharmony_ci execFile(node, [ '-e', script ], common.mustCall((err, stdout, stderr) => { 331cb0ef41Sopenharmony_ci assert(stderr.includes('Error: xyz'), 'createScript crashes'); 341cb0ef41Sopenharmony_ci })); 351cb0ef41Sopenharmony_ci}); 36