Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a71a4ac

Browse filesBrowse files
legendecasaduh95
authored andcommitted
src: add contextify interceptor debug logs
PR-URL: #62460 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 7ce95af commit a71a4ac
Copy full SHA for a71a4ac

3 files changed

+47Lines changed: 47 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/debug_utils-inl.h‎

Copy file name to clipboardExpand all lines: src/debug_utils-inl.h
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ struct ToStringHelper {
6262
static std::string Convert(const std::string& value) { return value; }
6363
static std::string_view Convert(std::string_view value) { return value; }
6464
static std::string Convert(bool value) { return value ? "true" : "false"; }
65+
66+
static std::string Convert(v8::Local<v8::Value> value) {
67+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
68+
if (value->IsString()) {
69+
Utf8Value utf8_value(isolate, value);
70+
return SPrintF("\"%s\"", utf8_value.ToString());
71+
}
72+
v8::MaybeLocal<v8::String> maybe_detail =
73+
value->ToDetailString(isolate->GetCurrentContext());
74+
v8::Local<v8::String> detail;
75+
if (!maybe_detail.ToLocal(&detail)) {
76+
// This will only occur when terminating. No exception is expected
77+
// with `ToDetailString`.
78+
return "<Unable to stringify v8::Value>";
79+
}
80+
Utf8Value utf8_value(isolate, detail);
81+
return utf8_value.ToString();
82+
}
83+
6584
template <unsigned BASE_BITS,
6685
typename T,
6786
typename = std::enable_if_t<std::is_integral_v<T>>>
Collapse file

‎src/debug_utils.h‎

Copy file name to clipboardExpand all lines: src/debug_utils.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str);
4646
NODE_ASYNC_PROVIDER_TYPES(V) \
4747
V(CRYPTO) \
4848
V(COMPILE_CACHE) \
49+
V(CONTEXTIFY) \
4950
V(DIAGNOSTICS) \
5051
V(HUGEPAGES) \
5152
V(INSPECTOR_SERVER) \
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "base_object-inl.h"
2525
#include "cppgc/allocation.h"
26+
#include "debug_utils-inl.h"
2627
#include "memory_tracker-inl.h"
2728
#include "module_wrap.h"
2829
#include "node_context_data.h"
@@ -480,6 +481,9 @@ Intercepted ContextifyContext::PropertyQueryCallback(
480481
return Intercepted::kNo;
481482
}
482483

484+
per_process::Debug(
485+
DebugCategory::CONTEXTIFY, "PropertyQuery(%s)\n", property);
486+
483487
Local<Context> context = ctx->context();
484488
Local<Object> sandbox = ctx->sandbox();
485489

@@ -526,6 +530,9 @@ Intercepted ContextifyContext::PropertyGetterCallback(
526530
return Intercepted::kNo;
527531
}
528532

533+
per_process::Debug(
534+
DebugCategory::CONTEXTIFY, "PropertyGetter(name: %s)\n", property);
535+
529536
Local<Context> context = ctx->context();
530537
Local<Object> sandbox = ctx->sandbox();
531538

@@ -563,6 +570,12 @@ Intercepted ContextifyContext::PropertySetterCallback(
563570
return Intercepted::kNo;
564571
}
565572

573+
per_process::Debug(DebugCategory::CONTEXTIFY,
574+
"PropertySetter(name: %s, value: %s), use-strict(%s)\n",
575+
property,
576+
value,
577+
args.ShouldThrowOnError());
578+
566579
Local<Context> context = ctx->context();
567580
PropertyAttribute attributes = PropertyAttribute::None;
568581
bool is_declared_on_global_proxy = ctx->global_proxy()
@@ -640,6 +653,9 @@ Intercepted ContextifyContext::PropertyDescriptorCallback(
640653
return Intercepted::kNo;
641654
}
642655

656+
per_process::Debug(
657+
DebugCategory::CONTEXTIFY, "PropertyDescriptor(name: %s)\n", property);
658+
643659
Local<Context> context = ctx->context();
644660

645661
Local<Object> sandbox = ctx->sandbox();
@@ -666,6 +682,9 @@ Intercepted ContextifyContext::PropertyDefinerCallback(
666682
return Intercepted::kNo;
667683
}
668684

685+
per_process::Debug(
686+
DebugCategory::CONTEXTIFY, "PropertyDefiner(name: %s)\n", property);
687+
669688
Local<Context> context = ctx->context();
670689
Isolate* isolate = context->GetIsolate();
671690

@@ -736,6 +755,9 @@ Intercepted ContextifyContext::PropertyDeleterCallback(
736755
return Intercepted::kNo;
737756
}
738757

758+
per_process::Debug(
759+
DebugCategory::CONTEXTIFY, "PropertyDeleter(name: %s)\n", property);
760+
739761
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), property);
740762

741763
if (success.FromMaybe(false)) {
@@ -763,6 +785,8 @@ void ContextifyContext::PropertyEnumeratorCallback(
763785
// Still initializing
764786
if (IsStillInitializing(ctx)) return;
765787

788+
per_process::Debug(DebugCategory::CONTEXTIFY, "PropertyEnumerator()\n");
789+
766790
Local<Array> properties;
767791
// Only get own named properties, exclude indices.
768792
if (!ctx->sandbox()
@@ -794,6 +818,9 @@ void ContextifyContext::IndexedPropertyEnumeratorCallback(
794818
// Still initializing
795819
if (IsStillInitializing(ctx)) return;
796820

821+
per_process::Debug(DebugCategory::CONTEXTIFY,
822+
"IndexedPropertyEnumerator()\n");
823+
797824
Local<Array> properties;
798825

799826
// Only get own index properties.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.