How to use define-properties - 10 common examples

To help you get started, we’ve selected a few define-properties examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ljharb / object.assign / test / native.js View on Github external
test('native', function (t) {
	t.equal(Object.assign.length, 2, 'Object.assign has a length of 2');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal(Object.assign.name, 'assign', 'Object.assign has name "assign"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(Object, 'assign'), 'Object.assign is not enumerable');
		et.end();
	});

	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());

	t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
		st['throws'](function () { return Object.assign(undefined); }, TypeError, 'undefined is not an object');
		st['throws'](function () { return Object.assign(null); }, TypeError, 'null is not an object');
		st.end();
	});

	// v8 in node 0.8 and 0.10 have non-enumerable string properties
	var stringCharsAreEnumerable = isEnumerable.call('xy', 0);
	t.test('when Object.assign is present and has pending exceptions', { skip: !stringCharsAreEnumerable || !Object.preventExtensions }, function (st) {
		/*
github ljharb / object.assign / test / shimmed.js View on Github external
test('shimmed', function (t) {
	t.equal(Object.assign.length, 2, 'Object.assign has a length of 2');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal(Object.assign.name, 'assign', 'Object.assign has name "assign"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(Object, 'assign'), 'Object.assign is not enumerable');
		et.end();
	});

	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());

	t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
		st['throws'](function () { return Object.assign(undefined); }, TypeError, 'undefined is not an object');
		st['throws'](function () { return Object.assign(null); }, TypeError, 'null is not an object');
		st.end();
	});

	// v8 in node 0.8 and 0.10 have non-enumerable string properties
	var stringCharsAreEnumerable = isEnumerable.call('xy', 0);
	t.test('when Object.assign is present and has pending exceptions', { skip: !stringCharsAreEnumerable || !Object.preventExtensions }, function (st) {
		/*
github mathiasbynens / Array.from / tests / tests.js View on Github external
'use strict';

/* eslint-disable no-invalid-this */

var test = require('tape');
var ES = require('es-abstract/es6');
var supportsDescriptors = require('define-properties').supportsDescriptors;

var makeIterator = function (array) {
	var nextIndex = 0;
	var value;
	return {
		'next': function () {
			if (nextIndex < array.length) {
				value = array[nextIndex];
				nextIndex = nextIndex + 1;
				return {
					'done': false,
					'value': value
				};
			} else {
				return {
					'done': true,
github es-shims / String.prototype.padStart / test / shimmed.js View on Github external
test('shimmed', function (t) {
	t.equal(String.prototype.padStart.length, 1, 'String#padStart has a length of 1');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal(String.prototype.padStart.name, 'padStart', 'String#padStart has name "padStart"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(String.prototype, 'padStart'), 'String#padStart is not enumerable');
		et.end();
	});

	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());

	t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
		st['throws'](function () { return padStart(undefined, 'a'); }, TypeError, 'undefined is not an object');
		st['throws'](function () { return padStart(null, 'a'); }, TypeError, 'null is not an object');
		st.end();
	});

	runTests(bind.call(Function.call, String.prototype.padStart), t);

	t.end();
});
github es-shims / Object.values / test / shimmed.js View on Github external
test('shimmed', function (t) {
	t.equal(Object.values.length, 1, 'Object.values has a length of 1');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal(Object.values.name, 'values', 'Object.values has name "values"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(Object, 'values'), 'Object.values is not enumerable');
		et.end();
	});

	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());

	t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
		st['throws'](function () { return Object.values(undefined); }, TypeError, 'undefined is not an object');
		st['throws'](function () { return Object.values(null); }, TypeError, 'null is not an object');
		st.end();
	});

	runTests(Object.values, t);

	t.end();
});
github airbnb / mocha-wrap / test / mocha / withOverrides.js View on Github external
'use strict';

var assert = require('assert');
var has = require('has');
var wrap = require('../..');
var thunk = function (v) { return function () { return v; }; };
var supportsDescriptors = require('define-properties').supportsDescriptors;

