Skip to content

Commit 59f8fcc

Browse files
sirtimidclaude
andcommitted
fix(ocap-kernel): inject global/globalThis into SES compartment for Rolldown CJS compat
Rolldown-generated IIFE bundles include CJS helper code that uses `var localThis = globalThis` to access intrinsics, and some bundled libraries (e.g. lodash) detect the global object via `typeof global == "object" && global` or `Function("return this")()`. In a SES Compartment: - `global` and `self` are not named bindings - `Function("return this")()` returns undefined in strict mode Inject `globalThis` and `global` on the compartment's own global after construction so these patterns resolve to the compartment's global object (which exposes all the hardened intrinsics). Also fix the openclaw-plugin integration test to call `register.register()` rather than treating the PluginEntry object itself as a function. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 82d796f commit 59f8fcc

4 files changed

Lines changed: 13 additions & 38 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
"typescript": "~5.8.2",
103103
"typescript-eslint": "^8.29.0",
104104
"vite": "^8.0.6",
105-
"vite-tsconfig-paths": "^6.1.1",
106105
"vitest": "^4.1.3",
107106
"vitest-fetch-mock": "^0.4.5"
108107
},

packages/evm-wallet-experiment/test/integration/openclaw-plugin.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ exec "${process.execPath}" "${ocapCliEntrypoint}" "$@"
262262
]);
263263

264264
tools = new Map<string, ToolDefinition>();
265-
register({
265+
register.register({
266266
pluginConfig: {
267267
ocapCliPath,
268268
walletKref: rootKref,

packages/ocap-kernel/src/vats/bundle-loader.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ export function loadBundle(
4545
...endowments,
4646
...inescapableGlobalProperties,
4747
});
48+
// Rolldown-generated CJS helpers use `var localThis = globalThis`, and
49+
// some bundled libraries (e.g. lodash) detect the global via
50+
// `typeof global == "object" && global` or `Function("return this")()`.
51+
// None of these work in a SES Compartment out of the box:
52+
// - `global` / `self` are not compartment bindings
53+
// - `Function("return this")()` returns `undefined` in strict mode
54+
// Inject these properties on the compartment's own global so that both
55+
// patterns resolve to the compartment's global (which has all the intrinsics).
56+
const cg = compartment.globalThis as Record<string, unknown>;
57+
cg.globalThis = compartment.globalThis;
58+
cg.global = compartment.globalThis;
4859
// The code declares `var __vatExports__ = (function(){...})({});`
4960
// We wrap it in an IIFE to capture and return the result.
5061
const vatExports = compartment.evaluate(

yarn.lock

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,7 +3970,6 @@ __metadata:
39703970
typescript: "npm:~5.8.2"
39713971
typescript-eslint: "npm:^8.29.0"
39723972
vite: "npm:^8.0.6"
3973-
vite-tsconfig-paths: "npm:^6.1.1"
39743973
vitest: "npm:^4.1.3"
39753974
vitest-fetch-mock: "npm:^0.4.5"
39763975
languageName: unknown
@@ -7767,7 +7766,7 @@ __metadata:
77677766
languageName: node
77687767
linkType: hard
77697768

7770-
"debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4, debug@npm:^4.3.6, debug@npm:^4.4.0, debug@npm:^4.4.3, debug@npm:~4.4.1":
7769+
"debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4, debug@npm:^4.3.6, debug@npm:^4.4.0, debug@npm:^4.4.3, debug@npm:~4.4.1":
77717770
version: 4.4.3
77727771
resolution: "debug@npm:4.4.3"
77737772
dependencies:
@@ -9736,13 +9735,6 @@ __metadata:
97369735
languageName: node
97379736
linkType: hard
97389737

9739-
"globrex@npm:^0.1.2":
9740-
version: 0.1.2
9741-
resolution: "globrex@npm:0.1.2"
9742-
checksum: 10/81ce62ee6f800d823d6b7da7687f841676d60ee8f51f934ddd862e4057316d26665c4edc0358d4340a923ac00a514f8b67c787e28fe693aae16350f4e60d55e9
9743-
languageName: node
9744-
linkType: hard
9745-
97469738
"gopd@npm:^1.0.1, gopd@npm:^1.2.0":
97479739
version: 1.2.0
97489740
resolution: "gopd@npm:1.2.0"
@@ -14971,20 +14963,6 @@ __metadata:
1497114963
languageName: node
1497214964
linkType: hard
1497314965

14974-
"tsconfck@npm:^3.0.3":
14975-
version: 3.1.5
14976-
resolution: "tsconfck@npm:3.1.5"
14977-
peerDependencies:
14978-
typescript: ^5.0.0
14979-
peerDependenciesMeta:
14980-
typescript:
14981-
optional: true
14982-
bin:
14983-
tsconfck: bin/tsconfck.js
14984-
checksum: 10/46b68f0fcec7da045490e427400c2a7fea67bdb6dae871257e8d2ec48e9dc99674214df86ff51c6d01ceb68ba9d7d806d3b69de432efa3c76b5fba160c252857
14985-
languageName: node
14986-
linkType: hard
14987-
1498814966
"tslib@npm:^1.9.3":
1498914967
version: 1.14.1
1499014968
resolution: "tslib@npm:1.14.1"
@@ -15695,19 +15673,6 @@ __metadata:
1569515673
languageName: node
1569615674
linkType: hard
1569715675

15698-
"vite-tsconfig-paths@npm:^6.1.1":
15699-
version: 6.1.1
15700-
resolution: "vite-tsconfig-paths@npm:6.1.1"
15701-
dependencies:
15702-
debug: "npm:^4.1.1"
15703-
globrex: "npm:^0.1.2"
15704-
tsconfck: "npm:^3.0.3"
15705-
peerDependencies:
15706-
vite: "*"
15707-
checksum: 10/f752bce4f3c5707f0df7af8a20294b1f325e26f50578b82c8262d851028616ebb1a3e73ab0789c55cf3c8da8d985e843193c0bec2cb31662c567ccdf137f1fd0
15708-
languageName: node
15709-
linkType: hard
15710-
1571115676
"vite@npm:^6.0.0 || ^7.0.0 || ^8.0.0, vite@npm:^8.0.6":
1571215677
version: 8.0.6
1571315678
resolution: "vite@npm:8.0.6"

0 commit comments

Comments
 (0)