Skip to content

Commit fecae25

Browse files
committed
Get DefaultPlatform from IsolateBase
1 parent ba0d83b commit fecae25

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

src/workerd/jsg/jsg.c++

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ void Lock::terminateExecution() {
272272
}
273273

274274
void Lock::pumpMessageLoop() {
275-
auto& system = const_cast<jsg::V8System&>(this->getV8System());
276-
while (v8::platform::PumpMessageLoop(&system.getDefaultPlatform(), v8Isolate)) {}
275+
auto platform = IsolateBase::from(v8Isolate).getDefaultPlatform();
276+
while (v8::platform::PumpMessageLoop(platform, v8Isolate)) {}
277277
}
278278

279279
Name Lock::newSymbol(kj::StringPtr symbol) {

src/workerd/jsg/jsg.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,9 +2721,6 @@ class Lock {
27212721
// Retrieve the worker environment.
27222722
virtual kj::Maybe<Value> getWorkerEnv() = 0;
27232723

2724-
protected:
2725-
virtual const V8System& getV8System() = 0;
2726-
27272724
private:
27282725
// Mark the jsg::Lock as being disallowed from being passed as a parameter into
27292726
// a kj promise coroutine. Note that this only blocks directly passing the Lock

src/workerd/jsg/setup.c++

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,9 @@ static v8::Isolate* newIsolate(v8::Isolate::CreateParams&& params, v8::CppHeap*
335335
}
336336
} // namespace
337337

338-
IsolateBase::IsolateBase(const V8System& system,
339-
v8::Isolate::CreateParams&& createParams,
340-
kj::Own<IsolateObserver> observer)
341-
: system(system),
338+
IsolateBase::IsolateBase(
339+
V8System& system, v8::Isolate::CreateParams&& createParams, kj::Own<IsolateObserver> observer)
340+
: defaultPlatform(&system.getDefaultPlatform()),
342341
cppHeap(newCppHeap(const_cast<V8PlatformWrapper*>(&system.platformWrapper))),
343342
ptr(newIsolate(kj::mv(createParams), cppHeap.release())),
344343
envAsyncContextKey(kj::refcounted<AsyncContextFrame::StorageKey>()),

src/workerd/jsg/setup.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ class IsolateBase {
8686
public:
8787
static IsolateBase& from(v8::Isolate* isolate);
8888

89-
auto& getV8System() {
90-
return system;
91-
}
92-
9389
// Unwraps a JavaScript exception as a kj::Exception.
9490
virtual kj::Exception unwrapException(
9591
v8::Local<v8::Context> context, v8::Local<v8::Value> exception) = 0;
@@ -227,6 +223,10 @@ class IsolateBase {
227223
return *envAsyncContextKey;
228224
}
229225

226+
v8::Platform* getDefaultPlatform() {
227+
return defaultPlatform;
228+
}
229+
230230
private:
231231
template <typename TypeWrapper>
232232
friend class Isolate;
@@ -259,7 +259,7 @@ class IsolateBase {
259259

260260
using Item = kj::OneOf<v8::Global<v8::Data>, RefToDelete>;
261261

262-
const V8System& system;
262+
v8::Platform* defaultPlatform;
263263
// TODO(cleanup): After v8 13.4 is fully released we can inline this into `newIsolate`
264264
// and remove this member.
265265
std::unique_ptr<class v8::CppHeap> cppHeap;
@@ -333,7 +333,7 @@ class IsolateBase {
333333
// Maps instructions to source code locations.
334334
kj::TreeMap<uintptr_t, CodeBlockInfo> codeMap;
335335

336-
explicit IsolateBase(const V8System& system,
336+
explicit IsolateBase(V8System& system,
337337
v8::Isolate::CreateParams&& createParams,
338338
kj::Own<IsolateObserver> observer);
339339
~IsolateBase() noexcept(false);
@@ -455,7 +455,7 @@ class Isolate: public IsolateBase {
455455
// and should be instantiated with `instantiateTypeWrapper` before `newContext` is called on
456456
// a jsg::Lock of this Isolate.
457457
template <typename MetaConfiguration>
458-
explicit Isolate(const V8System& system,
458+
explicit Isolate(V8System& system,
459459
MetaConfiguration&& configuration,
460460
kj::Own<IsolateObserver> observer,
461461
v8::Isolate::CreateParams createParams = {},
@@ -468,7 +468,7 @@ class Isolate: public IsolateBase {
468468
}
469469

470470
// Use this constructor when no wrappers have any required configuration.
471-
explicit Isolate(const V8System& system,
471+
explicit Isolate(V8System& system,
472472
kj::Own<IsolateObserver> observer,
473473
v8::Isolate::CreateParams createParams = {})
474474
: Isolate(system, nullptr, kj::mv(observer), kj::mv(createParams)) {}

src/workerd/server/tests/weakref/test.mjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
This is a node.js script which handlers workerd lifecycle and sends multiple requests.
3+
FinalizationRegistry callbacks run after the exported handler returns, and wd-test,
4+
which only run tests within a single test() handler, are not enough to test this behaviour
5+
*/
6+
17
import { env } from 'node:process';
28
import { beforeEach, afterEach, test } from 'node:test';
39
import assert from 'node:assert';
@@ -6,12 +12,14 @@ import { WorkerdServerHarness } from '../server-harness.mjs';
612
// Global that is reset for each test.
713
let workerd;
814

9-
assert(
10-
env.WORKERD_BINARY !== undefined,
15+
assert.notStrictEqual(
16+
env.WORKERD_BINARY,
17+
undefined,
1118
'You must set the WORKERD_BINARY environment variable.'
1219
);
13-
assert(
14-
env.WORKERD_CONFIG !== undefined,
20+
assert.notStrictEqual(
21+
env.WORKERD_CONFIG,
22+
undefined,
1523
'You must set the WORKERD_CONFIG environment variable.'
1624
);
1725

@@ -33,7 +41,7 @@ beforeEach(async () => {
3341
// Stop workerd.
3442
afterEach(async () => {
3543
const [code, signal] = await workerd.stop();
36-
assert(code === 0 || signal === 'SIGTERM');
44+
assert(code === 0 || signal === 'SIGTERM', `code=${code}, signal=${signal}`);
3745
workerd = null;
3846
});
3947

@@ -43,6 +51,6 @@ test('JS FinalizationRegistry', async () => {
4351
let httpPort = await workerd.getListenPort('http');
4452
for (let i = 0; i < 3; ++i) {
4553
const response = await fetch(`http://localhost:${httpPort}`);
46-
assert.equal(await response.text(), i);
54+
assert.strictEqual(await response.text(), `${i}`);
4755
}
4856
});

0 commit comments

Comments
 (0)