Skip to content

Commit b8bbc5b

Browse files
neildharfacebook-github-bot
authored andcommitted
Use handle for REPL result
Summary: The callRes PseudoHandle is held across allocations. Reviewed By: avp Differential Revision: D24483175 fbshipit-source-id: 0d41d56919bfac85c575bbc25a762a3d65e7025b
1 parent d66b9cb commit b8bbc5b

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

tools/hermes/repl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ int repl(const vm::RuntimeConfig &config) {
367367
}
368368
#endif
369369

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

425428
if (!ctx.jobsEmpty()) {
426429
// Run the jobs until there are no more.
427430
vm::MutableHandle<vm::Callable> job{runtime.get()};
428431
while (auto optJob = ctx.dequeueJob()) {
429432
job = std::move(*optJob);
430-
auto callRes = vm::Callable::executeCall0(
433+
auto jobCallRes = vm::Callable::executeCall0(
431434
job, runtime.get(), vm::Runtime::getUndefinedValue(), false);
432-
if (LLVM_UNLIKELY(callRes == vm::ExecutionStatus::EXCEPTION)) {
435+
if (LLVM_UNLIKELY(jobCallRes == vm::ExecutionStatus::EXCEPTION)) {
433436
threwException = true;
434437
runtime->printException(
435438
hasColors
@@ -446,7 +449,7 @@ int repl(const vm::RuntimeConfig &config) {
446449
continue;
447450
}
448451

449-
if ((*callRes)->isUndefined()) {
452+
if (resHandle->isUndefined()) {
450453
code.clear();
451454
continue;
452455
}
@@ -456,9 +459,7 @@ int repl(const vm::RuntimeConfig &config) {
456459
vm::operator<<(
457460
llvh::outs(),
458461
vm::StringPrimitive::createStringView(
459-
runtime.get(),
460-
vm::Handle<vm::StringPrimitive>::vmcast(
461-
runtime->makeHandle(std::move(*callRes))))
462+
runtime.get(), vm::Handle<vm::StringPrimitive>::vmcast(resHandle))
462463
.getUTF16Ref(tmp))
463464
<< "\n";
464465
code.clear();

0 commit comments

Comments
 (0)