From 3531392eb70a905a5d467a05c2461a4e58a1af19 Mon Sep 17 00:00:00 2001 From: Joao da Silva Date: Sun, 16 Jan 2022 17:17:46 +0100 Subject: [PATCH] Added File.sep --- docs/doc/file.md | 7 +++++++ src/js_api_file.cc | 9 +++++++++ src/js_strings.cc | 1 + src/js_strings.h | 1 + types/file.d.ts | 6 ++++++ 5 files changed, 24 insertions(+) diff --git a/docs/doc/file.md b/docs/doc/file.md index e3e70293..0a5ad5b7 100644 --- a/docs/doc/file.md +++ b/docs/doc/file.md @@ -5,6 +5,7 @@ class-name: File class-properties: - cwd - home + - sep - tmp class-methods: - basename @@ -47,6 +48,12 @@ The current working directory. The user home directory. +{% include property class="File" name="sep" type="string" %} + +The preferred path separator for the current platform. This is usually the +forward slash character `/`, but is a backslash `\` on Windows. + + {% include property class="File" name="tmp" type="string" %} The system directory for temporary files. diff --git a/src/js_api_file.cc b/src/js_api_file.cc index 1e63a58c..8c255e2d 100644 --- a/src/js_api_file.cc +++ b/src/js_api_file.cc @@ -432,6 +432,14 @@ void GetTmp(v8::Local property, } } +void GetSep(v8::Local property, + const v8::PropertyCallbackInfo& info) { + ASSERT(IsMainThread()); + JsApi* api = JsApi::Get(info.GetIsolate()); + char sep[2] = {std::filesystem::path::preferred_separator, '\0'}; + info.GetReturnValue().Set(api->js()->MakeString(sep)); +} + } // namespace v8::Local MakeFileApi(JsApi* api, const JsScope& scope) { @@ -460,6 +468,7 @@ v8::Local MakeFileApi(JsApi* api, const JsScope& scope) { scope.Set(file, StringId::cwd, GetCwd); scope.Set(file, StringId::home, GetHome); + scope.Set(file, StringId::sep, GetSep); scope.Set(file, StringId::tmp, GetTmp); scope.Set(file, StringId::basename, Basename); diff --git a/src/js_strings.cc b/src/js_strings.cc index 375672e8..18b3d325 100644 --- a/src/js_strings.cc +++ b/src/js_strings.cc @@ -331,6 +331,7 @@ JsStrings::JsStrings(v8::Isolate* isolate) { SET_STRING(ScrollLock); SET_STRING(Semicolon); SET_STRING(sender); + SET_STRING(sep); SET_STRING(setClipboardText); SET_STRING(setLineDash); SET_STRING(setTimeout); diff --git a/src/js_strings.h b/src/js_strings.h index 708bc68c..7b16bef1 100644 --- a/src/js_strings.h +++ b/src/js_strings.h @@ -326,6 +326,7 @@ enum class StringId { ScrollLock, Semicolon, sender, + sep, setClipboardText, setLineDash, setTimeout, diff --git a/types/file.d.ts b/types/file.d.ts index 2e273c4d..fece2fd6 100644 --- a/types/file.d.ts +++ b/types/file.d.ts @@ -9,6 +9,12 @@ interface File { */ readonly home: string; + /** + * The preferred path separator for the current platform. This is usually + * the forward slash character `/`, but is a backslash `\` on Windows. + */ + readonly sep: string; + /** * The system directory for temporary files. */