Skip to content

Commit fad04e2

Browse files
committed
[JSC] Proxy.revocable should not set up the revoke function on each call
https://bugs.webkit.org/show_bug.cgi?id=328635 Reviewed by Yusuke Suzuki. On each call, Proxy.revocable atomized "proxy" and "revoke", added them to an empty object one by one, and allocated a ProxyRevoke (an InternalFunction) with its `length` and `name` properties. This patch makes the revoke function a JSFunctionWithFields whose NativeExecutable is cached in VM, as Promise resolving functions do, and caches the Structure of the result object in JSGlobalObject. ProxyRevoke is removed. The revoke function now behaves like other JSFunctions when its own keys are enumerated: `length` and `name` come first even after they are deleted and redefined, and the keys are not cached per Structure. Baseline Patched proxy-revocable 96.7449+-3.8240 ^ 33.5181+-1.7186 ^ definitely 2.8863x faster Tests: JSTests/microbenchmarks/proxy-revocable.js JSTests/stress/proxy-revocable-result-and-revoke-function.js * JSTests/microbenchmarks/proxy-revocable.js: Added. * JSTests/stress/proxy-revocable-result-and-revoke-function.js: Added. (shouldBe): (testResult): (testRevokeFunction): (testRevoke): * JSTests/wasm/ipint-tests/ipint-stress.wasm: * Source/JavaScriptCore/CMakeLists.txt: * Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj: * Source/JavaScriptCore/Sources.txt: * Source/JavaScriptCore/heap/Heap.h: * Source/JavaScriptCore/heap/HeapSubspaceTypes.h: * Source/JavaScriptCore/runtime/CommonIdentifiers.h: * Source/JavaScriptCore/runtime/JSFunctionWithFields.h: * Source/JavaScriptCore/runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): (JSC::JSGlobalObject::visitChildrenImpl): * Source/JavaScriptCore/runtime/JSGlobalObject.h: (JSC::JSGlobalObject::proxyRevocableResultStructure const): (JSC::JSGlobalObject::proxyRevokeStructure const): Deleted. * Source/JavaScriptCore/runtime/ProxyConstructor.cpp: (JSC::createProxyRevocableResultStructure): (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/ProxyConstructor.h: * Source/JavaScriptCore/runtime/ProxyRevoke.cpp: Removed. * Source/JavaScriptCore/runtime/ProxyRevoke.h: Removed. * Source/JavaScriptCore/runtime/ProxyRevokeInlines.h: Removed. * Source/JavaScriptCore/runtime/VM.cpp: (JSC::VM::proxyRevokeExecutableSlow): (JSC::VM::visitAggregateImpl): * Source/JavaScriptCore/runtime/VM.h: * Source/JavaScriptCore/runtime/VMInlines.h: Canonical link: https://commits.webkit.org/324788@main
1 parent 013c6a8 commit fad04e2

20 files changed