describe('withOverrides plugin', function () {
	var obj = {};
	before(function () {
		obj.foo = 'before foo';
		obj.bar = 'before bar';
		obj.baz = -1;
		obj.quux = 'quux';
	});

	it('has properties set to initial values', function () {
		assert.deepEqual(obj, { foo: 'before foo', bar: 'before bar', baz: -1, quux: 'quux' });
	});

	wrap().withOverrides(thunk(obj), thunk({ foo: 'after foo' }))
	.it('foo is "after foo"', function () {
github es-shims / String.prototype.padEnd / test / shimmed.js View on Github external
test('shimmed', function (t) {
	t.equal(String.prototype.padEnd.length, 1, 'String#padEnd has a length of 1');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal(String.prototype.padEnd.name, 'padEnd', 'String#padEnd has name "padEnd"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(String.prototype, 'padEnd'), 'String#padEnd is not enumerable');
		et.end();
	});

	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());

	t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
		st['throws'](function () { return padEnd(undefined, 'a'); }, TypeError, 'undefined is not an object');
		st['throws'](function () { return padEnd(null, 'a'); }, TypeError, 'null is not an object');
		st.end();
	});

	runTests(bind.call(Function.call, String.prototype.padEnd), t);

	t.end();
});
github es-shims / String.prototype.trimLeft / test / shimmed.js View on Github external
test('shimmed', function (t) {
	t.equal(String.prototype.trimLeft.length, 0, 'String#trimLeft has a length of 0');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal((/^(?:trimLeft|trimStart)$/).test(String.prototype.trimLeft.name), true, 'String#trimLeft has name "trimLeft" or "trimStart"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(String.prototype, 'trimLeft'), 'String#trimLeft is not enumerable');
		et.end();
	});

	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());

	t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
		st['throws'](function () { return trimLeft(undefined, 'a'); }, TypeError, 'undefined is not an object');
		st['throws'](function () { return trimLeft(null, 'a'); }, TypeError, 'null is not an object');
		st.end();
	});

	runTests(bind.call(Function.call, String.prototype.trimLeft), t);

	t.end();
});
github es-shims / Object.values / test / tests.js View on Github external
st.deepEqual(values(f), [b], 'only own properties are included');
		st.end();
	});

	t.test('Symbol properties are omitted', { skip: !hasSymbols }, function (st) {
		var object = { a: a, b: b, c: c };
		var enumSym = Symbol('enum');
		var nonEnumSym = Symbol('non enum');
		object[enumSym] = enumSym;
		object.d = enumSym;
		Object.defineProperty(object, nonEnumSym, { enumerable: false, value: nonEnumSym });
		st.deepEqual(values(object), [a, b, c, enumSym], 'symbol properties are omitted');
		st.end();
	});

	t.test('not-yet-visited keys deleted on [[Get]] must not show up in output', { skip: !define.supportsDescriptors }, function (st) {
		var o = { a: 1, b: 2, c: 3 };
		Object.defineProperty(o, 'a', {
			get: function () {
				delete this.b;
				return 1;
			}
		});
		st.deepEqual(values(o), [1, 3], 'when "b" is deleted prior to being visited, it should not show up');
		st.end();
	});

	t.test('not-yet-visited keys made non-enumerable on [[Get]] must not show up in output', { skip: !define.supportsDescriptors }, function (st) {
		var o = { a: 'A', b: 'B' };
		Object.defineProperty(o, 'a', {
			get: function () {
				Object.defineProperty(o, 'b', { enumerable: false });
github es-shims / RegExp.prototype.flags / shim.js View on Github external
'use strict';

var supportsDescriptors = require('define-properties').supportsDescriptors;
var getPolyfill = require('./polyfill');
var gOPD = Object.getOwnPropertyDescriptor;
var defineProperty = Object.defineProperty;
var TypeErr = TypeError;
var getProto = Object.getPrototypeOf;
var regex = /a/;

module.exports = function shimFlags() {
	if (!supportsDescriptors || !getProto) {
		throw new TypeErr('RegExp.prototype.flags requires a true ES5 environment that supports property descriptors');
	}
	var polyfill = getPolyfill();
	var proto = getProto(regex);
	var descriptor = gOPD(proto, 'flags');
	if (!descriptor || descriptor.get !== polyfill) {
		defineProperty(proto, 'flags', {

define-properties

Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.

MIT
Latest version published 1 year ago

Package Health Score

67 / 100
Full package analysis