Repository navigation
fix(emulator): preserve own properties on bound functions in Proxied.getOriginal - #11487
anjalimishra-0007 wants to merge 1 commit into
Conversation
…getOriginal Fixes firebase#11471. Previously, calling value.bind(target) returned a new bound function without copying the original function's own property descriptors, stripping namespaced properties such as admin.firestore.FieldValue, admin.firestore.v1, and admin.database.ServerValue inside the Functions emulator runtime. Copying own property descriptors onto the bound function preserves enumerable, non-enumerable, symbol, and accessor properties while keeping target binding intact. Signed-off-by: Anjali Mishra <[email protected]>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request fixes an issue in the Functions emulator runtime where own properties on bound firebase-admin namespace functions (such as admin.firestore.FieldValue and admin.database.ServerValue) were dropped. This is resolved in src/emulator/functionsEmulatorRuntime.ts by using Object.defineProperties and Object.getOwnPropertyDescriptors to preserve own property descriptors on bound functions. Additionally, the ProxyTarget interface and Proxied class are now exported with updated JSDoc comments, and comprehensive unit tests have been added in src/emulator/functionsEmulatorRuntime.spec.ts to verify these changes. There are no review comments to address.
Description
Fixes #11471.
In the Functions emulator runtime (
src/emulator/functionsEmulatorRuntime.ts),Proxied.getOriginal()binds non-constructor functions withvalue.bind(target). Becausefirebase-adminexposes service namespaces (such asadmin.firestore,admin.database,admin.auth, andadmin.storage) as arrow functions carrying SDK members as own properties,Function.prototype.bind()returned a fresh function missing every enumerable and non-enumerable own property (such asadmin.firestore.FieldValue,admin.firestore.Timestamp,admin.firestore.v1, andadmin.database.ServerValue).This change:
Object.getOwnPropertyDescriptors(value)) onto the bound function viaObject.definePropertiesinProxied.getOriginal(), preserving enumerable, non-enumerable, symbol-keyed, and accessor properties while retainingtargetthis-binding.ProxiedandProxyTargetsoProxiedcan be unit tested directly.src/emulator/functionsEmulatorRuntime.spec.tscovering enumerable/non-enumerable/symbol/accessor namespace properties, methodthis-binding, constructors/non-functions, and wrapping thefirebase-adminfirestorenamespace.CHANGELOG.md.Scenarios Tested
npx mocha src/emulator/functionsEmulatorRuntime.spec.ts --forbid-only(4 passing)TZ=UTC npm run mocha:fast -- --forbid-only(5991 passing, 11 pre-existing pending)npm run lint:changed-files,npm run lint:other, andnpm run build:publish(all passed with 0 errors)Sample Commands
N/A — bug fix in internal Functions emulator SDK proxy wrapper.