Lines changed: 177 additions & 208 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(function() {
2+
var target = {};
3+
var handler = {};
4+
5+
for (var i = 0; i < 1e6; ++i)
6+
Proxy.revocable(target, handler);
7+
})();
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
function shouldBe(actual, expected) {
2+
if (actual !== expected)
3+
throw new Error(`Bad value: ${actual}, expected: ${expected}`);
4+
}
5+
6+
function shouldThrow(func, errorType) {
7+
let error;
8+
try {
9+
func();
10+
} catch (e) {
11+
error = e;
12+
}
13+
if (!(error instanceof errorType))
14+
throw new Error(`Expected ${errorType.name}, got: ${error}`);
15+
}
16+
17+
function checkDescriptor(object, key, value, writable, enumerable, configurable) {
18+
let descriptor = Object.getOwnPropertyDescriptor(object, key);
19+
shouldBe(descriptor.value, value);
20+
shouldBe(descriptor.writable, writable);
21+
shouldBe(descriptor.enumerable, enumerable);
22+
shouldBe(descriptor.configurable, configurable);
23+
}
24+
25+
function testResult() {
26+
let result = Proxy.revocable({}, {});
27+
shouldBe(Object.getPrototypeOf(result), Object.prototype);
28+
shouldBe(JSON.stringify(Reflect.ownKeys(result)), `["proxy","revoke"]`);
29+
checkDescriptor(result, "proxy", result.proxy, true, true, true);
30+
checkDescriptor(result, "revoke", result.revoke, true, true, true);
31+
32+
let { proxy, revoke } = result;
33+
for (let i = 0; i < 10; ++i)
34+
result["p" + i] = i;
35+
shouldBe(result.proxy, proxy);
36+
shouldBe(result.revoke, revoke);
37+
for (let i = 0; i < 10; ++i)
38+
shouldBe(result["p" + i], i);
39+
shouldBe(delete result.proxy, true);
40+
shouldBe("proxy" in result, false);
41+
shouldBe(result.revoke, revoke);
42+
result.revoke = 42;
43+
shouldBe(result.revoke, 42);
44+
}
45+
46+
function testRevokeFunction() {
47+
let { revoke } = Proxy.revocable({}, {});
48+
shouldBe(typeof revoke, "function");
49+
shouldBe(Object.getPrototypeOf(revoke), Function.prototype);
50+
shouldBe(JSON.stringify(Reflect.ownKeys(revoke)), `["length","name"]`);
51+
checkDescriptor(revoke, "length", 0, false, false, true);
52+
checkDescriptor(revoke, "name", "", false, false, true);
53+
shouldBe(revoke.toString(), "function () {\n [native code]\n}");
54+
shouldThrow(() => new revoke, TypeError);
55+
shouldThrow(() => Reflect.construct(Object, [], revoke), TypeError);
56+
57+
revoke.extra = 1;
58+
shouldBe(delete revoke.name, true);
59+
shouldBe(JSON.stringify(Reflect.ownKeys(revoke)), `["length","extra"]`);
60+
shouldBe(revoke(), undefined);
61+
}
62+
63+
function testRevoke() {
64+
let target = { value: 1 };
65+
let first = Proxy.revocable(target, {});
66+
let second = Proxy.revocable(target, {});
67+
shouldBe(first.revoke === second.revoke, false);
68+
shouldBe(first.proxy.value, 1);
69+
shouldBe(second.proxy.value, 1);
70+
71+
shouldBe(first.revoke.call(second.proxy, second.proxy), undefined);
72+
shouldThrow(() => first.proxy.value, TypeError);
73+
shouldBe(second.proxy.value, 1);
74+
75+
shouldBe(first.revoke(), undefined);
76+
shouldBe(second.proxy.value, 1);
77+
78+
shouldBe(second.revoke(), undefined);
79+
shouldThrow(() => second.proxy.value, TypeError);
80+
}
81+
82+
function testCallableTarget() {
83+
let { proxy, revoke } = Proxy.revocable(function () { return 42; }, {});
84+
shouldBe(typeof proxy, "function");
85+
shouldBe(proxy(), 42);
86+
revoke();
87+
shouldBe(typeof proxy, "function");
88+
shouldThrow(() => proxy(), TypeError);
89+
shouldThrow(() => new proxy, TypeError);
90+
}
91+
92+
function testRealm() {
93+
let other = createGlobalObject();
94+
let result = other.Proxy.revocable({}, {});
95+
shouldBe(Object.getPrototypeOf(result), other.Object.prototype);
96+
shouldBe(Object.getPrototypeOf(result.revoke), other.Function.prototype);
97+
shouldBe(JSON.stringify(Reflect.ownKeys(result)), `["proxy","revoke"]`);
98+
result.revoke();
99+
shouldThrow(() => result.proxy.value, TypeError);
100+
}
101+
102+
testResult();
103+
testRevokeFunction();
104+
testCallableTarget();
105+
testRealm();
106+
for (let i = 0; i < testLoopCount; ++i)
107+
testRevoke();
-2.57 MB
Binary file not shown.

