[web snapshot] Improve error handling in Realm.useWebSnapshot()

Bug: v8:11525, v8:11706
Change-Id: Ia1f15ab33708831323bed5cdd9b8d3cf029cb7a1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2928183
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Vicky Kontoura <vkont@google.com>
Cr-Commit-Position: refs/heads/master@{#74863}
This commit is contained in:
Vicky Kontoura 2021-05-31 09:52:33 +00:00 committed by V8 LUCI CQ
parent c211cb43a0
commit 48eaa74931

View File

@ -1876,7 +1876,7 @@ void Shell::RealmTakeWebSnapshot(
void Shell::RealmUseWebSnapshot(
const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
if (args.Length() < 2) {
if (args.Length() < 2 || !args[1]->IsObject()) {
isolate->ThrowError("Invalid argument");
return;
}
@ -1885,7 +1885,8 @@ void Shell::RealmUseWebSnapshot(
if (index == -1) return;
// Restore the snapshot data from the snapshot object.
Local<Object> snapshot_instance = args[1].As<Object>();
if (snapshot_instance->InternalFieldCount() != 1) {
Local<FunctionTemplate> snapshot_template = data->GetSnapshotObjectCtor();
if (!snapshot_template->HasInstance(snapshot_instance)) {
isolate->ThrowError("Invalid argument");
return;
}