Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4711

Make Code always store a string and remove function caching and eval

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • bson-5.0.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 3
    • Not Needed
    • Not Needed

      Use Case

      In order to get consistent behavior with BSON document size it is safer to utilize the toString method on a function passed to the Code constructor rather than the normalizedFunctionString helper we use now. In addition, javascript BSON code is generally not usable from your runtime as MongoDB binds the value of this server side. Eval also has negative impacts on performance so ideally it should be performed as needed as opposed to all instances of "code" types returned to the driver.

      User Impact

      • Migration requires code changes
        • the .code property on a Code instance will always be a string
        • evalFunctions and cacheFunctions will no longer be supported
        • if you desire a function from a Code instance you can call new Function(codeInstance.code)
      • Notable not changing:
        • serializeFunctions will continue to work and flag the serializer if it should treat functions on the input object as Code values.

      Acceptance Criteria

      Implementation Requirements

      • Change the Code constructor to call .toString on function inputs
      • Remove evalFunctions and cacheFunctions from the deserializer
      • Remove normalizeFunctionString helper

      Testing Requirements

      • Update tests that expected this behavior
      • Ensure serializeFunctions continues to work

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Durran Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: