Sha256: 3a126ecffc3e3cee302010d264d0864853953224fd5b5625633d1696b468a336

Contents?: true

Size: 1.78 KB

Versions: 243

Compression:

Stored size: 1.78 KB

Contents

'use strict';

var GetIntrinsic = require('get-intrinsic');

var $SyntaxError = GetIntrinsic('%SyntaxError%');
var $TypeError = GetIntrinsic('%TypeError%');
var $preventExtensions = GetIntrinsic('%Object.preventExtensions%', true);
var $gOPD = require('gopd');
var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);

var forEach = require('../helpers/forEach');

var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
var IsAccessorDescriptor = require('./IsAccessorDescriptor');
var ToPropertyDescriptor = require('./ToPropertyDescriptor');
var Type = require('./Type');

// https://262.ecma-international.org/6.0/#sec-setintegritylevel

module.exports = function SetIntegrityLevel(O, level) {
	if (Type(O) !== 'Object') {
		throw new $TypeError('Assertion failed: Type(O) is not Object');
	}
	if (level !== 'sealed' && level !== 'frozen') {
		throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`');
	}
	if (!$preventExtensions) {
		throw new $SyntaxError('SetIntegrityLevel requires native `Object.preventExtensions` support');
	}
	var status = $preventExtensions(O);
	if (!status) {
		return false;
	}
	if (!$gOPN) {
		throw new $SyntaxError('SetIntegrityLevel requires native `Object.getOwnPropertyNames` support');
	}
	var theKeys = $gOPN(O);
	if (level === 'sealed') {
		forEach(theKeys, function (k) {
			DefinePropertyOrThrow(O, k, { configurable: false });
		});
	} else if (level === 'frozen') {
		forEach(theKeys, function (k) {
			var currentDesc = $gOPD(O, k);
			if (typeof currentDesc !== 'undefined') {
				var desc;
				if (IsAccessorDescriptor(ToPropertyDescriptor(currentDesc))) {
					desc = { configurable: false };
				} else {
					desc = { configurable: false, writable: false };
				}
				DefinePropertyOrThrow(O, k, desc);
			}
		});
	}
	return true;
};

Version data entries

243 entries across 27 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.32 node_modules/es-abstract/2023/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2019/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2018/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2016/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2020/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2015/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2022/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2017/SetIntegrityLevel.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2021/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2023/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2015/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2021/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2018/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2022/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2019/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2016/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2020/SetIntegrityLevel.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2017/SetIntegrityLevel.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2023/SetIntegrityLevel.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2015/SetIntegrityLevel.js