source: imaps-frontend/node_modules/es-abstract/2018/SetIntegrityLevel.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $SyntaxError = require('es-errors/syntax');
6var $TypeError = require('es-errors/type');
7var $preventExtensions = GetIntrinsic('%Object.preventExtensions%', true);
8var $gOPD = require('gopd');
9var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);
10
11var forEach = require('../helpers/forEach');
12
13var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
14var IsAccessorDescriptor = require('./IsAccessorDescriptor');
15var ToPropertyDescriptor = require('./ToPropertyDescriptor');
16
17var isObject = require('../helpers/isObject');
18
19// https://262.ecma-international.org/6.0/#sec-setintegritylevel
20
21module.exports = function SetIntegrityLevel(O, level) {
22 if (!isObject(O)) {
23 throw new $TypeError('Assertion failed: Type(O) is not Object');
24 }
25 if (level !== 'sealed' && level !== 'frozen') {
26 throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`');
27 }
28 if (!$preventExtensions) {
29 throw new $SyntaxError('SetIntegrityLevel requires native `Object.preventExtensions` support');
30 }
31 var status = $preventExtensions(O);
32 if (!status) {
33 return false;
34 }
35 if (!$gOPN) {
36 throw new $SyntaxError('SetIntegrityLevel requires native `Object.getOwnPropertyNames` support');
37 }
38 var theKeys = $gOPN(O);
39 if (level === 'sealed') {
40 forEach(theKeys, function (k) {
41 DefinePropertyOrThrow(O, k, { configurable: false });
42 });
43 } else if (level === 'frozen') {
44 forEach(theKeys, function (k) {
45 var currentDesc = $gOPD(O, k);
46 if (typeof currentDesc !== 'undefined') {
47 var desc;
48 if (IsAccessorDescriptor(ToPropertyDescriptor(currentDesc))) {
49 desc = { configurable: false };
50 } else {
51 desc = { configurable: false, writable: false };
52 }
53 DefinePropertyOrThrow(O, k, desc);
54 }
55 });
56 }
57 return true;
58};
Note: See TracBrowser for help on using the repository browser.