Skip to content

Commit

Permalink
chore(hardened262): Prettify Moddable test262 cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Oct 19, 2024
1 parent 2f69ddd commit 0bc22aa
Show file tree
Hide file tree
Showing 59 changed files with 1,693 additions and 1,466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ flags: [onlyStrict]
includes: [propertyHelper.js]
---*/

var descriptor = Object.getOwnPropertyDescriptor(ModuleSource.prototype, 'bindings');
var descriptor = Object.getOwnPropertyDescriptor(
ModuleSource.prototype,
'bindings',
);

assert.sameValue(
typeof descriptor.get,
'function',
'typeof descriptor.get is function'
'typeof descriptor.get is function',
);
assert.sameValue(
typeof descriptor.set,
'undefined',
'typeof descriptor.set is undefined'
'typeof descriptor.set is undefined',
);

verifyNotEnumerable(ModuleSource.prototype, 'bindings');
Expand Down
118 changes: 59 additions & 59 deletions packages/hardened262/test/Compartment/ModuleSource/bindings/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,71 @@ flags: [onlyStrict]
---*/

const source = new ModuleSource(`
export var v0;
export default 0
export { v0 as w0 };
export var v0;
export default 0
export { v0 as w0 };
import v1 from "mod";
import * as ns1 from "mod";
import { x1 } from "mod";
import { v1 as w1 } from "mod";
import "mod";
import v1 from "mod";
import * as ns1 from "mod";
import { x1 } from "mod";
import { v1 as w1 } from "mod";
import "mod";
export { x2 } from "mod";
export { v2 as w2 } from "mod";
export * from "mod";
export * as ns2 from "mod";
export { x2 } from "mod";
export { v2 as w2 } from "mod";
export * from "mod";
export * as ns2 from "mod";
`);
const sourceBindingsString = JSON.stringify(source.bindings);

