Projekt

Obecné

Profil

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

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

    
5
var $gOPD = require('../helpers/getOwnPropertyDescriptor');
6
var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%');
7
var $TypeError = GetIntrinsic('%TypeError%');
8

    
9
var every = require('../helpers/every');
10

    
11
var IsDataDescriptor = require('./IsDataDescriptor');
12
var IsExtensible = require('./IsExtensible');
13
var ToPropertyDescriptor = require('./ToPropertyDescriptor');
14
var Type = require('./Type');
15

    
16
// https://www.ecma-international.org/ecma-262/6.0/#sec-testintegritylevel
17

    
18
module.exports = function TestIntegrityLevel(O, level) {
19
	if (Type(O) !== 'Object') {
20
		throw new $TypeError('Assertion failed: Type(O) is not Object');
21
	}
22
	if (level !== 'sealed' && level !== 'frozen') {
23
		throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`');
24
	}
25
	var status = IsExtensible(O);
26
	if (status) {
27
		return false;
28
	}
29
	var theKeys = $gOPN(O);
30
	return theKeys.length === 0 || every(theKeys, function (k) {
31
		var currentDesc = $gOPD(O, k);
32
		if (typeof currentDesc !== 'undefined') {
33
			if (currentDesc.configurable) {
34
				return false;
35
			}
36
			if (level === 'frozen' && IsDataDescriptor(ToPropertyDescriptor(currentDesc)) && currentDesc.writable) {
37
				return false;
38
			}
39
		}
40
		return true;
41
	});
42
};
(78-78/109)