Skip to content

Commit

Permalink
fixup! move string construction to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
debadree25 committed May 1, 2023
1 parent 869ff2a commit 268fc13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 1 addition & 3 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,7 @@ function installObjectURLMethods() {

const id = cryptoRandom.randomUUID();

bindingBlob.storeDataObject(id, obj[blob.kHandle], obj.size, obj.type);

return `blob:nodedata:${id}`;
return bindingBlob.storeDataObject(id, obj[blob.kHandle], obj.size, obj.type);
}

function revokeObjectURL(url) {
Expand Down
17 changes: 11 additions & 6 deletions src/node_blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,19 @@ void Blob::StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) {

size_t length = args[2].As<Uint32>()->Value();
Utf8Value type(env->isolate(), args[3]);
std::string key_str(*key, key.length());

binding_data->store_data_object(
std::string(*key, key.length()),
BlobBindingData::StoredDataObject(
BaseObjectPtr<Blob>(blob),
length,
std::string(*type, type.length())));
key_str,
BlobBindingData::StoredDataObject(BaseObjectPtr<Blob>(blob),
length,
std::string(*type, type.length())));
std::string final_url = "blob:nodedata:" + key_str;
args.GetReturnValue().Set(String::NewFromUtf8(env->isolate(),
final_url.c_str(),
v8::NewStringType::kNormal,
final_url.length())
.ToLocalChecked());
}

void RevokeObjectURLImpl(std::string_view input,
Expand Down Expand Up @@ -431,7 +437,6 @@ void Blob::RevokeObjectURL(const FunctionCallbackInfo<Value>& args) {

void Blob::FastRevokeObjectURL(Local<Value> receiver,
const FastOneByteString& input) {
printf("FastRevokeObjectURL\n");
BlobBindingData* binding_data = FromJSObject<BlobBindingData>(receiver);
std::string_view input_view(input.data, input.length);
RevokeObjectURLImpl(input_view, binding_data);
Expand Down

0 comments on commit 268fc13

Please sign in to comment.