From 2d349f67fa4adeae56e21a731c98edbd7dae7465 Mon Sep 17 00:00:00 2001 From: jiangkaiwen Date: Fri, 24 Feb 2023 11:17:17 +0800 Subject: [PATCH] Fix the accidental problem of dynamic-import case in ts2abc Issue:I6FF8I Signed-off-by: jiangkaiwen Change-Id: Ic9cea9ec7c39577dd3e5a8179614e97cca464804 --- test262/eshost.patch | 71 ++++++++++++++++++++++++++++------------ test262/run_sunspider.py | 5 ++- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/test262/eshost.patch b/test262/eshost.patch index 895a25e2ee..2872a2b4a4 100644 --- a/test262/eshost.patch +++ b/test262/eshost.patch @@ -1,13 +1,14 @@ -From 5a251716800252529f80e72a06eb5c84fab6e553 Mon Sep 17 00:00:00 2001 -Date: Thu, 17 Nov 2022 15:20:06 +0800 -Subject: [PATCH] Fix_eshost +From 70706af79b65cb3e6a2e8d3cb5335da2c81f5044 Mon Sep 17 00:00:00 2001 +Date: Fri, 24 Feb 2023 11:03:16 +0800 +Subject: [PATCH] eshost --- lib/Agent.js | 1 + - lib/ConsoleAgent.js | 35 +++++++++--------- + lib/ConsoleAgent.js | 43 ++++++++++++---------- lib/agents/panda.js | 88 +++++++++++++++++++++++++++++++++++++++++++++ + lib/dependencies.js | 6 ++-- runtimes/panda.js | 44 +++++++++++++++++++++++ - 4 files changed, 151 insertions(+), 17 deletions(-) + 5 files changed, 161 insertions(+), 21 deletions(-) create mode 100644 lib/agents/panda.js create mode 100644 runtimes/panda.js @@ -24,7 +25,7 @@ index edcdf0e..7e655c5 100644 if (typeof this.args === 'string') { this.args = this.args.includes(' ') ? diff --git a/lib/ConsoleAgent.js b/lib/ConsoleAgent.js -index 947c1db..cc194c8 100644 +index 947c1db..4c14f06 100644 --- a/lib/ConsoleAgent.js +++ b/lib/ConsoleAgent.js @@ -19,7 +19,7 @@ const { @@ -36,7 +37,7 @@ index 947c1db..cc194c8 100644 const now = Date.now(); return `f-${now}-${process.pid}-${(Math.random() * 0x100000000 + 1).toString(36)}.js`; } -@@ -47,9 +47,23 @@ class ConsoleAgent extends Agent { +@@ -47,9 +47,28 @@ class ConsoleAgent extends Agent { } } @@ -44,8 +45,12 @@ index 947c1db..cc194c8 100644 + let file = code.file; + let scenario = code.scenario === 'strict mode' ? '' : code.scenario; + let tmps = file.split(this.test262Dir); -+ let tempfile = path.join(this.out,tmps[1]); -+ tempfile = tempfile.substring(0,tempfile.indexOf('.js')); ++ let tempfile = path.join(this.out, tmps[1]); ++ tempfile = tempfile.substring(0, tempfile.indexOf('.js')); ++ let filebase = path.basename(tempfile); ++ if (tempfile.indexOf("/dynamic-import/") != -1) { ++ tempfile = path.join(tempfile, "/", filebase); ++ } + tempfile = path.normalize( + `${tempfile}${scenario}.js` + ); @@ -55,14 +60,15 @@ index 947c1db..cc194c8 100644 evalScript(code, options = {}) { - let tempfile = path.join(this[tpSym], generateTempFileName()); - let temppath = this[tpSym]; -+ ++ let filebase = path.basename(code.file); ++ let filepre = code.file.split(filebase)[0]; + let tempfile = this.genTempFileName(code); + let tempfilebase = path.basename(tempfile); -+ let deptemppath = tempfile.substring(0,tempfile.indexOf(tempfilebase)); - ++ let deptemppath = tempfile.substring(0, tempfile.indexOf(tempfilebase)); + let isExpectingRawSource = false; let hasDependencies = false; -@@ -57,11 +71,6 @@ class ConsoleAgent extends Agent { +@@ -57,11 +76,6 @@ class ConsoleAgent extends Agent { const sources = []; const dependencies = []; @@ -74,10 +80,10 @@ index 947c1db..cc194c8 100644 // When evalScript is called with a test262-stream test record: if (typeof code === 'object' && code.contents) { let {attrs, contents, file} = code; -@@ -84,13 +93,6 @@ class ConsoleAgent extends Agent { +@@ -84,13 +98,6 @@ class ConsoleAgent extends Agent { hasDependencies = false; } - + - if (options.module || attrs.flags.module || - hasModuleSpecifier(contents)) { - // When testing module or dynamic import code that imports itself, @@ -88,22 +94,25 @@ index 947c1db..cc194c8 100644 // The test record in "code" is no longer needed and // all further operations expect the "code" argument to be // a string, make that true for back-compat. -@@ -123,7 +125,7 @@ class ConsoleAgent extends Agent { +@@ -123,8 +130,9 @@ class ConsoleAgent extends Agent { // 3. Push the dependency and source into the sources to be written. // dependencies.forEach(file => { - let absname = path.join(temppath, file); +- let depsource = rawSource.get(path.basename(file)); + let absname = path.join(deptemppath, file); - let depsource = rawSource.get(path.basename(file)); - ++ let depfile = path.join(filepre, file); ++ let depsource = rawSource.get(depfile); + // Sometimes a test file might want to import itself, -@@ -161,7 +163,6 @@ class ConsoleAgent extends Agent { + // which is a valid exercise of the import semantics. +@@ -161,7 +169,6 @@ class ConsoleAgent extends Agent { sources.forEach(({0: file}) => fs.unlink(file, () => { /* ignore */ })); const result = this.normalizeResult({ stderr, stdout }); - result.error = this.parseError(result.stderr); - + return result; diff --git a/lib/agents/panda.js b/lib/agents/panda.js new file mode 100644 @@ -200,6 +209,26 @@ index 0000000..ab22b47 +PandaAgent.runtime = fs.readFileSync(runtimePath.for('panda'), 'utf8'); +module.exports = PandaAgent; \ No newline at end of file +diff --git a/lib/dependencies.js b/lib/dependencies.js +index 00de9a4..3de6002 100644 +--- a/lib/dependencies.js ++++ b/lib/dependencies.js +@@ -46,12 +46,12 @@ function getDependencies(file, accum = []) { + let basename = path.basename(file); + let contents = ''; + +- if (rawSourceCache.has(basename)) { +- contents = rawSourceCache.get(basename); ++ if (rawSourceCache.has(file)) { ++ contents = rawSourceCache.get(file); + } else { + try { + contents = fs.readFileSync(file, 'utf8'); +- rawSourceCache.set(basename, contents); ++ rawSourceCache.set(file, contents); + } catch (error) { + accum.splice(accum.indexOf(basename), 1); + } diff --git a/runtimes/panda.js b/runtimes/panda.js new file mode 100644 index 0000000..0acbd09 @@ -251,5 +280,5 @@ index 0000000..0acbd09 +}; +$262.source = $SOURCE; -- -2.25.1 +2.34.1 diff --git a/test262/run_sunspider.py b/test262/run_sunspider.py index 6837ac617b..cb0496ff40 100755 --- a/test262/run_sunspider.py +++ b/test262/run_sunspider.py @@ -369,7 +369,10 @@ class ArkProgram(): # pre-generate the dependencies' abc when ark_frontend is [es2panda] if (file_name in self.module_list or file_name in self.dynamicImport_list): - search_dir = os.path.dirname(js_file.replace(BASE_OUT_DIR, DATA_DIR)) + if ("dynamic-import" in js_file): + search_dir = os.path.dirname(js_file) + else: + search_dir = os.path.dirname(js_file.replace(BASE_OUT_DIR, DATA_DIR)) dependencies = collect_module_dependencies(js_file, search_dir, []) compile_as_module = self.check_compile_mode(js_file) if (self.ark_frontend == ARK_FRONTEND_LIST[1]): -- Gitee