Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 7b7258b

Browse files
committed
fix: patch property descriptors in Object.create
Closes #24
1 parent f587f17 commit 7b7258b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Diff for: zone.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,14 @@ Zone.patchMutationObserverClass = function (className) {
518518
Zone.patchDefineProperty = function () {
519519
var _defineProperty = Object.defineProperty;
520520
var _getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
521+
var _create = Object.create;
521522

522523
Object.defineProperty = function (obj, prop, desc) {
523524
if (isUnconfigurable(obj, prop)) {
524525
throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);
525526
}
526-
return rewriteDescriptor(obj, prop, desc);
527+
desc = rewriteDescriptor(obj, prop, desc);
528+
return _defineProperty(obj, prop, desc);
527529
};
528530

529531
Object.defineProperties = function (obj, props) {
@@ -533,6 +535,15 @@ Zone.patchDefineProperty = function () {
533535
return obj;
534536
};
535537

538+
Object.create = function (obj, proto) {
539+
if (typeof proto === 'object') {
540+
Object.keys(proto).forEach(function (prop) {
541+
proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
542+
});
543+
}
544+
return _create(obj, proto);
545+
};
546+
536547
Object.getOwnPropertyDescriptor = function (obj, prop) {
537548
var desc = _getOwnPropertyDescriptor(obj, prop);
538549
if (isUnconfigurable(obj, prop)) {
@@ -542,24 +553,23 @@ Zone.patchDefineProperty = function () {
542553
};
543554

544555
Zone._redefineProperty = function (obj, prop, desc) {
545-
return rewriteDescriptor(obj, prop, desc);
556+
desc = rewriteDescriptor(obj, prop, desc);
557+
return _defineProperty(obj, prop, desc);
546558
};
547559

548560
function isUnconfigurable (obj, prop) {
549561
return obj && obj.__unconfigurables && obj.__unconfigurables[prop];
550562
}
551563

552564
function rewriteDescriptor (obj, prop, desc) {
565+
desc.configurable = true;
553566
if (!desc.configurable) {
554-
desc.configurable = true;
555567
if (!obj.__unconfigurables) {
556-
_defineProperty(obj, '__unconfigurables', {
557-
value: {}
558-
});
568+
_defineProperty(obj, '__unconfigurables', { writable: true, value: {} });
559569
}
560570
obj.__unconfigurables[prop] = true;
561571
}
562-
return _defineProperty(obj, prop, desc);
572+
return desc;
563573
}
564574
};
565575

0 commit comments

Comments
 (0)