Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions tools/wave/ecmascript/generate-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ const writeFile = async (path, data) => {
};

const parseFrontmatter = (src) => {
let sharedArrayBufferTest = false;

var sharedArrayBuffer = src.indexOf("sharedarraybuffer");
if (sharedArrayBuffer === -1) {
sharedArrayBufferTest = false;
} else {
sharedArrayBufferTest = true;
}

var start = src.indexOf("/*---");
var end = src.indexOf("---*/");
if (start === -1 || end === -1) return null;
if (start === -1 || end === -1) return sharedArrayBufferTest;

var match,
includes = [],
Expand Down Expand Up @@ -160,6 +169,7 @@ const parseFrontmatter = (src) => {
flags: flags,
negative: negative,
isDynamic: /dynamic-import/.test(frontmatter),
sharedArrayBufferTest: sharedArrayBufferTest
}; // lol, do better
};

Expand Down Expand Up @@ -189,6 +199,8 @@ const generateTest = async ({
currentPath,
templateContent,
iframeTemplateContent,
headerContent,
headerIFrameContent,
}) => {
if (!currentPath) currentPath = testsPath;
let stats = await readStats(currentPath);
Expand All @@ -207,6 +219,8 @@ const generateTest = async ({
testsPath,
templateContent,
iframeTemplateContent,
headerContent,
headerIFrameContent,
});
}
} else {
Expand All @@ -217,13 +231,19 @@ const generateTest = async ({
return;
}

const jsSrc = await readFile(currentPath);
const meta = parseFrontmatter(jsSrc);
let isSharedArrayBufferTest = meta.sharedArrayBufferTest;

const jsRelativePath = path.relative(testsPath, currentPath);
// console.log(jsRelativePath.replace('.js', ''))
const jsOutputPath = path.join(outputPath, jsRelativePath);
const htmlOutputPath = jsOutputPath.replace(".js", ".html");
const iframeHtmlOutputPath = jsOutputPath.replace(".js", ".iframe.html");
const jsSrc = await readFile(currentPath);
const meta = parseFrontmatter(jsSrc);
const htmlOutputPath = jsOutputPath.replace(".js", isSharedArrayBufferTest == true ? ".https.html" : ".html");
const iframeHtmlOutputPath = jsOutputPath.replace(".js", isSharedArrayBufferTest == true ? ".iframe.https.html" : ".iframe.html");

const htmlOutputHeadersPath = jsOutputPath.replace(".js", ".https.html.headers");
const iframeHtmlOutputHeadersPath = jsOutputPath.replace(".js", ".iframe.https.html.headers");

const includes = (meta && meta.includes) || [];
//console.log(includes);
const testContent = replacePlaceholders(templateContent, {
Expand All @@ -240,6 +260,10 @@ const generateTest = async ({

await writeFile(htmlOutputPath, testContent);
await writeFile(iframeHtmlOutputPath, iframeTestContent);
if (isSharedArrayBufferTest) {
await writeFile(htmlOutputHeadersPath, headerContent);
await writeFile(iframeHtmlOutputHeadersPath, headerIFrameContent);
}
await fs.copy(currentPath, jsOutputPath);
testCount++;
}
Expand Down Expand Up @@ -276,6 +300,8 @@ function replacePlaceholders(
__dirname,
"test-template.iframe.html"
);
const HEADER_TEMPLATE_NAME = path.join(__dirname, "header-template.html");
const IFRAME_HEADER_TEMPLATE_NAME = path.join(__dirname, "header-template.html");
const DEFAULT_TEST_DIR = "./test262";
const DEFAULT_OUTPUT_DIR = ".";
const SUB_DIR_NAME = "ecmascript";
Expand All @@ -295,12 +321,16 @@ function replacePlaceholders(
console.log("Reading test templates ...");
const templateContent = await readFile(HTML_TEMPLATE_NAME);
const iframeTemplateContent = await readFile(IFRAME_HTML_TEMPLATE_NAME);
const headerContent = await readFile(HEADER_TEMPLATE_NAME);
const headerIFrameContent = await readFile(IFRAME_HEADER_TEMPLATE_NAME);
console.log("Generating tests ...");
await generateTest({
testsPath,
outputPath: testsOutputPath,
templateContent,
iframeTemplateContent,
headerContent,
headerIFrameContent,
});
await fs.copy(adapterSourcePath, adapterDestinationPath);
await fs.copy(harnessDir, harnessOutputDir);
Expand Down
2 changes: 2 additions & 0 deletions tools/wave/ecmascript/header-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy:same-origin
Cross-Origin-Embedder-Policy:require-corp
3 changes: 3 additions & 0 deletions wmas2022-subset.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ node tools/wave/ecmascript/generate-tests.js $ECMADISTDIR
cp $ECMADISTDIR/LICENSE $WPTBASEDIR/ecmascript
rm -rf ecmascript/tests/**/*lookBehind*
rm -rf ecmascript/tests/**/*lookbehind*
rm -rf ecmascript/tests/**/*Temporal*
rm -rf ecmascript/tests/**/*temporal*
rm -rf ecmascript/tests/staging

# Integrate webgl tests [WEBGL-103]
WEBGLDISTDIR=$DISTDIR/webgl
Expand Down
Loading