Skip to content

Commit

Permalink
Enable const variants of some const-safe jsg functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lapid authored and danlapid committed Oct 31, 2024
1 parent 8f2dc94 commit e62cb44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/workerd/jsg/jsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,12 @@ class Data {
handle(isolate, handle) {}

// Get the raw underlying v8 handle.
v8::Local<v8::Data> getHandle(v8::Isolate* isolate) {
v8::Local<v8::Data> getHandle(v8::Isolate* isolate) const {
return handle.Get(isolate);
}

// Get the raw underlying v8 handle.
v8::Local<v8::Data> getHandle(Lock& js);
v8::Local<v8::Data> getHandle(Lock& js) const;

Data addRef(v8::Isolate* isolate) {
return Data(isolate, getHandle(isolate));
Expand Down Expand Up @@ -865,7 +865,7 @@ class V8Ref: private Data {
}
KJ_DISALLOW_COPY(V8Ref);

v8::Local<T> getHandle(v8::Isolate* isolate) {
v8::Local<T> getHandle(v8::Isolate* isolate) const {
if constexpr (std::is_base_of<v8::Value, T>()) {
// V8 doesn't let us cast directly from v8::Data to subtypes of v8::Value, so we're forced to
// use this double cast... Ech.
Expand All @@ -874,7 +874,7 @@ class V8Ref: private Data {
return Data::getHandle(isolate).template As<T>();
}
}
v8::Local<T> getHandle(jsg::Lock& js);
v8::Local<T> getHandle(jsg::Lock& js) const;

V8Ref addRef(v8::Isolate* isolate) {
return V8Ref(isolate, getHandle(isolate));
Expand Down Expand Up @@ -1749,10 +1749,10 @@ class JsContext {
return object.get();
}

v8::Local<v8::Context> getHandle(v8::Isolate* isolate) {
v8::Local<v8::Context> getHandle(v8::Isolate* isolate) const {
return handle.Get(isolate);
}
v8::Local<v8::Context> getHandle(Lock& js);
v8::Local<v8::Context> getHandle(Lock& js) const;

private:
v8::Global<v8::Context> handle;
Expand Down Expand Up @@ -2780,16 +2780,16 @@ inline HashableV8Ref<T> HashableV8Ref<T>::addRef(jsg::Lock& js) {
}

template <typename T>
inline v8::Local<T> V8Ref<T>::getHandle(jsg::Lock& js) {
inline v8::Local<T> V8Ref<T>::getHandle(jsg::Lock& js) const {
return getHandle(js.v8Isolate);
}

inline v8::Local<v8::Data> Data::getHandle(jsg::Lock& js) {
inline v8::Local<v8::Data> Data::getHandle(jsg::Lock& js) const {
return getHandle(js.v8Isolate);
}

template <typename T>
inline v8::Local<v8::Context> JsContext<T>::getHandle(Lock& js) {
inline v8::Local<v8::Context> JsContext<T>::getHandle(Lock& js) const {
return handle.Get(js.v8Isolate);
}

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/jsg/jsvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class JsRef final {
JsRef& operator=(JsRef<T>& other) = delete;
JsRef& operator=(JsRef<T>&& other) = default;

T getHandle(Lock& js) KJ_WARN_UNUSED_RESULT {
T getHandle(Lock& js) const KJ_WARN_UNUSED_RESULT {
JsValue handle(value.getHandle(js));
return KJ_ASSERT_NONNULL(handle.tryCast<T>());
}
Expand Down

0 comments on commit e62cb44

Please sign in to comment.