1 A source holds its file open only while it is compiled. A live program thus 2 holds no open file, also not for the modules that it links. The text for an 3 error message is read from the path of the source. If that file is gone, the 4 message has no source context. 5 6 -- Testcase -- 7 import * as fs from 'fs'; 8 9 function open_files() { 10 return length(fs.lsdir("/proc/self/fd")); 11 } 12 13 function raise(label, fn, text) { 14 try { 15 fn(); 16 } 17 catch (e) { 18 print(label, ": ", e.message, ", line ", e.stacktrace[0].line, 19 index(e.stacktrace[0].context, text) < 0 ? ", no source text\n" : ", with source text\n"); 20 } 21 } 22 23 fs.mkdir("files"); 24 25 let fds = open_files(); 26 let held = []; 27 28 for (let i = 0; i < 100; i++) { 29 fs.writefile(`files/mod${i}.uc`, "export const value = 1;\n"); 30 fs.writefile(`files/root${i}.uc`, `import { value } from './mod${i}.uc';\nreturn value;\n`); 31 push(held, loadfile(`files/root${i}.uc`)); 32 } 33 34 print("open files for 100 live programs: ", open_files() - fds, "\n"); 35 36 fs.writefile("files/fail.uc", "let o = {};\n\nreturn {\n\tstore: () => null.x = 1,\n\tcall: () => o.missing()\n};\n"); 37 38 let fail = loadfile("files/fail.uc")(); 39 40 raise("store", fail.store, "null.x = 1"); 41 raise("call", fail.call, "o.missing()"); 42 43 fs.chdir("files"); 44 raise("store, other directory", fail.store, "null.x = 1"); 45 fs.chdir(".."); 46 47 fs.unlink("files/fail.uc"); 48 49 raise("store, file removed", fail.store, "null.x = 1"); 50 raise("call, file removed", fail.call, "o.missing()"); 51 52 fs.writefile("files/broken.uc", "let x = 1;\nlet = 2;\n"); 53 54 try { 55 loadfile("files/broken.uc"); 56 } 57 catch (e) { 58 print(e.message); 59 } 60 61 print("open files at the end: ", open_files() - fds, "\n"); 62 -- End -- 63 64 -- Args -- 65 -R 66 -- End -- 67 68 -- Expect stdout -- 69 open files for 100 live programs: 0 70 store: attempt to set property on null value, line 4, with source text 71 call: `o.missing` is not a function, got null instead, line 5, with source text 72 store, other directory: attempt to set property on null value, line 4, with source text 73 store, file removed: attempt to set property on null value, line 4, no source text 74 call, file removed: left-hand side is not a function, got null instead, line 5, no source text 75 Unable to compile source file 'files/broken.uc': 76 77 | Syntax error: Expecting variable name 78 | In line 2, byte 5: 79 | 80 | `let = 2;` 81 | ^-- Near here 82 open files at the end: 0 83 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt