| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ const { | |||
| 24 | 24 | StringPrototypeIncludes, | |
| 25 | 25 | StringPrototypeIndexOf, | |
| 26 | 26 | StringPrototypeSlice, | |
| 27 | - StringPrototypeSplit, | ||
| 28 | 27 | StringPrototypeStartsWith, | |
| 29 | 28 | Symbol, | |
| 30 | 29 | SymbolIterator, | |
@@ -1024,10 +1023,7 @@ ObjectDefineProperties(URL, { | |||
| 1024 | 1023 | }); | |
| 1025 | 1024 | ||
| 1026 | 1025 | function installObjectURLMethods() { | |
| 1027 | - const { | ||
| 1028 | - storeDataObject, | ||
| 1029 | - revokeDataObject, | ||
| 1030 | - } = internalBinding('blob'); | ||
| 1026 | + const bindingBlob = internalBinding('blob'); | ||
| 1031 | 1027 | ||
| 1032 | 1028 | function createObjectURL(obj) { | |
| 1033 | 1029 | const cryptoRandom = lazyCryptoRandom(); | |
@@ -1040,22 +1036,13 @@ function installObjectURLMethods() { | |||
| 1040 | 1036 | ||
| 1041 | 1037 | const id = cryptoRandom.randomUUID(); | |
| 1042 | 1038 | ||
| 1043 | - storeDataObject(id, obj[blob.kHandle], obj.size, obj.type); | ||
| 1039 | + bindingBlob.storeDataObject(id, obj[blob.kHandle], obj.size, obj.type); | ||
| 1044 | 1040 | ||
| 1045 | 1041 | return `blob:nodedata:${id}`; | |
| 1046 | 1042 | } | |
| 1047 | 1043 | ||
| 1048 | 1044 | function revokeObjectURL(url) { | |
| 1049 | - url = `${url}`; | ||
| 1050 | - try { | ||
| 1051 | - // TODO(@anonrig): Remove this try/catch by calling `parse` directly. | ||
| 1052 | - const parsed = new URL(url); | ||
| 1053 | - const split = StringPrototypeSplit(parsed.pathname, ':'); | ||
| 1054 | - if (split.length === 2) | ||
| 1055 | - revokeDataObject(split[1]); | ||
| 1056 | - } catch { | ||
| 1057 | - // If there's an error, it's ignored. | ||
| 1058 | - } | ||
| 1045 | + bindingBlob.revokeObjectURL(`${url}`); | ||
| 1059 | 1046 | } | |
| 1060 | 1047 | ||
| 1061 | 1048 | ObjectDefineProperties(URL, { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 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,6 +8,7 @@ | |||
| 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); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ class Blob : public BaseObject { | |||
| 37 | 37 | static void ToSlice(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 38 | 38 | static void StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 39 | 39 | static void GetDataObject(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 40 | - static void RevokeDataObject(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 40 | + static void RevokeObjectURL(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 41 | 41 | ||
| 42 | 42 | static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | |
| 43 | 43 | Environment* env); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments