From c2de8a0d14c73b18cc6ce0961d401894df35b636 Mon Sep 17 00:00:00 2001 From: Trigueros Alexandre Date: Mon, 9 Apr 2018 00:28:41 +0200 Subject: [PATCH 1/2] keep worker field as Worker (type) when cloning opts --- lib/shared/pouchdb-clone.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/shared/pouchdb-clone.js b/lib/shared/pouchdb-clone.js index 04a49e9..0164022 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)) { From 3e43e8e04a2bf67396997012f31ec4e9b0b88833 Mon Sep 17 00:00:00 2001 From: Trigueros Alexandre Date: Mon, 9 Apr 2018 00:42:10 +0200 Subject: [PATCH 2/2] fix jshint issue --- lib/shared/pouchdb-clone.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shared/pouchdb-clone.js b/lib/shared/pouchdb-clone.js index 0164022..0700bcb 100644 --- a/lib/shared/pouchdb-clone.js +++ b/lib/shared/pouchdb-clone.js @@ -15,8 +15,8 @@ function isPlainObject(value) { return true; } var Ctor = proto.constructor; - return (typeof Ctor == 'function' && - Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString); + return (typeof Ctor === 'function' && + Ctor instanceof Ctor && funcToString.call(Ctor) === objectCtorString); } function cloneArrayBuffer(buff) {