Throw custom error when WebView API is unavailable

This commit is contained in:
Kevin Sawicki 2016-02-05 10:55:32 -08:00
parent 6bc48ba123
commit 8cacd0b931
2 changed files with 8 additions and 5 deletions

View file

@ -404,10 +404,13 @@ var registerWebViewElement = function() {
// Forward proto.foo* method calls to WebViewImpl.foo*.
createBlockHandler = function(m) {
return function() {
var args, internal, ref1;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
internal = v8Util.getHiddenValue(this, 'internal');
return (ref1 = internal.webContents)[m].apply(ref1, args);
var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
var internal = v8Util.getHiddenValue(this, 'internal');
if (internal.webContents) {
return internal.webContents[m].apply(internal.webContents, args);
} else {
throw new Error('Cannot call ' + m + ' before the dom-ready event is emitted')
}
};
};
for (i = 0, len = methods.length; i < len; i++) {

View file

@ -570,7 +570,7 @@ describe('<webview> tag', function() {
readyError = error;
}
assert.equal(readyError.message, 'stop can only be called after the dom-ready event is emitted');
assert.equal(readyError.message, 'Cannot call stop before the dom-ready event is emitted');
});
});