const bindings = [
{
export: "v0",
as: "w0"
},
{
export: "v0"
},
{
export: "default"
},
{
import: "default",
as: "v1",
from: "mod"
},
{
importAllFrom: "mod",
as: "ns1"
},
{
import: "x1",
from: "mod"
},
{
import: "v1",
as: "w1",
from: "mod"
},
{
importFrom: "mod"
},
{
export: "x2",
from: "mod"
},
{
export: "v2",
as: "w2",
from: "mod"
},
{
exportAllFrom: "mod"
},
{
exportAllFrom: "mod",
as: "ns2"
}
{
export: 'v0',
as: 'w0',
},
{
export: 'v0',
},
{
export: 'default',
},
{
import: 'default',
as: 'v1',
from: 'mod',
},
{
importAllFrom: 'mod',
as: 'ns1',
},
{
import: 'x1',
from: 'mod',
},
{
import: 'v1',
as: 'w1',
from: 'mod',
},
{
importFrom: 'mod',
},
{
export: 'x2',
from: 'mod',
},
{
export: 'v2',
as: 'w2',
from: 'mod',
},
{
exportAllFrom: 'mod',
},
{
exportAllFrom: 'mod',
as: 'ns2',
},
];
const bindingsString = JSON.stringify(bindings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ flags: [onlyStrict]
includes: [propertyHelper.js]
---*/

var descriptor = Object.getOwnPropertyDescriptor(ModuleSource.prototype, 'needsImport');
var descriptor = Object.getOwnPropertyDescriptor(
ModuleSource.prototype,
'needsImport',
);

assert.sameValue(
typeof descriptor.get,
'function',
'typeof descriptor.get is function'
'typeof descriptor.get is function',
);
assert.sameValue(
typeof descriptor.set,
'undefined',
'typeof descriptor.set is undefined'
'typeof descriptor.set is undefined',
);

verifyNotEnumerable(ModuleSource.prototype, 'needsImport');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ flags: [onlyStrict]
---*/

const smr1 = new ModuleSource(`
import * as foo from "foo";
import * as foo from "foo";
`);
assert.sameValue(smr1.needsImport, false, "needsImport");
assert.sameValue(smr1.needsImport, false, 'needsImport');

const smr2 = new ModuleSource(`
const foo = await import("foo");
const foo = await import("foo");
`);
assert.sameValue(smr2.needsImport, true, "needsImport");
assert.sameValue(smr2.needsImport, true, 'needsImport');

const smr3 = new ModuleSource(`
async function foo() {
return await import("foo");
}
async function foo() {
return await import("foo");
}
`);
assert.sameValue(smr3.needsImport, true, "needsImport");

assert.sameValue(smr3.needsImport, true, 'needsImport');
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ flags: [onlyStrict]
includes: [propertyHelper.js]
---*/

var descriptor = Object.getOwnPropertyDescriptor(ModuleSource.prototype, 'needsImportMeta');
var descriptor = Object.getOwnPropertyDescriptor(
ModuleSource.prototype,
'needsImportMeta',
);

assert.sameValue(
typeof descriptor.get,
'function',
'typeof descriptor.get is function'
'typeof descriptor.get is function',
);
assert.sameValue(
typeof descriptor.set,
'undefined',
'typeof descriptor.set is undefined'
'typeof descriptor.set is undefined',
);

verifyNotEnumerable(ModuleSource.prototype, 'needsImportMeta');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ flags: [onlyStrict]
---*/

const smr1 = new ModuleSource(`
import * as foo from "foo";
import * as foo from "foo";
`);
assert.sameValue(smr1.needsImportMeta, false, "needsImportMeta");
assert.sameValue(smr1.needsImportMeta, false, 'needsImportMeta');

const smr2 = new ModuleSource(`
const foo = import.meta.uri;
const foo = import.meta.uri;
`);
assert.sameValue(smr2.needsImportMeta, true, "needsImportMeta");
assert.sameValue(smr2.needsImportMeta, true, 'needsImportMeta');

const smr3 = new ModuleSource(`
function foo() {
return import.meta.uri;
}
function foo() {
return import.meta.uri;
}
`);
assert.sameValue(smr3.needsImportMeta, true, "needsImportMeta");

assert.sameValue(smr3.needsImportMeta, true, 'needsImportMeta');
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ flags: [async,onlyStrict]
---*/

const foo = new ModuleSource(`
export const x = 1;
export const z = 3;
export const x = 1;
export const z = 3;
`);

const bar = {
bindings:[
{ import: "x", from: "foo" },
{ export: "y" },
{ export: "z", from: "foo" },
],
async execute($, Import, ImportMeta) {
assert.throws(TypeError, () => {
$.z = 0;
});
assert.throws(TypeError, () => {
delete $.y;
});
assert.throws(TypeError, () => {
$.x = 0;
});
$.y = 2;
}
bindings: [
{ import: 'x', from: 'foo' },
{ export: 'y' },
{ export: 'z', from: 'foo' },
],
async execute($, Import, ImportMeta) {
assert.throws(TypeError, () => {
$.z = 0;
});
assert.throws(TypeError, () => {
delete $.y;
});
assert.throws(TypeError, () => {
$.x = 0;
});
$.y = 2;
},
};

const c1 = new Compartment({
resolveHook(importSpecifier, referrerSpecifier) {
return importSpecifier;
},
modules: {
foo: { source:foo },
bar: { source:bar },
}
const c1 = new Compartment({
resolveHook(importSpecifier, referrerSpecifier) {
return importSpecifier;
},
modules: {
foo: { source: foo },
bar: { source: bar },
},
});

c1.import("bar")
.then((ns) => {
assert.sameValue(ns.x, undefined);
assert.sameValue(ns.y, 2);
assert.sameValue(ns.z, 3);
})
.then($DONE, $DONE);
c1.import('bar')
.then(ns => {
assert.sameValue(ns.x, undefined);
assert.sameValue(ns.y, 2);
assert.sameValue(ns.z, 3);
})
.then($DONE, $DONE);
Loading

0 comments on commit 0bc22aa

Please sign in to comment.