Skip to content

Commit

Permalink
Merge branch 'facebook:main' into convert-facebook-hermes-to-actions-…
Browse files Browse the repository at this point in the history
…20240206-163511
  • Loading branch information
robandpdx authored Mar 7, 2024
2 parents eabe5e4 + 2a57eeb commit bc1eacf
Show file tree
Hide file tree
Showing 197 changed files with 1,373,289 additions and 1,534,617 deletions.
24 changes: 15 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,24 +321,29 @@ jobs:
test-windows:
executor:
name: win/default
version: 2023.10.1
environment:
- CMAKE_DIR: 'C:\Program Files\CMake\bin'
steps:
- checkout:
path: hermes
- run:
name: Set up dependencies
command: |
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
ln -s C:\tools\miniconda3\python C:\tools\miniconda3\python3
choco install -y --no-progress cmake --version 3.14.7 --installargs 'ADD_CMAKE_TO_PATH=System'
if (-not $?) { throw "Failed to install CMake" }
ln -s (get-command python.exe).Path (get-command python.exe).Path.replace("python.exe", "python3.exe")
- run:
name: Run Hermes regression tests
command: |
$Env:PATH += ";$Env:CMAKE_DIR"
cmake -S hermes -B build -G 'Visual Studio 16 2019'
cmake --build build --target check-hermes -- -m /p:UseMultiToolTask=true -m /p:EnforceProcessCountAcrossBuilds=true
windows:
executor:
name: win/default
shell: powershell.exe
version: 2023.10.1
environment:
- HERMES_WS_DIR: 'C:\tmp\hermes'
- ICU_URL: "https://github.com/unicode-org/icu/releases/download/release-64-2/icu4c-64_2-Win64-MSVC2017.zip"
Expand Down Expand Up @@ -371,10 +376,9 @@ jobs:
- run:
name: Install dependencies
command: |
choco install --no-progress cmake --version 3.14.7 --installargs 'ADD_CMAKE_TO_PATH=System'
choco install -y --no-progress cmake --version 3.14.7 --installargs 'ADD_CMAKE_TO_PATH=System'
if (-not $?) { throw "Failed to install CMake" }
choco install --no-progress python3
if (-not $?) { throw "Failed to install Python" }
ln -s (get-command python.exe).Path (get-command python.exe).Path.replace("python.exe", "python3.exe")
- run:
name: Assemble Windows runtime dependencies
Expand All @@ -389,7 +393,7 @@ jobs:
- run:
name: Build Windows CLI
command: |
$Env:PATH += ";$Env:MSBUILD_DIR"
$Env:PATH += ";$Env:MSBUILD_DIR;$Env:CMAKE_DIR"
$Env:ICU_ROOT = "$Env:HERMES_WS_DIR\icu"
cd $Env:HERMES_WS_DIR
cmake -S hermes -B build -G 'Visual Studio 16 2019' -Ax64 -DHERMES_ENABLE_DEBUGGER=False $Env:RELEASE_FLAGS
Expand All @@ -404,6 +408,7 @@ jobs:
- run:
name: Create CLI tarball
command: |
$Env:PATH += ";$Env:CMAKE_DIR"
cd $Env:HERMES_WS_DIR
Copy-Item -Path "build\bin\Release\hermes.exe" -Destination "staging"
Copy-Item -Path "build\bin\Release\hvm.exe" -Destination "staging"
Expand Down Expand Up @@ -579,7 +584,8 @@ jobs:
-DCMAKE_BUILD_TYPE=Debug -DHERMES_UNICODE_LITE=ON \
-DCMAKE_CXX_FLAGS=-O2 -DCMAKE_C_FLAGS=-O2 \
-DCMAKE_EXE_LINKER_FLAGS="-sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=256KB" \
-DHERMES_ENABLE_DEBUGGER=OFF -DHERMES_SLOW_DEBUG=OFF
-DHERMES_ENABLE_DEBUGGER=OFF -DHERMES_SLOW_DEBUG=OFF \
-DHERMES_IS_MOBILE_BUILD=ON
cmake --build build_wasm_dbg --target hermesSandboxImpl -j 4
./wabt-1.0.33/bin/wasm2c build_wasm_dbg/API/hermes_sandbox/hermesSandboxImpl.wasm -n hermes \
Expand All @@ -591,7 +597,7 @@ jobs:
-DIMPORT_HERMESC=build_host/ImportHermesc.cmake \
-DCMAKE_BUILD_TYPE=Release -DHERMES_UNICODE_LITE=ON \
-DCMAKE_EXE_LINKER_FLAGS="-sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=256KB -g2" \
-DHERMES_ENABLE_DEBUGGER=OFF
-DHERMES_ENABLE_DEBUGGER=OFF -DHERMES_IS_MOBILE_BUILD=ON
cmake --build build_wasm_opt --target hermesSandboxImpl -j 4
./wabt-1.0.33/bin/wasm2c build_wasm_opt/API/hermes_sandbox/hermesSandboxImpl.wasm -n hermes \
Expand Down
15 changes: 13 additions & 2 deletions API/hermes/AsyncDebuggerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@
#include <hermes/DebuggerAPI.h>
#include <hermes/Public/HermesExport.h>
#include <hermes/hermes.h>
#include <hermes/inspector/chrome/ThreadSafetyAnalysis.h>

