Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Android napi: console.time / console.timeEnd dereference a missing map entry

Đang mở
#98 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend, mobile

Hướng nghiên cứu

Start with NativeScript/runtime/android/napi/modules/console/Console.cpp and compare the napi console creation and callbacks with createConsole() in the jsi tree. Reproduce with console.time("x"); console.timeEnd("x"); on a napi engine, then check that per-environment timer state is initialized, missing entries return safely, and access is synchronized. Done means the repro measures and logs elapsed time without undefined behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

Summary

On napi, console.time and console.timeEnd dereference a map iterator that is always end(). Console::s_envToConsoleTimersMap (NativeScript/runtime/android/napi/modules/console/Console.cpp) is never given an entry for any napi_env, so:

auto it = Console::s_envToConsoleTimersMap.find(env);
if (it == Console::s_envToConsoleTimersMap.end()) {
    // throw?
}
...
it->second.insert(std::make_pair(label, timeStamp));   // it == end()

timeCallback inserts into it->second with it == end(), which is undefined behaviour. timeEndCallback copies it->second by value and later erases from it, which is undefined for the same reason.

The jsi tree does not have this bug: its createConsole() emplaces an entry per runtime, and its callbacks return early when the entry is missing.

Repro

On any napi engine:

console.time("x");
console.timeEnd("x");

The result depends on the heap layout: anything from nothing visible to a corrupted heap or a crash.

Expected

console.time / console.timeEnd measure and log the elapsed time. Fix: create the per-env entry when the console is created, as jsi does, and bail out if it is missing. The map has the same cross-thread race as the jsi one, so it needs the same synchronization.

Environment

  • Branch: android-react-native at 64c7fed0
  • Binding layer: napi (all engines)
Ngôn ngữ chính
C++
Star
27
Fork
4
Merge trung bình
16 giờ 48 phút
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NativeScript/runtimes

Tất cả issue của NativeScript/runtimes

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.