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

Add toStringTag value on JSG resource types #1607

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 src/workerd/jsg/jsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace workerd::jsg {
::workerd::jsg::JsgKind::RESOURCE; \
using jsgSuper = jsgThis; \
using jsgThis = Type; \
inline kj::StringPtr jsgGetName() const { return #Type##_kjc; } \
garrettgu10 marked this conversation as resolved.
Show resolved Hide resolved
inline kj::StringPtr jsgGetMemoryName() const override { return #Type##_kjc; } \
inline size_t jsgGetMemorySelfSize() const override { return sizeof(Type); } \
inline void jsgGetMemoryInfo(jsg::MemoryTracker& tracker) const override { \
Expand Down
3 changes: 3 additions & 0 deletions src/workerd/jsg/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ 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);
garrettgu10 marked this conversation as resolved.
Show resolved Hide resolved
prototype->Set(toStringTagSymbol, v8StrIntern(isolate, typeWrapper.jsgGetName()), 0);
}

template <typename Type, typename GetNamedMethod, GetNamedMethod getNamedMethod>
Expand Down
1 change: 1 addition & 0 deletions src/workerd/jsg/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class Isolate: public IsolateBase {
class Type##_TypeWrapper final: public Type##_TypeWrapperBase { \
public: \
using Type##_TypeWrapperBase::TypeWrapper; \
kj::StringPtr jsgGetName() const { return #Type##_kjc; } \
}; \
class Type final: public ::workerd::jsg::Isolate<Type##_TypeWrapper> { \
public: \
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/jsg/wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Wrappable: public kj::Refcounted {
virtual void jsgVisitForGc(GcVisitor& visitor);

virtual kj::StringPtr jsgGetMemoryName() const {
KJ_UNIMPLEMENTED("jsgGetTypeName is not implemented. "
KJ_UNIMPLEMENTED("jsgGetMemoryName is not implemented. "
"It must be overridden by subclasses");
}

Expand Down
Loading