Commit f6c15e1f authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[web snapshots] Fix error reporting

We have 4 different cases:
1) Explicit web snapshots (--web-snapshot) & errors in the snapshot
2) Explicit web snapshots & errors in the embedded script
3) Auto-detected web snapshots (--experimental-web-snapshots) & errors
in the snapshot
4) Auto-detected web snapshots & errors in the embedded script

Before this CL: cases 2 & 4 resulted in a DCHECK failing and the error
in case 3 wasn't reported correctly.

This CL implements consistent error reporting for all of them.

Bug: v8:11525
Change-Id: If2e5039d9769b9cad2175dfd5c4f91edf61111ae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3277877Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77963}
parent c0756abf
......@@ -633,7 +633,9 @@ namespace internal {
T(OptionalChainingNoSuper, "Invalid optional chain from super property") \
T(OptionalChainingNoTemplate, "Invalid tagged template on optional chain") \
/* AggregateError */ \
T(AllPromisesRejected, "All promises were rejected")
T(AllPromisesRejected, "All promises were rejected") \
/* Web snapshots */ \
T(WebSnapshotError, "Web snapshot failed: %")
enum class MessageTemplate {
#define TEMPLATE(NAME, STRING) k##NAME,
......
......@@ -1434,26 +1434,16 @@ bool Shell::ExecuteWebSnapshot(Isolate* isolate, const char* file_name) {
std::string absolute_path = NormalizePath(file_name, GetWorkingDirectory());
TryCatch try_catch(isolate);
try_catch.SetVerbose(true);
int length = 0;
std::unique_ptr<uint8_t[]> snapshot_data(
reinterpret_cast<uint8_t*>(ReadChars(absolute_path.c_str(), &length)));
if (length == 0) {
isolate->ThrowError("Error reading the web snapshot");
DCHECK(try_catch.HasCaught());
ReportException(isolate, &try_catch);
return false;
}
i::WebSnapshotDeserializer deserializer(isolate);
if (!deserializer.UseWebSnapshot(snapshot_data.get(),
static_cast<size_t>(length))) {
DCHECK(try_catch.HasCaught());
ReportException(isolate, &try_catch);
return false;
}
DCHECK(!try_catch.HasCaught());
return true;
return deserializer.UseWebSnapshot(snapshot_data.get(),
static_cast<size_t>(length));
}
PerIsolateData::PerIsolateData(Isolate* isolate)
......
This diff is collapsed.
......@@ -234,6 +234,8 @@ class V8_EXPORT WebSnapshotDeserializer
private:
bool Deserialize();
bool DeserializeSnapshot();
bool DeserializeScript();
WebSnapshotDeserializer(const WebSnapshotDeserializer&) = delete;
WebSnapshotDeserializer& operator=(const WebSnapshotDeserializer&) = delete;
......
......@@ -748,5 +748,47 @@ TEST(Concatenation) {
}
}
// Test that errors from invalid concatenated code are handled correctly.
TEST(ConcatenationErrors) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
const char* snapshot_source = "var foo = {a: 1};\n";
const char* source_to_append = "wontparse+[)";
uint32_t kObjectCount = 1;
WebSnapshotData snapshot_data;
{
v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context);
CompileRun(snapshot_source);
v8::Local<v8::PrimitiveArray> exports = v8::PrimitiveArray::New(isolate, 1);
v8::Local<v8::String> str =
v8::String::NewFromUtf8(isolate, "foo").ToLocalChecked();
exports->Set(isolate, 0, str);
WebSnapshotSerializer serializer(isolate);
CHECK(serializer.TakeSnapshot(new_context, exports, snapshot_data));
CHECK(!serializer.has_error());
CHECK_NOT_NULL(snapshot_data.buffer);
CHECK_EQ(kObjectCount, serializer.object_count());
}
auto buffer_size = snapshot_data.buffer_size + strlen(source_to_append);
std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
memcpy(buffer.get(), snapshot_data.buffer, snapshot_data.buffer_size);
memcpy(buffer.get() + snapshot_data.buffer_size, source_to_append,
strlen(source_to_append));
{
v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate);
CHECK(!deserializer.UseWebSnapshot(buffer.get(), buffer_size));
}
}
} // namespace internal
} // namespace v8
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