Update test262 test script and a few keyword escape fixes (#7503)
* Update test262 and whitelist * Use test262-stream * Check escapes in contextual keywords * Check escapes when parsing new.target * Check escapes for getters/setters * Check escapes for static class methods * Check escapes on async arrow and functions
This commit is contained in:
@@ -4,7 +4,7 @@ const path = require("path");
|
||||
const chalk = require("chalk");
|
||||
const utils = require("./run_babylon_test262_utils");
|
||||
|
||||
const testDir = path.join(__dirname, "../../../build/test262/test");
|
||||
const testDir = path.join(__dirname, "../../../build/test262");
|
||||
const whitelistFile = path.join(__dirname, "test262_whitelist.txt");
|
||||
const plugins = ["asyncGenerators", "objectRestSpread", "optionalCatchBinding"];
|
||||
const shouldUpdate = process.argv.indexOf("--update-whitelist") > -1;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("graceful-fs");
|
||||
const path = require("path");
|
||||
const promisify = require("util").promisify;
|
||||
const TestStream = require("test262-stream");
|
||||
const pfs = {
|
||||
readFile: promisify(fs.readFile),
|
||||
writeFile: promisify(fs.writeFile),
|
||||
@@ -12,115 +12,35 @@ const pfs = {
|
||||
|
||||
const parse = require("../../../packages/babylon").parse;
|
||||
|
||||
const modulePattern = /^\s*-\s*module\s*$|^\s*flags\s*:.*\bmodule\b/m;
|
||||
const noStrictPattern = /^\s*-\s*noStrict\s*$|^\s*flags\s*:.*\bnoStrict\b/m;
|
||||
const onlyStrictPattern = /^\s*-\s*onlyStrict\s*$|^\s*flags\s*:.*\bonlyStrict\b/m;
|
||||
const rawPattern = /^\s*-\s*raw\s*$|^\s*flags\s*:.*\braw\b/m;
|
||||
const testNamePattern = /^(?!.*_FIXTURE).*\.[jJ][sS]$/;
|
||||
|
||||
function flatten(array) {
|
||||
const flattened = [];
|
||||
array.forEach(function(element) {
|
||||
if (Array.isArray(element)) {
|
||||
flattened.push.apply(flattened, element);
|
||||
} else {
|
||||
flattened.push(element);
|
||||
}
|
||||
});
|
||||
return flattened;
|
||||
}
|
||||
|
||||
function hasEarlyError(src) {
|
||||
return !!(
|
||||
src.match(/^\s*negative:\s*$/m) && src.match(/^\s+phase:\s*early\s*$/m)
|
||||
);
|
||||
}
|
||||
|
||||
function readDirDeep(dirName) {
|
||||
return pfs.readdir(dirName).then(function(contents) {
|
||||
return Promise.all(
|
||||
contents.map(function(name) {
|
||||
return findTests(path.join(dirName, name));
|
||||
})
|
||||
).then(flatten);
|
||||
});
|
||||
}
|
||||
|
||||
function findTests(name) {
|
||||
return pfs.stat(name).then(function(stat) {
|
||||
if (stat.isDirectory()) {
|
||||
return readDirDeep(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
});
|
||||
}
|
||||
|
||||
function readTest(fileName, testDir) {
|
||||
if (!testNamePattern.test(fileName)) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return pfs.readFile(fileName, "utf-8").then(function(contents) {
|
||||
return makeScenarios(path.relative(testDir, fileName), contents);
|
||||
});
|
||||
}
|
||||
|
||||
function makeScenarios(fileName, testContent) {
|
||||
const scenarios = [];
|
||||
const base = {
|
||||
fileName: fileName,
|
||||
isModule: modulePattern.test(testContent),
|
||||
expectedError: hasEarlyError(testContent),
|
||||
};
|
||||
const isNoStrict = noStrictPattern.test(testContent);
|
||||
const isOnlyStrict = onlyStrictPattern.test(testContent);
|
||||
const isRaw = rawPattern.test(testContent);
|
||||
|
||||
if (!isOnlyStrict) {
|
||||
scenarios.push(
|
||||
Object.assign(
|
||||
{
|
||||
id: fileName + "(default)",
|
||||
content: testContent,
|
||||
},
|
||||
base
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!isNoStrict && !isRaw) {
|
||||
scenarios.push(
|
||||
Object.assign(
|
||||
{
|
||||
id: fileName + "(strict mode)",
|
||||
content: "'use strict';\n" + testContent,
|
||||
},
|
||||
base
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return scenarios;
|
||||
}
|
||||
|
||||
exports.getTests = function(testDir) {
|
||||
return findTests(testDir)
|
||||
.then(function(testPaths) {
|
||||
return Promise.all(
|
||||
testPaths.map(function(path) {
|
||||
return readTest(path, testDir);
|
||||
})
|
||||
);
|
||||
})
|
||||
.then(flatten);
|
||||
const stream = new TestStream(testDir, { omitRuntime: true });
|
||||
const tests = [];
|
||||
|
||||
stream.on("data", test => {
|
||||
// strip test/
|
||||
const fileName = test.file.substr(5);
|
||||
|
||||
tests.push({
|
||||
contents: test.contents,
|
||||
fileName,
|
||||
id: `${fileName}(${test.scenario})`,
|
||||
sourceType: test.attrs.flags.module ? "module" : "script",
|
||||
expectedError:
|
||||
!!test.attrs.negative &&
|
||||
(test.attrs.negative.phase === "parse" ||
|
||||
test.attrs.negative.phase === "early"),
|
||||
});
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("end", () => resolve(tests));
|
||||
stream.on("error", reject);
|
||||
});
|
||||
};
|
||||
|
||||
exports.runTest = function(test, plugins) {
|
||||
const sourceType = test.isModule ? "module" : "script";
|
||||
|
||||
try {
|
||||
parse(test.content, { sourceType: sourceType, plugins: plugins });
|
||||
parse(test.contents, { sourceType: test.sourceType, plugins: plugins });
|
||||
test.actualError = false;
|
||||
} catch (err) {
|
||||
test.actualError = true;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user