Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-proto

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-proto - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

6

CHANGELOG.md

@@ -8,2 +8,8 @@ # Changelog

## [v1.0.1](https://github.com/ljharb/get-proto/compare/v1.0.0...v1.0.1) - 2025-01-02
### Commits
- [Fix] for the `Object.getPrototypeOf` window, throw for non-objects [`7fe6508`](https://github.com/ljharb/get-proto/commit/7fe6508b71419ebe1976bedb86001d1feaeaa49a)
## v1.0.0 - 2025-01-01

@@ -10,0 +16,0 @@

18

index.js

@@ -14,7 +14,15 @@ 'use strict';

}
: originalGetProto || (
getDunderProto ? function getProto(O) {
: originalGetProto
? function getProto(O) {
if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
throw new TypeError('getProto: not an object');
}
// @ts-expect-error TS can't narrow inside a closure, for some reason
return getDunderProto(O);
} : null
);
return originalGetProto(O);
}
: getDunderProto
? function getProto(O) {
// @ts-expect-error TS can't narrow inside a closure, for some reason
return getDunderProto(O);
}
: null;
{
"name": "get-proto",
"version": "1.0.0",
"version": "1.0.1",
"description": "Robustly get the [[Prototype]] of an object",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,11 +11,49 @@ 'use strict';

t.test('can get', { skip: !getProto }, function (st) {
var proto = { b: 2 };
var obj = { a: 1, __proto__: proto };
if (getProto) { // TS doesn't understand tape's skip
var proto = { b: 2 };
st.equal(getProto(proto), Object.prototype, 'proto: returns the [[Prototype]]');
// eslint-disable-next-line no-extra-parens
st.equal(/** @type {NonNullable<typeof getProto>} */ (getProto)(obj), proto, 'obj: returns the [[Prototype]]');
st.test('nullish value', function (s2t) {
// @ts-expect-error
s2t['throws'](function () { return getProto(undefined); }, TypeError, 'undefined is not an object');
// @ts-expect-error
s2t['throws'](function () { return getProto(null); }, TypeError, 'null is not an object');
s2t.end();
});
// eslint-disable-next-line no-extra-parens
st.equal(/** @type {NonNullable<typeof getProto>} */ (getProto)(proto), Object.prototype, 'proto: returns the [[Prototype]]');
// @ts-expect-error
st['throws'](function () { getProto(true); }, 'throws for true');
// @ts-expect-error
st['throws'](function () { getProto(false); }, 'throws for false');
// @ts-expect-error
st['throws'](function () { getProto(42); }, 'throws for 42');
// @ts-expect-error
st['throws'](function () { getProto(NaN); }, 'throws for NaN');
// @ts-expect-error
st['throws'](function () { getProto(0); }, 'throws for +0');
// @ts-expect-error
st['throws'](function () { getProto(-0); }, 'throws for -0');
// @ts-expect-error
st['throws'](function () { getProto(Infinity); }, 'throws for ∞');
// @ts-expect-error
st['throws'](function () { getProto(-Infinity); }, 'throws for -∞');
// @ts-expect-error
st['throws'](function () { getProto(''); }, 'throws for empty string');
// @ts-expect-error
st['throws'](function () { getProto('foo'); }, 'throws for non-empty string');
st.equal(getProto(/a/g), RegExp.prototype);
st.equal(getProto(new Date()), Date.prototype);
st.equal(getProto(function () {}), Function.prototype);
st.equal(getProto([]), Array.prototype);
st.equal(getProto({}), Object.prototype);
var nullObject = { __proto__: null };
if ('toString' in nullObject) {
st.comment('no null objects in this engine');
st.equal(getProto(nullObject), Object.prototype, '"null" object has Object.prototype as [[Prototype]]');
} else {
st.equal(getProto(nullObject), null, 'null object has null [[Prototype]]');
}
}
st.end();

@@ -22,0 +60,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc