Skip to content

Commit

Permalink
fix #393
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 14, 2018
1 parent 9600ebb commit 3ae8397
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.reflect.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function set(target, propertyKey, V /* , receiver */) {
if (has(ownDescriptor, 'value')) {
if (ownDescriptor.writable === false || !isObject(receiver)) return false;
if (existingDescriptor = getOwnPropertyDescriptorModule.f(receiver, propertyKey)) {
if (existingDescriptor.writable === false) return false;
if (existingDescriptor.get || existingDescriptor.set || existingDescriptor.writable === false) return false;
existingDescriptor.value = V;
definePropertyModule.f(receiver, propertyKey, existingDescriptor);
} else definePropertyModule.f(receiver, propertyKey, createPropertyDescriptor(0, V));
Expand Down
16 changes: 13 additions & 3 deletions tests/pure/es.reflect.set.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DESCRIPTORS } from '../helpers/constants';

import set from 'core-js-pure/features/reflect/set';
import { defineProperty, getOwnPropertyDescriptor, create } from 'core-js-pure/features/object';
import { defineProperty, getOwnPropertyDescriptor, create, getPrototypeOf } from 'core-js-pure/features/object';

QUnit.test('Reflect.set', assert => {
assert.isFunction(set);
Expand Down Expand Up @@ -68,8 +68,18 @@ QUnit.test('Reflect.set', assert => {
writable: false,
configurable: true,
});
// eslint-disable-next-line
assert.strictEqual(set(o.__proto__, 'test', 1, o), false);
assert.strictEqual(set(getPrototypeOf(o), 'test', 1, o), false);

// https://github.com/zloirock/core-js/issues/393
o = defineProperty({}, 'test', {
get() { /* empty */ },
});
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
o = defineProperty({}, 'test', {
// eslint-disable-next-line no-unused-vars
set(v) { /* empty */ },
});
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
}
assert.throws(() => set(42, 'q', 42), TypeError, 'throws on primitive');
});
16 changes: 13 additions & 3 deletions tests/tests/es.reflect.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DESCRIPTORS, NATIVE } from '../helpers/constants';

QUnit.test('Reflect.set', assert => {
const { set } = Reflect;
const { defineProperty, getOwnPropertyDescriptor, create } = Object;
const { defineProperty, getOwnPropertyDescriptor, create, getPrototypeOf } = Object;
assert.isFunction(set);
if (NATIVE) assert.arity(set, 3);
assert.name(set, 'set');
Expand Down Expand Up @@ -68,8 +68,18 @@ QUnit.test('Reflect.set', assert => {
writable: false,
configurable: true,
});
// eslint-disable-next-line
assert.strictEqual(set(o.__proto__, 'test', 1, o), false);
assert.strictEqual(set(getPrototypeOf(o), 'test', 1, o), false);

// https://github.com/zloirock/core-js/issues/393
o = defineProperty({}, 'test', {
get() { /* empty */ },
});
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
o = defineProperty({}, 'test', {
// eslint-disable-next-line no-unused-vars
set(v) { /* empty */ },
});
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
}
assert.throws(() => set(42, 'q', 42), TypeError, 'throws on primitive');
});

0 comments on commit 3ae8397

Please sign in to comment.