From 6bc159e3c636c39840b85159e6b1888e9c350fc5 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 28 Mar 2024 11:03:02 +0100 Subject: [PATCH] Another small refinement --- .../javascript/packages/core/src/jsdictionary.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/implementations/javascript/packages/core/src/jsdictionary.ts b/implementations/javascript/packages/core/src/jsdictionary.ts index 8b00da7..3aebfa7 100644 --- a/implementations/javascript/packages/core/src/jsdictionary.ts +++ b/implementations/javascript/packages/core/src/jsdictionary.ts @@ -1,5 +1,4 @@ -import { Equivalence, IsMap, _iterMap } from './flex'; -import { Dictionary, DictionaryType } from './dictionary'; +import { Equivalence, _iterMap } from './flex'; export interface JsDictionary { [key: string]: V; @@ -7,9 +6,12 @@ export interface JsDictionary { export namespace JsDictionary { export function isJsDictionary(x: any): x is JsDictionary { - // We accept only literal objects and objects created via `new Object` - // as dictionaries. - return Object.getPrototypeOf(Object.getPrototypeOf(x ?? false)) === null; + // We accept only literal objects and objects created via `new Object` as dictionaries. + // Furthermore, we require no function-valued `__as_preserve__` property to exist. + return typeof x === 'object' + && x !== null + && Object.getPrototypeOf(Object.getPrototypeOf(x)) === null + && typeof x.__as_preserve__ !== 'function'; } export function from(entries: Iterable<[symbol, V]>): JsDictionary {