#if defined(__clang__) && (!defined(SWIG)) && \
defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
#include <hermes/ThreadSafetyAnalysis.h>
#else
#ifndef TSA_GUARDED_BY
#define TSA_GUARDED_BY(x)
#endif
#ifndef TSA_NO_THREAD_SAFETY_ANALYSIS
#define TSA_NO_THREAD_SAFETY_ANALYSIS
#endif
#endif

namespace facebook {
namespace hermes {
Expand Down Expand Up @@ -83,7 +94,7 @@ class HERMES_EXPORT AsyncDebuggerAPI : private debugger::EventObserver {
/// Must be destroyed on the runtime thread or when you're sure nothing is
/// interacting with the runtime. Must be destroyed before destroying
/// HermesRuntime.
~AsyncDebuggerAPI();
~AsyncDebuggerAPI() override;

/// Add a callback function to invoke when the runtime pauses due to various
/// conditions such as hitting a "debugger;" statement. Can be called from any
Expand Down
13 changes: 13 additions & 0 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ if(HERMES_ENABLE_DEBUGGER)
# Some inspector sources need to be built without RTTI because they consume
# internal data structures compiled without RTTI.
set(INSPECTOR_NO_EH_RTTI_SOURCES
cdp/JSONValueInterfaces.cpp
cdp/MessageConverters.cpp
cdp/MessageInterfaces.cpp
cdp/MessageTypes.cpp
inspector/chrome/JSONValueInterfaces.cpp
inspector/chrome/MessageConverters.cpp
inspector/chrome/MessageInterfaces.cpp
Expand All @@ -32,8 +36,15 @@ if(HERMES_ENABLE_DEBUGGER)

set(CDP_API_SOURCES
cdp/CDPAgent.cpp
cdp/CallbackOStream.cpp
cdp/ConsoleMessage.cpp
cdp/DebuggerDomainAgent.cpp
cdp/ProfilerDomainAgent.cpp
cdp/RemoteObjectConverters.cpp
cdp/RemoteObjectsTable.cpp
cdp/RuntimeDomainAgent.cpp
cdp/ConsoleMessage.cpp
cdp/CDPDebugAPI.cpp
)

set(INSPECTOR_API_SOURCES
Expand All @@ -55,6 +66,8 @@ add_hermes_library(synthTraceParser SynthTraceParser.cpp LINK_LIBS hermesSupport
# All remaining targets in this file use both exceptions and RTTI.
set(HERMES_ENABLE_EH_RTTI ON)

add_subdirectory(cdp)

# List the files that define exported functions explicitly, and they can link
# against the internal functionality they need.
set(api_sources
Expand Down
15 changes: 15 additions & 0 deletions API/hermes/SynthTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ bool SynthTrace::CreateObjectRecord::operator==(const Record &that) const {
return objID_ == thatCasted.objID_;
}

bool SynthTrace::QueueMicrotaskRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
}
const auto &thatCasted = dynamic_cast<const QueueMicrotaskRecord &>(that);
return callbackID_ == thatCasted.callbackID_;
}

bool SynthTrace::DrainMicrotasksRecord::operator==(const Record &that) const {
if (!Record::operator==(that)) {
return false;
Expand Down Expand Up @@ -634,6 +642,11 @@ void SynthTrace::HasPropertyRecord::toJSONInternal(JSONEmitter &json) const {
#endif
}

void SynthTrace::QueueMicrotaskRecord::toJSONInternal(JSONEmitter &json) const {
Record::toJSONInternal(json);
json.emitKeyValue("callbackID", callbackID_);
}

void SynthTrace::DrainMicrotasksRecord::toJSONInternal(
JSONEmitter &json) const {
Record::toJSONInternal(json);
Expand Down Expand Up @@ -831,6 +844,7 @@ llvh::raw_ostream &operator<<(
CASE(CreatePropNameID);
CASE(CreateHostObject);
CASE(CreateHostFunction);
CASE(QueueMicrotask);
CASE(DrainMicrotasks);
CASE(GetProperty);
CASE(SetProperty);
Expand Down Expand Up @@ -877,6 +891,7 @@ std::istream &operator>>(std::istream &is, SynthTrace::RecordType &type) {
CASE(CreatePropNameID)
CASE(CreateHostObject)
CASE(CreateHostFunction)
CASE(QueueMicrotask)
CASE(DrainMicrotasks)
CASE(GetProperty)
CASE(SetProperty)
Expand Down
21 changes: 21 additions & 0 deletions API/hermes/SynthTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class SynthTrace {
CreatePropNameID,
CreateHostObject,
CreateHostFunction,
QueueMicrotask,
DrainMicrotasks,
GetProperty,
SetProperty,
Expand Down Expand Up @@ -723,6 +724,26 @@ class SynthTrace {
void toJSONInternal(::hermes::JSONEmitter &json) const override;
};

struct QueueMicrotaskRecord : public Record {
static constexpr RecordType type{RecordType::QueueMicrotask};
const ObjectID callbackID_;

QueueMicrotaskRecord(TimeSinceStart time, ObjectID callbackID)
: Record(time), callbackID_(callbackID) {}

bool operator==(const Record &that) const final;

RecordType getType() const override {
return type;
}

void toJSONInternal(::hermes::JSONEmitter &json) const override;

std::vector<ObjectID> uses() const override {
return {callbackID_};
}
};

struct DrainMicrotasksRecord : public Record {
static constexpr RecordType type{RecordType::DrainMicrotasks};
int maxMicrotasksHint_;
Expand Down
7 changes: 7 additions & 0 deletions API/hermes/SynthTraceParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ SynthTrace getTrace(JSONArray *array, SynthTrace::ObjectID globalObjID) {
trace.emplace_back<SynthTrace::CreateObjectRecord>(
timeFromStart, objID->getValue());
break;
case RecordType::QueueMicrotask: {
auto callbackID =
getNumberAs<SynthTrace::ObjectID>(obj->get("callbackID"));
trace.emplace_back<SynthTrace::QueueMicrotaskRecord>(
timeFromStart, callbackID);
break;
}
case RecordType::DrainMicrotasks: {
int maxMicrotasksHint = getNumberAs<int>(obj->get("maxMicrotasksHint"));
trace.emplace_back<SynthTrace::DrainMicrotasksRecord>(
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions API/hermes/TraceInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,14 @@ Value TraceInterpreter::execFunction(
locals);
break;
}
case RecordType::QueueMicrotask: {
const auto &queueRecord =
static_cast<const SynthTrace::QueueMicrotaskRecord &>(*rec);
jsi::Function callback =
getObjForUse(queueRecord.callbackID_).asFunction(rt_);
rt_.queueMicrotask(callback);
break;
}
case RecordType::DrainMicrotasks: {
const auto &drainRecord =
static_cast<const SynthTrace::DrainMicrotasksRecord &>(*rec);
Expand Down
6 changes: 6 additions & 0 deletions API/hermes/TracingRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ jsi::Value TracingRuntime::evaluateJavaScript(
return res;
}

void TracingRuntime::queueMicrotask(const jsi::Function &callback) {
RD::queueMicrotask(callback);
trace_.emplace_back<SynthTrace::QueueMicrotaskRecord>(
getTimeSinceStart(), getUniqueID(callback));
}

bool TracingRuntime::drainMicrotasks(int maxMicrotasksHint) {
auto res = RD::drainMicrotasks(maxMicrotasksHint);
trace_.emplace_back<SynthTrace::DrainMicrotasksRecord>(
Expand Down
1 change: 1 addition & 0 deletions API/hermes/TracingRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TracingRuntime : public jsi::RuntimeDecorator<jsi::Runtime> {
const std::shared_ptr<const jsi::Buffer> &buffer,
const std::string &sourceURL) override;

void queueMicrotask(const jsi::Function &callback) override;
bool drainMicrotasks(int maxMicrotasksHint = -1) override;

jsi::Object createObject() override;
Expand Down
Loading

0 comments on commit bc1eacf

Please sign in to comment.