Skip to content

Commit 407ef56

Browse files
committed
Merge pull request nwjs#3251 from subzey/throws
Use only instances of Error in throw statement
2 parents 356d3d5 + 4ebd72c commit 407ef56

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

src/api/clipboard/clipboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Clipboard.prototype.set = function(data, type) {
3030
type = 'text';
3131

3232
if (type != 'text')
33-
throw new String("Type of '" + type + "' is not supported");
33+
throw new TypeError("Type of '" + type + "' is not supported");
3434

3535
nw.callObjectMethod(this, 'Set', [ data, type ]);
3636
}
@@ -40,7 +40,7 @@ Clipboard.prototype.get = function(type) {
4040
type = 'text';
4141

4242
if (type != 'text')
43-
throw new String('Only support getting plain text from Clipboard');
43+
throw new TypeError('Only support getting plain text from Clipboard');
4444

4545
var result = nw.callObjectMethodSync(this, 'Get', [ type ]);
4646
if (type == 'text')

src/api/menu/menu.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Menu(option) {
2727
option = { type: 'contextmenu' };
2828

2929
if (option.type != 'contextmenu' && option.type != 'menubar')
30-
throw new String('Invalid menu type: ' + option.type);
30+
throw new TypeError('Invalid menu type: ' + option.type);
3131

3232
this.type = option.type;
3333
v8_util.setHiddenValue(this, 'items', []);
@@ -40,12 +40,12 @@ Menu.prototype.__defineGetter__('items', function() {
4040
});
4141

4242
Menu.prototype.__defineSetter__('items', function(val) {
43-
throw new String('Menu.items is immutable');
43+
throw new Error('Menu.items is immutable');
4444
});
4545

4646
Menu.prototype.append = function(menu_item) {
4747
if (v8_util.getConstructorName(menu_item) != 'MenuItem')
48-
throw new String("Menu.append() requires a valid MenuItem");
48+
throw new TypeError("Menu.append() requires a valid MenuItem");
4949

5050
this.items.push(menu_item);
5151
nw.callObjectMethod(this, 'Append', [ menu_item.id ]);

src/api/menuitem/menuitem.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ var v8_util = process.binding('v8_util');
2222

2323
function MenuItem(option) {
2424
if (typeof option != 'object')
25-
throw new String('Invalid option.');
25+
throw new TypeError('Invalid option.');
2626

2727
if (!option.hasOwnProperty('type'))
2828
option.type = 'normal';
2929

3030
if (option.type != 'normal' &&
3131
option.type != 'checkbox' &&
3232
option.type != 'separator')
33-
throw new String('Invalid MenuItem type: ' + option.type);
33+
throw new TypeError('Invalid MenuItem type: ' + option.type);
3434

3535
if (option.type == 'normal' || option.type == 'checkbox') {
3636
if (option.type == 'checkbox')
3737
option.checked = Boolean(option.checked);
3838

3939
if (!option.hasOwnProperty('label'))
40-
throw new String('A normal MenuItem must have a label');
40+
throw new TypeError('A normal MenuItem must have a label');
4141
else
4242
option.label = String(option.label);
4343

@@ -59,7 +59,7 @@ function MenuItem(option) {
5959

6060
if (option.hasOwnProperty('submenu')) {
6161
if (v8_util.getConstructorName(option.submenu) != 'Menu')
62-
throw new String("'submenu' must be a valid Menu");
62+
throw new TypeError("'submenu' must be a valid Menu");
6363

6464
// Transfer only object id
6565
v8_util.setHiddenValue(this, 'submenu', option.submenu);
@@ -68,7 +68,7 @@ function MenuItem(option) {
6868

6969
if (option.hasOwnProperty('click')) {
7070
if (typeof option.click != 'function')
71-
throw new String("'click' must be a valid Function");
71+
throw new TypeError("'click' must be a valid Function");
7272
else
7373
this.click = option.click;
7474
}
@@ -100,7 +100,7 @@ MenuItem.prototype.__defineGetter__('type', function() {
100100
});
101101

102102
MenuItem.prototype.__defineSetter__('type', function() {
103-
throw new String("'type' is immutable at runtime");
103+
throw new Error("'type' is immutable at runtime");
104104
});
105105

106106
MenuItem.prototype.__defineGetter__('label', function() {
@@ -162,7 +162,7 @@ MenuItem.prototype.__defineGetter__('checked', function() {
162162

163163
MenuItem.prototype.__defineSetter__('checked', function(val) {
164164
if (this.type != 'checkbox')
165-
throw new String("'checked' property is only available for checkbox");
165+
throw new TypeError("'checked' property is only available for checkbox");
166166

167167
this.handleSetter('checked', 'SetChecked', Boolean, val);
168168
});
@@ -181,7 +181,7 @@ MenuItem.prototype.__defineGetter__('submenu', function() {
181181

182182
MenuItem.prototype.__defineSetter__('submenu', function(val) {
183183
if (v8_util.getConstructorName(val) != 'Menu')
184-
throw new String("'submenu' property requries a valid Menu");
184+
throw new TypeError("'submenu' property requries a valid Menu");
185185

186186
v8_util.setHiddenValue(this, 'submenu', val);
187187
nw.callObjectMethod(this, 'SetSubmenu', [ val.id ]);

src/api/screen/screen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require('util').inherits(Screen, exports.Base);
2929
// Override the addListener method.
3030
Screen.prototype.on = Screen.prototype.addListener = function(ev, callback) {
3131
if ( ev != "displayBoundsChanged" && ev != "displayAdded" && ev != "displayRemoved" && ev != "chooseDesktopMedia")
32-
throw new String('only following event can be listened: displayBoundsChanged, displayAdded, displayRemoved');
32+
throw new TypeError('only following event can be listened: displayBoundsChanged, displayAdded, displayRemoved');
3333

3434
var onRemoveListener = function (type, listener) {
3535
if (this._numListener > 0) {
@@ -43,7 +43,7 @@ Screen.prototype.on = Screen.prototype.addListener = function(ev, callback) {
4343

4444
if(this._numListener == 0) {
4545
if (nw.callStaticMethodSync('Screen', 'AddScreenChangeCallback', [ this.id ])[0] == false ) {
46-
throw new String('nw.callStaticMethodSync(Screen, AddScreenChangeCallback) fails');
46+
throw new Error('nw.callStaticMethodSync(Screen, AddScreenChangeCallback) fails');
4747
return;
4848
}
4949
process.EventEmitter.prototype.addListener.apply(this, ["removeListener", onRemoveListener]);

src/api/shortcut/shorcut.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var v8_util = process.binding('v8_util');
2222

2323
function Shortcut(option) {
2424
if (typeof option != 'object')
25-
throw new String('Invalid option.');
25+
throw new TypeError('Invalid option.');
2626

2727
if (!option.hasOwnProperty('key'))
2828
throw new TypeError("Shortcut requires 'key' to specify key combinations.");

src/api/tray/tray.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ var v8_util = process.binding('v8_util');
2222

2323
function Tray(option) {
2424
if (typeof option != 'object')
25-
throw new String('Invalid option');
25+
throw new TypeError('Invalid option');
2626

2727
if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon'))
28-
throw new String("Must set 'title' or 'icon' field in option");
28+
throw new TypeError("Must set 'title' or 'icon' field in option");
2929

3030
if (!option.hasOwnProperty('title'))
3131
option.title = '';
@@ -52,15 +52,15 @@ function Tray(option) {
5252

5353
if (option.hasOwnProperty('click')) {
5454
if (typeof option.click != 'function') {
55-
throw new String("'click' must be a valid Function");
55+
throw new TypeError("'click' must be a valid Function");
5656
} else {
5757
this.click = option.click;
5858
}
5959
}
6060

6161
if (option.hasOwnProperty('menu')) {
6262
if (v8_util.getConstructorName(option.menu) != 'Menu')
63-
throw new String("'menu' must be a valid Menu");
63+
throw new TypeError("'menu' must be a valid Menu");
6464

6565
// Transfer only object id
6666
v8_util.setHiddenValue(this, 'menu', option.menu);
@@ -130,7 +130,7 @@ Tray.prototype.__defineGetter__('menu', function() {
130130

131131
Tray.prototype.__defineSetter__('menu', function(val) {
132132
if (v8_util.getConstructorName(val) != 'Menu')
133-
throw new String("'menu' property requries a valid Menu");
133+
throw new TypeError("'menu' property requries a valid Menu");
134134

135135
v8_util.setHiddenValue(this, 'menu', val);
136136
nw.callObjectMethod(this, 'SetMenu', [ val.id ]);

src/api/window_bindings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ Window.prototype.__defineSetter__('menu', function(menu) {
221221
return;
222222
}
223223
if (v8_util.getConstructorName(menu) != 'Menu')
224-
throw new String("'menu' property requries a valid Menu");
224+
throw new TypeError("'menu' property requries a valid Menu");
225225

226226
if (menu.type != 'menubar')
227-
throw new String('Only menu of type "menubar" can be used as this.window menu');
227+
throw new TypeError('Only menu of type "menubar" can be used as this.window menu');
228228

229229
v8_util.setHiddenValue(this, 'menu', menu);
230230
CallObjectMethod(this, 'SetMenu', [ menu.id ]);
@@ -432,7 +432,7 @@ Window.prototype.setBadgeLabel = function(label) {
432432

433433
Window.prototype.setProgressBar = function(progress) {
434434
if (typeof progress != "number")
435-
throw new String('progress must be a number');
435+
throw new TypeError('progress must be a number');
436436
CallObjectMethod(this, 'SetProgressBar', [ progress ]);
437437
}
438438

@@ -442,7 +442,7 @@ Window.prototype.setTransparent = function(transparent) {
442442

443443
Window.prototype.setPosition = function(position) {
444444
if (position != 'center' && position != 'mouse')
445-
throw new String('Invalid postion');
445+
throw new TypeError('Invalid postion');
446446
CallObjectMethod(this, 'SetPosition', [ position ]);
447447
}
448448

0 commit comments

Comments
 (0)