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