Coverage Report

Created: 2025-06-24 06:43

/src/hermes/lib/VM/JSLib/print.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "JSLibInternal.h"
9
10
#include "hermes/VM/Operations.h"
11
#include "hermes/VM/StringView.h"
12
13
#include "llvh/Support/raw_ostream.h"
14
15
namespace hermes {
16
namespace vm {
17
18
/// Convert all arguments to string and print them followed by new line.
19
5
CallResult<HermesValue> print(void *, Runtime &runtime, NativeArgs args) {
20
5
  GCScope scope(runtime);
21
5
  auto marker = scope.createMarker();
22
5
  bool first = true;
23
24
96.9k
  for (Handle<> arg : args.handles()) {
25
96.9k
    scope.flushToMarker(marker);
26
96.9k
    auto res = toString_RJS(runtime, arg);
27
96.9k
    if (res == ExecutionStatus::EXCEPTION)
28
0
      return ExecutionStatus::EXCEPTION;
29
30
96.9k
    if (!first)
31
96.9k
      llvh::outs() << " ";
32
96.9k
    SmallU16String<32> tmp;
33
96.9k
    llvh::outs() << StringPrimitive::createStringView(
34
96.9k
                        runtime, runtime.makeHandle(std::move(*res)))
35
96.9k
                        .getUTF16Ref(tmp);
36
96.9k
    first = false;
37
96.9k
  }
38
39
5
  llvh::outs() << "\n";
40
5
  llvh::outs().flush();
41
5
  return HermesValue::encodeUndefinedValue();
42
5
}
43
44
} // namespace vm
45
} // namespace hermes