Skip to content

Commit

Permalink
Added File.sep
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodasilva committed Jan 16, 2022
1 parent eaa5ebe commit 3531392
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/doc/file.md
Expand Up @@ -5,6 +5,7 @@ class-name: File
class-properties:
- cwd
- home
- sep
- tmp
class-methods:
- basename
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/js_api_file.cc
Expand Up @@ -432,6 +432,14 @@ void GetTmp(v8::Local<v8::Name> property,
}
}

void GetSep(v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& 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<v8::Object> MakeFileApi(JsApi* api, const JsScope& scope) {
Expand Down Expand Up @@ -460,6 +468,7 @@ v8::Local<v8::Object> 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);
Expand Down
1 change: 1 addition & 0 deletions src/js_strings.cc
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/js_strings.h
Expand Up @@ -326,6 +326,7 @@ enum class StringId {
ScrollLock,
Semicolon,
sender,
sep,
setClipboardText,
setLineDash,
setTimeout,
Expand Down
6 changes: 6 additions & 0 deletions types/file.d.ts
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 3531392

Please sign in to comment.