Skip to content

Commit 7690b03

Browse files
committed
src: move ToNamespacedPath call of webstorage
1 parent ac75b2e commit 7690b03

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

lib/internal/webstorage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
66
const { getOptionValue } = require('internal/options');
77
const { emitExperimentalWarning } = require('internal/util');
88
const { kConstructorKey, Storage } = internalBinding('webstorage');
9-
const { resolve, toNamespacedPath } = require('path');
9+
const { resolve } = require('path');
1010
const { getValidatedPath } = require('internal/fs/utils');
1111
const kInMemoryPath = ':memory:';
1212

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

36-
location = toNamespacedPath(resolve(getValidatedPath(location)));
36+
location = resolve(getValidatedPath(location));
3737
lazyLocalStorage = new Storage(kConstructorKey, location);
3838
}
3939

src/node_webstorage.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "node.h"
77
#include "node_errors.h"
88
#include "node_mem-inl.h"
9+
#include "path.h"
910
#include "sqlite3.h"
1011
#include "util-inl.h"
1112

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

80-
Storage::Storage(Environment* env, Local<Object> object, Local<String> location)
81+
Storage::Storage(Environment* env,
82+
Local<Object> object,
83+
std::string_view location)
8184
: BaseObject(env, object) {
8285
MakeWeak();
83-
node::Utf8Value utf8_location(env->isolate(), location);
8486
symbols_.Reset(env->isolate(), Map::New(env->isolate()));
8587
db_ = nullptr;
86-
location_ = utf8_location.ToString();
88+
location_ = std::string(location);
8789
}
8890

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

210212
CHECK(args.IsConstructCall());
211213
CHECK(args[1]->IsString());
212-
new Storage(env, args.This(), args[1].As<String>());
214+
215+
BufferValue location(env->isolate(), args[1]);
216+
CHECK_NOT_NULL(*location);
217+
ToNamespacedPath(env, &location);
218+
new Storage(env, args.This(), location.ToStringView());
213219
}
214220

215221
void Storage::Clear() {

src/node_webstorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Storage : public BaseObject {
2727
public:
2828
Storage(Environment* env,
2929
v8::Local<v8::Object> object,
30-
v8::Local<v8::String> location);
30+
std::string_view location);
3131
void MemoryInfo(MemoryTracker* tracker) const override;
3232
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
3333

0 commit comments

Comments
 (0)