‎Source/JavaScriptCore/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,6 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
13821382
runtime/PrototypeKey.h
13831383
runtime/ProxyConstructor.h
13841384
runtime/ProxyObject.h
1385-
runtime/ProxyRevoke.h
13861385
runtime/PureNaN.h
13871386
runtime/PutDirectIndexMode.h
13881387
runtime/PutPropertySlot.h

‎Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,6 @@
13771377
73AD062923FF662600F53593 /* DeleteByStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 73AD062823FF662600F53593 /* DeleteByStatus.h */; };
13781378
790081391E95A8EC0052D7CD /* WasmModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 790081371E95A8EC0052D7CD /* WasmModule.h */; settings = {ATTRIBUTES = (Private, ); }; };
13791379
7905BB691D12050E0019FE57 /* InlineAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 7905BB671D12050E0019FE57 /* InlineAccess.h */; };
1380-
79160DBE1C8E3EC8008C085A /* ProxyRevoke.h in Headers */ = {isa = PBXBuildFile; fileRef = 79160DBC1C8E3EC8008C085A /* ProxyRevoke.h */; settings = {ATTRIBUTES = (Private, ); }; };
13811380
7919B7801E03559C005BEED8 /* B3Compile.h in Headers */ = {isa = PBXBuildFile; fileRef = 7919B77F1E03559C005BEED8 /* B3Compile.h */; settings = {ATTRIBUTES = (Private, ); }; };
13821381
79233C2B1D34715700C5A834 /* JITMathIC.h in Headers */ = {isa = PBXBuildFile; fileRef = 79233C291D34715700C5A834 /* JITMathIC.h */; };
13831382
79281BD120B62B3E002E2A60 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */; };
@@ -4347,7 +4346,6 @@
43474346
276B38BA2A71D25B00252F4E /* ProxyObjectInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyObjectInlines.h; sourceTree = "<group>"; };
43484347
276B38BB2A71D25B00252F4E /* JSAsyncFunctionInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAsyncFunctionInlines.h; sourceTree = "<group>"; };
43494348
276B38BC2A71D25B00252F4E /* JSModuleEnvironmentInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSModuleEnvironmentInlines.h; sourceTree = "<group>"; };
4350-
276B38FA2A71D2B100252F4E /* ProxyRevokeInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyRevokeInlines.h; sourceTree = "<group>"; };
43514349
276B38FB2A71D2B200252F4E /* JSStringIteratorInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringIteratorInlines.h; sourceTree = "<group>"; };
43524350
276B38FC2A71D2B200252F4E /* PropertyTableInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyTableInlines.h; sourceTree = "<group>"; };
43534351
276B38FD2A71D2B200252F4E /* NativeErrorConstructorInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeErrorConstructorInlines.h; sourceTree = "<group>"; };
@@ -5083,8 +5081,6 @@
50835081
790081371E95A8EC0052D7CD /* WasmModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmModule.h; sourceTree = "<group>"; };
50845082
7905BB661D12050E0019FE57 /* InlineAccess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineAccess.cpp; sourceTree = "<group>"; };
50855083
7905BB671D12050E0019FE57 /* InlineAccess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineAccess.h; sourceTree = "<group>"; };
5086-
79160DBB1C8E3EC8008C085A /* ProxyRevoke.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProxyRevoke.cpp; sourceTree = "<group>"; };
5087-
79160DBC1C8E3EC8008C085A /* ProxyRevoke.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyRevoke.h; sourceTree = "<group>"; };
50885084
7919B77F1E03559C005BEED8 /* B3Compile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3Compile.h; path = b3/B3Compile.h; sourceTree = "<group>"; };
50895085
79233C291D34715700C5A834 /* JITMathIC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITMathIC.h; sourceTree = "<group>"; };
50905086
79281BDC20B62B3E002E2A60 /* testmem */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testmem; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -9659,9 +9655,6 @@
96599655
79B00CBA1C6AB07E0088C65D /* ProxyObject.cpp */,
96609656
79B00CBB1C6AB07E0088C65D /* ProxyObject.h */,
96619657
276B38BA2A71D25B00252F4E /* ProxyObjectInlines.h */,
9662-
79160DBB1C8E3EC8008C085A /* ProxyRevoke.cpp */,
9663-
79160DBC1C8E3EC8008C085A /* ProxyRevoke.h */,
9664-
276B38FA2A71D2B100252F4E /* ProxyRevokeInlines.h */,
96659658
0F5780A118FE1E98001E72D9 /* PureNaN.h */,
96669659
0F0CD4C015F1A6040032F1C0 /* PutDirectIndexMode.h */,
96679660
147B84620E6DE6B1004775A4 /* PutPropertySlot.h */,
@@ -12795,7 +12788,6 @@
1279512788
276B38D72A71D26400252F4E /* ProxyConstructorInlines.h in Headers */,
1279612789
79B00CBF1C6AB07E0088C65D /* ProxyObject.h in Headers */,
1279712790
276B38DF2A71D26400252F4E /* ProxyObjectInlines.h in Headers */,
12798-
79160DBE1C8E3EC8008C085A /* ProxyRevoke.h in Headers */,
1279912791
0F5780A218FE1E98001E72D9 /* PureNaN.h in Headers */,
1280012792
0F15CD231BA5F9860031FFD3 /* PutByIdFlags.h in Headers */,
1280112793
0F9332A414CA7DD90085F3C6 /* PutByStatus.h in Headers */,

