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

Log all accesses to toStringTag #1674

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 24 additions & 0 deletions src/workerd/jsg/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,30 @@ struct ResourceTypeBuilder {
inspectProperties = v8::ObjectTemplate::New(isolate);
prototype->Set(symbol, inspectProperties, static_cast<v8::PropertyAttribute>(
v8::PropertyAttribute::ReadOnly | v8::PropertyAttribute::DontEnum));

auto toStringTagSymbol = v8::Symbol::GetToStringTag(isolate);

prototype->SetAccessor(toStringTagSymbol, ResourceTypeBuilder::getAndLogToStringTag, &ResourceTypeBuilder::setAndLogToStringTag);
}

static void setAndLogToStringTag(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info){
LOG_ERROR_PERIODICALLY("toStringTag has been set");
auto isolate = info.GetIsolate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this it would be simpler just to store the given value within a jsg::Value member field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally tried doing that, but I couldn't get access to the ResourceTypeBuilder instance from within this function, since I need to be able to give a pointer to it to SetAccessor. Any suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think we would have to use the object itself to store the property, since we would want two objets to have separate toStringTags even if they share a single ObjectTemplate.

auto context = isolate->GetCurrentContext();
auto res = info.This()->Set(context, ::workerd::jsg::v8StrIntern(isolate, "__workerd_internal_toStringTag"), value);
if(res.IsNothing()) {
LOG_ERROR_PERIODICALLY("toStringTag has failed to set");
}
}

static void getAndLogToStringTag(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info){
LOG_ERROR_PERIODICALLY("toStringTag has been gotten");
auto isolate = info.GetIsolate();
auto context = isolate->GetCurrentContext();
v8::Local<v8::Value> val;
if(info.This()->Get(context, ::workerd::jsg::v8StrIntern(isolate, "__workerd_internal_toStringTag")).ToLocal(&val)) {
info.GetReturnValue().Set(val);
}
}

template <typename Type, typename GetNamedMethod, GetNamedMethod getNamedMethod>
Expand Down
Loading