Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup: try using an own object
There are some issues involving the proxy. This tries to circumvent
the issue by not making any copy of the newly set object.
  • Loading branch information
BridgeAR committed Jan 6, 2019
commit ba9c391fbc5bc6331bcc634e8fb22d3bd75612a9
15 changes: 9 additions & 6 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,26 +744,29 @@ if (experimentalModules) {
function setExtensionsProxy(extensions) {
// Intersect manipulating the extensions.
extensionNames = Object.keys(extensions);
extensionCopy = { ...extensions };
extensionCopy = Object.create(null);
for (const name of extensionNames) {
extensionCopy[name] = true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like an awful lot of work for to avoid Object.keys here.
How much is the win here for just Object.keys? Can we leave this whole Proxy of the Module out and still get the majority of the wins?

return new Proxy(extensions, {
set(obj, prop, value) {
if (extensions[prop] === undefined) {
extensionCopy[prop] = value;
if (extensionCopy[prop] === undefined) {
extensionCopy[prop] = true;
extensionNames.push(prop);
}
return Reflect.set(obj, prop, value);
},
defineProperty(target, prop, descriptor) {
if (extensions[prop] === undefined) {
Object.defineProperty(extensionCopy, prop, descriptor);
if (extensionCopy[prop] === undefined) {
extensionCopy[prop] = true;
extensionNames.push(prop);
}
return Reflect.defineProperty(target, prop, descriptor);
},
deleteProperty(target, prop) {
const pos = extensionNames.indexOf(prop);
if (pos !== -1) {
delete extensionCopy[prop];
extensionCopy[prop] = false;
extensionNames.splice(pos, 1);
}
return Reflect.deleteProperty(target, prop);
Expand Down