Skip to content

Commit 04bb677

Browse files
anonrigRafaelGSS
authored andcommitted
src: move ToNamespacedPath call of webstorage
PR-URL: #53875 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 43afcbf commit 04bb677

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/internal/webstorage.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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');
109
const { getValidatedPath } = require('internal/fs/utils');
1110
const kInMemoryPath = ':memory:';
1211

@@ -25,16 +24,15 @@ ObjectDefineProperties(module.exports, {
2524
enumerable: true,
2625
get() {
2726
if (lazyLocalStorage === undefined) {
28-
let location = getOptionValue('--localstorage-file');
27+
const location = getOptionValue('--localstorage-file');
2928

3029
if (location === '') {
3130
throw new ERR_INVALID_ARG_VALUE('--localstorage-file',
3231
location,
3332
'is an invalid localStorage location');
3433
}
3534

36-
location = toNamespacedPath(resolve(getValidatedPath(location)));
37-
lazyLocalStorage = new Storage(kConstructorKey, location);
35+
lazyLocalStorage = new Storage(kConstructorKey, getValidatedPath(location));
3836
}
3937

4038
return lazyLocalStorage;

src/node_webstorage.cc

+14-4
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

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

79-
Storage::Storage(Environment* env, Local<Object> object, Local<String> location)
80+
Storage::Storage(Environment* env,
81+
Local<Object> object,
82+
std::string_view location)
8083
: BaseObject(env, object) {
8184
MakeWeak();
82-
Utf8Value utf8_location(env->isolate(), location);
8385
symbols_.Reset(env->isolate(), Map::New(env->isolate()));
8486
db_ = nullptr;
85-
location_ = utf8_location.ToString();
87+
location_ = std::string(location);
8688
}
8789

8890
Storage::~Storage() {
@@ -209,7 +211,15 @@ 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+
// Only call namespaced path if the location is not "in memory".
218+
if (location.ToStringView() != kInMemoryPath) {
219+
ToNamespacedPath(env, &location);
220+
}
221+
222+
new Storage(env, args.This(), location.ToStringView());
213223
}
214224

215225
void Storage::Clear() {

src/node_webstorage.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ struct stmt_deleter {
2323
};
2424
using stmt_unique_ptr = std::unique_ptr<sqlite3_stmt, stmt_deleter>;
2525

26+
static constexpr std::string_view kInMemoryPath = ":memory:";
27+
2628
class Storage : public BaseObject {
2729
public:
2830
Storage(Environment* env,
2931
v8::Local<v8::Object> object,
30-
v8::Local<v8::String> location);
32+
std::string_view location);
3133
void MemoryInfo(MemoryTracker* tracker) const override;
3234
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
3335

0 commit comments

Comments
 (0)