From 1c94e77b0eaa843d0c6ec0bde08cb2deceafb337 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 29 May 2024 23:54:38 +0300 Subject: [PATCH] Restore tests and update pdf.js submodule --- pdf.js | 2 +- test/test.js | 346 +++++++++++++++++++++++++-------------------------- 2 files changed, 174 insertions(+), 174 deletions(-) diff --git a/pdf.js b/pdf.js index 97a8acd..849a4e2 160000 --- a/pdf.js +++ b/pdf.js @@ -1 +1 @@ -Subproject commit 97a8acd2dcbf73a7fbe26e24a38a2f29605e5718 +Subproject commit 849a4e27f507db7fdb7760b3eeb610d172499785 diff --git a/test/test.js b/test/test.js index 6f54f39..669216b 100644 --- a/test/test.js +++ b/test/test.js @@ -37,179 +37,179 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); describe('PDF Worker', function () { - // it('should import annotations', async function () { - // let buf = fs.readFileSync(__dirname + '/pdfs/1.pdf'); - // let result = await pdfWorker.importAnnotations(buf, []); - // - // let expectedResult = { - // imported: [{ - // type: 'highlight', - // position: { pageIndex: 0, rects: [[328, 395, 557, 406], [317, 385, 455, 396]] }, - // dateModified: '2019-06-05T13:52:44.000Z', - // authorName: '', - // comment: 'A comment for the highlighted text', - // color: '#ffff00', - // pageLabel: '1', - // text: 'Compilers for statically typed languages rely on type information to generate efficient machine code', - // sortIndex: '00000|002514|00386', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 0, - // rects: [[231.284, 402.126, 293.107, 410.142], [54, 392.164, 293.107, 400.18], [54, 382.201, 293.107, 390.217], [54, 372.238, 293.107, 380.254], [54, 362.276, 273.955, 370.292]] - // }, - // dateModified: '2020-02-07T07:24:34.000Z', - // authorName: '', - // comment: 'Sounds promising', - // color: '#c9222a', - // pageLabel: '1', - // text: 'We present an alternative compilation technique for dynamically-typed languages that identifies frequently executed loop traces at run-time and then generates machine code on the fly that is specialized for the actual dynamic types occurring on each path through the loop', - // sortIndex: '00000|000779|00381', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { pageIndex: 0, rects: [[54, 199.237, 293.1, 207.253], [54, 189.274, 67.943, 197.29]] }, - // dateModified: '2020-02-07T07:24:37.000Z', - // authorName: '', - // comment: 'Comment 2', - // color: '#589fee', - // pageLabel: '1', - // text: 'Dynamic languages such as JavaScript, Python, and Ruby, are popular', - // sortIndex: '00000|001536|00584', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 0, - // rects: [[54, 199.237, 293.1, 207.253], [54, 189.274, 293.107, 197.29], [54, 179.311, 293.107, 187.327], [54, 169.349, 234.673, 177.365]] - // }, - // dateModified: '2020-02-07T07:23:13.000Z', - // authorName: '', - // comment: 'Comment 1', - // color: '#f8c348', - // pageLabel: '1', - // text: 'Dynamic languages such as JavaScript, Python, and Ruby, are popular since they are expressive, accessible to non-experts, and make deployment as easy as distributing a source file. They are used for small scripts as well as for complex applications', - // sortIndex: '00000|001536|00584', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 0, - // rects: [[328.969, 196.896, 556.115, 204.912], [317.014, 186.933, 556.121, 194.949], [317.014, 176.971, 556.121, 184.987], [317.014, 167.008, 398.671, 175.024]] - // }, - // dateModified: '2020-02-07T07:23:32.000Z', - // authorName: '', - // comment: 'An important point', - // color: '#589fee', - // pageLabel: '1', - // text: 'Unlike method-based dynamic compilers, our dynamic compiler operates at the granularity of individual loops. This design choice is based on the expectation that programs spend most of their time in hot loops', - // sortIndex: '00000|003552|00587', - // tags: [], - // transferable: true - // }, { - // type: 'note', - // position: { pageIndex: 1, rects: [[343.157, 557.388, 365.157, 579.388]] }, - // dateModified: '2019-06-05T13:53:32.000Z', - // authorName: '', - // comment: 'Another comment', - // color: '#ffff00', - // pageLabel: '2', - // sortIndex: '00001|003623|00212', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 1, - // rects: [[65.955, 620.429, 293.101, 628.445], [54, 610.467, 293.106, 618.528], [54, 600.504, 177.745, 608.52]] - // }, - // dateModified: '2020-02-07T07:23:50.000Z', - // authorName: '', - // comment: 'A problem of nested loops', - // color: '#6cc055', - // pageLabel: '2', - // text: 'Nested loops can be difficult to optimize for tracing VMs. In a na¨ıve implementation, inner loops would become hot first, and the VM would start tracing there.', - // sortIndex: '00001|000459|00163', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { pageIndex: 1, rects: [[54, 470.99, 293.107, 479.006], [54, 461.027, 268.978, 469.043]] }, - // dateModified: '2020-02-07T07:24:04.000Z', - // authorName: '', - // comment: '', - // color: '#f8c348', - // pageLabel: '2', - // text: 'The system stops extending the inner tree when it reaches an outer loop, but then it starts a new trace at the outer loop header.', - // sortIndex: '00001|001247|00312', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 1, - // rects: [[65.955, 301.625, 293.101, 309.641], [54, 291.662, 293.104, 299.678], [54, 281.7, 293.107, 289.716], [54, 271.737, 263.85, 279.753]] - // }, - // dateModified: '2020-02-07T07:24:12.000Z', - // authorName: '', - // comment: '', - // color: '#f8c348', - // pageLabel: '2', - // text: 'We implemented these techniques for an existing JavaScript interpreter, SpiderMonkey. We call the resulting tracing VM TraceMonkey. TraceMonkey supports all the JavaScript features of SpiderMonkey, with a 2x-20x speedup for traceable programs', - // sortIndex: '00001|002143|00482', - // tags: [], - // transferable: true - // }, { - // type: 'note', - // position: { pageIndex: 1, rects: [[478.3, 697, 500.3, 719]] }, - // dateModified: '2020-02-07T07:23:40.000Z', - // authorName: '', - // comment: 'Use this in my thesis', - // color: '#f8c348', - // pageLabel: '2', - // sortIndex: '00001|003310|00073', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 1, - // rects: [[328.969, 176.096, 556.115, 184.112], [317.014, 166.133, 376.291, 174.149]] - // }, - // dateModified: '2020-02-07T07:24:24.000Z', - // authorName: '', - // comment: '', - // color: '#f8c348', - // pageLabel: '2', - // text: 'TraceMonkey always begins executing a program in the bytecode interpreter.', - // sortIndex: '00001|004682|00607', - // tags: [], - // transferable: true - // }, { - // type: 'highlight', - // position: { - // pageIndex: 1, - // rects: [[338.883, 136.245, 556.121, 144.261], [317.014, 126.282, 556.121, 134.298], [317.014, 116.32, 534.474, 124.336]] - // }, - // dateModified: '2020-02-07T07:24:29.000Z', - // authorName: '', - // comment: '', - // color: '#f8c348', - // pageLabel: '2', - // text: 'At the start of execution, there are no compiled traces yet, so the trace monitor counts the number of times each loop back edge is executed until a loop becomes hot, currently after 2 crossings', - // sortIndex: '00001|004901|00647', - // tags: [], - // transferable: true - // }], deleted: [] - // }; - // - // expect(result).to.deep.equal(expectedResult); - // }); + it('should import annotations', async function () { + let buf = fs.readFileSync(__dirname + '/pdfs/1.pdf'); + let result = await pdfWorker.importAnnotations(buf, []); + + let expectedResult = { + imported: [{ + type: 'highlight', + position: { pageIndex: 0, rects: [[328, 395, 557, 406], [317, 385, 455, 396]] }, + dateModified: '2019-06-05T13:52:44.000Z', + authorName: '', + comment: 'A comment for the highlighted text', + color: '#ffff00', + pageLabel: '1', + text: 'Compilers for statically typed languages rely on type information to generate efficient machine code', + sortIndex: '00000|002514|00386', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 0, + rects: [[231.284, 402.126, 293.107, 410.142], [54, 392.164, 293.107, 400.18], [54, 382.201, 293.107, 390.217], [54, 372.238, 293.107, 380.254], [54, 362.276, 273.955, 370.292]] + }, + dateModified: '2020-02-07T07:24:34.000Z', + authorName: '', + comment: 'Sounds promising', + color: '#c9222a', + pageLabel: '1', + text: 'We present an alternative compilation technique for dynamically-typed languages that identifies frequently executed loop traces at run-time and then generates machine code on the fly that is specialized for the actual dynamic types occurring on each path through the loop', + sortIndex: '00000|000779|00381', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { pageIndex: 0, rects: [[54, 199.237, 293.1, 207.253], [54, 189.274, 67.943, 197.29]] }, + dateModified: '2020-02-07T07:24:37.000Z', + authorName: '', + comment: 'Comment 2', + color: '#589fee', + pageLabel: '1', + text: 'Dynamic languages such as JavaScript, Python, and Ruby, are popular', + sortIndex: '00000|001536|00584', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 0, + rects: [[54, 199.237, 293.1, 207.253], [54, 189.274, 293.107, 197.29], [54, 179.311, 293.107, 187.327], [54, 169.349, 234.673, 177.365]] + }, + dateModified: '2020-02-07T07:23:13.000Z', + authorName: '', + comment: 'Comment 1', + color: '#f8c348', + pageLabel: '1', + text: 'Dynamic languages such as JavaScript, Python, and Ruby, are popular since they are expressive, accessible to non-experts, and make deployment as easy as distributing a source file. They are used for small scripts as well as for complex applications', + sortIndex: '00000|001536|00584', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 0, + rects: [[328.969, 196.896, 556.115, 204.912], [317.014, 186.933, 556.121, 194.949], [317.014, 176.971, 556.121, 184.987], [317.014, 167.008, 398.671, 175.024]] + }, + dateModified: '2020-02-07T07:23:32.000Z', + authorName: '', + comment: 'An important point', + color: '#589fee', + pageLabel: '1', + text: 'Unlike method-based dynamic compilers, our dynamic compiler operates at the granularity of individual loops. This design choice is based on the expectation that programs spend most of their time in hot loops', + sortIndex: '00000|003552|00587', + tags: [], + transferable: true + }, { + type: 'note', + position: { pageIndex: 1, rects: [[343.157, 557.388, 365.157, 579.388]] }, + dateModified: '2019-06-05T13:53:32.000Z', + authorName: '', + comment: 'Another comment', + color: '#ffff00', + pageLabel: '2', + sortIndex: '00001|003623|00212', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 1, + rects: [[65.955, 620.429, 293.101, 628.445], [54, 610.467, 293.106, 618.528], [54, 600.504, 177.745, 608.52]] + }, + dateModified: '2020-02-07T07:23:50.000Z', + authorName: '', + comment: 'A problem of nested loops', + color: '#6cc055', + pageLabel: '2', + text: 'Nested loops can be difficult to optimize for tracing VMs. In a na ̈ıve implementation, inner loops would become hot first, and the VM would start tracing there.', + sortIndex: '00001|000459|00163', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { pageIndex: 1, rects: [[54, 470.99, 293.107, 479.006], [54, 461.027, 268.978, 469.043]] }, + dateModified: '2020-02-07T07:24:04.000Z', + authorName: '', + comment: '', + color: '#f8c348', + pageLabel: '2', + text: 'The system stops extending the inner tree when it reaches an outer loop, but then it starts a new trace at the outer loop header.', + sortIndex: '00001|001247|00312', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 1, + rects: [[65.955, 301.625, 293.101, 309.641], [54, 291.662, 293.104, 299.678], [54, 281.7, 293.107, 289.716], [54, 271.737, 263.85, 279.753]] + }, + dateModified: '2020-02-07T07:24:12.000Z', + authorName: '', + comment: '', + color: '#f8c348', + pageLabel: '2', + text: 'We implemented these techniques for an existing JavaScript interpreter, SpiderMonkey. We call the resulting tracing VM TraceMonkey. TraceMonkey supports all the JavaScript features of SpiderMonkey, with a 2x-20x speedup for traceable programs', + sortIndex: '00001|002143|00482', + tags: [], + transferable: true + }, { + type: 'note', + position: { pageIndex: 1, rects: [[478.3, 697, 500.3, 719]] }, + dateModified: '2020-02-07T07:23:40.000Z', + authorName: '', + comment: 'Use this in my thesis', + color: '#f8c348', + pageLabel: '2', + sortIndex: '00001|003310|00073', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 1, + rects: [[328.969, 176.096, 556.115, 184.112], [317.014, 166.133, 376.291, 174.149]] + }, + dateModified: '2020-02-07T07:24:24.000Z', + authorName: '', + comment: '', + color: '#f8c348', + pageLabel: '2', + text: 'TraceMonkey always begins executing a program in the bytecode interpreter.', + sortIndex: '00001|004682|00607', + tags: [], + transferable: true + }, { + type: 'highlight', + position: { + pageIndex: 1, + rects: [[338.883, 136.245, 556.121, 144.261], [317.014, 126.282, 556.121, 134.298], [317.014, 116.32, 534.474, 124.336]] + }, + dateModified: '2020-02-07T07:24:29.000Z', + authorName: '', + comment: '', + color: '#f8c348', + pageLabel: '2', + text: 'At the start of execution, there are no compiled traces yet, so the trace monitor counts the number of times each loop back edge is executed until a loop becomes hot, currently after 2 crossings', + sortIndex: '00001|004901|00647', + tags: [], + transferable: true + }], deleted: [] + }; + + expect(result).to.deep.equal(expectedResult); + }); it('should write annotations', async function () { let annotations = [{