Skip to content

Commit

Permalink
Use handle for REPL result
Browse files Browse the repository at this point in the history
Summary: The callRes PseudoHandle is held across allocations.

Reviewed By: avp

Differential Revision: D24483175

fbshipit-source-id: 0d41d56919bfac85c575bbc25a762a3d65e7025b
  • Loading branch information
neildhar authored and facebook-github-bot committed Oct 23, 2020
1 parent d66b9cb commit b8bbc5b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tools/hermes/repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ int repl(const vm::RuntimeConfig &config) {
}
#endif

vm::MutableHandle<> resHandle{runtime.get()};
// SetUnbuffered because there is no explicit flush after prompt (>>).
// There is also no explicitly flush at end of line. (An automatic flush
// mechanism is not guaranteed to be present, from my experiment on Windows)
Expand Down Expand Up @@ -420,16 +421,18 @@ int repl(const vm::RuntimeConfig &config) {
llvh::outs().resetColor();
code.clear();
threwException = true;
} else {
resHandle = std::move(*callRes);
}

if (!ctx.jobsEmpty()) {
// Run the jobs until there are no more.
vm::MutableHandle<vm::Callable> job{runtime.get()};
while (auto optJob = ctx.dequeueJob()) {
job = std::move(*optJob);
auto callRes = vm::Callable::executeCall0(
auto jobCallRes = vm::Callable::executeCall0(
job, runtime.get(), vm::Runtime::getUndefinedValue(), false);
if (LLVM_UNLIKELY(callRes == vm::ExecutionStatus::EXCEPTION)) {
if (LLVM_UNLIKELY(jobCallRes == vm::ExecutionStatus::EXCEPTION)) {
threwException = true;
runtime->printException(
hasColors
Expand All @@ -446,7 +449,7 @@ int repl(const vm::RuntimeConfig &config) {
continue;
}

if ((*callRes)->isUndefined()) {
if (resHandle->isUndefined()) {
code.clear();
continue;
}
Expand All @@ -456,9 +459,7 @@ int repl(const vm::RuntimeConfig &config) {
vm::operator<<(
llvh::outs(),
vm::StringPrimitive::createStringView(
runtime.get(),
vm::Handle<vm::StringPrimitive>::vmcast(
runtime->makeHandle(std::move(*callRes))))
runtime.get(), vm::Handle<vm::StringPrimitive>::vmcast(resHandle))
.getUTF16Ref(tmp))
<< "\n";
code.clear();
Expand Down

0 comments on commit b8bbc5b

Please sign in to comment.