mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 08:27:19 +02:00
Add an optional parameter in buildPostScriptJsFunction to force use of the PSStackBasedInterpreter code
This way the test-only function `buildPostScriptProgramFunction` can be removed.
This commit is contained in:
parent
853d5436c1
commit
ccab310a39
@ -795,9 +795,15 @@ class PSStackBasedInterpreter {
|
|||||||
* @param {number[]} range – flat [min0,max0, …]
|
* @param {number[]} range – flat [min0,max0, …]
|
||||||
* @returns {Function} – `(src, srcOffset, dest, destOffset) => void`
|
* @returns {Function} – `(src, srcOffset, dest, destOffset) => void`
|
||||||
*/
|
*/
|
||||||
function buildPostScriptJsFunction(source, domain, range) {
|
function buildPostScriptJsFunction(
|
||||||
|
source,
|
||||||
|
domain,
|
||||||
|
range,
|
||||||
|
forceInterpreter = false
|
||||||
|
) {
|
||||||
const program = parsePostScriptFunction(source);
|
const program = parsePostScriptFunction(source);
|
||||||
const ir = new PsJsCompiler(domain, range).compile(program);
|
const ir =
|
||||||
|
!forceInterpreter && new PsJsCompiler(domain, range).compile(program);
|
||||||
if (ir) {
|
if (ir) {
|
||||||
return (src, srcOffset, dest, destOffset) => {
|
return (src, srcOffset, dest, destOffset) => {
|
||||||
PsJsCompiler.execute(ir, src, srcOffset, dest, destOffset);
|
PsJsCompiler.execute(ir, src, srcOffset, dest, destOffset);
|
||||||
@ -807,14 +813,4 @@ function buildPostScriptJsFunction(source, domain, range) {
|
|||||||
return PSStackBasedInterpreter.build(program, domain, range);
|
return PSStackBasedInterpreter.build(program, domain, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export { buildPostScriptJsFunction };
|
||||||
* @param {import("./ast.js").PsProgram} program
|
|
||||||
* @param {number[]} domain – flat [min0,max0, …]
|
|
||||||
* @param {number[]} range – flat [min0,max0, …]
|
|
||||||
* @returns {Function} – `(src, srcOffset, dest, destOffset) => void`
|
|
||||||
*/
|
|
||||||
function buildPostScriptProgramFunction(program, domain, range) {
|
|
||||||
return PSStackBasedInterpreter.build(program, domain, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { buildPostScriptJsFunction, buildPostScriptProgramFunction };
|
|
||||||
|
|||||||
@ -13,10 +13,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
|
||||||
buildPostScriptJsFunction,
|
|
||||||
buildPostScriptProgramFunction,
|
|
||||||
} from "../../src/core/postscript/js_evaluator.js";
|
|
||||||
import {
|
import {
|
||||||
buildPostScriptWasmFunction,
|
buildPostScriptWasmFunction,
|
||||||
compilePostScriptToWasm,
|
compilePostScriptToWasm,
|
||||||
@ -39,6 +35,7 @@ import {
|
|||||||
PsTernaryNode,
|
PsTernaryNode,
|
||||||
PsUnaryNode,
|
PsUnaryNode,
|
||||||
} from "../../src/core/postscript/ast.js";
|
} from "../../src/core/postscript/ast.js";
|
||||||
|
import { buildPostScriptJsFunction } from "../../src/core/postscript/js_evaluator.js";
|
||||||
|
|
||||||
// Precision argument for toBeCloseTo() in trigonometric tests.
|
// Precision argument for toBeCloseTo() in trigonometric tests.
|
||||||
const TRIGONOMETRY_EPS = 1e-10;
|
const TRIGONOMETRY_EPS = 1e-10;
|
||||||
@ -209,10 +206,11 @@ describe("PostScript Type 4 lexer, parser, and Wasm compiler", function () {
|
|||||||
// direct program interpreter otherwise.
|
// direct program interpreter otherwise.
|
||||||
const jsFn = buildPostScriptJsFunction(src, domain, range);
|
const jsFn = buildPostScriptJsFunction(src, domain, range);
|
||||||
// Direct interpreter: always available, never uses PSStackToTree.
|
// Direct interpreter: always available, never uses PSStackToTree.
|
||||||
const interpFn = buildPostScriptProgramFunction(
|
const interpFn = buildPostScriptJsFunction(
|
||||||
parsePostScriptFunction(src),
|
src,
|
||||||
domain,
|
domain,
|
||||||
range
|
range,
|
||||||
|
/* forceInterpreter = */ true
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!wasmFn) {
|
if (!wasmFn) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user