[inspector] return meaningful error on Debug.setScriptSource for ES module
BUG=v8:1569 R=dgozman@chromium.org,alph@chromium.org Review-Url: https://codereview.chromium.org/2669713002 Cr-Commit-Position: refs/heads/master@{#42935}
This commit is contained in:
parent
51ed12f96e
commit
6b6ed60155
@ -522,6 +522,15 @@ Response V8DebuggerAgentImpl::setScriptSource(
|
||||
Maybe<protocol::Runtime::ExceptionDetails>* optOutCompileError) {
|
||||
if (!enabled()) return Response::Error(kDebuggerNotEnabled);
|
||||
|
||||
ScriptsMap::iterator it = m_scripts.find(scriptId);
|
||||
if (it == m_scripts.end()) {
|
||||
return Response::Error("No script with given id found");
|
||||
}
|
||||
if (it->second->isModule()) {
|
||||
// TODO(kozyatinskiy): LiveEdit should support ES6 module
|
||||
return Response::Error("Editing module's script is not supported.");
|
||||
}
|
||||
|
||||
v8::HandleScope handles(m_isolate);
|
||||
v8::Local<v8::String> newSource = toV8String(m_isolate, newContent);
|
||||
bool compileError = false;
|
||||
@ -530,9 +539,7 @@ Response V8DebuggerAgentImpl::setScriptSource(
|
||||
&m_pausedCallFrames, stackChanged, &compileError);
|
||||
if (!response.isSuccess() || compileError) return response;
|
||||
|
||||
ScriptsMap::iterator it = m_scripts.find(scriptId);
|
||||
if (it != m_scripts.end()) it->second->setSource(newSource);
|
||||
|
||||
it->second->setSource(newSource);
|
||||
std::unique_ptr<Array<CallFrame>> callFrames;
|
||||
response = currentCallFrames(&callFrames);
|
||||
if (!response.isSuccess()) return response;
|
||||
|
@ -0,0 +1,8 @@
|
||||
Checks that Debugger.setScriptSource doesn't crash with modules
|
||||
{
|
||||
error : {
|
||||
code : -32000
|
||||
message : Editing module's script is not supported.
|
||||
}
|
||||
id : <messageId>
|
||||
}
|
33
test/inspector/debugger/es6-module-set-script-source.js
Normal file
33
test/inspector/debugger/es6-module-set-script-source.js
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
print('Checks that Debugger.setScriptSource doesn\'t crash with modules');
|
||||
|
||||
var module1 = `
|
||||
export function foo() {
|
||||
return 42;
|
||||
}`;
|
||||
|
||||
var editedModule1 = `
|
||||
export function foo() {
|
||||
return 239;
|
||||
}`;
|
||||
|
||||
var module2 = `
|
||||
import { foo } from 'module1';
|
||||
console.log(foo());
|
||||
`;
|
||||
|
||||
var module1Id;
|
||||
Protocol.Debugger.onScriptParsed(message => {
|
||||
if (message.params.url === 'module1')
|
||||
module1Id = message.params.scriptId;
|
||||
});
|
||||
Protocol.Debugger.enable()
|
||||
.then(() => InspectorTest.addModule(module1, 'module1'))
|
||||
.then(() => InspectorTest.addModule(module2, 'module2'))
|
||||
.then(() => InspectorTest.waitPendingTasks())
|
||||
.then(() => Protocol.Debugger.setScriptSource({ scriptId: module1Id, scriptSource: editedModule1 }))
|
||||
.then(InspectorTest.logMessage)
|
||||
.then(InspectorTest.completeTest);
|
@ -4,7 +4,7 @@ Running test: testIncorrectScriptId
|
||||
{
|
||||
error : {
|
||||
code : -32000
|
||||
message : Uncaught Script not found
|
||||
message : No script with given id found
|
||||
}
|
||||
id : <messageId>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user