diff --git a/lib/shared/pouchdb-clone.js b/lib/shared/pouchdb-clone.js index 04a49e9..0700bcb 100644 --- a/lib/shared/pouchdb-clone.js +++ b/lib/shared/pouchdb-clone.js @@ -5,6 +5,20 @@ function isBinaryObject(object) { (typeof Blob !== 'undefined' && object instanceof Blob); } +var funcToString = Function.prototype.toString; +var objectCtorString = funcToString.call(Object); + +function isPlainObject(value) { + var proto = Object.getPrototypeOf(value); + /* istanbul ignore if */ + if (proto === null) { // not sure when this happens, but I guess it can + return true; + } + var Ctor = proto.constructor; + return (typeof Ctor === 'function' && + Ctor instanceof Ctor && funcToString.call(Ctor) === objectCtorString); +} + function cloneArrayBuffer(buff) { if (typeof buff.slice === 'function') { return buff.slice(0); @@ -52,6 +66,10 @@ module.exports = function clone(object) { return cloneBinaryObject(object); } + if (!isPlainObject(object)) { + return object; // don't clone objects like Workers + } + newObject = {}; for (i in object) { if (Object.prototype.hasOwnProperty.call(object, i)) {