Skip to content

Commit

Permalink
fix #392
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 20, 2018
1 parent 249f750 commit 2774ed2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core-js/modules/es.reflect.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ function set(target, propertyKey, V /* , receiver */) {
}
if (has(ownDescriptor, 'value')) {
if (ownDescriptor.writable === false || !isObject(receiver)) return false;
existingDescriptor = getOwnPropertyDescriptorModule.f(receiver, propertyKey) || createPropertyDescriptor(0);
existingDescriptor.value = V;
definePropertyModule.f(receiver, propertyKey, existingDescriptor);
if (existingDescriptor = getOwnPropertyDescriptorModule.f(receiver, propertyKey)) {
if (existingDescriptor.writable === false) return false;
existingDescriptor.value = V;
definePropertyModule.f(receiver, propertyKey, existingDescriptor);
} else definePropertyModule.f(receiver, propertyKey, createPropertyDescriptor(0, V));
return true;
}
return ownDescriptor.set === undefined ? false : (ownDescriptor.set.call(receiver, V), true);
Expand Down
8 changes: 8 additions & 0 deletions tests/pure/es.reflect.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ QUnit.test('Reflect.set', assert => {
assert.strictEqual(target.u, 0, 'set u');
assert.strictEqual(set(target, 'c', 2, target), false, 'set c');
assert.strictEqual(target.c, 1, 'set c');

// https://github.com/zloirock/core-js/issues/392
const o = defineProperty({}, 'test', {
writable: false,
configurable: true,
});
// eslint-disable-next-line
assert.strictEqual(set(o.__proto__, 'test', 1, o), false);
}
assert.throws(() => set(42, 'q', 42), TypeError, 'throws on primitive');
});
8 changes: 8 additions & 0 deletions tests/tests/es.reflect.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ QUnit.test('Reflect.set', assert => {
assert.strictEqual(target.u, 0, 'set u');
assert.strictEqual(set(target, 'c', 2, target), false, 'set c');
assert.strictEqual(target.c, 1, 'set c');

// https://github.com/zloirock/core-js/issues/392
const o = defineProperty({}, 'test', {
writable: false,
configurable: true,
});
// eslint-disable-next-line
assert.strictEqual(set(o.__proto__, 'test', 1, o), false);
}
assert.throws(() => set(42, 'q', 42), TypeError, 'throws on primitive');
});

0 comments on commit 2774ed2

Please sign in to comment.