Skip to content

Commit

Permalink
Fix assert when throwing a Proxy
Browse files Browse the repository at this point in the history
Summary:
Fix assertion fired when throwing a Proxy. We're removing the assert
because having a function that cannot be used when it's a particular
type of object is confusing.

Additionally, if the assert is removed, then we'd call `getParent` on
JSProxy. That means the JSProxy's prototype becomes observable. JSProxy
currently uses objectPrototype even though the prototype should just be
null. Since it'll become observable, we need to fix it properly now.

Reviewed By: neildhar

Differential Revision: D68246102

fbshipit-source-id: f99425fd4c441fb7236cf5a185a30564b60278c5
  • Loading branch information
dannysu authored and facebook-github-bot committed Jan 23, 2025
1 parent 7a10f20 commit 16abe15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 0 additions & 2 deletions include/hermes/VM/JSObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,6 @@ class JSObject : public GCCell {

/// \return the `__proto__` internal property, which may be nullptr.
JSObject *getParent(Runtime &runtime) const {
assert(
!flags_.proxyObject && "getParent cannot be used with proxy objects");
return parent_.get(runtime);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/VM/JSProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ void JSProxyBuildMeta(const GCCell *cell, Metadata::Builder &mb) {
PseudoHandle<JSProxy> JSProxy::create(Runtime &runtime) {
JSProxy *proxy = runtime.makeAFixed<JSProxy>(
runtime,
Handle<JSObject>::vmcast(&runtime.objectPrototype),
// Proxy should not have an observable prototype, so we just set it to
// null.
Runtime::makeNullHandle<JSObject>(),
runtime.getHiddenClassForPrototype(
runtime.objectPrototypeRawPtr, JSObject::numOverlapSlots<JSProxy>()));
nullptr, JSObject::numOverlapSlots<JSProxy>()));

proxy->flags_.proxyObject = true;

Expand Down

0 comments on commit 16abe15

Please sign in to comment.