Skip to content

Commit fee4658

Browse files
committed
wip
1 parent 9eb09d6 commit fee4658

File tree

9 files changed

+24
-23
lines changed

9 files changed

+24
-23
lines changed

src/workerd/jsg/iterator.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class GeneratorWrapper {
565565
GeneratorNext<T>*,
566566
kj::Maybe<v8::Local<v8::Object>> parentObject) {
567567
if (handle->IsObject()) {
568-
auto isolate = context->GetIsolate();
568+
auto isolate = js.v8Isolate;
569569
auto& typeWrapper = TypeWrapper::from(isolate);
570570
auto object = handle.template As<v8::Object>();
571571

@@ -602,8 +602,7 @@ class GeneratorWrapper {
602602
.value = kj::mv(v),
603603
};
604604
} else {
605-
throwTypeError(
606-
context->GetIsolate(), TypeErrorContext::other(), TypeWrapper::getName((T*)nullptr));
605+
throwTypeError(js.v8Isolate, TypeErrorContext::other(), TypeWrapper::getName((T*)nullptr));
607606
}
608607
}
609608

@@ -617,7 +616,7 @@ class GeneratorWrapper {
617616
Generator<T>*,
618617
kj::Maybe<v8::Local<v8::Object>> parentObject) {
619618
if (handle->IsObject()) {
620-
auto isolate = context->GetIsolate();
619+
auto isolate = js.v8Isolate;
621620
auto object = handle.As<v8::Object>();
622621
auto iter = check(object->Get(context, v8::Symbol::GetIterator(isolate)));
623622
if (iter->IsFunction()) {
@@ -638,7 +637,7 @@ class GeneratorWrapper {
638637
AsyncGenerator<T>*,
639638
kj::Maybe<v8::Local<v8::Object>> parentObject) {
640639
if (handle->IsObject()) {
641-
auto isolate = context->GetIsolate();
640+
auto isolate = js.v8Isolate;
642641
auto object = handle.As<v8::Object>();
643642
auto iter = check(object->Get(context, v8::Symbol::GetAsyncIterator(isolate)));
644643
// If there is no async iterator, let's try a sync iterator
@@ -713,13 +712,13 @@ class SequenceWrapper {
713712
v8::Local<v8::Value> handle,
714713
Sequence<U>*,
715714
kj::Maybe<v8::Local<v8::Object>> parentObject) {
716-
auto isolate = context->GetIsolate();
715+
auto isolate = js.v8Isolate;
717716
auto& typeWrapper = TypeWrapper::from(isolate);
718717
KJ_IF_SOME(gen,
719718
typeWrapper.tryUnwrap(js, context, handle, (Generator<U>*)nullptr, parentObject)) {
720719
kj::Vector<U> items;
721720
// We intentionally ignore the forEach return value.
722-
gen.forEach(Lock::from(isolate), [&items](Lock&, U item, auto&) { items.add(kj::mv(item)); });
721+
gen.forEach(js, [&items](Lock&, U item, auto&) { items.add(kj::mv(item)); });
723722
return Sequence<U>(items.releaseAsArray());
724723
}
725724
return kj::none;

src/workerd/jsg/jsg.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,10 +1787,11 @@ class JsContext {
17871787
static_assert(
17881788
std::is_base_of_v<ContextGlobal, T>, "context global type must extend jsg::ContextGlobal");
17891789

1790-
JsContext(v8::Local<v8::Context> handle,
1790+
JsContext(v8::Isolate* isolate,
1791+
v8::Local<v8::Context> handle,
17911792
Ref<T> object,
17921793
kj::Maybe<kj::Own<void>> maybeNewRegistryHandle = kj::none)
1793-
: handle(handle->GetIsolate(), handle),
1794+
: handle(isolate, handle),
17941795
object(kj::mv(object)),
17951796
maybeNewRegistryHandle(kj::mv(maybeNewRegistryHandle)) {}
17961797

src/workerd/jsg/jsvalue.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ void JsMessage::addJsStackTrace(Lock& js, kj::Vector<kj::String>& lines) {
699699
}
700700
} else {
701701
for (auto i: kj::zeroTo(trace->GetFrameCount())) {
702-
auto frame = trace->GetFrame(context->GetIsolate(), i);
702+
auto frame = trace->GetFrame(js.v8Isolate, i);
703703
kj::StringTree locationStr;
704704

705705
auto scriptName = frame->GetScriptName();

src/workerd/jsg/jsvalue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ struct JsValueWrapper {
625625
if constexpr (kj::isSameType<T, JsString>()) {
626626
return T(check(handle->ToString(context)));
627627
} else if constexpr (kj::isSameType<T, JsBoolean>()) {
628-
return T(handle->ToBoolean(context->GetIsolate()));
628+
return T(handle->ToBoolean(js.v8Isolate));
629629
} else if constexpr (kj::isSameType<T, JsNumber>()) {
630630
return T(check(handle->ToNumber(context)));
631631
} else {
@@ -643,7 +643,7 @@ struct JsValueWrapper {
643643
v8::Local<v8::Value> handle,
644644
JsRef<T>*,
645645
kj::Maybe<v8::Local<v8::Object>> parentObject) {
646-
auto isolate = context->GetIsolate();
646+
auto isolate = js.v8Isolate;
647647
KJ_IF_SOME(result,
648648
TypeWrapper::from(isolate).tryUnwrap(js, context, handle, (T*)nullptr, parentObject)) {
649649
return JsRef(js, result);

src/workerd/jsg/modules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ v8::MaybeLocal<v8::Promise> dynamicImportCallback(v8::Local<v8::Context> context
621621
v8::Local<v8::Value> resource_name,
622622
v8::Local<v8::String> specifier,
623623
v8::Local<v8::FixedArray> import_attributes) {
624-
auto& js = Lock::from(context->GetIsolate());
624+
auto& js = Lock::from(v8::Isolate::GetCurrent());
625625
auto registry = ModuleRegistry::from(js);
626626
auto& wrapper = TypeWrapper::from(js.v8Isolate);
627627

src/workerd/jsg/promise.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ class PromiseWrapper {
628628
context, &thenUnwrap<TypeWrapper, T>, {}, 1, v8::ConstructorBehavior::kThrow));
629629
promise = check(promise->Then(context, then));
630630
}
631-
return Promise<T>(context->GetIsolate(), promise);
631+
return Promise<T>(js.v8Isolate, promise);
632632
} else {
633633
// Input is a resolved value (not a promise). Try to unwrap it now.
634634

@@ -639,13 +639,12 @@ class PromiseWrapper {
639639
// Unfortunately this needs to be gated by a compatibility flag because there are
640640
// existing workers that appear to rely on the old behavior -- although it's not clear
641641
// if those workers actually work the way they were intended to.
642-
if (config.unwrapCustomThenables && isThenable(context, handle)) {
642+
if (config.unwrapCustomThenables && isThenable(js, context, handle)) {
643643
auto paf = check(v8::Promise::Resolver::New(context));
644644
check(paf->Resolve(context, handle));
645645
return tryUnwrap(js, context, paf->GetPromise(), (Promise<T>*)nullptr, parentObject);
646646
}
647647

648-
auto& js = Lock::from(context->GetIsolate());
649648
if constexpr (isVoid<T>()) {
650649
// When expecting Promise<void>, we treat absolutely any non-promise value as being
651650
// an immediately-resolved promise. This is consistent with JavaScript where you'd
@@ -675,10 +674,10 @@ class PromiseWrapper {
675674
private:
676675
const JsgConfig config;
677676

678-
static bool isThenable(v8::Local<v8::Context> context, v8::Local<v8::Value> handle) {
677+
static bool isThenable(Lock& js, v8::Local<v8::Context> context, v8::Local<v8::Value> handle) {
679678
if (handle->IsObject()) {
680679
auto obj = handle.As<v8::Object>();
681-
return check(obj->Has(context, v8StrIntern(context->GetIsolate(), "then")));
680+
return check(obj->Has(context, v8StrIntern(js.v8Isolate, "then")));
682681
}
683682
return false;
684683
}

src/workerd/jsg/resource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ class ResourceWrapper {
17741774

17751775
return JSG_WITHIN_CONTEXT_SCOPE(js, context, [&](jsg::Lock& js) {
17761776
setupJavascript(js);
1777-
return JsContext<T>(context, kj::mv(ptr), kj::mv(maybeNewModuleRegistry));
1777+
return JsContext<T>(js.v8Isolate, context, kj::mv(ptr), kj::mv(maybeNewModuleRegistry));
17781778
});
17791779
}
17801780

@@ -1788,7 +1788,7 @@ class ResourceWrapper {
17881788
if (handle->IsObject()) {
17891789
v8::Local<v8::Object> instance =
17901790
v8::Local<v8::Object>::Cast(handle)->FindInstanceInPrototypeChain(
1791-
getTemplate(context->GetIsolate(), nullptr));
1791+
getTemplate(js.v8Isolate, nullptr));
17921792
if (!instance.IsEmpty()) {
17931793
return extractInternalPointer<T, false>(context, instance);
17941794
}

src/workerd/jsg/struct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class StructWrapper<Self, T, TypeTuple<FieldWrappers...>, kj::_::Indexes<indices
116116
// For similar reasons, if we are initializing this dictionary from null/undefined, and the
117117
// dictionary has required members, we throw.
118118

119-
auto isolate = context->GetIsolate();
119+
auto isolate = js.v8Isolate;
120120

121121
if (handle->IsUndefined() || handle->IsNull()) {
122122
if constexpr (((webidl::isOptional<typename FieldWrappers::Type> ||

src/workerd/jsg/type-wrapper.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ namespace workerd::jsg {
3131
// from any particular JS value.
3232
// A concept that identifies types that can be unwrapped without needing a JS value
3333
template <typename TypeWrapper, typename T>
34-
concept ValueLessParameter = requires(
35-
TypeWrapper wrapper, v8::Local<v8::Context> context, T* ptr) { wrapper.unwrap(context, ptr); };
34+
concept ValueLessParameter =
35+
requires(TypeWrapper wrapper, Lock& js, v8::Local<v8::Context> context, T* ptr) {
36+
wrapper.unwrap(js, context, ptr);
37+
};
3638

3739
// TypeWrapper mixin for V8 handles.
3840
//

0 commit comments

Comments
 (0)