Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
acquitelol committed Oct 23, 2024
2 parents 24c4ee0 + d964f6b commit e137569
Show file tree
Hide file tree
Showing 92 changed files with 2,088 additions and 532 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ jobs:
-destination 'platform=visionOS Simulator,name=Apple Vision Pro' \
-scheme ApplePlatformsIntegrationVisionOSTests
working_directory: test/ApplePlatformsIntegrationTestApp
- run:
name: Test Apple TV application
command: |
xcodebuild test \
-workspace ApplePlatformsIntegrationTests.xcworkspace \
-configuration Debug \
-destination 'platform=tvOS Simulator,name=Apple TV' \
-scheme ApplePlatformsIntegrationTVOSTests
working_directory: test/ApplePlatformsIntegrationTestApp

build-apple-runtime:
<<: *apple_defaults
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/AsyncDebuggerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <hermes/Public/HermesExport.h>
#include <hermes/hermes.h>

#if defined(__clang__) && (!defined(SWIG)) && \
#if defined(__clang__) && (!defined(SWIG)) && defined(_LIBCPP_VERSION) && \
defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
#include <hermes/ThreadSafetyAnalysis.h>
#else
Expand Down
4 changes: 4 additions & 0 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ if(APPLE AND HERMES_BUILD_APPLE_FRAMEWORK)
add_custom_command(TARGET libhermes POST_BUILD
COMMAND /usr/libexec/PlistBuddy -c "Add :MinimumOSVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:libhermes>/Info.plist
)
elseif(HERMES_APPLE_TARGET_PLATFORM MATCHES "appletv")
add_custom_command(TARGET libhermes POST_BUILD
COMMAND /usr/libexec/PlistBuddy -c "Add :MinimumOSVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:libhermes>/Info.plist
)
elseif(HERMES_APPLE_TARGET_PLATFORM MATCHES "catalyst")
add_custom_command(TARGET libhermes POST_BUILD
COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:libhermes>/Resources/Info.plist
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/ThreadSafetyAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Enable thread safety attributes only with clang.
// The attributes can be safely erased when compiling with other compilers.
#if defined(__clang__) && (!defined(SWIG)) && \
#if defined(__clang__) && (!defined(SWIG)) && defined(_LIBCPP_VERSION) && \
defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
#define TSA_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#else
Expand Down
67 changes: 57 additions & 10 deletions API/hermes/TracingRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ void TracingRuntime::replaceNondeterministicFuncs() {
auto fun = args[0].getObject(*runtime_).getFunction(*runtime_);
jsi::Value result;
if (count > 1 && args[1].isObject()) {
result = fun.callWithThis(*runtime_, args[1].asObject(*runtime_));
result = fun.callWithThis(
*runtime_, args[1].asObject(*runtime_), &args[2], count - 2);
} else {
result = fun.call(*runtime_);
}
Expand Down Expand Up @@ -181,25 +182,71 @@ void TracingRuntime::replaceNondeterministicFuncs() {
globalThis.WeakRef = WeakRef;
}
// Trace date getters and conversion functions as they can produce values
// that depend on the execution environment's timezone. Setters can set
// values that use the timezone, but the effect will not be observable
// because of the overridden getters.
var DateReal = globalThis.Date;
var dateNowReal = DateReal.now;
var nativeDateNow = function now() { return callUntraced(dateNowReal); };
[
"getDate",
"getDay",
"getFullYear",
"getHours",
"getMilliseconds",
"getMinutes",
"getMonth",
"getSeconds",
"getTime",
"getTimezoneOffset",
"getUTCDate",
"getUTCDay",
"getUTCFullYear",
"getUTCHours",
"getUTCMilliseconds",
"getUTCMinutes",
"getUTCMonth",
"getUTCSeconds",
"getYear",
"toDateString",
"toGMTString",
"toISOString",
"toJSON",
"toLocaleDateString",
"toLocaleString",
"toLocaleTimeString",
"toString",
"toTimeString",
"toUTCString",
"valueOf",
Symbol.toPrimitive
].forEach((property) => {
const original = DateReal.prototype[property];
const replacement = function(...args) {
return callUntraced(original, this, ...args);
};
Object.defineProperty(replacement, "name", {value: original.name});
Object.defineProperty(DateReal.prototype, property, {
value: replacement,
writable: true,
configurable: true
});
});
function Date(...args){
// Convert non-deterministic calls like `Date()` and `new Date()` into the
// deterministic form `new Date(Date.now())`, so they can be traced.
// Trace calls to `Date()`.
if(!new.target){
return new DateReal(nativeDateNow()).toString();
}
if (arguments.length == 0){
return new DateReal(nativeDateNow());
return callUntraced(DateReal);
}
// While `new Date()` technically records the current time, there is no way
// to observe it since we override all the getters.
return new DateReal(...args);
}
// Cannot use Object.assign because Date methods are not enumerable
for (p of Object.getOwnPropertyNames(DateReal)){
Date[p] = DateReal[p];
}
Date.now = nativeDateNow;
var dateNowReal = DateReal.now;
Date.now = function now() { return callUntraced(dateNowReal); };
globalThis.Date = Date;
const defineProperty = Object.defineProperty;
Expand Down
231 changes: 136 additions & 95 deletions API/hermes/cdp/CDPAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ CDPAgentImpl::DomainAgentsImpl::~DomainAgentsImpl() {
}
}

/// Remove the prefix \p prefix from \p str if it exists. \returns true if the
/// prefix was matched and removed, false otherwise.
static bool removePrefix(std::string_view &str, std::string_view prefix) {
// TODO: Use starts_with when we can use C++20.
if (str.size() >= prefix.size() && str.substr(0, prefix.size()) == prefix) {
str.remove_prefix(prefix.size());
return true;
}
return false;
}

void CDPAgentImpl::DomainAgentsImpl::handleCommand(
std::shared_ptr<message::Request> command) {
size_t domainLength = command->method.find('.');
Expand All @@ -367,102 +378,132 @@ void CDPAgentImpl::DomainAgentsImpl::handleCommand(
.toJsonStr());
return;
}
std::string domain = command->method.substr(0, domainLength);

// TODO: Do better dispatch
if (command->method == "Debugger.enable") {
debuggerAgent_->enable(static_cast<m::debugger::EnableRequest &>(*command));
} else if (command->method == "Debugger.disable") {
debuggerAgent_->disable(
static_cast<m::debugger::DisableRequest &>(*command));
} else if (command->method == "Debugger.pause") {
debuggerAgent_->pause(static_cast<m::debugger::PauseRequest &>(*command));
} else if (command->method == "Debugger.resume") {
debuggerAgent_->resume(static_cast<m::debugger::ResumeRequest &>(*command));
} else if (command->method == "Debugger.stepInto") {
debuggerAgent_->stepInto(
static_cast<m::debugger::StepIntoRequest &>(*command));
} else if (command->method == "Debugger.stepOut") {
debuggerAgent_->stepOut(
static_cast<m::debugger::StepOutRequest &>(*command));
} else if (command->method == "Debugger.stepOver") {
debuggerAgent_->stepOver(
static_cast<m::debugger::StepOverRequest &>(*command));
} else if (command->method == "Debugger.setPauseOnExceptions") {
debuggerAgent_->setPauseOnExceptions(
static_cast<m::debugger::SetPauseOnExceptionsRequest &>(*command));
} else if (command->method == "Debugger.evaluateOnCallFrame") {
debuggerAgent_->evaluateOnCallFrame(
static_cast<m::debugger::EvaluateOnCallFrameRequest &>(*command));
} else if (command->method == "Debugger.setBreakpoint") {
debuggerAgent_->setBreakpoint(
static_cast<m::debugger::SetBreakpointRequest &>(*command));
} else if (command->method == "Debugger.setBreakpointByUrl") {
debuggerAgent_->setBreakpointByUrl(
static_cast<m::debugger::SetBreakpointByUrlRequest &>(*command));
} else if (command->method == "Debugger.removeBreakpoint") {
debuggerAgent_->removeBreakpoint(
static_cast<m::debugger::RemoveBreakpointRequest &>(*command));
} else if (command->method == "Debugger.setBreakpointsActive") {
debuggerAgent_->setBreakpointsActive(
static_cast<m::debugger::SetBreakpointsActiveRequest &>(*command));
} else if (command->method == "Runtime.enable") {
runtimeAgent_->enable(static_cast<m::runtime::EnableRequest &>(*command));
} else if (command->method == "Runtime.disable") {
runtimeAgent_->disable(static_cast<m::runtime::DisableRequest &>(*command));
} else if (command->method == "Runtime.getHeapUsage") {
runtimeAgent_->getHeapUsage(
static_cast<m::runtime::GetHeapUsageRequest &>(*command));
} else if (command->method == "Runtime.globalLexicalScopeNames") {
runtimeAgent_->globalLexicalScopeNames(
static_cast<m::runtime::GlobalLexicalScopeNamesRequest &>(*command));
} else if (command->method == "Runtime.compileScript") {
runtimeAgent_->compileScript(
static_cast<m::runtime::CompileScriptRequest &>(*command));
} else if (command->method == "Runtime.getProperties") {
runtimeAgent_->getProperties(
static_cast<m::runtime::GetPropertiesRequest &>(*command));
} else if (command->method == "Runtime.evaluate") {
runtimeAgent_->evaluate(
static_cast<m::runtime::EvaluateRequest &>(*command));
} else if (command->method == "Runtime.callFunctionOn") {
runtimeAgent_->callFunctionOn(
static_cast<m::runtime::CallFunctionOnRequest &>(*command));
} else if (command->method == "Runtime.discardConsoleEntries") {
runtimeAgent_->discardConsoleEntries(
static_cast<m::runtime::DiscardConsoleEntriesRequest &>(*command));
} else if (command->method == "Profiler.start") {
profilerAgent_->start(static_cast<m::profiler::StartRequest &>(*command));
} else if (command->method == "Profiler.stop") {
profilerAgent_->stop(static_cast<m::profiler::StopRequest &>(*command));
} else if (command->method == "HeapProfiler.takeHeapSnapshot") {
heapProfilerAgent_->takeHeapSnapshot(
static_cast<m::heapProfiler::TakeHeapSnapshotRequest &>(*command));
} else if (command->method == "HeapProfiler.getObjectByHeapObjectId") {
heapProfilerAgent_->getObjectByHeapObjectId(
static_cast<m::heapProfiler::GetObjectByHeapObjectIdRequest &>(
*command));
} else if (command->method == "HeapProfiler.getHeapObjectId") {
heapProfilerAgent_->getHeapObjectId(
static_cast<m::heapProfiler::GetHeapObjectIdRequest &>(*command));
} else if (command->method == "HeapProfiler.collectGarbage") {
heapProfilerAgent_->collectGarbage(
static_cast<m::heapProfiler::CollectGarbageRequest &>(*command));
} else if (command->method == "HeapProfiler.startTrackingHeapObjects") {
heapProfilerAgent_->startTrackingHeapObjects(
static_cast<m::heapProfiler::StartTrackingHeapObjectsRequest &>(
*command));
} else if (command->method == "HeapProfiler.stopTrackingHeapObjects") {
heapProfilerAgent_->stopTrackingHeapObjects(
static_cast<m::heapProfiler::StopTrackingHeapObjectsRequest &>(
*command));
} else if (command->method == "HeapProfiler.startSampling") {
heapProfilerAgent_->startSampling(
static_cast<m::heapProfiler::StartSamplingRequest &>(*command));
} else if (command->method == "HeapProfiler.stopSampling") {
heapProfilerAgent_->stopSampling(
static_cast<m::heapProfiler::StopSamplingRequest &>(*command));
std::string_view method = command->method;
bool handled = true;
if (removePrefix(method, "Debugger.")) {
if (method == "enable") {
debuggerAgent_->enable(
static_cast<m::debugger::EnableRequest &>(*command));
} else if (method == "disable") {
debuggerAgent_->disable(
static_cast<m::debugger::DisableRequest &>(*command));
} else if (method == "pause") {
debuggerAgent_->pause(static_cast<m::debugger::PauseRequest &>(*command));
} else if (method == "resume") {
debuggerAgent_->resume(
static_cast<m::debugger::ResumeRequest &>(*command));
} else if (method == "stepInto") {
debuggerAgent_->stepInto(
static_cast<m::debugger::StepIntoRequest &>(*command));
} else if (method == "stepOut") {
debuggerAgent_->stepOut(
static_cast<m::debugger::StepOutRequest &>(*command));
} else if (method == "stepOver") {
debuggerAgent_->stepOver(
static_cast<m::debugger::StepOverRequest &>(*command));
} else if (method == "setBlackboxedRanges") {
debuggerAgent_->setBlackboxedRanges(
static_cast<m::debugger::SetBlackboxedRangesRequest &>(*command));
} else if (method == "setPauseOnExceptions") {
debuggerAgent_->setPauseOnExceptions(
static_cast<m::debugger::SetPauseOnExceptionsRequest &>(*command));
} else if (method == "evaluateOnCallFrame") {
debuggerAgent_->evaluateOnCallFrame(
static_cast<m::debugger::EvaluateOnCallFrameRequest &>(*command));
} else if (method == "setBreakpoint") {
debuggerAgent_->setBreakpoint(
static_cast<m::debugger::SetBreakpointRequest &>(*command));
} else if (method == "setBreakpointByUrl") {
debuggerAgent_->setBreakpointByUrl(
static_cast<m::debugger::SetBreakpointByUrlRequest &>(*command));
} else if (method == "removeBreakpoint") {
debuggerAgent_->removeBreakpoint(
static_cast<m::debugger::RemoveBreakpointRequest &>(*command));
} else if (method == "setBreakpointsActive") {
debuggerAgent_->setBreakpointsActive(
static_cast<m::debugger::SetBreakpointsActiveRequest &>(*command));
} else {
handled = false;
}
} else if (removePrefix(method, "Runtime.")) {
if (method == "enable") {
runtimeAgent_->enable(static_cast<m::runtime::EnableRequest &>(*command));
} else if (method == "disable") {
runtimeAgent_->disable(
static_cast<m::runtime::DisableRequest &>(*command));
} else if (method == "getHeapUsage") {
runtimeAgent_->getHeapUsage(
static_cast<m::runtime::GetHeapUsageRequest &>(*command));
} else if (method == "globalLexicalScopeNames") {
runtimeAgent_->globalLexicalScopeNames(
static_cast<m::runtime::GlobalLexicalScopeNamesRequest &>(*command));
} else if (method == "compileScript") {
runtimeAgent_->compileScript(
static_cast<m::runtime::CompileScriptRequest &>(*command));
} else if (method == "getProperties") {
runtimeAgent_->getProperties(
static_cast<m::runtime::GetPropertiesRequest &>(*command));
} else if (method == "evaluate") {
runtimeAgent_->evaluate(
static_cast<m::runtime::EvaluateRequest &>(*command));
} else if (method == "callFunctionOn") {
runtimeAgent_->callFunctionOn(
static_cast<m::runtime::CallFunctionOnRequest &>(*command));
} else if (method == "discardConsoleEntries") {
runtimeAgent_->discardConsoleEntries(
static_cast<m::runtime::DiscardConsoleEntriesRequest &>(*command));
} else if (method == "releaseObject") {
runtimeAgent_->releaseObject(
static_cast<m::runtime::ReleaseObjectRequest &>(*command));
} else if (method == "releaseObjectGroup") {
runtimeAgent_->releaseObjectGroup(
static_cast<m::runtime::ReleaseObjectGroupRequest &>(*command));
} else {
handled = false;
}
} else if (removePrefix(method, "Profiler.")) {
if (method == "start") {
profilerAgent_->start(static_cast<m::profiler::StartRequest &>(*command));
} else if (method == "stop") {
profilerAgent_->stop(static_cast<m::profiler::StopRequest &>(*command));
} else {
handled = false;
}
} else if (removePrefix(method, "HeapProfiler.")) {
if (method == "takeHeapSnapshot") {
heapProfilerAgent_->takeHeapSnapshot(
static_cast<m::heapProfiler::TakeHeapSnapshotRequest &>(*command));
} else if (method == "getObjectByHeapObjectId") {
heapProfilerAgent_->getObjectByHeapObjectId(
static_cast<m::heapProfiler::GetObjectByHeapObjectIdRequest &>(
*command));
} else if (method == "getHeapObjectId") {
heapProfilerAgent_->getHeapObjectId(
static_cast<m::heapProfiler::GetHeapObjectIdRequest &>(*command));
} else if (method == "collectGarbage") {
heapProfilerAgent_->collectGarbage(
static_cast<m::heapProfiler::CollectGarbageRequest &>(*command));
} else if (method == "startTrackingHeapObjects") {
heapProfilerAgent_->startTrackingHeapObjects(
static_cast<m::heapProfiler::StartTrackingHeapObjectsRequest &>(
*command));
} else if (method == "stopTrackingHeapObjects") {
heapProfilerAgent_->stopTrackingHeapObjects(
static_cast<m::heapProfiler::StopTrackingHeapObjectsRequest &>(
*command));
} else if (method == "startSampling") {
heapProfilerAgent_->startSampling(
static_cast<m::heapProfiler::StartSamplingRequest &>(*command));
} else if (method == "stopSampling") {
heapProfilerAgent_->stopSampling(
static_cast<m::heapProfiler::StopSamplingRequest &>(*command));
} else {
handled = false;
}
} else {
handled = false;
}
if (!handled) {
messageCallback_(message::makeErrorResponse(
command->id,
message::ErrorCode::MethodNotFound,
Expand Down
8 changes: 8 additions & 0 deletions API/hermes/cdp/DebuggerDomainAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ void DebuggerDomainAgent::stepOver(const m::debugger::StepOverRequest &req) {
sendResponseToClient(m::makeOkResponse(req.id));
}

void DebuggerDomainAgent::setBlackboxedRanges(
const m::debugger::SetBlackboxedRangesRequest &req) {
sendResponseToClient(m::makeErrorResponse(
req.id,
m::ErrorCode::MethodNotFound,
"setBlackboxedRanges is not implemented yet"));
}

void DebuggerDomainAgent::setPauseOnExceptions(
const m::debugger::SetPauseOnExceptionsRequest &req) {
if (!checkDebuggerEnabled(req)) {
Expand Down
Loading

0 comments on commit e137569

Please sign in to comment.