Skip to content

Commit 62bc9d1

Browse files
Alexey Shvaykaaperezdc
authored andcommitted
Cherry-pick 265870.535@safari-7616-branch (049d074). https://bugs.webkit.org/show_bug.cgi?id=261287
JSObject::anyObjectInChainMayInterceptIndexedAccesses and JSObject::didBecomePrototype need to account for JSGlobalProxy https://bugs.webkit.org/show_bug.cgi?id=261287 rdar://114860483 Reviewed by Yusuke Suzuki. Since JSObject::anyObjectInChainMayInterceptIndexedAccesses() walks up the [[Prototype]] chain, whenever an indexed property is defined on a JSGlobalObject, we should add MayHaveIndexedAccessors flag to JSGlobalProxy instead. Currently, mayInterceptIndexedAccesses() is never queried on JSGlobalObject instances. This change also fixes mayBePrototype() to be queried from JSGlobalProxy rather than JSGlobalObject, which is correct given setPrototypeDirect() used to call didBecomePrototype() only on the proxy. However, for extra robustness, this we propagate didBecomePrototype() to the global object as well. * JSTests/stress/regress-114860483.js: Added. * Source/JavaScriptCore/runtime/JSObjectInlines.h: (JSC::JSObject::didBecomePrototype): * Source/JavaScriptCore/runtime/JSObject.cpp: (JSC::JSObject::notifyPresenceOfIndexedAccessors): Canonical link: https://commits.webkit.org/265870.535@safari-7616-branch
1 parent e0e6399 commit 62bc9d1

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

JSTests/stress/regress-114860483.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function assertArgumentsContent() {
2+
const str = [...arguments].join();
3+
if (str !== `,1.1,1.1,1.1,1.1,1.1`)
4+
throw new Error("Bad assertion!");
5+
}
6+
7+
function createClonedArguments() {
8+
return arguments.callee.arguments;
9+
}
10+
11+
function main() {
12+
gc();
13+
14+
const global_proxy = this;
15+
Reflect.defineProperty(global_proxy, 0, {
16+
get() {
17+
for (let i = 100; i < 200; i++)
18+
cloned_arguments[i] = 1.1;
19+
20+
for (let i = 0; i < 100; i++)
21+
cloned_arguments[i] = 1.1;
22+
23+
gc();
24+
25+
// Creating invalid date objects.
26+
for (let i = 0; i < 100; i++) {
27+
new Date('a');
28+
}
29+
}
30+
});
31+
32+
const cloned_arguments = createClonedArguments(null, new Date(), new Date(), new Date(), new Date(), new Date());
33+
delete cloned_arguments[0];
34+
35+
Reflect.setPrototypeOf(cloned_arguments, global_proxy);
36+
37+
assertArgumentsContent.apply(null, cloned_arguments);
38+
}
39+
40+
main();

Source/JavaScriptCore/runtime/JSObject.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,11 @@ void JSObject::enterDictionaryIndexingMode(VM& vm)
11621162

11631163
void JSObject::notifyPresenceOfIndexedAccessors(VM& vm)
11641164
{
1165+
if (UNLIKELY(isGlobalObject())) {
1166+
jsCast<JSGlobalObject*>(this)->globalThis()->notifyPresenceOfIndexedAccessors(vm);
1167+
return;
1168+
}
1169+
11651170
if (mayInterceptIndexedAccesses())
11661171
return;
11671172

Source/JavaScriptCore/runtime/JSObjectInlines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ inline void JSObject::didBecomePrototype(VM& vm)
508508
DeferredStructureTransitionWatchpointFire deferred(vm, oldStructure);
509509
setStructure(vm, Structure::becomePrototypeTransition(vm, oldStructure, &deferred));
510510
}
511+
512+
if (UNLIKELY(type() == GlobalProxyType))
513+
jsCast<JSGlobalProxy*>(this)->target()->didBecomePrototype(vm);
511514
}
512515

513516
inline bool JSObject::canGetIndexQuicklyForTypedArray(unsigned i) const

0 commit comments

Comments
 (0)