| 
1 | 1 | #include "node_blob.h"  | 
 | 2 | +#include "ada.h"  | 
2 | 3 | #include "async_wrap-inl.h"  | 
3 | 4 | #include "base_object-inl.h"  | 
4 | 5 | #include "env-inl.h"  | 
 | 
7 | 8 | #include "node_errors.h"  | 
8 | 9 | #include "node_external_reference.h"  | 
9 | 10 | #include "node_file.h"  | 
 | 11 | +#include "util.h"  | 
10 | 12 | #include "v8.h"  | 
11 | 13 | 
 
  | 
12 | 14 | #include <algorithm>  | 
@@ -119,7 +121,7 @@ void Blob::Initialize(  | 
119 | 121 |   SetMethod(context, target, "createBlob", New);  | 
120 | 122 |   SetMethod(context, target, "storeDataObject", StoreDataObject);  | 
121 | 123 |   SetMethod(context, target, "getDataObject", GetDataObject);  | 
122 |  | -  SetMethod(context, target, "revokeDataObject", RevokeDataObject);  | 
 | 124 | +  SetMethod(context, target, "revokeObjectURL", RevokeObjectURL);  | 
123 | 125 |   SetMethod(context, target, "concat", Concat);  | 
124 | 126 |   SetMethod(context, target, "createBlobFromFilePath", BlobFromFilePath);  | 
125 | 127 | }  | 
@@ -414,15 +416,24 @@ void Blob::StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) {  | 
414 | 416 |         std::string(*type, type.length())));  | 
415 | 417 | }  | 
416 | 418 | 
 
  | 
417 |  | -void Blob::RevokeDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) {  | 
 | 419 | +// TODO(@anonrig): Add V8 Fast API to the following function  | 
 | 420 | +void Blob::RevokeObjectURL(const FunctionCallbackInfo<Value>& args) {  | 
 | 421 | +  CHECK_GE(args.Length(), 1);  | 
 | 422 | +  CHECK(args[0]->IsString());  | 
418 | 423 |   BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args);  | 
419 |  | - | 
420 | 424 |   Environment* env = Environment::GetCurrent(args);  | 
421 |  | -  CHECK(args[0]->IsString());  // ID key  | 
 | 425 | +  Utf8Value input(env->isolate(), args[0].As<String>());  | 
 | 426 | +  auto out = ada::parse<ada::url_aggregator>(input.ToStringView());  | 
422 | 427 | 
 
  | 
423 |  | -  Utf8Value key(env->isolate(), args[0]);  | 
 | 428 | +  if (!out) {  | 
 | 429 | +    return;  | 
 | 430 | +  }  | 
424 | 431 | 
 
  | 
425 |  | -  binding_data->revoke_data_object(std::string(*key, key.length()));  | 
 | 432 | +  auto path = std::string(out->get_pathname());  | 
 | 433 | +  auto sections = SplitString(path, ':', false);  | 
 | 434 | +  if (sections.size() == 2) {  | 
 | 435 | +    binding_data->revoke_data_object(sections.at(1));  | 
 | 436 | +  }  | 
426 | 437 | }  | 
427 | 438 | 
 
  | 
428 | 439 | void Blob::GetDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) {  | 
@@ -538,7 +549,7 @@ void Blob::RegisterExternalReferences(ExternalReferenceRegistry* registry) {  | 
538 | 549 |   registry->Register(Blob::ToSlice);  | 
539 | 550 |   registry->Register(Blob::StoreDataObject);  | 
540 | 551 |   registry->Register(Blob::GetDataObject);  | 
541 |  | -  registry->Register(Blob::RevokeDataObject);  | 
 | 552 | +  registry->Register(Blob::RevokeObjectURL);  | 
542 | 553 |   registry->Register(Blob::Reader::Pull);  | 
543 | 554 |   registry->Register(Concat);  | 
544 | 555 |   registry->Register(BlobFromFilePath);  | 
 | 
0 commit comments