shim: test that all functions in compartments are instances of Function
in fact they should be 'instanceof' the Function object in any compartment
within the same RootRealm: they all share a prototype object.
MODIFY
shim/src/evaluators.js
shim/src/evaluators.js
@@ -226,7 +226,6 @@ export function createFunctionEvaluator(unsafeRec, safeEval) {
// Ensure that any function created in any compartment in a root realm is an
// instance of Function in any compartment of the same root ralm.
defineProperty(safeFunction, 'prototype', { value: unsafeFunction.prototype });
- // todo: write a test case
// Provide a custom output without overwriting the Function.prototype.toString
// which is called by some third-party libraries.

MODIFY
shim/test/realm/identity-compartment.js
shim/test/realm/identity-compartment.js
@@ -50,10 +50,11 @@ test('identity eval', t => {
// Function is realm-specific
test('identity Function', t => {
- t.plan(8);
+ t.plan(11);
const r1 = Realm.makeRootRealm();
const r2 = r1.global.Realm.makeCompartment();
+ const r3 = r1.global.Realm.makeCompartment();
t.ok(r2.evaluate('Function instanceof Function'));
t.ok(r2.evaluate('Function instanceof Object'));
@@ -63,4 +64,9 @@ test('identity Function', t => {
t.notOk(r2.evaluate('Function') instanceof Object);
t.notEqual(r2.evaluate('Function'), r1.evaluate('Function'));
t.notEqual(r2.evaluate('Function'), Function);
+
+ const f2 = r2.evaluate('function x(a, b) { return a+b; }; x');
+ t.ok(f2 instanceof r1.global.Function);
+ t.ok(f2 instanceof r2.global.Function);
+ t.ok(f2 instanceof r3.global.Function);
});

MODIFY
shim/test/realm/identity-single.js
shim/test/realm/identity-single.js
@@ -40,7 +40,7 @@ test('identity eval', t => {
// Function is realm-specific
test('identity Function', t => {
- t.plan(4);
+ t.plan(5);
const r = Realm.makeRootRealm();
@@ -48,4 +48,7 @@ test('identity Function', t => {
t.ok(r.evaluate('Function instanceof Object'));
t.notOk(r.evaluate('Function') instanceof Function);
t.notOk(r.evaluate('Function') instanceof Object);
+
+ const f = r.evaluate('function x(a, b) { return a+b; }; x');
+ t.ok(f instanceof r.global.Function);
});

shim: test that all functions in compartments are instances of Function

in fact they should be 'instanceof' the Function object in any compartment
within the same RootRealm: they all share a prototype object.