diff --git a/doc/api/url.md b/doc/api/url.md index 1fd63a842fb200..81d30b8abb92bb 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -659,7 +659,8 @@ added: v16.7.0 * `id` {string} A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`. -Removes the stored {Blob} identified by the given ID. +Removes the stored {Blob} identified by the given ID. Attempting to revoke a +ID that isn’t registered will silently fail. ### Class: `URLSearchParams` diff --git a/src/node_blob.cc b/src/node_blob.cc index 4643da4c17496c..ee61437f402fcd 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -444,7 +444,9 @@ void BlobBindingData::store_data_object( } void BlobBindingData::revoke_data_object(const std::string& uuid) { - CHECK_NE(data_objects_.find(uuid), data_objects_.end()); + if (data_objects_.find(uuid) == data_objects_.end()) { + return; + } data_objects_.erase(uuid); CHECK_EQ(data_objects_.find(uuid), data_objects_.end()); } diff --git a/test/parallel/test-blob-createobjecturl.js b/test/parallel/test-blob-createobjecturl.js index a8fd377dd3ef70..70c64b138db1ac 100644 --- a/test/parallel/test-blob-createobjecturl.js +++ b/test/parallel/test-blob-createobjecturl.js @@ -29,6 +29,10 @@ const assert = require('assert'); Buffer.from(await otherBlob.arrayBuffer()).toString(), 'hello'); URL.revokeObjectURL(id); + + // should do nothing + URL.revokeObjectURL(id); + assert.strictEqual(resolveObjectURL(id), undefined); // Leaving a Blob registered should not cause an assert