mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: add contextify interceptor debug logs
PR-URL: https://github.com/nodejs/node/pull/62460 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 parent
318e2c7cd3
commit
144ef93735
3 files changed
+47
No files matched your search
@@ -62,6 +62,25 @@ struct ToStringHelper {
|
||||
static std::string Convert(const std::string& value) { return value; }
|
||||
static std::string_view Convert(std::string_view value) { return value; }
|
||||
static std::string Convert(bool value) { return value ? "true" : "false"; }
|
||||
|
||||
static std::string Convert(v8::Local<v8::Value> value) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
if (value->IsString()) {
|
||||
Utf8Value utf8_value(isolate, value);
|
||||
return SPrintF("\"%s\"", utf8_value.ToString());
|
||||
}
|
||||
v8::MaybeLocal<v8::String> maybe_detail =
|
||||
value->ToDetailString(isolate->GetCurrentContext());
|
||||
v8::Local<v8::String> detail;
|
||||
if (!maybe_detail.ToLocal(&detail)) {
|
||||
// This will only occur when terminating. No exception is expected
|
||||
// with `ToDetailString`.
|
||||
return "<Unable to stringify v8::Value>";
|
||||
}
|
||||
Utf8Value utf8_value(isolate, detail);
|
||||
return utf8_value.ToString();
|
||||
}
|
||||
|
||||
template <unsigned BASE_BITS,
|
||||
typename T,
|
||||
typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||
|
||||
@@ -47,6 +47,7 @@ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str);
|
||||
V(BOOTSTRAP) \
|
||||
V(CRYPTO) \
|
||||
V(COMPILE_CACHE) \
|
||||
V(CONTEXTIFY) \
|
||||
V(DIAGNOSTICS) \
|
||||
V(HUGEPAGES) \
|
||||
V(INSPECTOR_SERVER) \
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "base_object-inl.h"
|
||||
#include "cppgc/allocation.h"
|
||||
#include "debug_utils-inl.h"
|
||||
#include "memory_tracker-inl.h"
|
||||
#include "module_wrap.h"
|
||||
#include "node_context_data.h"
|
||||
@@ -484,6 +485,9 @@ Intercepted ContextifyContext::PropertyQueryCallback(
|
||||
return Intercepted::kNo;
|
||||
}
|
||||
|
||||
per_process::Debug(
|
||||
DebugCategory::CONTEXTIFY, "PropertyQuery(%s)\n", property);
|
||||
|
||||
Local<Context> context = ctx->context();
|
||||
Local<Object> sandbox = ctx->sandbox();
|
||||
|
||||
@@ -530,6 +534,9 @@ Intercepted ContextifyContext::PropertyGetterCallback(
|
||||
return Intercepted::kNo;
|
||||
}
|
||||
|
||||
per_process::Debug(
|
||||
DebugCategory::CONTEXTIFY, "PropertyGetter(name: %s)\n", property);
|
||||
|
||||
Local<Context> context = ctx->context();
|
||||
Local<Object> sandbox = ctx->sandbox();
|
||||
|
||||
@@ -567,6 +574,12 @@ Intercepted ContextifyContext::PropertySetterCallback(
|
||||
return Intercepted::kNo;
|
||||
}
|
||||
|
||||
per_process::Debug(DebugCategory::CONTEXTIFY,
|
||||
"PropertySetter(name: %s, value: %s), use-strict(%s)\n",
|
||||
property,
|
||||
value,
|
||||
args.ShouldThrowOnError());
|
||||
|
||||
Local<Context> context = ctx->context();
|
||||
PropertyAttribute attributes = PropertyAttribute::None;
|
||||
bool is_declared_on_global_proxy = ctx->global_proxy()
|
||||
@@ -655,6 +668,9 @@ Intercepted ContextifyContext::PropertyDescriptorCallback(
|
||||
return Intercepted::kNo;
|
||||
}
|
||||
|
||||
per_process::Debug(
|
||||
DebugCategory::CONTEXTIFY, "PropertyDescriptor(name: %s)\n", property);
|
||||
|
||||
Local<Context> context = ctx->context();
|
||||
|
||||
Local<Object> sandbox = ctx->sandbox();
|
||||
@@ -681,6 +697,9 @@ Intercepted ContextifyContext::PropertyDefinerCallback(
|
||||
return Intercepted::kNo;
|
||||
}
|
||||
|
||||
per_process::Debug(
|
||||
DebugCategory::CONTEXTIFY, "PropertyDefiner(name: %s)\n", property);
|
||||
|
||||
Local<Context> context = ctx->context();
|
||||
Isolate* isolate = Isolate::GetCurrent();
|
||||
|
||||
@@ -751,6 +770,9 @@ Intercepted ContextifyContext::PropertyDeleterCallback(
|
||||
return Intercepted::kNo;
|
||||
}
|
||||
|
||||
per_process::Debug(
|
||||
DebugCategory::CONTEXTIFY, "PropertyDeleter(name: %s)\n", property);
|
||||
|
||||
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), property);
|
||||
|
||||
if (success.FromMaybe(false)) {
|
||||
@@ -778,6 +800,8 @@ void ContextifyContext::PropertyEnumeratorCallback(
|
||||
// Still initializing
|
||||
if (IsStillInitializing(ctx)) return;
|
||||
|
||||
per_process::Debug(DebugCategory::CONTEXTIFY, "PropertyEnumerator()\n");
|
||||
|
||||
Local<Array> properties;
|
||||
// Only get own named properties, exclude indices.
|
||||
if (!ctx->sandbox()
|
||||
@@ -809,6 +833,9 @@ void ContextifyContext::IndexedPropertyEnumeratorCallback(
|
||||
// Still initializing
|
||||
if (IsStillInitializing(ctx)) return;
|
||||
|
||||
per_process::Debug(DebugCategory::CONTEXTIFY,
|
||||
"IndexedPropertyEnumerator()\n");
|
||||
|
||||
Local<Array> properties;
|
||||
|
||||
// Only get own index properties.
|
||||
|
||||
Reference in new issue
Block a user