Commit 6b6ed601 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[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}
parent 51ed12f9
......@@ -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;
......
Checks that Debugger.setScriptSource doesn't crash with modules
{
error : {
code : -32000
message : Editing module's script is not supported.
}
id : <messageId>
}
// 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>
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment