Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-after-move in console implementation #44297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void RuntimeTarget::installConsoleHandler() {
jsi::Runtime& runtime,
const jsi::Value& thisVal,
const jsi::Value* args,
size_t count) mutable {
size_t count) {
jsi::Value retVal = innerFn(runtime, thisVal, args, count);
if (originalConsole) {
auto val = originalConsole->getProperty(runtime, methodName);
Expand Down Expand Up @@ -202,27 +202,21 @@ void RuntimeTarget::installConsoleHandler() {
jsi::Runtime& runtime,
const jsi::Value& /*thisVal*/,
const jsi::Value* args,
size_t count) mutable {
size_t count) {
auto timestampMs = getTimestampMs();
delegateExecutorSync(
[&runtime,
args,
count,
body = std::move(body),
state,
timestampMs](auto& runtimeTargetDelegate) {
auto stackTrace =
runtimeTargetDelegate.captureStackTrace(
runtime, /* framesToSkip */ 1);
body(
runtime,
args,
count,
runtimeTargetDelegate,
*state,
timestampMs,
std::move(stackTrace));
});
delegateExecutorSync([&](auto& runtimeTargetDelegate) {
auto stackTrace =
runtimeTargetDelegate.captureStackTrace(
runtime, /* framesToSkip */ 1);
body(
runtime,
args,
count,
runtimeTargetDelegate,
*state,
timestampMs,
std::move(stackTrace));
});
return jsi::Value::undefined();
})));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,16 @@ TEST_P(ConsoleApiTest, testConsoleLogStack) {
)");
}

TEST_P(ConsoleApiTest, testConsoleLogTwice) {
InSequence s;
expectConsoleApiCall(
AllOf(AtJsonPtr("/type", "log"), AtJsonPtr("/args/0/value", "hello")));
eval("console.log('hello');");
expectConsoleApiCall(AllOf(
AtJsonPtr("/type", "log"), AtJsonPtr("/args/0/value", "hello again")));
eval("console.log('hello again');");
}

static const auto paramValues = testing::Values(
Params{
.withConsolePolyfill = true,
Expand Down