Skip to content

Commit d8ce9fc

Browse files
fbmal7facebook-github-bot
authored andcommitted
Fix null pointer to proxy handler
Summary: Take a reference to the `handler` of the proxy before calling `findTrap`, as we currently do for `target`. This respects the spec, [10.5.8 [[Get]]](https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver). According to spec, here is the ordering of events ``` 1. Perform ? ValidateNonRevokedProxy(O). 2. Let target be O.[[ProxyTarget]]. 3. Let handler be O.[[ProxyHandler]]. .... 7. Let trapResult be ? Call(trap, handler, « target, P, Receiver »). ``` So, the very first thing we must do is take a reference to `handler` once we have established we are not a revoked proxy. Then, this handler is used as a reference elsewhere in the code. Reviewed By: neildhar Differential Revision: D47347863 fbshipit-source-id: c067481f0e776e3adfda8ba99782188ca21b89fc
1 parent 132de30 commit d8ce9fc

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/VM/JSProxy.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,12 @@ CallResult<PseudoHandle<>> JSProxy::getNamed(
944944
if (LLVM_UNLIKELY(depthTracker.overflowed())) {
945945
return runtime.raiseStackOverflow(Runtime::StackOverflowKind::NativeStack);
946946
}
947-
Handle<JSObject> target =
948-
runtime.makeHandle(detail::slots(*selfHandle).target);
947+
// Make sure to retrieve the target and handler before calling findTrap, as
948+
// that may result in these fields being erased if the proxy is revoked in the
949+
// handler.
950+
auto &slots = detail::slots(*selfHandle);
951+
Handle<JSObject> target = runtime.makeHandle(slots.target);
952+
Handle<JSObject> handler = runtime.makeHandle(slots.handler);
949953
CallResult<Handle<Callable>> trapRes =
950954
detail::findTrap(selfHandle, runtime, Predefined::get);
951955
if (trapRes == ExecutionStatus::EXCEPTION) {
@@ -962,7 +966,7 @@ CallResult<PseudoHandle<>> JSProxy::getNamed(
962966
runtime.getStringPrimFromSymbolID(name)))
963967
: runtime.makeHandle(name),
964968
*trapRes,
965-
runtime.makeHandle(detail::slots(*selfHandle).handler),
969+
handler,
966970
target,
967971
receiver);
968972
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// RUN: %hermes -O %s | %FileCheck %s
9+
10+
var handler = {
11+
get get() {
12+
revoke();
13+
return ()=>{
14+
gc();
15+
return () => { print("complete"); }
16+
};
17+
}
18+
};
19+
let { proxy, revoke } = Proxy.revocable([], handler);
20+
proxy.prop();
21+
// CHECK: complete

0 commit comments

Comments
 (0)