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

XMLWordPrintableJSON

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

      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
              Reporter:
              Neal Beeken
              Durran Jordan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: