-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
113 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var LibraryVips = { | ||
$VIPS__deps: [ | ||
#if ENVIRONMENT_MAY_BE_WEB | ||
'$ENV', | ||
#endif | ||
'$ClassHandle', | ||
'$deletionQueue', | ||
], | ||
$VIPS__postset: 'VIPS.init();', | ||
$VIPS: { | ||
init() { | ||
#if ENVIRONMENT_MAY_BE_WEB | ||
addOnPreRun(() => { | ||
// Enforce a fixed thread pool by default on web | ||
ENV['VIPS_MAX_THREADS'] = {{{ PTHREAD_POOL_SIZE }}}; | ||
}); | ||
#endif | ||
|
||
// Add preventAutoDelete method to ClassHandle | ||
Object.assign(ClassHandle.prototype, { | ||
'preventAutoDelete'() { | ||
const index = deletionQueue.indexOf(this); | ||
if (index > -1) { | ||
deletionQueue.splice(index, 1); | ||
} | ||
this.$$.deleteScheduled = false; | ||
return this; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
addToLibrary(LibraryVips); | ||
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$VIPS'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* global vips, expect, cleanup */ | ||
'use strict'; | ||
|
||
describe('auto delete', () => { | ||
after(function () { | ||
cleanup(); | ||
expect(vips.deletionQueue.length).to.equal(0); | ||
}); | ||
|
||
it('auto delete', function () { | ||
const im = vips.Image.black(100, 100); | ||
expect(vips.deletionQueue.length).to.equal(1); | ||
expect(() => im.clone()).to.throw(/Object already scheduled for deletion/); | ||
|
||
im.gaussblur(0.3); // creates new handle | ||
expect(vips.deletionQueue.length).to.equal(2); | ||
|
||
cleanup(); | ||
expect(vips.deletionQueue.length).to.equal(0); | ||
}); | ||
|
||
describe('preventAutoDelete', () => { | ||
it('all handles', function () { | ||
const handles = Object.entries(vips).filter( | ||
([key, Handle]) => | ||
key !== 'Object' && !!Handle?.prototype?.preventAutoDelete | ||
); | ||
expect(handles.length).to.equal(12); | ||
|
||
for (const [name] of handles) { | ||
const h = new vips[name](); | ||
expect(vips.deletionQueue.length).to.equal(1); | ||
|
||
h.preventAutoDelete(); | ||
expect(vips.deletionQueue.length).to.equal(0); | ||
|
||
h.delete(); | ||
expect(() => h.delete()).to.throw(new RegExp(`${name} instance already deleted`)); | ||
} | ||
}); | ||
|
||
it('cloned handle', function () { | ||
const im = new vips.Image(); | ||
expect(vips.deletionQueue.length).to.equal(1); | ||
|
||
im.preventAutoDelete(); | ||
expect(vips.deletionQueue.length).to.equal(0); | ||
|
||
// cloned objects do not retain prevent auto delete status | ||
const cloned = im.clone(); | ||
expect(vips.deletionQueue.length).to.equal(1); | ||
|
||
cleanup(); | ||
expect(vips.deletionQueue.length).to.equal(0); | ||
|
||
im.delete(); // should not fail | ||
expect(() => im.delete()).to.throw(/Image instance already deleted/); | ||
|
||
// already deleted by cleanup, should fail | ||
expect(() => cloned.delete()).to.throw(/Image instance already deleted/); | ||
}); | ||
}); | ||
}); |