| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b9a16e9 commit 72a1b06
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const { | |||
| 7 | 7 | const { getOptionValue } = require('internal/options'); | |
| 8 | 8 | const { getValidatedPath } = require('internal/fs/utils'); | |
| 9 | 9 | const fsBindings = internalBinding('fs'); | |
| 10 | - const { fs: fsConstants } = internalBinding('constants'); | ||
| 10 | + const { internal: internalConstants } = internalBinding('constants'); | ||
| 11 | 11 | ||
| 12 | 12 | const experimentalWasmModules = getOptionValue('--experimental-wasm-modules'); | |
| 13 | 13 | ||
@@ -55,7 +55,7 @@ function getFormatOfExtensionlessFile(url) { | |||
| 55 | 55 | if (!experimentalWasmModules) { return 'module'; } | |
| 56 | 56 | const path = getValidatedPath(url); | |
| 57 | 57 | switch (fsBindings.getFormatOfExtensionlessFile(path)) { | |
| 58 | - case fsConstants.EXTENSIONLESS_FORMAT_WASM: | ||
| 58 | + case internalConstants.EXTENSIONLESS_FORMAT_WASM: | ||
| 59 | 59 | return 'wasm'; | |
| 60 | 60 | default: | |
| 61 | 61 | return 'module'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1040,7 +1040,7 @@ void DefineCryptoConstants(Local<Object> target) { | |||
| 1040 | 1040 | #endif | |
| 1041 | 1041 | } | |
| 1042 | 1042 | ||
| 1043 | - void DefineSystemConstants(Local<Object> target) { | ||
| 1043 | + void DefineFsConstants(Local<Object> target) { | ||
| 1044 | 1044 | NODE_DEFINE_CONSTANT(target, UV_FS_SYMLINK_DIR); | |
| 1045 | 1045 | NODE_DEFINE_CONSTANT(target, UV_FS_SYMLINK_JUNCTION); | |
| 1046 | 1046 | // file access modes | |
@@ -1058,10 +1058,6 @@ void DefineSystemConstants(Local<Object> target) { | |||
| 1058 | 1058 | NODE_DEFINE_CONSTANT(target, UV_DIRENT_CHAR); | |
| 1059 | 1059 | NODE_DEFINE_CONSTANT(target, UV_DIRENT_BLOCK); | |
| 1060 | 1060 | ||
| 1061 | - // Define module specific constants | ||
| 1062 | - NODE_DEFINE_CONSTANT(target, EXTENSIONLESS_FORMAT_JAVASCRIPT); | ||
| 1063 | - NODE_DEFINE_CONSTANT(target, EXTENSIONLESS_FORMAT_WASM); | ||
| 1064 | - | ||
| 1065 | 1061 | NODE_DEFINE_CONSTANT(target, S_IFMT); | |
| 1066 | 1062 | NODE_DEFINE_CONSTANT(target, S_IFREG); | |
| 1067 | 1063 | NODE_DEFINE_CONSTANT(target, S_IFDIR); | |
@@ -1249,6 +1245,12 @@ void DefineDLOpenConstants(Local<Object> target) { | |||
| 1249 | 1245 | #endif | |
| 1250 | 1246 | } | |
| 1251 | 1247 | ||
| 1248 | + void DefineInternalConstants(Local<Object> target) { | ||
| 1249 | + // Define module specific constants | ||
| 1250 | + NODE_DEFINE_CONSTANT(target, EXTENSIONLESS_FORMAT_JAVASCRIPT); | ||
| 1251 | + NODE_DEFINE_CONSTANT(target, EXTENSIONLESS_FORMAT_WASM); | ||
| 1252 | + } | ||
| 1253 | + | ||
| 1252 | 1254 | void DefineTraceConstants(Local<Object> target) { | |
| 1253 | 1255 | NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_BEGIN); | |
| 1254 | 1256 | NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_END); | |
@@ -1323,15 +1325,20 @@ void CreatePerContextProperties(Local<Object> target, | |||
| 1323 | 1325 | CHECK(trace_constants->SetPrototype(env->context(), | |
| 1324 | 1326 | Null(env->isolate())).FromJust()); | |
| 1325 | 1327 | ||
| 1328 | + Local<Object> internal_constants = Object::New(isolate); | ||
| 1329 | + CHECK(internal_constants->SetPrototype(env->context(), | ||
| 1330 | + Null(env->isolate())).FromJust()); | ||
| 1331 | + | ||
| 1326 | 1332 | DefineErrnoConstants(err_constants); | |
| 1327 | 1333 | DefineWindowsErrorConstants(err_constants); | |
| 1328 | 1334 | DefineSignalConstants(sig_constants); | |
| 1329 | 1335 | DefinePriorityConstants(priority_constants); | |
| 1330 | - DefineSystemConstants(fs_constants); | ||
| 1336 | + DefineFsConstants(fs_constants); | ||
| 1331 | 1337 | DefineCryptoConstants(crypto_constants); | |
| 1332 | 1338 | DefineZlibConstants(zlib_constants); | |
| 1333 | 1339 | DefineDLOpenConstants(dlopen_constants); | |
| 1334 | 1340 | DefineTraceConstants(trace_constants); | |
| 1341 | + DefineInternalConstants(internal_constants); | ||
| 1335 | 1342 | ||
| 1336 | 1343 | // Define libuv constants. | |
| 1337 | 1344 | NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR); | |
@@ -1377,6 +1384,11 @@ void CreatePerContextProperties(Local<Object> target, | |||
| 1377 | 1384 | FIXED_ONE_BYTE_STRING(isolate, "trace"), | |
| 1378 | 1385 | trace_constants) | |
| 1379 | 1386 | .Check(); | |
| 1387 | + target | ||
| 1388 | + ->Set(env->context(), | ||
| 1389 | + FIXED_ONE_BYTE_STRING(isolate, "internal"), | ||
| 1390 | + internal_constants) | ||
| 1391 | + .Check(); | ||
| 1380 | 1392 | } | |
| 1381 | 1393 | ||
| 1382 | 1394 | } // namespace constants | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const constants = internalBinding('constants'); | |||
| 7 | 7 | const assert = require('assert'); | |
| 8 | 8 | ||
| 9 | 9 | assert.deepStrictEqual( | |
| 10 | - Object.keys(constants).sort(), ['crypto', 'fs', 'os', 'trace', 'zlib'] | ||
| 10 | + Object.keys(constants).sort(), ['crypto', 'fs', 'internal', 'os', 'trace', 'zlib'] | ||
| 11 | 11 | ); | |
| 12 | 12 | ||
| 13 | 13 | assert.deepStrictEqual( | |
@@ -28,6 +28,6 @@ function test(obj) { | |||
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | 30 | [ | |
| 31 | - constants, constants.crypto, constants.fs, constants.os, constants.trace, | ||
| 31 | + constants, constants.crypto, constants.fs, constants.internal, constants.os, constants.trace, | ||
| 32 | 32 | constants.zlib, constants.os.dlopen, constants.os.errno, constants.os.signals, | |
| 33 | 33 | ].forEach(test); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,3 +6,72 @@ const assert = require('assert'); | |||
| 6 | 6 | // Check if the two constants accepted by chmod() on Windows are defined. | |
| 7 | 7 | assert.notStrictEqual(fs.constants.S_IRUSR, undefined); | |
| 8 | 8 | assert.notStrictEqual(fs.constants.S_IWUSR, undefined); | |
| 9 | + | ||
| 10 | + // Check null prototype. | ||
| 11 | + assert.strictEqual(Object.getPrototypeOf(fs.constants), null); | ||
| 12 | + | ||
| 13 | + const knownFsConstantNames = [ | ||
| 14 | + 'UV_FS_SYMLINK_DIR', | ||
| 15 | + 'UV_FS_SYMLINK_JUNCTION', | ||
| 16 | + 'O_RDONLY', | ||
| 17 | + 'O_WRONLY', | ||
| 18 | + 'O_RDWR', | ||
| 19 | + 'UV_DIRENT_UNKNOWN', | ||
| 20 | + 'UV_DIRENT_FILE', | ||
| 21 | + 'UV_DIRENT_DIR', | ||
| 22 | + 'UV_DIRENT_LINK', | ||
| 23 | + 'UV_DIRENT_FIFO', | ||
| 24 | + 'UV_DIRENT_SOCKET', | ||
| 25 | + 'UV_DIRENT_CHAR', | ||
| 26 | + 'UV_DIRENT_BLOCK', | ||
| 27 | + 'S_IFMT', | ||
| 28 | + 'S_IFREG', | ||
| 29 | + 'S_IFDIR', | ||
| 30 | + 'S_IFCHR', | ||
| 31 | + 'S_IFBLK', | ||
| 32 | + 'S_IFIFO', | ||
| 33 | + 'S_IFLNK', | ||
| 34 | + 'S_IFSOCK', | ||
| 35 | + 'O_CREAT', | ||
| 36 | + 'O_EXCL', | ||
| 37 | + 'UV_FS_O_FILEMAP', | ||
| 38 | + 'O_NOCTTY', | ||
| 39 | + 'O_TRUNC', | ||
| 40 | + 'O_APPEND', | ||
| 41 | + 'O_DIRECTORY', | ||
| 42 | + 'O_EXCL', | ||
| 43 | + 'O_NOATIME', | ||
| 44 | + 'O_NOFOLLOW', | ||
| 45 | + 'O_SYNC', | ||
| 46 | + 'O_DSYNC', | ||
| 47 | + 'O_SYMLINK', | ||
| 48 | + 'O_DIRECT', | ||
| 49 | + 'O_NONBLOCK', | ||
| 50 | + 'S_IRWXU', | ||
| 51 | + 'S_IRUSR', | ||
| 52 | + 'S_IWUSR', | ||
| 53 | + 'S_IXUSR', | ||
| 54 | + 'S_IRWXG', | ||
| 55 | + 'S_IRGRP', | ||
| 56 | + 'S_IWGRP', | ||
| 57 | + 'S_IXGRP', | ||
| 58 | + 'S_IRWXO', | ||
| 59 | + 'S_IROTH', | ||
| 60 | + 'S_IWOTH', | ||
| 61 | + 'S_IXOTH', | ||
| 62 | + 'F_OK', | ||
| 63 | + 'R_OK', | ||
| 64 | + 'W_OK', | ||
| 65 | + 'X_OK', | ||
| 66 | + 'UV_FS_COPYFILE_EXCL', | ||
| 67 | + 'COPYFILE_EXCL', | ||
| 68 | + 'UV_FS_COPYFILE_FICLONE', | ||
| 69 | + 'COPYFILE_FICLONE', | ||
| 70 | + 'UV_FS_COPYFILE_FICLONE_FORCE', | ||
| 71 | + 'COPYFILE_FICLONE_FORCE', | ||
| 72 | + ]; | ||
| 73 | + const fsConstantNames = Object.keys(fs.constants); | ||
| 74 | + const unknownFsConstantNames = fsConstantNames.filter((constant) => { | ||
| 75 | + return !knownFsConstantNames.includes(constant); | ||
| 76 | + }); | ||
| 77 | + assert.deepStrictEqual(unknownFsConstantNames, [], `Unknown fs.constants: ${unknownFsConstantNames.join(', ')}`); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,8 +191,6 @@ export interface ConstantsBinding { | |||
| 191 | 191 | COPYFILE_FICLONE: 2; | |
| 192 | 192 | UV_FS_COPYFILE_FICLONE_FORCE: 4; | |
| 193 | 193 | COPYFILE_FICLONE_FORCE: 4; | |
| 194 | - EXTENSIONLESS_FORMAT_JAVASCRIPT: 0; | ||
| 195 | - EXTENSIONLESS_FORMAT_WASM: 1; | ||
| 196 | 194 | }; | |
| 197 | 195 | crypto: { | |
| 198 | 196 | OPENSSL_VERSION_NUMBER: 269488319; | |
@@ -389,4 +387,8 @@ export interface ConstantsBinding { | |||
| 389 | 387 | TRACE_EVENT_PHASE_LEAVE_CONTEXT: 41; | |
| 390 | 388 | TRACE_EVENT_PHASE_LINK_IDS: 61; | |
| 391 | 389 | }; | |
| 390 | + internal: { | ||
| 391 | + EXTENSIONLESS_FORMAT_JAVASCRIPT: 0; | ||
| 392 | + EXTENSIONLESS_FORMAT_WASM: 1; | ||
| 393 | + }; | ||
| 392 | 394 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -235,7 +235,7 @@ declare namespace InternalFSBinding { | |||
| 235 | 235 | function writeString(fd: number, value: string, pos: unknown, encoding: unknown, req: undefined, ctx: FSSyncContext): number; | |
| 236 | 236 | function writeString(fd: number, value: string, pos: unknown, encoding: unknown, usePromises: typeof kUsePromises): Promise<number>; | |
| 237 | 237 | ||
| 238 | - function getFormatOfExtensionlessFile(url: string): ConstantsBinding['fs']; | ||
| 238 | + function getFormatOfExtensionlessFile(url: string): ConstantsBinding['internal']; | ||
| 239 | 239 | ||
| 240 | 240 | function writeFileUtf8(path: string, data: string, flag: number, mode: number): void; | |
| 241 | 241 | function writeFileUtf8(fd: number, data: string, flag: number, mode: number): void; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments