Merge pull request #746 from laurentj/fix-mergeobjects
Fix mergeobjects
Showing
1 changed file
with
14 additions
and
3 deletions
... | @@ -634,7 +634,7 @@ function isPlainObject(obj) { | ... | @@ -634,7 +634,7 @@ function isPlainObject(obj) { |
634 | * @param Object opts optional options to be passed in | 634 | * @param Object opts optional options to be passed in |
635 | * @return Object | 635 | * @return Object |
636 | */ | 636 | */ |
637 | function mergeObjectsInSlimerjs(origin, add, opts) { | 637 | function mergeObjectsInGecko(origin, add, opts) { |
638 | "use strict"; | 638 | "use strict"; |
639 | 639 | ||
640 | var options = opts || {}, | 640 | var options = opts || {}, |
... | @@ -648,7 +648,18 @@ function mergeObjectsInSlimerjs(origin, add, opts) { | ... | @@ -648,7 +648,18 @@ function mergeObjectsInSlimerjs(origin, add, opts) { |
648 | origin[p] = keepReferences ? add[p] : clone(add[p]); | 648 | origin[p] = keepReferences ? add[p] : clone(add[p]); |
649 | } | 649 | } |
650 | } else { | 650 | } else { |
651 | origin[p] = add[p]; | 651 | // if a property is only a getter, we could have a Javascript error |
652 | // in strict mode "TypeError: setting a property that has only a getter" | ||
653 | // when setting the value to the new object (gecko 25+). | ||
654 | // To avoid it, let's define the property on the new object, do not set | ||
655 | // directly the value | ||
656 | var prop = Object.getOwnPropertyDescriptor(add, p); | ||
657 | if (prop.get && !prop.set) { | ||
658 | Object.defineProperty(origin, p, prop) | ||
659 | } | ||
660 | else { | ||
661 | origin[p] = add[p]; | ||
662 | } | ||
652 | } | 663 | } |
653 | } | 664 | } |
654 | return origin; | 665 | return origin; |
... | @@ -672,7 +683,7 @@ function mergeObjects(origin, add, opts) { | ... | @@ -672,7 +683,7 @@ function mergeObjects(origin, add, opts) { |
672 | // Because of an issue in the module system of slimerjs (security membranes?) | 683 | // Because of an issue in the module system of slimerjs (security membranes?) |
673 | // constructor is undefined. | 684 | // constructor is undefined. |
674 | // let's use an other algorithm | 685 | // let's use an other algorithm |
675 | return mergeObjectsInSlimerjs(origin, add); | 686 | return mergeObjectsInGecko(origin, add, options); |
676 | } | 687 | } |
677 | 688 | ||
678 | for (var p in add) { | 689 | for (var p in add) { | ... | ... |
-
Please register or sign in to post a comment