-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
A non-default option for serialization allows for the automatically stringifying javascript functions. Function.prototype.toString has changed between versions of node, so we need to normalize so as to not potentially break compatibility with earlier expectations. This should have marginal performance effects only in the case where users are actually using this functionality. NODE-1499
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ var writeIEEE754 = require('../float_parser').writeIEEE754, | |
Map = require('../map'), | ||
Binary = require('../binary').Binary; | ||
|
||
const normalizedFunctionString = require('./utils').normalizedFunctionString; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mbroadst
Author
Member
|
||
|
||
// try { | ||
// var _Buffer = Uint8Array; | ||
// } catch (e) { | ||
|
@@ -443,7 +445,8 @@ var serializeFunction = function(buffer, key, value, index, checkKeys, depth, is | |
index = index + numberOfWrittenBytes; | ||
buffer[index++] = 0; | ||
// Function string | ||
var functionString = value.toString(); | ||
var functionString = normalizedFunctionString(value); | ||
|
||
// Write the string | ||
var size = buffer.write(functionString, index + 4, 'utf8') + 1; | ||
// Write the size of the string to buffer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Normalizes our expected stringified form of a function across versions of node | ||
* @param {Function} fn The function to stringify | ||
*/ | ||
function normalizedFunctionString(fn) { | ||
return fn.toString().replace('function(', 'function ('); | ||
This comment has been minimized.
Sorry, something went wrong.
BridgeAR
|
||
} | ||
|
||
module.exports = { | ||
normalizedFunctionString | ||
This comment has been minimized.
Sorry, something went wrong.
jasonout
|
||
}; |
This breaks compatibility with older versions of node, just changing
const
forvar
fixes the problem (as in lib/bson/parser/calculate_size.js:16)I made a PR for this #254