diff --git a/__test__/canvas-class.spec.ts b/__test__/canvas-class.spec.ts index b3f2942a..90fbf4f8 100644 --- a/__test__/canvas-class.spec.ts +++ b/__test__/canvas-class.spec.ts @@ -19,3 +19,9 @@ test('ctx.canvas should be equal to canvas', (t) => { const ctx = canvas.getContext('2d') t.is(ctx.canvas, canvas) }) + +test('[SVG] ctx.canvas should be equal to canvas', (t) => { + const canvas = createCanvas(100, 100, SvgExportFlag.NoPrettyXML) + const ctx = canvas.getContext('2d') + t.is(ctx.canvas, canvas) +}) diff --git a/src/lib.rs b/src/lib.rs index b88e2dbc..9f324ab6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -469,6 +469,13 @@ impl SVGCanvas { Property::new(STROKE_STYLE_HIDDEN_NAME)? .with_value(&env.create_string("#000")?) .with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable), + Property::new("canvas")? + .with_value(&this) + .with_property_attributes( + PropertyAttributes::Default + | PropertyAttributes::Writable + | PropertyAttributes::Enumerable, + ), ])?; env.adjust_external_memory((width * height * 4) as i64)?; this.define_properties(&[Property::new("ctx")?