Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/node/rest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from "node:assert";
import { test } from "node:test";
import { testHelper } from "./testHelper.js";

testHelper("__rest", __rest => {
test("copies an own __proto__ key as a data property", () => {
const source = JSON.parse('{"a":1,"__proto__":{"polluted":true}}');
const rest = __rest(source, ["a"]);
assert.equal(Object.getPrototypeOf(rest), Object.prototype);
assert.equal(rest.polluted, undefined);
assert.deepEqual(Object.keys(rest), ["__proto__"]);
assert.deepEqual(Object.getOwnPropertyDescriptor(rest, "__proto__"), { value: { polluted: true }, writable: true, enumerable: true, configurable: true });
});
});
6 changes: 4 additions & 2 deletions tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export var __assign = function() {

export function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) {
if (p === "__proto__") Object.defineProperty(t, p, { value: s[p], writable: true, enumerable: true, configurable: true });
else t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
Expand Down
6 changes: 4 additions & 2 deletions tslib.es6.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export var __assign = function() {

export function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) {
if (p === "__proto__") Object.defineProperty(t, p, { value: s[p], writable: true, enumerable: true, configurable: true });
else t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
Expand Down
6 changes: 4 additions & 2 deletions tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ var __rewriteRelativeImportExtension;

__rest = function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) {
if (p === "__proto__") Object.defineProperty(t, p, { value: s[p], writable: true, enumerable: true, configurable: true });
else t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
Expand Down