11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst vm = require('vm'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cifunction a() { 71cb0ef41Sopenharmony_ci try { 81cb0ef41Sopenharmony_ci return a(); 91cb0ef41Sopenharmony_ci } catch { 101cb0ef41Sopenharmony_ci // Throw an exception as near to the recursion-based RangeError as possible. 111cb0ef41Sopenharmony_ci return vm.runInThisContext('() => 42')(); 121cb0ef41Sopenharmony_ci } 131cb0ef41Sopenharmony_ci} 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciassert.strictEqual(a(), 42); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cifunction b() { 181cb0ef41Sopenharmony_ci try { 191cb0ef41Sopenharmony_ci return b(); 201cb0ef41Sopenharmony_ci } catch { 211cb0ef41Sopenharmony_ci // This writes a lot of noise to stderr, but it still works. 221cb0ef41Sopenharmony_ci return vm.runInNewContext('() => 42')(); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci} 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciassert.strictEqual(b(), 42); 27