Skip to content

Commit 7c8037f

Browse files
ExE-Bossdomenic
authored andcommitted
Improve generated Proxy code performance
By using a shared handler object, we get the performance increases record in #156 (comment).
1 parent be6cfcc commit 7c8037f

File tree

2 files changed

+950
-935
lines changed

2 files changed

+950
-935
lines changed

lib/constructs/interface.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class Interface {
582582
}
583583
}
584584

585-
generateLegacyProxy() {
585+
generateLegacyProxyHandler() {
586586
const hasIndexedSetter = this.indexedSetter !== null;
587587
const hasNamedSetter = this.namedSetter !== null;
588588
const hasNamedDeleter = this.namedDeleter !== null;
@@ -694,7 +694,7 @@ class Interface {
694694
};
695695

696696
this.str += `
697-
obj = new Proxy(obj, {
697+
const proxyHandler = {
698698
`;
699699

700700
// [[Get]] (necessary because of proxy semantics)
@@ -1094,7 +1094,7 @@ class Interface {
10941094
`;
10951095

10961096
this.str += `
1097-
});
1097+
};
10981098
`;
10991099
}
11001100

@@ -1142,7 +1142,9 @@ class Interface {
11421142
`;
11431143

11441144
if (this.isLegacyPlatformObj) {
1145-
this.generateLegacyProxy();
1145+
this.str += `
1146+
obj = new Proxy(obj, proxyHandler);
1147+
`;
11461148
}
11471149

11481150
this.str += `
@@ -1456,6 +1458,9 @@ class Interface {
14561458
this.generateExport();
14571459
this.generateIface();
14581460
this.generateInstall();
1461+
if (this.isLegacyPlatformObj) {
1462+
this.generateLegacyProxyHandler();
1463+
}
14591464

14601465
this.generateMixins();
14611466
this.generateRequires();

0 commit comments

Comments
 (0)