Sha256: 07dbf07e13a767b7fabbea22ea9d1cc804d3fa452c9e58c69cdce4341aa2a2d5

Contents?: true

Size: 1.98 KB

Versions: 29

Compression:

Stored size: 1.98 KB

Contents

// Big thanks to @WebReflection for sorting this out
// https://gist.github.com/WebReflection/5593554

'use strict';

var isObject      = require('../is-object')
  , value         = require('../valid-value')

  , isPrototypeOf = Object.prototype.isPrototypeOf
  , defineProperty = Object.defineProperty
  , nullDesc = { configurable: true, enumerable: false, writable: true,
		value: undefined }
  , validate;

validate = function (obj, prototype) {
	value(obj);
	if ((prototype === null) || isObject(prototype)) return obj;
	throw new TypeError('Prototype must be null or an object');
};

module.exports = (function (status) {
	var fn, set;
	if (!status) return null;
	if (status.level === 2) {
		if (status.set) {
			set = status.set;
			fn = function (obj, prototype) {
				set.call(validate(obj, prototype), prototype);
				return obj;
			};
		} else {
			fn = function (obj, prototype) {
				validate(obj, prototype).__proto__ = prototype;
				return obj;
			};
		}
	} else {
		fn = function self(obj, prototype) {
			var isNullBase;
			validate(obj, prototype);
			isNullBase = isPrototypeOf.call(self.nullPolyfill, obj);
			if (isNullBase) delete self.nullPolyfill.__proto__;
			if (prototype === null) prototype = self.nullPolyfill;
			obj.__proto__ = prototype;
			if (isNullBase) defineProperty(self.nullPolyfill, '__proto__', nullDesc);
			return obj;
		};
	}
	return Object.defineProperty(fn, 'level', { configurable: false,
		enumerable: false, writable: false, value: status.level });
}((function () {
	var x = Object.create(null), y = {}, set
	  , desc = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__');

	if (desc) {
		try {
			set = desc.set; // Opera crashes at this point
			set.call(x, y);
		} catch (ignore) { }
		if (Object.getPrototypeOf(x) === y) return { set: set, level: 2 };
	}

	x.__proto__ = y;
	if (Object.getPrototypeOf(x) === y) return { level: 2 };

	x = {};
	x.__proto__ = y;
	if (Object.getPrototypeOf(x) === y) return { level: 1 };

	return false;
}())));

require('../create');

Version data entries

29 entries across 19 versions & 7 rubygems

Version Path
guard-sass-lint-0.1.2 node_modules/es5-ext/object/set-prototype-of/shim.js
guard-sass-lint-0.1.1 node_modules/es5-ext/object/set-prototype-of/shim.js
lanes-0.8.0 node_modules/es5-ext/object/set-prototype-of/shim.js
node-compiler-0.9.1 vendor/node/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/set-prototype-of/shim.js
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/set-prototype-of/shim.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/set-prototype-of/shim.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/es5-ext/object/set-prototype-of/shim.js
node-compiler-0.7.0 vendor/node-v7.1.0/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/set-prototype-of/shim.js
node-compiler-0.7.0 vendor/node-v6.9.1/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/set-prototype-of/shim.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/es5-ext/object/set-prototype-of/shim.js
blackboard-3.1.9 lib/site_template/node_modules/es5-ext/object/set-prototype-of/shim.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/object/set-prototype-of/shim.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-map/node_modules/es5-ext/object/set-prototype-of/shim.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-map/node_modules/es5-ext/object/set-prototype-of/shim.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/object/set-prototype-of/shim.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/object/set-prototype-of/shim.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/object/set-prototype-of/shim.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/object/set-prototype-of/shim.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/object/set-prototype-of/shim.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/object/set-prototype-of/shim.js