@@ -1339,12 +1339,10 @@ describe("api", function () {
1339
1339
. catch ( done . fail ) ;
1340
1340
} ) ;
1341
1341
1342
- it ( "cleans up document resources" , function ( done ) {
1343
- const promise = pdfDocument . cleanup ( ) ;
1344
- promise . then ( function ( ) {
1345
- expect ( true ) . toEqual ( true ) ;
1346
- done ( ) ;
1347
- } , done . fail ) ;
1342
+ it ( "cleans up document resources" , async function ( ) {
1343
+ await pdfDocument . cleanup ( ) ;
1344
+
1345
+ expect ( true ) . toEqual ( true ) ;
1348
1346
} ) ;
1349
1347
1350
1348
it ( "checks that fingerprints are unique" , function ( done ) {
@@ -1982,85 +1980,69 @@ describe("api", function () {
1982
1980
] ) . then ( done ) ;
1983
1981
} ) ;
1984
1982
1985
- it ( "cleans up document resources after rendering of page" , function ( done ) {
1983
+ it ( "cleans up document resources after rendering of page" , async function ( ) {
1986
1984
const loadingTask = getDocument ( buildGetDocumentParams ( basicApiFileName ) ) ;
1987
- let canvasAndCtx ;
1985
+ const pdfDoc = await loadingTask . promise ;
1986
+ const pdfPage = await pdfDoc . getPage ( 1 ) ;
1988
1987
1989
- loadingTask . promise
1990
- . then ( pdfDoc => {
1991
- return pdfDoc . getPage ( 1 ) . then ( pdfPage => {
1992
- const viewport = pdfPage . getViewport ( { scale : 1 } ) ;
1993
- canvasAndCtx = CanvasFactory . create (
1994
- viewport . width ,
1995
- viewport . height
1996
- ) ;
1988
+ const viewport = pdfPage . getViewport ( { scale : 1 } ) ;
1989
+ const canvasAndCtx = CanvasFactory . create (
1990
+ viewport . width ,
1991
+ viewport . height
1992
+ ) ;
1997
1993
1998
- const renderTask = pdfPage . render ( {
1999
- canvasContext : canvasAndCtx . context ,
2000
- canvasFactory : CanvasFactory ,
2001
- viewport,
2002
- } ) ;
2003
- return renderTask . promise . then ( ( ) => {
2004
- return pdfDoc . cleanup ( ) ;
2005
- } ) ;
2006
- } ) ;
2007
- } )
2008
- . then ( ( ) => {
2009
- expect ( true ) . toEqual ( true ) ;
1994
+ const renderTask = pdfPage . render ( {
1995
+ canvasContext : canvasAndCtx . context ,
1996
+ canvasFactory : CanvasFactory ,
1997
+ viewport,
1998
+ } ) ;
1999
+ await renderTask . promise ;
2010
2000
2011
- CanvasFactory . destroy ( canvasAndCtx ) ;
2012
- loadingTask . destroy ( ) . then ( done ) ;
2013
- } , done . fail ) ;
2001
+ await pdfDoc . cleanup ( ) ;
2002
+
2003
+ expect ( true ) . toEqual ( true ) ;
2004
+
2005
+ CanvasFactory . destroy ( canvasAndCtx ) ;
2006
+ await loadingTask . destroy ( ) ;
2014
2007
} ) ;
2015
2008
2016
- it ( "cleans up document resources during rendering of page" , function ( done ) {
2009
+ it ( "cleans up document resources during rendering of page" , async function ( ) {
2017
2010
const loadingTask = getDocument (
2018
2011
buildGetDocumentParams ( "tracemonkey.pdf" )
2019
2012
) ;
2020
- let canvasAndCtx ;
2013
+ const pdfDoc = await loadingTask . promise ;
2014
+ const pdfPage = await pdfDoc . getPage ( 1 ) ;
2021
2015
2022
- loadingTask . promise
2023
- . then ( pdfDoc => {
2024
- return pdfDoc . getPage ( 1 ) . then ( pdfPage => {
2025
- const viewport = pdfPage . getViewport ( { scale : 1 } ) ;
2026
- canvasAndCtx = CanvasFactory . create (
2027
- viewport . width ,
2028
- viewport . height
2029
- ) ;
2016
+ const viewport = pdfPage . getViewport ( { scale : 1 } ) ;
2017
+ const canvasAndCtx = CanvasFactory . create (
2018
+ viewport . width ,
2019
+ viewport . height
2020
+ ) ;
2030
2021
2031
- const renderTask = pdfPage . render ( {
2032
- canvasContext : canvasAndCtx . context ,
2033
- canvasFactory : CanvasFactory ,
2034
- viewport,
2035
- } ) ;
2022
+ const renderTask = pdfPage . render ( {
2023
+ canvasContext : canvasAndCtx . context ,
2024
+ canvasFactory : CanvasFactory ,
2025
+ viewport,
2026
+ } ) ;
2027
+ // Ensure that clean-up runs during rendering.
2028
+ renderTask . onContinue = function ( cont ) {
2029
+ waitSome ( cont ) ;
2030
+ } ;
2036
2031
2037
- renderTask . onContinue = function ( cont ) {
2038
- waitSome ( cont ) ;
2039
- } ;
2032
+ try {
2033
+ await pdfDoc . cleanup ( ) ;
2040
2034
2041
- return pdfDoc
2042
- . cleanup ( )
2043
- . then (
2044
- ( ) => {
2045
- throw new Error ( "shall fail cleanup" ) ;
2046
- } ,
2047
- reason => {
2048
- expect ( reason instanceof Error ) . toEqual ( true ) ;
2049
- expect ( reason . message ) . toEqual (
2050
- "startCleanup: Page 1 is currently rendering."
2051
- ) ;
2052
- }
2053
- )
2054
- . then ( ( ) => {
2055
- return renderTask . promise ;
2056
- } )
2057
- . then ( ( ) => {
2058
- CanvasFactory . destroy ( canvasAndCtx ) ;
2059
- loadingTask . destroy ( ) . then ( done ) ;
2060
- } ) ;
2061
- } ) ;
2062
- } )
2063
- . catch ( done . fail ) ;
2035
+ throw new Error ( "shall fail cleanup" ) ;
2036
+ } catch ( reason ) {
2037
+ expect ( reason instanceof Error ) . toEqual ( true ) ;
2038
+ expect ( reason . message ) . toEqual (
2039
+ "startCleanup: Page 1 is currently rendering."
2040
+ ) ;
2041
+ }
2042
+ await renderTask . promise ;
2043
+
2044
+ CanvasFactory . destroy ( canvasAndCtx ) ;
2045
+ await loadingTask . destroy ( ) ;
2064
2046
} ) ;
2065
2047
2066
2048
it ( "caches image resources at the document/page level as expected (issue 11878)" , async function ( ) {
0 commit comments