Skip to content

Commit 6707006

Browse files
authored
Merge pull request #5598 from cloudflare/jasnell/consolidate-typewrapper-config
2 parents ac40077 + 4840c8a commit 6707006

6 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/workerd/api/http.c++

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <workerd/jsg/ser.h>
1818
#include <workerd/jsg/url.h>
1919
#include <workerd/util/abortable.h>
20+
#include <workerd/util/autogate.h>
2021
#include <workerd/util/entropy.h>
2122
#include <workerd/util/http-util.h>
2223
#include <workerd/util/mimetype.h>

src/workerd/jsg/fast-api-test.c++

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ struct Test {
170170

171171
CallCounter runTest(Test test) {
172172
jsg::callCounter.reset();
173-
jsg::test::Evaluator<FastMethodContext, FastMethodIsolate> e(v8System);
173+
JsgConfig config = {
174+
.fastApiEnabled = true,
175+
};
176+
jsg::test::Evaluator<FastMethodContext, FastMethodIsolate, JsgConfig> e(v8System, config);
174177

175178
auto target = test.target == ""_kjc ? kj::str(test.expr) : kj::str(test.target, ".", test.expr);
176179
e.expectEval(target, test.expectedReturnType, test.expectedReturnValue);
@@ -234,7 +237,10 @@ KJ_TEST("Fast methods should work with getters/setters") {
234237

235238
KJ_TEST("Fast methods properly catch JSG_FAIL_REQUIRE errors") {
236239
jsg::callCounter.reset();
237-
jsg::test::Evaluator<FastMethodContext, FastMethodIsolate> e(v8System);
240+
JsgConfig config = {
241+
.fastApiEnabled = true,
242+
};
243+
jsg::test::Evaluator<FastMethodContext, FastMethodIsolate, JsgConfig> e(v8System, config);
238244

239245
// Test that directly calling the method results in an error
240246
e.expectEval("throwError(42)", "throws", "TypeError: Test error with code 42");

src/workerd/jsg/jsg-test.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ class Evaluator {
3030
// in cases that the isolate includes types that require configuration, but currently the
3131
// type is always default-constructed. What if you want to specify a test config?
3232
public:
33-
explicit Evaluator(V8System& v8System): v8System(v8System) {}
33+
explicit Evaluator(V8System& v8System, ConfigurationType config = {})
34+
: v8System(v8System),
35+
config(config) {}
3436

3537
IsolateType& getIsolate() {
3638
// Slightly more efficient to only instantiate each isolate type once (17s vs. 20s):
3739
static IsolateType isolate(
38-
v8System, v8::IsolateGroup::GetDefault(), ConfigurationType(), kj::heap<IsolateObserver>());
40+
v8System, v8::IsolateGroup::GetDefault(), config, kj::heap<IsolateObserver>());
3941
return isolate;
4042
}
4143

@@ -162,6 +164,7 @@ class Evaluator {
162164

163165
private:
164166
V8System& v8System;
167+
ConfigurationType config;
165168
};
166169

167170
struct NumberBox: public Object {

src/workerd/jsg/jsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,7 @@ struct JsgConfig {
21512151
bool noSubstituteNull = false;
21522152
bool unwrapCustomThenables = false;
21532153
bool fetchIterableTypeSupport = false;
2154+
bool fastApiEnabled = false;
21542155
};
21552156

21562157
static constexpr JsgConfig DEFAULT_JSG_CONFIG = {};

src/workerd/jsg/type-wrapper.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <workerd/jsg/value.h>
2020
#include <workerd/jsg/web-idl.h>
2121
#include <workerd/jsg/wrappable.h>
22-
#include <workerd/util/autogate.h>
2322

2423
#include <v8-wasm.h>
2524

@@ -412,17 +411,15 @@ class TypeWrapper: public DynamicResourceTypeMap<Self>,
412411
public UnimplementedWrapper,
413412
public JsValueWrapper<Self> {
414413
// TODO(soon): Should the TypeWrapper object be stored on the isolate rather than the context?
415-
bool fastApiEnabled = false;
416-
417414
public:
418415
template <typename MetaConfiguration>
419416
TypeWrapper(v8::Isolate* isolate, MetaConfiguration&& configuration)
420417
: TypeWrapperBase<Self, T>(configuration)...,
421418
MaybeWrapper<Self>(configuration),
422419
GeneratorWrapper<Self>(configuration),
423-
PromiseWrapper<Self>(configuration) {
420+
PromiseWrapper<Self>(configuration),
421+
config(getConfig(configuration)) {
424422
isolate->SetData(SET_DATA_TYPE_WRAPPER, this);
425-
fastApiEnabled = util::Autogate::isEnabled(util::AutogateKey::V8_FAST_API);
426423
}
427424
KJ_DISALLOW_COPY_AND_MOVE(TypeWrapper);
428425

@@ -435,7 +432,7 @@ class TypeWrapper: public DynamicResourceTypeMap<Self>,
435432
}
436433

437434
bool isFastApiEnabled() const {
438-
return fastApiEnabled;
435+
return config.fastApiEnabled;
439436
}
440437

441438
using TypeWrapperBase<Self, T>::getName...;
@@ -600,6 +597,9 @@ class TypeWrapper: public DynamicResourceTypeMap<Self>,
600597
void initReflection(Holder* holder, PropertyReflection<U>&... reflections) {
601598
(initReflection(holder, reflections), ...);
602599
}
600+
601+
private:
602+
const JsgConfig config;
603603
};
604604

605605
template <typename Self, typename... Types>

src/workerd/server/workerd-api.c++

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <workerd/rust/transpiler/lib.rs.h>
5959
#include <workerd/server/actor-id-impl.h>
6060
#include <workerd/server/fallback-service.h>
61+
#include <workerd/util/autogate.h>
6162
#include <workerd/util/thread-scopes.h>
6263
#include <workerd/util/use-perfetto-categories.h>
6364

@@ -268,6 +269,7 @@ struct WorkerdApi::Impl final {
268269
.noSubstituteNull = features.getNoSubstituteNull(),
269270
.unwrapCustomThenables = features.getUnwrapCustomThenables(),
270271
.fetchIterableTypeSupport = features.getFetchIterableTypeSupport(),
272+
.fastApiEnabled = util::Autogate::isEnabled(util::AutogateKey::V8_FAST_API),
271273
}) {}
272274
operator const CompatibilityFlags::Reader() const {
273275
return features;

0 commit comments

Comments
 (0)