Sha256: 13d6bc0bb4e11c638962dace9dea09d82c16b8a63016e967fc56f5be435fe902

Contents?: true

Size: 1.55 KB

Versions: 27

Compression:

Stored size: 1.55 KB

Contents

'use strict';

var hasPropertyDescriptors = require('has-property-descriptors');

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

var $defineProperty = hasPropertyDescriptors() && GetIntrinsic('%Object.defineProperty%', true);

var hasArrayLengthDefineBug = hasPropertyDescriptors.hasArrayLengthDefineBug();

// eslint-disable-next-line global-require
var isArray = hasArrayLengthDefineBug && require('../helpers/IsArray');

var callBound = require('call-bind/callBound');

var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');

// eslint-disable-next-line max-params
module.exports = function DefineOwnProperty(IsDataDescriptor, SameValue, FromPropertyDescriptor, O, P, desc) {
	if (!$defineProperty) {
		if (!IsDataDescriptor(desc)) {
			// ES3 does not support getters/setters
			return false;
		}
		if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
			return false;
		}

		// fallback for ES3
		if (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {
			// a non-enumerable existing property
			return false;
		}

		// property does not exist at all, or exists but is enumerable
		var V = desc['[[Value]]'];
		// eslint-disable-next-line no-param-reassign
		O[P] = V; // will use [[Define]]
		return SameValue(O[P], V);
	}
	if (
		hasArrayLengthDefineBug
		&& P === 'length'
		&& '[[Value]]' in desc
		&& isArray(O)
		&& O.length !== desc['[[Value]]']
	) {
		// eslint-disable-next-line no-param-reassign
		O.length = desc['[[Value]]'];
		return O.length === desc['[[Value]]'];
	}

	$defineProperty(O, P, FromPropertyDescriptor(desc));
	return true;
};

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.32 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.29 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.28 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.27 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.26 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.25 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.24 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.23 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.22 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.21 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.20 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.19 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.18 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.17 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.16 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.14 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.13 node_modules/es-abstract/helpers/DefineOwnProperty.js
immosquare-cleaner-0.1.12 node_modules/es-abstract/helpers/DefineOwnProperty.js