Skip to content

Commit

Permalink
fix: send null in debugger callback when no error (electron#14814)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored Sep 27, 2018
1 parent 985d35f commit 7dc7cd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions atom/browser/api/atom_api_debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
return;
base::DictionaryValue* error_body = nullptr;
base::DictionaryValue error;
if (dict->GetDictionary("error", &error_body))
bool has_error;
if ((has_error = dict->GetDictionary("error", &error_body))) {
error.Swap(error_body);
}

base::DictionaryValue* result_body = nullptr;
base::DictionaryValue result;
if (dict->GetDictionary("result", &result_body))
result.Swap(result_body);
send_command_callback.Run(error, result);
send_command_callback.Run(has_error ? error.Clone() : base::Value(),
result);
}
}

Expand Down
5 changes: 3 additions & 2 deletions spec/api-debugger-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('debugger module', () => {
}

const callback = (err, res) => {
expect(err.message).to.be.undefined()
expect(err).to.be.null()
expect(res.wasThrown).to.be.undefined()
expect(res.result.value).to.equal(6)

Expand All @@ -131,7 +131,7 @@ describe('debugger module', () => {
return done(`unexpected error : ${err}`)
}
const callback = (err, res) => {
expect(err.message).to.be.undefined()
expect(err).to.be.null()
expect(res.wasThrown).to.be.undefined()
expect(res.result.value).to.equal(6)
w.webContents.debugger.detach()
Expand Down Expand Up @@ -178,6 +178,7 @@ describe('debugger module', () => {
}

w.webContents.debugger.sendCommand('Test', err => {
expect(err).to.not.be.null()
expect(err.message).to.equal("'Test' wasn't found")
w.webContents.debugger.detach()
done()
Expand Down

0 comments on commit 7dc7cd1

Please sign in to comment.