‎Source/JavaScriptCore/Sources.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,6 @@ runtime/PropertySlot.cpp
10391039
runtime/PropertyTable.cpp
10401040
runtime/ProxyConstructor.cpp
10411041
runtime/ProxyObject.cpp
1042-
runtime/ProxyRevoke.cpp
10431042
runtime/RandomizingFuzzerAgent.cpp
10441043
runtime/ReflectObject.cpp
10451044
runtime/RegExp.cpp

‎Source/JavaScriptCore/heap/Heap.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ class Heap;
268268
v(moduleNamespaceObjectSpace, moduleNamespaceObjectHeapCellType, JSModuleNamespaceObject) \
269269
v(nativeStdFunctionSpace, nativeStdFunctionHeapCellType, JSNativeStdFunction) \
270270
v(proxyObjectSpace, cellHeapCellType, ProxyObject) \
271-
v(proxyRevokeSpace, cellHeapCellType, ProxyRevoke) \
272271
v(rawJSONObjectSpace, cellHeapCellType, JSRawJSONObject) \
273272
v(scopedArgumentsTableSpace, destructibleCellHeapCellType, ScopedArgumentsTable) \
274273
v(setIteratorSpace, cellHeapCellType, JSSetIterator) \

‎Source/JavaScriptCore/heap/HeapSubspaceTypes.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
#include "NativeExecutable.h"
107107
#include "ProgramExecutable.h"
108108
#include "PropertyTable.h"
109-
#include "ProxyRevoke.h"
110109
#include "RegExpObject.h"
111110
#include "ScopedArguments.h"
112111
#include "StrictEvalActivation.h"

‎Source/JavaScriptCore/runtime/CommonIdentifiers.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
macro(profiledBytecodes) \
245245
macro(propertyIsEnumerable) \
246246
macro(prototype) \
247+
macro(proxy) \
247248
macro(raw) \
248249
macro(rawJSON) \
249250
macro(read) \
@@ -255,6 +256,7 @@
255256
macro(resolve) \
256257
macro(reject) \
257258
macro(reason) \
259+
macro(revoke) \
258260
macro(roundingIncrement) \
259261
macro(roundingMode) \
260262
macro(roundingPriority) \

‎Source/JavaScriptCore/runtime/JSFunctionWithFields.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class JSFunctionWithFields final : public JSFunction {
6060
PromiseAnyContext = 0,
6161
PromiseAnyReject = 1,
6262

63+
RevocableProxy = 0,
64+
6365
#if ENABLE(WEBASSEMBLY)
6466
WebAssemblySuspendingWrappedCallable = 0,
6567
WebAssemblyPromisingWrappedFunction = 0,

0 commit comments

Comments
 (0)