This is an automated email from the ASF dual-hosted git repository. raulcd pushed a commit to branch maint-16.x.x in repository https://gitbox.apache.org/repos/asf/arrow.git
commit 0e6f68e34f8dbf023e730fcd28c6a7e162448c31 Author: Mike Bostock <[email protected]> AuthorDate: Tue Apr 16 14:24:39 2024 -0700 GH-40407: [JS] Fix string coercion in MapRowProxyHandler.ownKeys (#40408) --- js/src/row/map.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/src/row/map.ts b/js/src/row/map.ts index d0ccb872ec..9f826f083b 100644 --- a/js/src/row/map.ts +++ b/js/src/row/map.ts @@ -24,6 +24,8 @@ import { instance as setVisitor } from '../visitor/set.js'; /** @ignore */ export const kKeys = Symbol.for('keys'); /** @ignore */ export const kVals = Symbol.for('vals'); +/** @ignore */ export const kKeysAsStrings = Symbol.for('kKeysAsStrings'); +/** @ignore */ export const _kKeysAsStrings = Symbol.for('_kKeysAsStrings'); export class MapRow<K extends DataType = any, V extends DataType = any> { @@ -31,6 +33,7 @@ export class MapRow<K extends DataType = any, V extends DataType = any> { declare private [kKeys]: Vector<K>; declare private [kVals]: Data<V>; + declare private [_kKeysAsStrings]: string[]; constructor(slice: Data<Struct<{ key: K; value: V }>>) { this[kKeys] = new Vector([slice.children[0]]).memoize() as Vector<K>; @@ -38,6 +41,11 @@ export class MapRow<K extends DataType = any, V extends DataType = any> { return new Proxy(this, new MapRowProxyHandler<K, V>()); } + /** @ignore */ + get [kKeysAsStrings]() { + return this[_kKeysAsStrings] || (this[_kKeysAsStrings] = Array.from(this[kKeys].toArray(), String)); + } + [Symbol.iterator]() { return new MapRowIterator(this[kKeys], this[kVals]); } @@ -107,13 +115,13 @@ class MapRowProxyHandler<K extends DataType = any, V extends DataType = any> imp deleteProperty() { return false; } preventExtensions() { return true; } ownKeys(row: MapRow<K, V>) { - return row[kKeys].toArray().map(String); + return row[kKeysAsStrings]; } has(row: MapRow<K, V>, key: string | symbol) { - return row[kKeys].includes(key); + return row[kKeysAsStrings].includes(key as string); } getOwnPropertyDescriptor(row: MapRow<K, V>, key: string | symbol) { - const idx = row[kKeys].indexOf(key); + const idx = row[kKeysAsStrings].indexOf(key as string); if (idx !== -1) { return { writable: true, enumerable: true, configurable: true }; } @@ -124,7 +132,7 @@ class MapRowProxyHandler<K extends DataType = any, V extends DataType = any> imp if (Reflect.has(row, key)) { return (row as any)[key]; } - const idx = row[kKeys].indexOf(key); + const idx = row[kKeysAsStrings].indexOf(key as string); if (idx !== -1) { const val = getVisitor.visit(Reflect.get(row, kVals), idx); // Cache key/val lookups @@ -133,7 +141,7 @@ class MapRowProxyHandler<K extends DataType = any, V extends DataType = any> imp } } set(row: MapRow<K, V>, key: string | symbol, val: V) { - const idx = row[kKeys].indexOf(key); + const idx = row[kKeysAsStrings].indexOf(key as string); if (idx !== -1) { setVisitor.visit(Reflect.get(row, kVals), idx, val); // Cache key/val lookups @@ -149,4 +157,5 @@ Object.defineProperties(MapRow.prototype, { [Symbol.toStringTag]: { enumerable: false, configurable: false, value: 'Row' }, [kKeys]: { writable: true, enumerable: false, configurable: false, value: null }, [kVals]: { writable: true, enumerable: false, configurable: false, value: null }, + [_kKeysAsStrings]: { writable: true, enumerable: false, configurable: false, value: null }, });
