From 88a11a3fbd9142b3bcf4566fd8503f6f7e02dfe7 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 13 Jan 2020 15:36:22 -0800 Subject: [PATCH] fix(getProperties): return empty map for non-objects (#470) --- src/firefox/ffExecutionContext.ts | 5 ++++- test/jshandle.spec.js | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/firefox/ffExecutionContext.ts b/src/firefox/ffExecutionContext.ts index 44ec084beb..7821fc91ca 100644 --- a/src/firefox/ffExecutionContext.ts +++ b/src/firefox/ffExecutionContext.ts @@ -113,9 +113,12 @@ export class FFExecutionContext implements js.ExecutionContextDelegate { } async getProperties(handle: js.JSHandle): Promise> { + const objectId = handle._remoteObject.objectId; + if (!objectId) + return new Map(); const response = await this._session.send('Runtime.getObjectProperties', { executionContextId: this._executionContextId, - objectId: handle._remoteObject.objectId, + objectId, }); const result = new Map(); for (const property of response.properties) diff --git a/test/jshandle.spec.js b/test/jshandle.spec.js index 0dcd0d61cc..710967d177 100644 --- a/test/jshandle.spec.js +++ b/test/jshandle.spec.js @@ -115,6 +115,11 @@ module.exports.describe = function({testRunner, expect, CHROMIUM, FFOX, WEBKIT}) expect(foo).toBeTruthy(); expect(await foo.jsonValue()).toBe('bar'); }); + it('should return empty map for non-objects', async({page, server}) => { + const aHandle = await page.evaluateHandle(() => 123); + const properties = await aHandle.getProperties(); + expect(properties.size).toBe(0); + }); it('should return even non-own properties', async({page, server}) => { const aHandle = await page.evaluateHandle(() => { class A {