1 | import superPropBase from "./superPropBase.js";
|
---|
2 | import defineProperty from "./defineProperty.js";
|
---|
3 |
|
---|
4 | function set(target, property, value, receiver) {
|
---|
5 | if (typeof Reflect !== "undefined" && Reflect.set) {
|
---|
6 | set = Reflect.set;
|
---|
7 | } else {
|
---|
8 | set = function set(target, property, value, receiver) {
|
---|
9 | var base = superPropBase(target, property);
|
---|
10 | var desc;
|
---|
11 |
|
---|
12 | if (base) {
|
---|
13 | desc = Object.getOwnPropertyDescriptor(base, property);
|
---|
14 |
|
---|
15 | if (desc.set) {
|
---|
16 | desc.set.call(receiver, value);
|
---|
17 | return true;
|
---|
18 | } else if (!desc.writable) {
|
---|
19 | return false;
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | desc = Object.getOwnPropertyDescriptor(receiver, property);
|
---|
24 |
|
---|
25 | if (desc) {
|
---|
26 | if (!desc.writable) {
|
---|
27 | return false;
|
---|
28 | }
|
---|
29 |
|
---|
30 | desc.value = value;
|
---|
31 | Object.defineProperty(receiver, property, desc);
|
---|
32 | } else {
|
---|
33 | defineProperty(receiver, property, value);
|
---|
34 | }
|
---|
35 |
|
---|
36 | return true;
|
---|
37 | };
|
---|
38 | }
|
---|
39 |
|
---|
40 | return set(target, property, value, receiver);
|
---|
41 | }
|
---|
42 |
|
---|
43 | export default function _set(target, property, value, receiver, isStrict) {
|
---|
44 | var s = set(target, property, value, receiver || target);
|
---|
45 |
|
---|
46 | if (!s && isStrict) {
|
---|
47 | throw new Error('failed to set property');
|
---|
48 | }
|
---|
49 |
|
---|
50 | return value;
|
---|
51 | } |
---|