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 */
|
/*global Set */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Deep clone a simple object.
|
Deep clone a simple object. Ignores non-enumerable properties.
|
||||||
@private
|
@private
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -53,7 +53,7 @@ function doop(o, seen) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
clone = Object.create( Object.getPrototypeOf(o) );
|
clone = Object.create( Object.getPrototypeOf(o) );
|
||||||
props = Object.getOwnPropertyNames(o);
|
props = Object.keys(o);
|
||||||
for (i = 0, l = props.length; i < l; i++) {
|
for (i = 0, l = props.length; i < l; i++) {
|
||||||
descriptor = Object.getOwnPropertyDescriptor(o, props[i]);
|
descriptor = Object.getOwnPropertyDescriptor(o, props[i]);
|
||||||
if (descriptor.value) {
|
if (descriptor.value) {
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
/*global describe, expect, it */
|
/*global describe, expect, it */
|
||||||
|
'use strict';
|
||||||
|
|
||||||
describe('jsdoc/util/doop', function() {
|
describe('jsdoc/util/doop', function() {
|
||||||
var doop = require('jsdoc/util/doop');
|
var doop = require('jsdoc/util/doop');
|
||||||
|
|
||||||
@ -77,6 +79,19 @@ describe('jsdoc/util/doop', function() {
|
|||||||
compareForEquality(inp, out);
|
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() {
|
it('should not create a circular reference if an object is seen more than once', function() {
|
||||||
var input = { a: {} };
|
var input = { a: {} };
|
||||||
var output;
|
var output;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user