Skip to content

Commit

Permalink
Assert that NativeConstructors return object when constructed
Browse files Browse the repository at this point in the history
Summary:
`NativeConstructor`s make their own `this` when constructed. This means
that we *must* be returning an object out of `NativeConstructor`s in
this situation. Add an assert for this invariant.

Reviewed By: tmikov

Differential Revision: D66511004

fbshipit-source-id: a9ed322f9197cf458e99e21f781cd9f5f59e71e1
  • Loading branch information
fbmal7 authored and facebook-github-bot committed Dec 18, 2024
1 parent be237c7 commit cf8cc6e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/VM/Callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,13 @@ CallResult<PseudoHandle<>> NativeConstructor::_callImpl(
newTarget.isUndefined() ||
vmisa<Callable>(newTarget) &&
"new.target for a NativeConstructor should either be undefined or a callable");
return NativeFunction::_callImpl(selfHandle, runtime);
auto res = NativeFunction::_callImpl(selfHandle, runtime);
if (LLVM_LIKELY(res != ExecutionStatus::EXCEPTION)) {
assert(
(newTarget.isUndefined() || vmisa<JSObject>(res->getHermesValue())) &&
"NativeConstructor needs to return an object when called as constructor.");
}
return res;
}
#endif

Expand Down

0 comments on commit cf8cc6e

Please sign in to comment.