Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
// NOTE: We're not modifying the global `self` here. We receive its value passed
// to the paper.js function scope, and this is the one that is modified here.
self = self || require('./node/self.js');
var window = self.window,
document = self.document;
var window = self.CANVAS_NOT_FOUND ? null : self.window;
var document = self.document;
5 changes: 2 additions & 3 deletions src/node/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ module.exports = function(self, requireName) {
try {
Canvas = require('canvas').Canvas;
} catch(error) {
// Remove `self.window`, so we still have the global `self` reference,
// but no `window` object:
// Add/set CANVAS_NOT_FOUND=true:
// - On the browser, this corresponds to a worker context.
// - On Node.js, it basically means the canvas is missing or not working
// which can be treated the same way.
delete self.window;
self.CANVAS_NOT_FOUND = true;
// Check the required module's name to see if it contains canvas, and
// only complain about its lack if the module requires it.
if (/\bcanvas\b/.test(requireName)) {
Expand Down