From ed637b04d75e4ebd6ea523f23e6dee7f64b68145 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Fri, 19 Nov 2021 00:47:56 +0100 Subject: Widget: Make contextless widget construction work Due to the fact the widget factory code is now in strict mode, the check for being called without using the `new` keyword started breaking if you save the widget constructor to a variable before calling it: ```js var customWidget = $.custom.customWidget; customWidget( {}, elem ); ``` as then `this` is undefined and checking for `this._createWidget` crashes. Account for that with an additional check. Fixes gh-2015 Closes gh-2019 --- tests/unit/widget/core.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/unit/widget/core.js b/tests/unit/widget/core.js index e36459f72..1054bf092 100644 --- a/tests/unit/widget/core.js +++ b/tests/unit/widget/core.js @@ -92,6 +92,18 @@ QUnit.test( "element normalization", function( assert ) { $.ui.testWidget(); } ); +QUnit.test( "contextless construction", function( assert ) { + assert.expect( 1 ); + var testWidget, + elem = $( "
" ); + + $.widget( "ui.testWidget", {} ); + testWidget = $.ui.testWidget; + + testWidget( {}, elem ); + assert.ok( true, "No crash" ); +} ); + QUnit.test( "custom selector expression", function( assert ) { assert.expect( 1 ); var elem = $( "
" ).appendTo( "#qunit-fixture" ); -- cgit v1.2.3