Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for Internet Explorer #77

Merged
merged 3 commits into from
Mar 9, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions clone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var clone = (function() {
'use strict';

function _instanceof(obj, type) {
return type != null && obj instanceof type;
}

var nativeMap;
try {
nativeMap = Map;
Expand Down Expand Up @@ -80,11 +84,11 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) {
return parent;
}

if (parent instanceof nativeMap) {
if (_instanceof(parent, nativeMap)) {
child = new nativeMap();
} else if (parent instanceof nativeSet) {
} else if (_instanceof(parent, nativeSet)) {
child = new nativeSet();
} else if (parent instanceof nativePromise) {
} else if (_instanceof(parent, nativePromise)) {
child = new nativePromise(function (resolve, reject) {
parent.then(function(value) {
resolve(_clone(value, depth - 1));
Expand All @@ -103,7 +107,7 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) {
child = new Buffer(parent.length);
parent.copy(child);
return child;
} else if (parent instanceof Error) {
} else if (_instanceof(parent, Error)) {
child = Object.create(parent);
} else {
if (typeof prototype == 'undefined') {
Expand All @@ -126,28 +130,18 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) {
allChildren.push(child);
}

if (parent instanceof nativeMap) {
var keyIterator = parent.keys();
while(true) {
var next = keyIterator.next();
if (next.done) {
break;
}
var keyChild = _clone(next.value, depth - 1);
var valueChild = _clone(parent.get(next.value), depth - 1);
if (_instanceof(parent, nativeMap)) {
parent.forEach(function(value, key) {
var keyChild = _clone(key, depth - 1);
var valueChild = _clone(value, depth - 1);
child.set(keyChild, valueChild);
}
});
}
if (parent instanceof nativeSet) {
var iterator = parent.keys();
while(true) {
var next = iterator.next();
if (next.done) {
break;
}
var entryChild = _clone(next.value, depth - 1);
if (_instanceof(parent, nativeSet)) {
parent.forEach(function(value) {
var entryChild = _clone(value, depth - 1);
child.add(entryChild);
}
});
}

for (var i in parent) {
Expand Down