{"ScriptPreparationCode":"\r\nvar MACHINE_ID = Math.floor(Math.random() * 0xFFFFFF);\r\nvar index = ObjectID.index = parseInt(Math.random() * 0xFFFFFF, 10);\r\nvar pid = (typeof process === \u0027undefined\u0027 || typeof process.pid !== \u0027number\u0027 ? Math.floor(Math.random() * 100000) : process.pid) % 0xFFFF;\r\n\r\n/**\r\n * Determine if an object is Buffer\r\n *\r\n * Author: Feross Aboukhadijeh \u003Cfeross@feross.org\u003E \u003Chttp://feross.org\u003E\r\n * License: MIT\r\n *\r\n */\r\nvar isBuffer = function (obj) {\r\n return !!(\r\n obj != null \u0026\u0026\r\n obj.constructor \u0026\u0026\r\n typeof obj.constructor.isBuffer === \u0027function\u0027 \u0026\u0026\r\n obj.constructor.isBuffer(obj)\r\n )\r\n};\r\n\r\n// Precomputed hex table enables speedy hex string conversion\r\nvar hexTable = [];\r\nfor (var i = 0; i \u003C 256; i\u002B\u002B) {\r\n hexTable[i] = (i \u003C= 15 ? \u00270\u0027 : \u0027\u0027) \u002B i.toString(16);\r\n}\r\n\r\n// Regular expression that checks for hex value\r\nvar checkForHexRegExp = new RegExp(\u0027^[0-9a-fA-F]{24}$\u0027);\r\n\r\n// Lookup tables\r\nvar decodeLookup = [];\r\ni = 0;\r\nwhile (i \u003C 10) decodeLookup[0x30 \u002B i] = i\u002B\u002B;\r\nwhile (i \u003C 16) decodeLookup[0x41 - 10 \u002B i] = decodeLookup[0x61 - 10 \u002B i] = i\u002B\u002B;\r\n\r\n/**\r\n * Create a new immutable ObjectID instance\r\n *\r\n * @class Represents the BSON ObjectID type\r\n * @param {String|Number} id Can be a 24 byte hex string, 12 byte binary string or a Number.\r\n * @return {Object} instance of ObjectID.\r\n */\r\nfunction ObjectID(id) {\r\n if(!(this instanceof ObjectID)) return new ObjectID(id);\r\n if(id \u0026\u0026 ((id instanceof ObjectID) || id._bsontype===\u0022ObjectID\u0022))\r\n return id;\r\n\r\n this._bsontype = \u0027ObjectID\u0027;\r\n\r\n // The most common usecase (blank id, new objectId instance)\r\n if (id == null || typeof id === \u0027number\u0027) {\r\n // Generate a new id\r\n this.id = this.generate(id);\r\n // Return the object\r\n return;\r\n }\r\n\r\n // Check if the passed in id is valid\r\n var valid = ObjectID.isValid(id);\r\n\r\n // Throw an error if it\u0027s not a valid setup\r\n if (!valid \u0026\u0026 id != null) {\r\n throw new Error(\r\n \u0027Argument passed in must be a single String of 12 bytes or a string of 24 hex characters\u0027\r\n );\r\n } else if (valid \u0026\u0026 typeof id === \u0027string\u0027 \u0026\u0026 id.length === 24) {\r\n return ObjectID.createFromHexString(id);\r\n } else if (id != null \u0026\u0026 id.length === 12) {\r\n // assume 12 byte string\r\n this.id = id;\r\n } else if (id != null \u0026\u0026 typeof id.toHexString === \u0027function\u0027) {\r\n // Duck-typing to support ObjectId from different npm packages\r\n return id;\r\n } else {\r\n throw new Error(\r\n \u0027Argument passed in must be a single String of 12 bytes or a string of 24 hex characters\u0027\r\n );\r\n }\r\n}\r\nObjectID.default = ObjectID;\r\n\r\n/**\r\n * Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID.\r\n *\r\n * @param {Number} time an integer number representing a number of seconds.\r\n * @return {ObjectID} return the created ObjectID\r\n * @api public\r\n */\r\nObjectID.createFromTime = function(time){\r\n time = parseInt(time, 10) % 0xFFFFFFFF;\r\n return new ObjectID(hex(8,time)\u002B\u00220000000000000000\u0022);\r\n};\r\n\r\n/**\r\n * Creates an ObjectID from a hex string representation of an ObjectID.\r\n *\r\n * @param {String} hexString create a ObjectID from a passed in 24 byte hexstring.\r\n * @return {ObjectID} return the created ObjectID\r\n * @api public\r\n */\r\nObjectID.createFromHexString = function(hexString) {\r\n // Throw an error if it\u0027s not a valid setup\r\n if (typeof hexString === \u0027undefined\u0027 || (hexString != null \u0026\u0026 hexString.length !== 24)) {\r\n throw new Error(\r\n \u0027Argument passed in must be a single String of 12 bytes or a string of 24 hex characters\u0027\r\n );\r\n }\r\n\r\n // Calculate lengths\r\n var data = \u0027\u0027;\r\n var i = 0;\r\n\r\n while (i \u003C 24) {\r\n data \u002B= String.fromCharCode((decodeLookup[hexString.charCodeAt(i\u002B\u002B)] \u003C\u003C 4) | decodeLookup[hexString.charCodeAt(i\u002B\u002B)]);\r\n }\r\n\r\n return new ObjectID(data);\r\n};\r\n\r\n/**\r\n * Checks if a value is a valid bson ObjectId\r\n *\r\n * @param {String} objectid Can be a 24 byte hex string or an instance of ObjectID.\r\n * @return {Boolean} return true if the value is a valid bson ObjectID, return false otherwise.\r\n * @api public\r\n *\r\n * THE NATIVE DOCUMENTATION ISN\u0027T CLEAR ON THIS GUY!\r\n * http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html#objectid-isvalid\r\n */\r\nObjectID.isValid = function(id) {\r\n if (id == null) return false;\r\n\r\n if (typeof id === \u0027number\u0027) {\r\n return true;\r\n }\r\n\r\n if (typeof id === \u0027string\u0027) {\r\n return id.length === 12 || (id.length === 24 \u0026\u0026 checkForHexRegExp.test(id));\r\n }\r\n\r\n if (id instanceof ObjectID) {\r\n return true;\r\n }\r\n\r\n if (isBuffer(id)) {\r\n return true;\r\n }\r\n\r\n // Duck-Typing detection of ObjectId like objects\r\n if (\r\n typeof id.toHexString === \u0027function\u0027 \u0026\u0026\r\n (id.id instanceof _Buffer || typeof id.id === \u0027string\u0027)\r\n ) {\r\n return id.id.length === 12 || (id.id.length === 24 \u0026\u0026 checkForHexRegExp.test(id.id));\r\n }\r\n\r\n return false;\r\n};\r\n\r\nObjectID.prototype = {\r\n constructor: ObjectID,\r\n\r\n /**\r\n * Return the ObjectID id as a 24 byte hex string representation\r\n *\r\n * @return {String} return the 24 byte hex string representation.\r\n * @api public\r\n */\r\n toHexString: function() {\r\n if (!this.id || !this.id.length) {\r\n throw new Error(\r\n \u0027invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [\u0027 \u002B\r\n JSON.stringify(this.id) \u002B\r\n \u0027]\u0027\r\n );\r\n }\r\n\r\n if (this.id.length === 24) {\r\n return this.id;\r\n }\r\n\r\n if (isBuffer(this.id)) {\r\n return this.id.toString(\u0027hex\u0027)\r\n }\r\n\r\n var hexString = \u0027\u0027;\r\n for (var i = 0; i \u003C this.id.length; i\u002B\u002B) {\r\n hexString \u002B= hexTable[this.id.charCodeAt(i)];\r\n }\r\n\r\n return hexString;\r\n },\r\n\r\n /**\r\n * Compares the equality of this ObjectID with \u0060otherID\u0060.\r\n *\r\n * @param {Object} otherId ObjectID instance to compare against.\r\n * @return {Boolean} the result of comparing two ObjectID\u0027s\r\n * @api public\r\n */\r\n equals: function (otherId){\r\n if (otherId instanceof ObjectID) {\r\n return this.toString() === otherId.toString();\r\n } else if (\r\n typeof otherId === \u0027string\u0027 \u0026\u0026\r\n ObjectID.isValid(otherId) \u0026\u0026\r\n otherId.length === 12 \u0026\u0026\r\n isBuffer(this.id)\r\n ) {\r\n return otherId === this.id.toString(\u0027binary\u0027);\r\n } else if (typeof otherId === \u0027string\u0027 \u0026\u0026 ObjectID.isValid(otherId) \u0026\u0026 otherId.length === 24) {\r\n return otherId.toLowerCase() === this.toHexString();\r\n } else if (typeof otherId === \u0027string\u0027 \u0026\u0026 ObjectID.isValid(otherId) \u0026\u0026 otherId.length === 12) {\r\n return otherId === this.id;\r\n } else if (otherId != null \u0026\u0026 (otherId instanceof ObjectID || otherId.toHexString)) {\r\n return otherId.toHexString() === this.toHexString();\r\n } else {\r\n return false;\r\n }\r\n },\r\n\r\n /**\r\n * Returns the generation date (accurate up to the second) that this ID was generated.\r\n *\r\n * @return {Date} the generation date\r\n * @api public\r\n */\r\n getTimestamp: function(){\r\n var timestamp = new Date();\r\n var time;\r\n if (isBuffer(this.id)) {\r\n time = this.id[3] | (this.id[2] \u003C\u003C 8) | (this.id[1] \u003C\u003C 16) | (this.id[0] \u003C\u003C 24);\r\n } else {\r\n time = this.id.charCodeAt(3) | (this.id.charCodeAt(2) \u003C\u003C 8) | (this.id.charCodeAt(1) \u003C\u003C 16) | (this.id.charCodeAt(0) \u003C\u003C 24);\r\n }\r\n timestamp.setTime(Math.floor(time) * 1000);\r\n return timestamp;\r\n },\r\n\r\n /**\r\n * Generate a 12 byte id buffer used in ObjectID\u0027s\r\n *\r\n * @method\r\n * @param {number} [time] optional parameter allowing to pass in a second based timestamp.\r\n * @return {string} return the 12 byte id buffer string.\r\n */\r\n generate: function (time) {\r\n if (\u0027number\u0027 !== typeof time) {\r\n time = ~~(Date.now() / 1000);\r\n }\r\n\r\n //keep it in the ring!\r\n time = parseInt(time, 10) % 0xFFFFFFFF;\r\n\r\n var inc = next();\r\n\r\n return String.fromCharCode(\r\n ((time \u003E\u003E 24) \u0026 0xFF),\r\n ((time \u003E\u003E 16) \u0026 0xFF),\r\n ((time \u003E\u003E 8) \u0026 0xFF),\r\n (time \u0026 0xFF),\r\n ((MACHINE_ID \u003E\u003E 16) \u0026 0xFF),\r\n ((MACHINE_ID \u003E\u003E 8) \u0026 0xFF),\r\n (MACHINE_ID \u0026 0xFF),\r\n ((pid \u003E\u003E 8) \u0026 0xFF),\r\n (pid \u0026 0xFF),\r\n ((inc \u003E\u003E 16) \u0026 0xFF),\r\n ((inc \u003E\u003E 8) \u0026 0xFF),\r\n (inc \u0026 0xFF)\r\n )\r\n },\r\n};\r\n\r\nfunction next() {\r\n return index = (index\u002B1) % 0xFFFFFF;\r\n}\r\n\r\nfunction hex(length, n) {\r\n n = n.toString(16);\r\n return (n.length===length)? n : \u002200000000\u0022.substring(n.length, length) \u002B n;\r\n}\r\n\r\nfunction buffer(str) {\r\n var i=0,out=[];\r\n\r\n if(str.length===24)\r\n for(;i\u003C24; out.push(parseInt(str[i]\u002Bstr[i\u002B1], 16)),i\u002B=2);\r\n\r\n else if(str.length===12)\r\n for(;i\u003C12; out.push(str.charCodeAt(i)),i\u002B\u002B);\r\n\r\n return out;\r\n}\r\n\r\nvar inspect = (Symbol \u0026\u0026 Symbol.for \u0026\u0026 Symbol.for(\u0027nodejs.util.inspect.custom\u0027)) || \u0027inspect\u0027;\r\n\r\n/**\r\n * Converts to a string representation of this Id.\r\n *\r\n * @return {String} return the 24 byte hex string representation.\r\n * @api private\r\n */\r\nObjectID.prototype[inspect] = function() { return \u0022ObjectID(\u0022\u002Bthis\u002B\u0022)\u0022 };\r\nObjectID.prototype.toJSON = ObjectID.prototype.toHexString;\r\nObjectID.prototype.toString = ObjectID.prototype.toHexString;\r\n\r\nvar TEST_objectids = new Array(1000).fill(null).map(() =\u003E new ObjectID());\r\n","TestCases":[{"Name":"Splice","Code":"const empty = []\r\nempty.splice(0, 0, ...TEST_objectids)","IsDeferred":false},{"Name":"Push","Code":"const empty = []\r\nempty.push(...TEST_objectids)","IsDeferred":false}]}