Skip to content

Commit

Permalink
fixup! Enable using context-specific type wrapper instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
danlapid committed Dec 7, 2024
1 parent e078c59 commit 9c25460
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/workerd/jsg/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,13 @@ class Isolate: public IsolateBase {

template <typename T, typename... Args>
JsContext<T> newContextWithWrapper(
kj::Own<TypeWrapper>& wrapper, NewContextOptions options, Args&&... args) {
TypeWrapper* wrapper, NewContextOptions options, Args&&... args) {
// TODO(soon): Requiring move semantics for the global object is awkward. This should instead
// allocate the object (forwarding arguments to the constructor) and return something like
// a Ref.
auto context = wrapper->newContext(*this, options, jsgIsolate.getObserver(),
static_cast<T*>(nullptr), kj::fwd<Args>(args)...);
context.getHandle(v8Isolate)->SetAlignedPointerInEmbedderData(3, wrapper.get());
context.getHandle(v8Isolate)->SetAlignedPointerInEmbedderData(3, wrapper);
return context;
}

Expand All @@ -626,7 +626,8 @@ class Isolate: public IsolateBase {
JsContext<T> newContext(NewContextOptions options, Args&&... args) {
KJ_DASSERT(!jsgIsolate.wrappers.empty());
KJ_DASSERT(jsgIsolate.wrappers[0].get() != nullptr);
return newContextWithWrapper<T>(jsgIsolate.wrappers[0], options, kj::fwd<Args>(args)...);
return newContextWithWrapper<T>(
jsgIsolate.wrappers[0].get(), options, kj::fwd<Args>(args)...);
}

// Creates a new JavaScript "context", i.e. the global object. This is the first step to
Expand All @@ -643,7 +644,7 @@ class Isolate: public IsolateBase {
jsgIsolate.hasExtraWrappers = true;
auto& wrapper = jsgIsolate.wrappers.add(
kj::heap<TypeWrapper>(jsgIsolate.ptr, kj::fwd<MetaConfiguration>(configuration)));
return newContextWithWrapper<T>(wrapper, options, kj::fwd<Args>(args)...);
return newContextWithWrapper<T>(wrapper.get(), options, kj::fwd<Args>(args)...);
}

void reportError(const JsValue& value) override {
Expand Down Expand Up @@ -706,10 +707,7 @@ class Isolate: public IsolateBase {
return getWrapperByContext(js.v8Context());
}
}
inline TypeWrapper* getWrapperByContext(v8::Local<v8::Context>&& context) {
return getWrapperByContext(context);
}
inline TypeWrapper* getWrapperByContext(v8::Local<v8::Context>& context) {
inline TypeWrapper* getWrapperByContext(v8::Local<v8::Context> context) {
if (KJ_LIKELY(!hasExtraWrappers)) {
return wrappers[0].get();
} else {
Expand Down

0 comments on commit 9c25460

Please sign in to comment.