Skip to content

Commit

Permalink
fixup! lib: use null-prototype objects for property descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 1, 2022
1 parent ed9c8b5 commit 5d0986a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/internal/console/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ for (const prop of ReflectOwnKeys(Console.prototype)) {
if (typeof desc.value === 'function') { // fix the receiver
const name = desc.value.name;
desc.value = FunctionPrototypeBind(desc.value, globalConsole);
ReflectDefineProperty(desc.value, 'name', { value: name });
ReflectDefineProperty(desc.value, 'name', { __proto__: null, value: name });
}
ReflectDefineProperty(globalConsole, prop, desc);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
// https://encoding.spec.whatwg.org

const {
ArrayPrototypeMap,
ObjectCreate,
ObjectDefineProperties,
ObjectEntries,
ObjectFromEntries,
ObjectGetOwnPropertyDescriptors,
SafeMap,
StringPrototypeSlice,
Expand Down Expand Up @@ -532,7 +535,7 @@ function makeTextDecoderJS() {
// Mix in some shared properties.
ObjectDefineProperties(
TextDecoder.prototype,
ObjectGetOwnPropertyDescriptors({
ObjectFromEntries(ArrayPrototypeMap(ObjectEntries(ObjectGetOwnPropertyDescriptors({
get encoding() {
validateDecoder(this);
return this[kEncoding];
Expand Down Expand Up @@ -566,7 +569,7 @@ ObjectDefineProperties(
const { inspect } = require('internal/util/inspect');
return `${constructor.name} ${inspect(obj)}`;
}
})
})), ({ 0: key, 1: desc }) => [key, { __proto__: null, ...desc }]))
);

ObjectDefineProperties(TextDecoder.prototype, {
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ function getNewKey(key) {

function copyAccessor(dest, prefix, key, { enumerable, get, set }) {
ReflectDefineProperty(dest, `${prefix}Get${key}`, {
__proto__: null,
value: uncurryThis(get),
enumerable
});
if (set !== undefined) {
ReflectDefineProperty(dest, `${prefix}Set${key}`, {
__proto__: null,
value: uncurryThis(set),
enumerable
});
Expand All @@ -79,6 +81,7 @@ function copyPropsRenamed(src, dest, prefix) {
ReflectDefineProperty(dest, name, desc);
if (varargsMethods.includes(name)) {
ReflectDefineProperty(dest, `${name}Apply`, {
__proto__: null,
// `src` is bound as the `this` so that the static `this` points
// to the object it was defined on,
// e.g.: `ArrayOfApply` gets a `this` of `Array`:
Expand All @@ -105,6 +108,7 @@ function copyPropsRenamedBound(src, dest, prefix) {
ReflectDefineProperty(dest, name, desc);
if (varargsMethods.includes(name)) {
ReflectDefineProperty(dest, `${name}Apply`, {
__proto__: null,
value: applyBind(value, src),
});
}
Expand All @@ -128,6 +132,7 @@ function copyPrototype(src, dest, prefix) {
ReflectDefineProperty(dest, name, desc);
if (varargsMethods.includes(name)) {
ReflectDefineProperty(dest, `${name}Apply`, {
__proto__: null,
value: applyBind(value),
});
}
Expand Down
9 changes: 8 additions & 1 deletion lib/internal/worker/js_transferable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';
const {
ArrayPrototypeMap,
Error,
ObjectDefineProperties,
ObjectEntries,
ObjectFromEntries,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
Expand Down Expand Up @@ -40,7 +43,11 @@ function setup() {

function makeTransferable(obj) {
const inst = ReflectConstruct(JSTransferable, [], obj.constructor);
ObjectDefineProperties(inst, ObjectGetOwnPropertyDescriptors(obj));
ObjectDefineProperties(inst,
ObjectFromEntries(ArrayPrototypeMap(
ObjectEntries(ObjectGetOwnPropertyDescriptors(obj)),
({ 0: key, 1: desc }) => [key, { __proto__: null, ...desc }]
)));
ObjectSetPrototypeOf(inst, ObjectGetPrototypeOf(obj));
return inst;
}
Expand Down

0 comments on commit 5d0986a

Please sign in to comment.