diff --git a/lib/helper.js b/lib/helper.js index 192707b1f9e..18ef2b7b27d 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -28,7 +28,17 @@ class Helper { console.assert(args.length === 0, 'Cannot evaluate a string with arguments'); return fun; } - return `(${fun})(${args.map(x => JSON.stringify(x)).join(',')})`; + return `(${fun})(${args.map(serializeArgument).join(',')})`; + + /** + * @param {*} arg + * @return {string} + */ + function serializeArgument(arg) { + if (Object.is(arg, undefined)) + return 'undefined'; + return JSON.stringify(arg); + } } /** diff --git a/test/test.js b/test/test.js index 888592cc044..01634278f2d 100644 --- a/test/test.js +++ b/test/test.js @@ -246,6 +246,10 @@ describe('Page', function() { const result = await page.evaluate(() => -Infinity); expect(Object.is(result, -Infinity)).toBe(true); })); + it('should accept "undefined" as one of multiple parameters', SX(async function() { + const result = await page.evaluate((a, b) => Object.is(a, undefined) && Object.is(b, 'foo'), undefined, 'foo'); + expect(result).toBe(true); + })); it('should not fail for window object', SX(async function() { const result = await page.evaluate(() => window); expect(result).toBe('Window');