bugzilla.mozilla.org has resumed normal operation. Attachments prior to 2014 will be unavailable for a few days. This is tracked in Bug 1475801.
Please report any other irregularities here.

Incorrect TypeError with Path2D.addPath




Canvas: 2D
4 years ago
3 years ago


(Reporter: The 8472, Unassigned)


Windows 7

Firefox Tracking Flags

(Not tracked)



(1 attachment)



4 years ago
Created attachment 8531216 [details]
screenshot of type check in debugger

I'm getting "TypeError: Argument 1 of Path2D.addPath does not implement interface Path2D." when trying to cache Path2D objects generated from Strings.

Generating the objects from scratch every time doesn't cause the exception, but it's more expensive.
Is it disallowed to reuse path objects (in which case the exception is misleading) or should this work?

I've made sure that I'm passing in the correct type with an instanceof check, see attached screenshot.
Please provide a reduced test case.
Keywords: testcase-wanted


4 years ago
Flags: needinfo?(bugzilla.mozilla.org)

Comment 2

4 years ago
I tried but failed. Both methods involved are fairly trivial and I don't see anything that I might be doing wrong.

The method generating the Path2D

	toCanvasPath: function() {
		if(this.pathCache instanceof Path2D)
			return this.pathCache
		return (this.pathCache = new Path2D(this.pathString()))

The method consuming it:

	drawOnto: function(ctx) {
		let path = new Path2D()
		let paths = this.paths.forEach(p => {path.addPath(p.toCanvasPath())})
		// ... then use path on ctx

As far as I can tell this is always guaranteed to be a Path2D object, but to make doubly sure I added the type check (see screenshot) to ensure correctness and it still throws a TypeError.

Could this be some JIT bug like bug 861947?
Anything else I can do on my end to make sure I'm not holding it wrong?
Flags: needinfo?(bugzilla.mozilla.org)

Comment 3

4 years ago
javascript.options.baselinejit	false
javascript.options.ion	false

Problem still occurs, so probably not JIT-related.

Comment 4

4 years ago
Was a problem on my end after all. On some occasions the objects holding onto the cached paths were run through a deep clone algorithm which instantiated copies from the prototype without calling the constructor. That's why instanceof succeeded but it was not a real Path2D host object.
Last Resolved: 4 years ago
Resolution: --- → INVALID
Keywords: testcase-wanted
You need to log in before you can comment on or make changes to this bug.