Skip to content

Commit

Permalink
src: move ToNamespacedPath call of webstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jul 16, 2024
1 parent ac75b2e commit 7690b03
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/internal/webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
const { getOptionValue } = require('internal/options');
const { emitExperimentalWarning } = require('internal/util');
const { kConstructorKey, Storage } = internalBinding('webstorage');
const { resolve, toNamespacedPath } = require('path');
const { resolve } = require('path');
const { getValidatedPath } = require('internal/fs/utils');
const kInMemoryPath = ':memory:';

Expand All @@ -33,7 +33,7 @@ ObjectDefineProperties(module.exports, {
'is an invalid localStorage location');
}

location = toNamespacedPath(resolve(getValidatedPath(location)));
location = resolve(getValidatedPath(location));
lazyLocalStorage = new Storage(kConstructorKey, location);
}

Expand Down
14 changes: 10 additions & 4 deletions src/node_webstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "node.h"
#include "node_errors.h"
#include "node_mem-inl.h"
#include "path.h"
#include "sqlite3.h"
#include "util-inl.h"

Expand Down Expand Up @@ -77,13 +78,14 @@ static void ThrowQuotaExceededException(Local<Context> context) {
isolate->ThrowException(exception);
}

Storage::Storage(Environment* env, Local<Object> object, Local<String> location)
Storage::Storage(Environment* env,
Local<Object> object,
std::string_view location)
: BaseObject(env, object) {
MakeWeak();
node::Utf8Value utf8_location(env->isolate(), location);
symbols_.Reset(env->isolate(), Map::New(env->isolate()));
db_ = nullptr;
location_ = utf8_location.ToString();
location_ = std::string(location);
}

Storage::~Storage() {
Expand Down Expand Up @@ -209,7 +211,11 @@ void Storage::New(const FunctionCallbackInfo<Value>& args) {

CHECK(args.IsConstructCall());
CHECK(args[1]->IsString());
new Storage(env, args.This(), args[1].As<String>());

BufferValue location(env->isolate(), args[1]);
CHECK_NOT_NULL(*location);
ToNamespacedPath(env, &location);
new Storage(env, args.This(), location.ToStringView());
}

void Storage::Clear() {
Expand Down
2 changes: 1 addition & 1 deletion src/node_webstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Storage : public BaseObject {
public:
Storage(Environment* env,
v8::Local<v8::Object> object,
v8::Local<v8::String> location);
std::string_view location);
void MemoryInfo(MemoryTracker* tracker) const override;
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);

Expand Down

0 comments on commit 7690b03

Please sign in to comment.