Skip to content

fix(emulator): preserve own properties on bound functions in Proxied.getOriginal - #11487

Open
anjalimishra-0007 wants to merge 1 commit into
firebase:mainfrom
anjalimishra-0007:fix/proxied-preserve-own-properties
Open

anjalimishra-0007 wants to merge 1 commit into
firebase:mainfrom
anjalimishra-0007:fix/proxied-preserve-own-properties

Conversation

@anjalimishra-0007

Copy link
Copy Markdown
Contributor

Description

Fixes #11471.

In the Functions emulator runtime (src/emulator/functionsEmulatorRuntime.ts), Proxied.getOriginal() binds non-constructor functions with value.bind(target). Because firebase-admin exposes service namespaces (such as admin.firestore, admin.database, admin.auth, and admin.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 as admin.firestore.FieldValue, admin.firestore.Timestamp, admin.firestore.v1, and admin.database.ServerValue).

This change:

  • Copies all own property descriptors (Object.getOwnPropertyDescriptors(value)) onto the bound function via Object.defineProperties in Proxied.getOriginal(), preserving enumerable, non-enumerable, symbol-keyed, and accessor properties while retaining target this-binding.
  • Exports Proxied and ProxyTarget so Proxied can be unit tested directly.
  • Adds unit tests in src/emulator/functionsEmulatorRuntime.spec.ts covering enumerable/non-enumerable/symbol/accessor namespace properties, method this-binding, constructors/non-functions, and wrapping the firebase-admin firestore namespace.
  • Updates 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, and npm run build:publish (all passed with 0 errors)

Sample Commands

N/A — bug fix in internal Functions emulator SDK proxy wrapper.

…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]>
@google-cla

google-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Proxied.getOriginal() drops own properties from bound Firebase Admin namespace functions

1 participant