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

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎lib/internal/webstorage.js‎

Lines changed: 2 additions & 4 deletions
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
constkInMemoryPath=':memory:';
1211

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

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

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

4038
returnlazyLocalStorage;

‎src/node_webstorage.cc‎

Lines changed: 14 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

@@ -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-
newStorage(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+
newStorage(env, args.This(), location.ToStringView());
213223
}
214224

215225
voidStorage::Clear() {

‎src/node_webstorage.h‎

Lines changed: 3 additions & 1 deletion
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+
staticconstexpr std::string_view kInMemoryPath = ":memory:";
27+
2628
classStorage : publicBaseObject {
2729
public:
2830
Storage(Environment* env,
2931
v8::Local<v8::Object> object,
30-
v8::Local<v8::String> location);
32+
std::string_view location);
3133
voidMemoryInfo(MemoryTracker* tracker) constoverride;
3234
staticvoidNew(const v8::FunctionCallbackInfo<v8::Value>& args);
3335

0 commit comments

Comments
 (0)