Base code for node-hermes
Summary: Baseline code, basically the same as jsi to initialize the folder. Just for coherency as more commits are added right now, since there is nothing really new here. #utd-hermes-ignore-wasm Reviewed By: avp Differential Revision: D28818665 fbshipit-source-id: 7452646d8bf8913c97d321cd7ed80102dad780ac
This commit is contained in:
Родитель
63792f543a
Коммит
2ff7dbad6a
|
@ -651,6 +651,7 @@ if(HERMES_ENABLE_TEST_SUITE)
|
|||
hbc-deltaprep
|
||||
hbc-diff
|
||||
dependency-extractor
|
||||
node-hermes
|
||||
)
|
||||
|
||||
set(coverage_directory "")
|
||||
|
@ -672,6 +673,7 @@ if(HERMES_ENABLE_TEST_SUITE)
|
|||
hbcdump=${HERMES_TOOLS_OUTPUT_DIR}/hbcdump
|
||||
hbc-deltaprep=${HERMES_TOOLS_OUTPUT_DIR}/hbc-deltaprep
|
||||
hbc_diff=${HERMES_TOOLS_OUTPUT_DIR}/hbc-diff
|
||||
node-hermes=${HERMES_TOOLS_OUTPUT_DIR}/node-hermes
|
||||
build_mode=${HERMES_ASSUMED_BUILD_MODE_IN_LIT_TEST}
|
||||
exception_on_oom_enabled=${HERMESVM_EXCEPTION_ON_OOM}
|
||||
serialize_enabled=${HERMESVM_SERIALIZE}
|
||||
|
|
|
@ -90,3 +90,5 @@ if lit_config.params.get("hbc_diff"):
|
|||
config.substitutions.append(("%hbc-diff", lit_config.params["hbc_diff"].replace('\\', '/')))
|
||||
if lit_config.params.get("dependency_extractor"):
|
||||
config.substitutions.append(("%dependency-extractor", lit_config.params["dependency_extractor"].replace('\\', '/')))
|
||||
if lit_config.params.get("node-hermes"):
|
||||
config.substitutions.append(("%node-hermes", lit_config.params["node-hermes"].replace('\\', '/')))
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
// RUN: %node-hermes %s | %FileCheck --match-full-lines %s
|
||||
|
||||
print('No Requires');
|
||||
// CHECK-LABEL: No Requires
|
||||
|
||||
var x = 5;
|
||||
print(x);
|
||||
// CHECK-NEXT: 5
|
|
@ -17,4 +17,5 @@ add_subdirectory(emhermesc)
|
|||
add_subdirectory(fuzzers)
|
||||
add_subdirectory(dependency-extractor)
|
||||
add_subdirectory(hermes-parser)
|
||||
add_subdirectory(node-hermes)
|
||||
add_subdirectory(synth)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
include_directories(${HERMES_SOURCE_DIR}/API)
|
||||
include_directories(${HERMES_JSI_DIR})
|
||||
|
||||
set(HERMES_ENABLE_EH ON)
|
||||
set(CXX_STANDARD 14)
|
||||
set(CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_hermes_tool(node-hermes
|
||||
node-hermes.cpp
|
||||
${ALL_HEADER_FILES}
|
||||
LINK_LIBS hermesapi
|
||||
)
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "hermes/Support/OSCompat.h"
|
||||
#include "hermes/hermes.h"
|
||||
|
||||
#include "llvh/Support/CommandLine.h"
|
||||
#include "llvh/Support/FileSystem.h"
|
||||
#include "llvh/Support/InitLLVM.h"
|
||||
#include "llvh/Support/MemoryBuffer.h"
|
||||
#include "llvh/Support/PrettyStackTrace.h"
|
||||
#include "llvh/Support/Program.h"
|
||||
#include "llvh/Support/Signals.h"
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
// -help options
|
||||
static llvh::cl::opt<std::string> EvalScript(
|
||||
"eval",
|
||||
llvh::cl::desc("evaluate script"),
|
||||
llvh::cl::value_desc("script"));
|
||||
|
||||
static llvh::cl::opt<std::string> InputFilename(
|
||||
llvh::cl::Positional,
|
||||
llvh::cl::desc("<file>"),
|
||||
llvh::cl::init("-"));
|
||||
|
||||
class FileBuffer : public jsi::Buffer {
|
||||
public:
|
||||
static std::shared_ptr<jsi::Buffer> bufferFromFile(llvh::StringRef path) {
|
||||
auto fileBuffer = llvh::MemoryBuffer::getFileOrSTDIN(path);
|
||||
if (!fileBuffer)
|
||||
return nullptr;
|
||||
return std::make_shared<FileBuffer>(std::move(*fileBuffer));
|
||||
}
|
||||
|
||||
FileBuffer(std::unique_ptr<llvh::MemoryBuffer> buffer)
|
||||
: buffer_(std::move(buffer)){};
|
||||
size_t size() const override {
|
||||
return buffer_->getBufferSize();
|
||||
}
|
||||
const uint8_t *data() const override {
|
||||
return reinterpret_cast<const uint8_t *>(buffer_->getBufferStart());
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<llvh::MemoryBuffer> buffer_;
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Normalize the arg vector.
|
||||
llvh::InitLLVM initLLVM(argc, argv);
|
||||
// Print a stack trace if we signal out.
|
||||
llvh::sys::PrintStackTraceOnErrorSignal("Node Hermes");
|
||||
llvh::PrettyStackTraceProgram X(argc, argv);
|
||||
// Call llvm_shutdown() on exit to print stats and free memory.
|
||||
llvh::llvm_shutdown_obj Y;
|
||||
|
||||
llvh::cl::ParseCommandLineOptions(argc, argv, "Node Hermes \n");
|
||||
|
||||
// Suppress any ASAN leak complaints for the alt signal stack on exit.
|
||||
::hermes::oscompat::SigAltStackLeakSuppressor sigAltLeakSuppressor;
|
||||
|
||||
if (!EvalScript.empty() && InputFilename != "-") {
|
||||
llvh::errs() << "Cannot use both --eval <script> and <file>" << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
auto jsiBuffer = !EvalScript.empty()
|
||||
? std::make_shared<jsi::StringBuffer>(EvalScript)
|
||||
: FileBuffer::bufferFromFile(InputFilename);
|
||||
|
||||
if (!jsiBuffer) {
|
||||
llvh::errs() << "Error! Failed to open file: " << InputFilename << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::string srcPath = !EvalScript.empty() ? "<eval>"
|
||||
: InputFilename == "-" ? "<stdin>"
|
||||
: std::string(InputFilename);
|
||||
|
||||
auto runtime = facebook::hermes::makeHermesRuntime();
|
||||
|
||||
try {
|
||||
// add function headers for require, value of last expression becomes the
|
||||
// return value
|
||||
auto result = runtime->evaluateJavaScript(jsiBuffer, srcPath);
|
||||
|
||||
} catch (const jsi::JSIException &e) {
|
||||
llvh::errs() << "JavaScript terminated via uncaught exception: " << e.what()
|
||||
<< '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Загрузка…
Ссылка в новой задаче