Skip to content

Commit 54ee002

Browse files
committed
bumped SLOT_BITS to 24, minor touch ups
1 parent 69dcdd7 commit 54ee002

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

Plugins/PackageToJS/Templates/runtime.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function deserializeError(error) {
241241

242242
const globalVariable = globalThis;
243243

244-
const SLOT_BITS = 22;
244+
const SLOT_BITS = 24;
245245
const SLOT_MASK = (1 << SLOT_BITS) - 1;
246246
const GEN_MASK = (1 << (32 - SLOT_BITS)) - 1;
247247
class JSObjectSpace {
@@ -250,6 +250,7 @@ class JSObjectSpace {
250250
this._values = [];
251251
this._stateBySlot = [];
252252
this._freeSlotStack = [];
253+
// Note: 0 is preserved for invalid references, 1 is preserved for globalThis
253254
this._values[0] = undefined;
254255
this._values[1] = globalVariable;
255256
this._slotByValue.set(globalVariable, 1);
@@ -316,13 +317,13 @@ class JSObjectSpace {
316317
_getValidatedSlotState(reference) {
317318
const slot = reference & SLOT_MASK;
318319
if (slot === 0)
319-
throw new ReferenceError("Attempted to use invalid reference " + reference);
320+
throw new ReferenceError(`Attempted to use invalid reference ${reference}`);
320321
const state = this._stateBySlot[slot];
321322
if (state === undefined || (state & SLOT_MASK) === 0) {
322-
throw new ReferenceError("Attempted to use invalid reference " + reference);
323+
throw new ReferenceError(`Attempted to use invalid reference ${reference}`);
323324
}
324-
if ((state >>> SLOT_BITS) !== (reference >>> SLOT_BITS)) {
325-
throw new ReferenceError("Attempted to use stale reference " + reference);
325+
if (state >>> SLOT_BITS !== reference >>> SLOT_BITS) {
326+
throw new ReferenceError(`Attempted to use stale reference ${reference}`);
326327
}
327328
return state;
328329
}

Runtime/src/object-heap.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { globalVariable } from "./find-global.js";
22
import { ref } from "./types.js";
33

4-
const SLOT_BITS = 22;
4+
const SLOT_BITS = 24;
55
const SLOT_MASK = (1 << SLOT_BITS) - 1;
66
const GEN_MASK = (1 << (32 - SLOT_BITS)) - 1;
77

@@ -17,6 +17,7 @@ export class JSObjectSpace {
1717
this._stateBySlot = [];
1818
this._freeSlotStack = [];
1919

20+
// Note: 0 is preserved for invalid references, 1 is preserved for globalThis
2021
this._values[0] = undefined;
2122
this._values[1] = globalVariable;
2223
this._slotByValue.set(globalVariable, 1);
@@ -95,17 +96,17 @@ export class JSObjectSpace {
9596
const slot = reference & SLOT_MASK;
9697
if (slot === 0)
9798
throw new ReferenceError(
98-
"Attempted to use invalid reference " + reference,
99+
`Attempted to use invalid reference ${reference}`,
99100
);
100101
const state = this._stateBySlot[slot];
101102
if (state === undefined || (state & SLOT_MASK) === 0) {
102103
throw new ReferenceError(
103-
"Attempted to use invalid reference " + reference,
104+
`Attempted to use invalid reference ${reference}`,
104105
);
105106
}
106107
if (state >>> SLOT_BITS !== reference >>> SLOT_BITS) {
107108
throw new ReferenceError(
108-
"Attempted to use stale reference " + reference,
109+
`Attempted to use stale reference ${reference}`,
109110
);
110111
}
111112
return state;

0 commit comments

Comments
 (0)