Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #298 from arv/fix-canvas-2d-context
Browse files Browse the repository at this point in the history
Fix issue with missing instance properties on canvas context classes
  • Loading branch information
dfreedm committed Nov 5, 2013
2 parents 45c3ae4 + 3dd1711 commit 4b62222
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/wrappers/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
}
});

registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D);
registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D,
document.createElement('canvas').getContext('2d'));

scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D;
})(window.ShadowDOMPolyfill);
10 changes: 9 additions & 1 deletion src/wrappers/WebGLRenderingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@
}
});

registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext);
// Blink/WebKit has broken DOM bindings. Usually we would create an instance
// of the object and pass it into registerWrapper as a "blueprint" but
// creating WebGL contexts is expensive and might fail so we use a dummy
// object with dummy instance properties for these broken browsers.
var instanceProperties = /WebKit/.test(navigator.userAgent) ?
{drawingBufferHeight: null, drawingBufferWidth: null} : {};

registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext,
instanceProperties);

scope.wrappers.WebGLRenderingContext = WebGLRenderingContext;
})(window.ShadowDOMPolyfill);
39 changes: 39 additions & 0 deletions test/js/HTMLCanvasElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ suite('HTMLCanvasElement', function() {
assert.equal(context.canvas, canvas);
});

test('context instance properties', function() {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');

assert.isString(context.fillStyle);
assert.isString(context.strokeStyle);
assert.isString(context.textBaseline);
assert.isString(context.textAlign);
assert.isString(context.font);
assert.isNumber(context.lineDashOffset);
assert.isString(context.shadowColor);
assert.isNumber(context.shadowBlur);
assert.isNumber(context.shadowOffsetY);
assert.isNumber(context.shadowOffsetX);
assert.isNumber(context.miterLimit);
assert.isString(context.lineJoin);
assert.isString(context.lineCap);
assert.isNumber(context.lineWidth);
assert.isNumber(context.globalAlpha);
});

test('2d drawImage using new Image', function(done) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
Expand Down Expand Up @@ -113,6 +134,24 @@ suite('HTMLCanvasElement', function() {
img.src = iconUrl;
});

test('WebGL context instance properties', function() {
var canvas = document.createElement('canvas');
var gl = null;
// Firefox throws exception if graphics card is not supported
try {
gl = canvas.getContext('webgl');
} catch (ex) {
}
// IE10 does not have WebGL.
// Chrome returns null if the graphics card is not supported
if (!gl) {
return;
}

assert.isNumber(gl.drawingBufferHeight);
assert.isNumber(gl.drawingBufferWidth);
});

test('WebGL texSubImage2D', function(done) {
var canvas = document.createElement('canvas');
var gl = null;
Expand Down

0 comments on commit 4b62222

Please sign in to comment.