Projekt

Obecné

Profil

Stáhnout (1.44 KB) Statistiky
| Větev: | Revize:
1
'use strict';
2

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

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

    
7
var isPropertyDescriptor = require('../helpers/isPropertyDescriptor');
8
var DefineOwnProperty = require('../helpers/DefineOwnProperty');
9

    
10
var FromPropertyDescriptor = require('./FromPropertyDescriptor');
11
var IsAccessorDescriptor = require('./IsAccessorDescriptor');
12
var IsDataDescriptor = require('./IsDataDescriptor');
13
var IsPropertyKey = require('./IsPropertyKey');
14
var SameValue = require('./SameValue');
15
var ToPropertyDescriptor = require('./ToPropertyDescriptor');
16
var Type = require('./Type');
17

    
18
// https://www.ecma-international.org/ecma-262/6.0/#sec-definepropertyorthrow
19

    
20
module.exports = function DefinePropertyOrThrow(O, P, desc) {
21
	if (Type(O) !== 'Object') {
22
		throw new $TypeError('Assertion failed: Type(O) is not Object');
23
	}
24

    
25
	if (!IsPropertyKey(P)) {
26
		throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
27
	}
28

    
29
	var Desc = isPropertyDescriptor({
30
		Type: Type,
31
		IsDataDescriptor: IsDataDescriptor,
32
		IsAccessorDescriptor: IsAccessorDescriptor
33
	}, desc) ? desc : ToPropertyDescriptor(desc);
34
	if (!isPropertyDescriptor({
35
		Type: Type,
36
		IsDataDescriptor: IsDataDescriptor,
37
		IsAccessorDescriptor: IsAccessorDescriptor
38
	}, Desc)) {
39
		throw new $TypeError('Assertion failed: Desc is not a valid Property Descriptor');
40
	}
41

    
42
	return DefineOwnProperty(
43
		IsDataDescriptor,
44
		SameValue,
45
		FromPropertyDescriptor,
46
		O,
47
		P,
48
		Desc
49
	);
50
};
(20-20/117)