|
| 1 | +import test from 'ava'; |
| 2 | +import '../index.js'; |
| 3 | + |
| 4 | +// The Float*Arrays are not fully harmless because they open a NaN side-channel |
| 5 | +// on some implementations like v8. However, they are still in the |
| 6 | +// start compartment, the intrinsics, and therefore repaired and frozen. They |
| 7 | +// are not endowed to constructed compartments by default, but can be |
| 8 | +// explicitly endowed. |
| 9 | +// The Int*Arrays remain fully harmless and universal. |
| 10 | +// |
| 11 | +test('float arrays in compartments', t => { |
| 12 | + t.false(Object.isFrozen(Float64Array)); |
| 13 | + t.false(Object.isFrozen(Int32Array)); |
| 14 | + lockdown(); |
| 15 | + t.true(Object.isFrozen(Float64Array)); |
| 16 | + t.true(Object.isFrozen(Int32Array)); |
| 17 | + |
| 18 | + const c1 = new Compartment(); |
| 19 | + const c2 = new Compartment({ |
| 20 | + __options__: true, |
| 21 | + globals: { Float64Array }, |
| 22 | + }); |
| 23 | + |
| 24 | + t.false('Float64Array' in c1.globalThis); |
| 25 | + t.true('Int32Array' in c1.globalThis); |
| 26 | + t.true('Float64Array' in c2.globalThis); |
| 27 | + |
| 28 | + t.is(c1.evaluate('Float64Array'), undefined); |
| 29 | + t.is(c1.evaluate('Int32Array'), Int32Array); |
| 30 | + t.is(c2.evaluate('Float64Array'), Float64Array); |
| 31 | + |
| 32 | + t.throws( |
| 33 | + () => { |
| 34 | + c1.evaluate(`new Float64Array()`); |
| 35 | + }, |
| 36 | + { |
| 37 | + message: 'Float64Array is not a constructor', |
| 38 | + }, |
| 39 | + ); |
| 40 | + t.true(c1.evaluate('new Int32Array()') instanceof Int32Array); |
| 41 | + t.true(c2.evaluate('new Float64Array()') instanceof Float64Array); |
| 42 | +}); |
0 commit comments