Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -12696,6 +12696,7 @@ static void* IdPointer(int id);

static bool HasDivergedFromRecording();
static bool AllowSideEffects();
static void OnAnnotation(const char* kind, const char* contents);

}; // class recordreplay

Expand Down
9 changes: 9 additions & 0 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10416,6 +10416,7 @@ static const char* (*gRecordReplayGetRecordingId)();
static char* (*gRecordReplayCurrentExecutionPoint)();
static void (*gRecordReplayFree)(void*);
static size_t (*gRecordReplayElapsedTimeMs)();
static void (*gRecordReplayOnAnnotation)(const char*, const char*);

namespace internal {

Expand Down Expand Up @@ -10822,6 +10823,12 @@ bool recordreplay::AllowSideEffects() {
return true;
}

void recordreplay::OnAnnotation(const char* kind, const char* contents) {
if (IsRecordingOrReplaying()) {
gRecordReplayOnAnnotation(kind, contents);
}
}

extern "C" size_t V8RecordReplayNewBookmark() {
if (recordreplay::IsRecordingOrReplaying()) {
return gRecordReplayNewBookmark();
Expand Down Expand Up @@ -10929,6 +10936,8 @@ void recordreplay::SetRecordingOrReplaying(void* handle) {
RecordReplayLoadSymbol(handle, "RecordReplayCurrentExecutionPoint", gRecordReplayCurrentExecutionPoint);
RecordReplayLoadSymbol(handle, "RecordReplayFree", gRecordReplayFree);
RecordReplayLoadSymbol(handle, "RecordReplayElapsedTimeMs", gRecordReplayElapsedTimeMs);
RecordReplayLoadSymbol(handle, "RecordReplayOnAnnotation",
gRecordReplayOnAnnotation);

void (*setDefaultCommandCallback)(char* (*callback)(const char* command, const char* params));
RecordReplayLoadSymbol(handle, "RecordReplaySetDefaultCommandCallback", setDefaultCommandCallback);
Expand Down
1 change: 1 addition & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const rawMethods = internalBinding('process_methods');
recordingId: rawMethods.recordReplayRecordingId,
currentPoint: rawMethods.recordReplayCurrentExecutionPoint,
elapsedTime: rawMethods.recordReplayElapsedTimeMs,
annotationHook: rawMethods.recordReplayAnnotationHook,

currentPointURL() {
const recordingId = rawMethods.recordReplayRecordingId();
Expand Down
35 changes: 35 additions & 0 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ typedef int mode_t;
#include <termios.h> // tcgetattr, tcsetattr
#endif

static const char* AnnotationHookJSName = "recordreplay.annotationHook";

namespace v8 {

extern void FunctionCallbackIsRecordingOrReplaying(const FunctionCallbackInfo<Value>& args);
Expand Down Expand Up @@ -546,6 +548,36 @@ static void RecordReplaySendCDPMessage(const FunctionCallbackInfo<Value>& args)
gRecordReplayInspectorSession->Dispatch(messageView);
}

// Called from javascript.
// `recordreplay.annotationHook(kind, contents)`
// Since this function is called from userland JS, we avoid assertions.
// We don't want flawed uses of the API to crash the recording.
static void RecordReplayAnnotationHook(
const FunctionCallbackInfo<Value>& args) {
if (!(args.Length() >= 2 && args[0]->IsString())) {
v8::recordreplay::Print("[RuntimeError] %s called with incorrect arguments",
AnnotationHookJSName);
return;
}

v8::Isolate* isolate = args.GetIsolate();
v8::Local<v8::Object> payload = v8::Object::New(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
payload->Set(context, v8::String::NewFromUtf8(isolate, "message").ToLocalChecked(), args[1]).Check();

v8::Local<v8::String> json;
if (!v8::JSON::Stringify(context, payload).ToLocal(&json)) {
v8::recordreplay::Print(
"[RuntimeError] %s contents failed to json stringify",
AnnotationHookJSName);
return;
}

v8::String::Utf8Value kind(args.GetIsolate(), args[0]);
v8::String::Utf8Value contents(args.GetIsolate(), json);
v8::recordreplay::OnAnnotation(*kind, *contents);
}

v8::CFunction BindingData::fast_number_(v8::CFunction::Make(FastNumber));
v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt));

Expand Down Expand Up @@ -697,6 +729,8 @@ static void Initialize(Local<Object> target,
v8::FunctionCallbackRecordReplayCurrentExecutionPoint);
env->SetMethod(target, "recordReplayElapsedTimeMs",
v8::FunctionCallbackRecordReplayElapsedTimeMs);
env->SetMethod(
target, "recordReplayAnnotationHook", RecordReplayAnnotationHook);
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
Expand Down Expand Up @@ -740,6 +774,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(v8::FunctionCallbackRecordReplayGetRecordingId);
registry->Register(v8::FunctionCallbackRecordReplayCurrentExecutionPoint);
registry->Register(v8::FunctionCallbackRecordReplayElapsedTimeMs);
registry->Register(RecordReplayAnnotationHook);
}

} // namespace process
Expand Down
Loading