From 88697add1b55c54bfb9f74982d3cbb6c96efe489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 21 May 2019 15:28:07 -0500 Subject: [PATCH] js: Throw GObject.NotImplementedError when requiring overriding Since version 1.50.0, gjs defines GObject.NotImplementedError for throwing errors when a "virtual" method that requires a subclass implementation is not defined. So use this instead of a generic JS Error in such cases. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/549 --- js/gdm/batch.js | 2 +- js/ui/iconGrid.js | 5 +++-- js/ui/overviewControls.js | 2 +- js/ui/switcherPopup.js | 2 +- js/ui/workspace.js | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/js/gdm/batch.js b/js/gdm/batch.js index bd84c9230..3671210e0 100644 --- a/js/gdm/batch.js +++ b/js/gdm/batch.js @@ -124,7 +124,7 @@ var Batch = class extends Task { } process() { - throw new Error('Not implemented'); + throw new GObject.NotImplementedError(`process in ${this.constructor.name}`); } runTask() { diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js index 77e871028..4d32e8bcf 100644 --- a/js/ui/iconGrid.js +++ b/js/ui/iconGrid.js @@ -79,7 +79,7 @@ class BaseIcon extends St.Bin { // This can be overridden by a subclass, or by the createIcon // parameter to _init() createIcon(size) { - throw new Error('no implementation of createIcon in ' + this); + throw new GObject.NotImplementedError(`createIcon in ${this.constructor.name}`); } setIconSize(size) { @@ -416,7 +416,8 @@ var IconGrid = GObject.registerClass({ animatePulse(animationDirection) { if (animationDirection != AnimationDirection.IN) - throw new Error("Pulse animation only implements 'in' animation direction"); + throw new GObject.NotImplementedError("Pulse animation only implements " + + "'in' animation direction"); this._cancelAnimation(); diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js index 930bbb220..f10ba7306 100644 --- a/js/ui/overviewControls.js +++ b/js/ui/overviewControls.js @@ -122,7 +122,7 @@ var SlidingControl = class { } _getSlide() { - throw new Error('getSlide() must be overridden'); + throw new GObject.NotImplementedError(`_getSlide in ${this.constructor.name}`); } _updateSlide() { diff --git a/js/ui/switcherPopup.js b/js/ui/switcherPopup.js index d324a90f4..50a926e29 100644 --- a/js/ui/switcherPopup.js +++ b/js/ui/switcherPopup.js @@ -162,7 +162,7 @@ var SwitcherPopup = GObject.registerClass({ } _keyPressHandler(keysym, action) { - throw new Error('Not implemented'); + throw new GObject.NotImplementedError(`_keyPressHandler in ${this.constructor.name}`); } _keyPressEvent(actor, event) { diff --git a/js/ui/workspace.js b/js/ui/workspace.js index 175fedce9..50ac141d9 100644 --- a/js/ui/workspace.js +++ b/js/ui/workspace.js @@ -835,7 +835,7 @@ var LayoutStrategy = class { // (optionally) for each row in @layout.rows. This method is // intended to be called by subclasses. _computeRowSizes(layout) { - throw new Error('_computeRowSizes not implemented'); + throw new GObject.NotImplementedError(`_computeRowSizes in ${this.constructor.name}`); } // Compute strategy-specific window slots for each window in @@ -848,7 +848,7 @@ var LayoutStrategy = class { // * gridHeight - The totial height used by the grid, unscaled, unspaced. // * rows - A list of rows, which should be instantiated by _newRow. computeLayout(windows, layout) { - throw new Error('computeLayout not implemented'); + throw new GObject.NotImplementedError(`computeLayout in ${this.constructor.name}`); } // Given @layout, compute the overall scale and space of the layout.