@isolated-vm/experimental 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/value/function.cc +2 -2
- package/addon/value/value.cc +1 -0
- package/backend/backend_v8.d.ts +1 -0
- package/dist/frontend/agent.d.ts +0 -1
- package/dist/frontend/agent.d.ts.map +1 -1
- package/dist/frontend/agent.js +1 -6
- package/dist/frontend/agent.js.map +1 -1
- package/dist/test/00.transfer.js +53 -23
- package/dist/test/00.transfer.js.map +1 -1
- package/dist/test/20.array_buffer.js +222 -105
- package/dist/test/20.array_buffer.js.map +1 -1
- package/dist/test/90.isolation/00.dispose.d.ts +2 -0
- package/dist/test/90.isolation/00.dispose.d.ts.map +1 -0
- package/dist/test/90.isolation/00.dispose.js +28 -0
- package/dist/test/90.isolation/00.dispose.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility/linker.js +1 -1
- package/dist/utility/linker.js.map +1 -1
- package/frontend/agent.ts +1 -7
- package/package.json +13 -10
- package/test/00.transfer.ts +17 -11
- package/test/20.array_buffer.ts +83 -61
- package/test/90.isolation/00.dispose.ts +15 -0
- package/utility/linker.ts +1 -1
package/test/20.array_buffer.ts
CHANGED
|
@@ -3,9 +3,13 @@ import { describe, test } from "node:test";
|
|
|
3
3
|
import * as ivm from "@isolated-vm/experimental";
|
|
4
4
|
import { injectAssert, unsafeEvalAsString, unsafeEvalAsStringInRealm } from "./fixtures.js";
|
|
5
5
|
|
|
6
|
+
const hostSupportsSharedArraySupport =
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
process.isBun === undefined && process.versions.deno === undefined;
|
|
9
|
+
|
|
6
10
|
await describe("array buffer", async () => {
|
|
7
|
-
await using agent = await ivm.Agent.create();
|
|
8
11
|
await describe("transfer out", async () => {
|
|
12
|
+
await using agent = await ivm.Agent.create();
|
|
9
13
|
const ab = await unsafeEvalAsString(agent, () => {
|
|
10
14
|
const uint8 = new Uint8Array([ 1, 2, 3 ]);
|
|
11
15
|
return uint8.buffer;
|
|
@@ -14,16 +18,20 @@ await describe("array buffer", async () => {
|
|
|
14
18
|
assert.deepStrictEqual(uint8, new Uint8Array([ 1, 2, 3 ]));
|
|
15
19
|
});
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const ab =
|
|
21
|
-
|
|
21
|
+
if (hostSupportsSharedArraySupport) {
|
|
22
|
+
await test("transfer out same reference", async () => {
|
|
23
|
+
await using agent = await ivm.Agent.create();
|
|
24
|
+
const ab = await unsafeEvalAsString(agent, () => {
|
|
25
|
+
// nb: also tests zero-length buffer
|
|
26
|
+
const ab = new ArrayBuffer(0);
|
|
27
|
+
return [ ab, ab ];
|
|
28
|
+
});
|
|
29
|
+
assert.strictEqual(ab[0], ab[1]);
|
|
22
30
|
});
|
|
23
|
-
|
|
24
|
-
});
|
|
31
|
+
}
|
|
25
32
|
|
|
26
33
|
await test("transfer in", async () => {
|
|
34
|
+
await using agent = await ivm.Agent.create();
|
|
27
35
|
const realm = await agent.createRealm();
|
|
28
36
|
await injectAssert(agent, realm);
|
|
29
37
|
const global = await realm.acquireGlobalObject();
|
|
@@ -36,6 +44,7 @@ await describe("array buffer", async () => {
|
|
|
36
44
|
});
|
|
37
45
|
|
|
38
46
|
await test("transfer in same reference", async () => {
|
|
47
|
+
await using agent = await ivm.Agent.create();
|
|
39
48
|
const realm = await agent.createRealm();
|
|
40
49
|
await injectAssert(agent, realm);
|
|
41
50
|
const global = await realm.acquireGlobalObject();
|
|
@@ -50,71 +59,80 @@ await describe("array buffer", async () => {
|
|
|
50
59
|
});
|
|
51
60
|
|
|
52
61
|
await describe("shared array buffer", async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const sab =
|
|
62
|
+
if (hostSupportsSharedArraySupport) {
|
|
63
|
+
await describe("transfer out", async () => {
|
|
64
|
+
await using agent = await ivm.Agent.create();
|
|
65
|
+
const realm = await agent.createRealm();
|
|
66
|
+
const sab = await unsafeEvalAsStringInRealm(agent, realm, () => {
|
|
67
|
+
const sab = new SharedArrayBuffer(3);
|
|
68
|
+
const uint8 = new Uint8Array(sab);
|
|
69
|
+
uint8.set([ 1, 2, 3 ]);
|
|
70
|
+
// @ts-expect-error
|
|
71
|
+
globalThis.uint8 = uint8;
|
|
72
|
+
return sab;
|
|
73
|
+
});
|
|
74
|
+
assert.ok(sab instanceof SharedArrayBuffer);
|
|
58
75
|
const uint8 = new Uint8Array(sab);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return sab;
|
|
63
|
-
});
|
|
64
|
-
assert.ok(sab instanceof SharedArrayBuffer);
|
|
65
|
-
const uint8 = new Uint8Array(sab);
|
|
66
|
-
assert.deepStrictEqual(uint8, new Uint8Array([ 1, 2, 3 ]));
|
|
67
|
-
uint8.set([ 3, 2, 1 ]);
|
|
68
|
-
const next = await unsafeEvalAsStringInRealm(agent, realm, () => {
|
|
76
|
+
assert.deepStrictEqual(uint8, new Uint8Array([ 1, 2, 3 ]));
|
|
77
|
+
uint8.set([ 3, 2, 1 ]);
|
|
78
|
+
const next = await unsafeEvalAsStringInRealm(agent, realm, () => {
|
|
69
79
|
// @ts-expect-error
|
|
70
80
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
const uint8: Uint8Array = globalThis.uint8;
|
|
82
|
+
return [ ...uint8 ];
|
|
83
|
+
});
|
|
84
|
+
assert.deepStrictEqual(next, [ 3, 2, 1 ]);
|
|
73
85
|
});
|
|
74
|
-
assert.deepStrictEqual(next, [ 3, 2, 1 ]);
|
|
75
|
-
});
|
|
76
86
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
await test("transfer out same reference", async () => {
|
|
88
|
+
await using agent = await ivm.Agent.create();
|
|
89
|
+
const ab = await unsafeEvalAsString(agent, () => {
|
|
90
|
+
// nb: also tests zero-length buffer
|
|
91
|
+
const sab = new SharedArrayBuffer(0);
|
|
92
|
+
return [ sab, sab ];
|
|
93
|
+
});
|
|
94
|
+
assert.strictEqual(ab[0], ab[1]);
|
|
82
95
|
});
|
|
83
|
-
assert.strictEqual(ab[0], ab[1]);
|
|
84
|
-
});
|
|
85
96
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
await test("transfer in", async () => {
|
|
98
|
+
await using agent = await ivm.Agent.create();
|
|
99
|
+
const realm = await agent.createRealm();
|
|
100
|
+
await injectAssert(agent, realm);
|
|
101
|
+
const global = await realm.acquireGlobalObject();
|
|
102
|
+
const sab = new SharedArrayBuffer(3);
|
|
103
|
+
const uint8 = new Uint8Array(sab);
|
|
104
|
+
uint8.set([ 1, 2, 3 ]);
|
|
105
|
+
await global.set("sab", sab);
|
|
106
|
+
await unsafeEvalAsStringInRealm(agent, realm, () => {
|
|
107
|
+
// @ts-expect-error
|
|
108
|
+
const uint8 = new Uint8Array(globalThis.sab);
|
|
109
|
+
assert.ok(uint8.buffer instanceof SharedArrayBuffer);
|
|
110
|
+
assert.deepStrictEqual([ ...uint8 ], [ 1, 2, 3 ]);
|
|
111
|
+
});
|
|
98
112
|
});
|
|
99
|
-
}
|
|
113
|
+
}
|
|
100
114
|
|
|
101
115
|
await test("transfer in same reference", async () => {
|
|
116
|
+
await using agent = await ivm.Agent.create();
|
|
102
117
|
const realm = await agent.createRealm();
|
|
103
118
|
await injectAssert(agent, realm);
|
|
104
119
|
const global = await realm.acquireGlobalObject();
|
|
105
|
-
const
|
|
106
|
-
await global.set("
|
|
120
|
+
const ab = new ArrayBuffer(0);
|
|
121
|
+
await global.set("abs", [ ab, ab ]);
|
|
107
122
|
await unsafeEvalAsStringInRealm(agent, realm, () => {
|
|
108
123
|
// @ts-expect-error
|
|
109
124
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
110
|
-
assert.strictEqual(
|
|
125
|
+
assert.strictEqual(`${abs[0]}`, "[object ArrayBuffer]");
|
|
126
|
+
// @ts-expect-error
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
128
|
+
assert.strictEqual(abs[0], abs[1]);
|
|
111
129
|
});
|
|
112
130
|
});
|
|
113
131
|
});
|
|
114
132
|
|
|
115
133
|
await describe("typed array", async () => {
|
|
116
|
-
await using agent = await ivm.Agent.create();
|
|
117
134
|
await test("transfer out", async () => {
|
|
135
|
+
await using agent = await ivm.Agent.create();
|
|
118
136
|
const [ uint8, uint8_copy ] = await unsafeEvalAsString(agent, () => {
|
|
119
137
|
const uint8 = new Uint8Array([ 1, 2, 3 ]);
|
|
120
138
|
return [ uint8, new Uint8Array(uint8.buffer) ];
|
|
@@ -124,6 +142,7 @@ await describe("typed array", async () => {
|
|
|
124
142
|
});
|
|
125
143
|
|
|
126
144
|
await test("transfer in", async () => {
|
|
145
|
+
await using agent = await ivm.Agent.create();
|
|
127
146
|
const realm = await agent.createRealm();
|
|
128
147
|
await injectAssert(agent, realm);
|
|
129
148
|
const global = await realm.acquireGlobalObject();
|
|
@@ -137,15 +156,18 @@ await describe("typed array", async () => {
|
|
|
137
156
|
});
|
|
138
157
|
});
|
|
139
158
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
if (hostSupportsSharedArraySupport) {
|
|
160
|
+
await test("shared transfer out", async () => {
|
|
161
|
+
await using agent = await ivm.Agent.create();
|
|
162
|
+
const [ shared_uint8, shared_uint8_copy ] = await unsafeEvalAsString(agent, () => {
|
|
163
|
+
const sab = new SharedArrayBuffer(3);
|
|
164
|
+
const uint8 = new Uint8Array(sab);
|
|
165
|
+
uint8.set([ 1, 2, 3 ]);
|
|
166
|
+
return [ uint8, new Uint8Array(uint8.buffer) ];
|
|
167
|
+
});
|
|
168
|
+
assert.ok(shared_uint8.buffer instanceof SharedArrayBuffer);
|
|
169
|
+
assert.deepStrictEqual(shared_uint8, new Uint8Array([ 1, 2, 3 ]));
|
|
170
|
+
assert.strictEqual(shared_uint8.buffer, shared_uint8_copy.buffer);
|
|
146
171
|
});
|
|
147
|
-
|
|
148
|
-
assert.deepStrictEqual(shared_uint8, new Uint8Array([ 1, 2, 3 ]));
|
|
149
|
-
assert.strictEqual(shared_uint8.buffer, shared_uint8_copy.buffer);
|
|
150
|
-
});
|
|
172
|
+
}
|
|
151
173
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import * as ivm from "@isolated-vm/experimental";
|
|
4
|
+
import {} from "@isolated-vm/experimental/test/fixtures";
|
|
5
|
+
|
|
6
|
+
await test("dispose while running", async () => {
|
|
7
|
+
const result = async function() {
|
|
8
|
+
await using agent = await ivm.Agent.create();
|
|
9
|
+
const realm = await agent.createRealm();
|
|
10
|
+
const script = ivm.expectComplete(await agent.compileScript("for(;;);"));
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
12
|
+
return script.run(realm);
|
|
13
|
+
}();
|
|
14
|
+
assert.strictEqual(await result, undefined);
|
|
15
|
+
});
|
package/utility/linker.ts
CHANGED
|
@@ -44,7 +44,7 @@ export function makeDirectResolver(): ResolverSync<string> {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export function makeLocalResolver(meta: ImportMeta): ResolverSync<string> {
|
|
47
|
-
return
|
|
47
|
+
return specifier => meta.resolve(specifier);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function makeCachedLoader<Type extends AbstractModule | undefined>(loader: LoaderAsync<Type>): LoaderAsync<Type> {
|