From f55e99796fe38aa13dc6fa20d6588882169eac6f Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Wed, 24 Jul 2024 18:18:02 +0200 Subject: [PATCH] Prevent harness code not loading when async/generator/asyncGenerator not supported (#4164) * Dont throw when async/generato/asyncGenerator not supported * Apply suggestions from code review --- harness/hidden-constructors.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/harness/hidden-constructors.js b/harness/hidden-constructors.js index 8a517475a2..d73facfbcf 100644 --- a/harness/hidden-constructors.js +++ b/harness/hidden-constructors.js @@ -10,6 +10,18 @@ defines: - GeneratorFunction ---*/ -var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; -var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor; -var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; +var AsyncFunction; +var AsyncGeneratorFunction; +var GeneratorFunction; + +try { + AsyncFunction = Object.getPrototypeOf(new Function('async function () {}')).constructor; +} catch(e) {} + +try { + AsyncGeneratorFunction = Object.getPrototypeOf(new Function('async function* () {}')).constructor; +} catch(e) {} + +try { + GeneratorFunction = Object.getPrototypeOf(new Function('function* () {}')).constructor; +} catch(e) {}