Projekt

Obecné

Profil

Stáhnout (811 Bajtů) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
var GetIntrinsic = require('../GetIntrinsic');
4

    
5
var $TypeError = GetIntrinsic('%TypeError%');
6

    
7
var IsPropertyKey = require('./IsPropertyKey');
8
var Type = require('./Type');
9

    
10
// https://ecma-international.org/ecma-262/6.0/#sec-set-o-p-v-throw
11

    
12
module.exports = function Set(O, P, V, Throw) {
13
	if (Type(O) !== 'Object') {
14
		throw new $TypeError('Assertion failed: `O` must be an Object');
15
	}
16
	if (!IsPropertyKey(P)) {
17
		throw new $TypeError('Assertion failed: `P` must be a Property Key');
18
	}
19
	if (Type(Throw) !== 'Boolean') {
20
		throw new $TypeError('Assertion failed: `Throw` must be a Boolean');
21
	}
22
	if (Throw) {
23
		O[P] = V; // eslint-disable-line no-param-reassign
24
		return true;
25
	} else {
26
		try {
27
			O[P] = V; // eslint-disable-line no-param-reassign
28
		} catch (e) {
29
			return false;
30
		}
31
	}
32
};
(77-77/117)