Skip to content

Commit

Permalink
Fix for #10
Browse files Browse the repository at this point in the history
  • Loading branch information
seanl-adg committed Jan 16, 2018
1 parent 7395f6d commit b8e2cd8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class DeepOverrideHost {
(<Function>providedDesc.beforeGet).call(_this, propState.owner.$raw);
}
let value = this.invokeGetter(propState, _this);
if (_this === propState.owner.$raw || propState.owner.$raw!.isPrototypeOf(_this)) {
if (_this === propState.owner.$raw || DeepOverrideHost.isPrototypeOf.call(propState.owner.$raw, _this)) {
this.applyObjectStateRaw(value, propState.obj);
}
return value;
Expand All @@ -268,7 +268,7 @@ class DeepOverrideHost {
* @param incoming Z
*/
$set(propState: IPropertyState, incoming: any, _this: any): any {
if (_this !== propState.owner.$raw) {
if (_this !== propState.owner.$raw && !DeepOverrideHost.isPrototypeOf.call(propState.owner.$raw, _this)) {
return this.invokeSetter(propState, incoming, _this);
}
if (propState.providedDesc && propState.providedDesc.beforeSet) {
Expand Down Expand Up @@ -438,7 +438,7 @@ class DeepOverrideHost {
let anyKeyIsPresent = false;
while (i--) {
let key = DeepOverrideHost.DESC_KEYS[i];
if (desc.hasOwnProperty(key)) {
if (DeepOverrideHost.hasOwnProperty.call(desc, key)) {
anyKeyIsPresent = true;
cloned[key] = desc[key];
}
Expand All @@ -454,6 +454,7 @@ class DeepOverrideHost {
static getPrototypeOf = Object.getPrototypeOf;

static hasOwnProperty = Object.prototype.hasOwnProperty;
static isPrototypeOf = Object.prototype.isPrototypeOf;

// Object#__lookupGetter__ is not supported on IE10 and lower.
static lookupGetter = Object.prototype.__lookupGetter__ || function (prop: PropertyKey) {
Expand All @@ -466,7 +467,7 @@ class DeepOverrideHost {
};
static lookupDescriptor = (obj: object, prop: PropertyKey): PropertyDescriptor | undefined => {
if (!(prop in obj)) { return; }
while (!obj.hasOwnProperty(prop)) {
while (!DeepOverrideHost.hasOwnProperty.call(obj, prop)) {
obj = DeepOverrideHost.getPrototypeOf(obj);
}
return DeepOverrideHost.getOwnPropertyDescriptor(obj, prop);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deep-override",
"version": "1.0.2",
"version": "1.0.3",
"main": "index.js",
"license": "MIT",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,23 @@ suite('AG_defineProperty', function() {
});

test('Shadowing class instance properties', function() {
let getCount = setCount = 0;
AG_defineProperty('A.prototype.b.c', {
get: function() {
getCount++;
return false;
},
set: function() { }
set: function() {
setCount++;
}
}, base);
base.A = class { };
base.a = new base.A();
base.a.b = { c: true };

base.a.b = { c: true }; // This implicitly invokes the setter.
base.a.b.c = true;
assert.equal(base.a.b.c, false);
assert.equal(getCount, 1);
assert.equal(setCount, 2);
});
});

Expand Down

0 comments on commit b8e2cd8

Please sign in to comment.