|
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,29 @@ 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 | + } |
| 431 | + |
| 432 | + auto pathname = out->get_pathname(); |
| 433 | + auto start_index = pathname.find(':'); |
424 | 434 |
|
425 |
| - binding_data->revoke_data_object(std::string(*key, key.length())); |
| 435 | + if (start_index != std::string_view::npos && start_index != pathname.size()) { |
| 436 | + auto end_index = pathname.find(':', start_index + 1); |
| 437 | + if (end_index == std::string_view::npos) { |
| 438 | + auto id = std::string(pathname.substr(start_index + 1)); |
| 439 | + binding_data->revoke_data_object(id); |
| 440 | + } |
| 441 | + } |
426 | 442 | }
|
427 | 443 |
|
428 | 444 | void Blob::GetDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
@@ -538,7 +554,7 @@ void Blob::RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
538 | 554 | registry->Register(Blob::ToSlice);
|
539 | 555 | registry->Register(Blob::StoreDataObject);
|
540 | 556 | registry->Register(Blob::GetDataObject);
|
541 |
| - registry->Register(Blob::RevokeDataObject); |
| 557 | + registry->Register(Blob::RevokeObjectURL); |
542 | 558 | registry->Register(Blob::Reader::Pull);
|
543 | 559 | registry->Register(Concat);
|
544 | 560 | registry->Register(BlobFromFilePath);
|
|
0 commit comments