mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
omit non-enumerable properties from cloned objects (#784)
Drastically improves performance in some cases (for example, when using the `--explain`/`-X` option).
This commit is contained in:
parent
c832f24e57
commit
9e699ff8a9
@ -1,7 +1,7 @@
|
||||
/*global Set */
|
||||
|
||||
/**
|
||||
Deep clone a simple object.
|
||||
Deep clone a simple object. Ignores non-enumerable properties.
|
||||
@private
|
||||
*/
|
||||
'use strict';
|
||||
@ -53,7 +53,7 @@ function doop(o, seen) {
|
||||
}
|
||||
else {
|
||||
clone = Object.create( Object.getPrototypeOf(o) );
|
||||
props = Object.getOwnPropertyNames(o);
|
||||
props = Object.keys(o);
|
||||
for (i = 0, l = props.length; i < l; i++) {
|
||||
descriptor = Object.getOwnPropertyDescriptor(o, props[i]);
|
||||
if (descriptor.value) {
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
/*global describe, expect, it */
|
||||
'use strict';
|
||||
|
||||
describe('jsdoc/util/doop', function() {
|
||||
var doop = require('jsdoc/util/doop');
|
||||
|
||||
@ -77,6 +79,19 @@ describe('jsdoc/util/doop', function() {
|
||||
compareForEquality(inp, out);
|
||||
});
|
||||
|
||||
it('should not clone non-enumerable properties', function() {
|
||||
var clone;
|
||||
var obj = { a: 1 };
|
||||
|
||||
Object.defineProperty(obj, 'foo', {
|
||||
value: 2
|
||||
});
|
||||
|
||||
clone = doop(obj);
|
||||
|
||||
expect(clone.foo).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should not create a circular reference if an object is seen more than once', function() {
|
||||
var input = { a: {} };
|
||||
var output;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user