diff --git a/SECURITY.md b/SECURITY.md index 1d0b16e..a07c25b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -10,4 +10,5 @@ | < 4.0 | :x: | ## Reporting a Vulnerability + Go to Issues Report a Vulnerability diff --git a/api.js b/api.js index 6854d0a..85882a9 100644 --- a/api.js +++ b/api.js @@ -1,5 +1,5 @@ // Ensure 'serverApi' is declared only once const serverApi = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/block-css-value.js b/block-css-value.js index 38bbe57..ea2b889 100644 --- a/block-css-value.js +++ b/block-css-value.js @@ -1,5 +1,5 @@ // Ensure 'BLOCK_CSS_VALUE' is declared only once const BLOCK_CSS_VALUE = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/block-types.js b/block-types.js index d4b6ced..db5f45a 100644 --- a/block-types.js +++ b/block-types.js @@ -1,5 +1,5 @@ // Ensure 'BLOCK_TYPES' is declared only once const BLOCK_TYPES = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/browser-info.js b/browser-info.js index b637040..3e82012 100644 --- a/browser-info.js +++ b/browser-info.js @@ -1,5 +1,5 @@ // Ensure 'BrowserInfo' is declared only once const BrowserInfo = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/debug.js b/debug.js index 5ae8d5f..6dbb8e0 100644 --- a/debug.js +++ b/debug.js @@ -1,4 +1,4 @@ // Ensure 'debug' is declared only once const debug = (message) => { - console.log(message); + console.log(message); }; diff --git a/dialog.js b/dialog.js index 38030db..6ffafe9 100644 --- a/dialog.js +++ b/dialog.js @@ -1,6 +1 @@ - - - - - -// ...existing code...}; // ...existing code...const Dialog = { \ No newline at end of file +// ...existing code...}; // ...existing code...const Dialog = { diff --git a/helpers.js b/helpers.js index 03443b1..2531008 100644 --- a/helpers.js +++ b/helpers.js @@ -1,5 +1,5 @@ // Ensure 'guidSeed' is declared only once const guidSeed = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/icon-badge-periods.js b/icon-badge-periods.js index 3b25b53..aac9f83 100644 --- a/icon-badge-periods.js +++ b/icon-badge-periods.js @@ -1,5 +1,5 @@ // Ensure 'ICON_BADGE_PERIODS' is declared only once const ICON_BADGE_PERIODS = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/index.html b/index.html index d1f4ad7..d4d3800 100644 --- a/index.html +++ b/index.html @@ -1,46 +1,49 @@ - + - - - + + + AI-Powered Toolbox - - - + + +
-

AI-Powered Online Toolbox

-

Your go-to tools enhanced by Artificial Intelligence for networking and IP-related tasks.

+

AI-Powered Online Toolbox

+

+ Your go-to tools enhanced by Artificial Intelligence for networking and + IP-related tasks. +

-
-
-

What's My IP Address

- -

Your IP will appear here.

-
-
-

IP Lookup / Geolocation

- - -

Results will appear here.

-
-
-

Internet Speed Test

- -

Speed test results will appear here.

-
-
-

Ping

- - -

Ping results will appear here.

-
-
- +
+
+

What's My IP Address

+ +

Your IP will appear here.

+
+
+

IP Lookup / Geolocation

+ + +

Results will appear here.

+
+
+

Internet Speed Test

+ +

Speed test results will appear here.

+
+
+

Ping

+ + +

Ping results will appear here.

+
+
+
- + diff --git a/message-types.js b/message-types.js index fc338c2..5e83433 100644 --- a/message-types.js +++ b/message-types.js @@ -1,5 +1,5 @@ // Ensure 'MESSAGE_TYPES' is declared only once const MESSAGE_TYPES = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/node_modules/lzma-native/deps/include/lzma.h b/node_modules/lzma-native/deps/include/lzma.h index 7d0bdc7..4b42bce 100644 --- a/node_modules/lzma-native/deps/include/lzma.h +++ b/node_modules/lzma-native/deps/include/lzma.h @@ -69,101 +69,100 @@ */ #ifndef LZMA_MANUAL_HEADERS - /* - * I suppose this works portably also in C++. Note that in C++, - * we need to get size_t into the global namespace. - */ -# include - - /* - * Skip inttypes.h if we already have all the required macros. If we - * have the macros, we assume that we have the matching typedefs too. - */ -# if !defined(UINT32_C) || !defined(UINT64_C) \ - || !defined(UINT32_MAX) || !defined(UINT64_MAX) - /* - * MSVC versions older than 2013 have no C99 support, and - * thus they cannot be used to compile liblzma. Using an - * existing liblzma.dll with old MSVC can work though(*), - * but we need to define the required standard integer - * types here in a MSVC-specific way. - * - * (*) If you do this, the existing liblzma.dll probably uses - * a different runtime library than your MSVC-built - * application. Mixing runtimes is generally bad, but - * in this case it should work as long as you avoid - * the few rarely-needed liblzma functions that allocate - * memory and expect the caller to free it using free(). - */ -# if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800 - typedef unsigned __int8 uint8_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; -# else - /* Use the standard inttypes.h. */ -# ifdef __cplusplus - /* - * C99 sections 7.18.2 and 7.18.4 specify - * that C++ implementations define the limit - * and constant macros only if specifically - * requested. Note that if you want the - * format macros (PRIu64 etc.) too, you need - * to define __STDC_FORMAT_MACROS before - * including lzma.h, since re-including - * inttypes.h with __STDC_FORMAT_MACROS - * defined doesn't necessarily work. - */ -# ifndef __STDC_LIMIT_MACROS -# define __STDC_LIMIT_MACROS 1 -# endif -# ifndef __STDC_CONSTANT_MACROS -# define __STDC_CONSTANT_MACROS 1 -# endif -# endif - -# include -# endif - - /* - * Some old systems have only the typedefs in inttypes.h, and - * lack all the macros. For those systems, we need a few more - * hacks. We assume that unsigned int is 32-bit and unsigned - * long is either 32-bit or 64-bit. If these hacks aren't - * enough, the application has to setup the types manually - * before including lzma.h. - */ -# ifndef UINT32_C -# if defined(_WIN32) && defined(_MSC_VER) -# define UINT32_C(n) n ## UI32 -# else -# define UINT32_C(n) n ## U -# endif -# endif - -# ifndef UINT64_C -# if defined(_WIN32) && defined(_MSC_VER) -# define UINT64_C(n) n ## UI64 -# else - /* Get ULONG_MAX. */ -# include -# if ULONG_MAX == 4294967295UL -# define UINT64_C(n) n ## ULL -# else -# define UINT64_C(n) n ## UL -# endif -# endif -# endif - -# ifndef UINT32_MAX -# define UINT32_MAX (UINT32_C(4294967295)) -# endif - -# ifndef UINT64_MAX -# define UINT64_MAX (UINT64_C(18446744073709551615)) -# endif -# endif -#endif /* ifdef LZMA_MANUAL_HEADERS */ +/* + * I suppose this works portably also in C++. Note that in C++, + * we need to get size_t into the global namespace. + */ +#include + +/* + * Skip inttypes.h if we already have all the required macros. If we + * have the macros, we assume that we have the matching typedefs too. + */ +#if !defined(UINT32_C) || !defined(UINT64_C) || !defined(UINT32_MAX) || \ + !defined(UINT64_MAX) +/* + * MSVC versions older than 2013 have no C99 support, and + * thus they cannot be used to compile liblzma. Using an + * existing liblzma.dll with old MSVC can work though(*), + * but we need to define the required standard integer + * types here in a MSVC-specific way. + * + * (*) If you do this, the existing liblzma.dll probably uses + * a different runtime library than your MSVC-built + * application. Mixing runtimes is generally bad, but + * in this case it should work as long as you avoid + * the few rarely-needed liblzma functions that allocate + * memory and expect the caller to free it using free(). + */ +#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800 +typedef unsigned __int8 uint8_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +/* Use the standard inttypes.h. */ +#ifdef __cplusplus +/* + * C99 sections 7.18.2 and 7.18.4 specify + * that C++ implementations define the limit + * and constant macros only if specifically + * requested. Note that if you want the + * format macros (PRIu64 etc.) too, you need + * to define __STDC_FORMAT_MACROS before + * including lzma.h, since re-including + * inttypes.h with __STDC_FORMAT_MACROS + * defined doesn't necessarily work. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS 1 +#endif +#endif + +#include +#endif + +/* + * Some old systems have only the typedefs in inttypes.h, and + * lack all the macros. For those systems, we need a few more + * hacks. We assume that unsigned int is 32-bit and unsigned + * long is either 32-bit or 64-bit. If these hacks aren't + * enough, the application has to setup the types manually + * before including lzma.h. + */ +#ifndef UINT32_C +#if defined(_WIN32) && defined(_MSC_VER) +#define UINT32_C(n) n##UI32 +#else +#define UINT32_C(n) n##U +#endif +#endif + +#ifndef UINT64_C +#if defined(_WIN32) && defined(_MSC_VER) +#define UINT64_C(n) n##UI64 +#else +/* Get ULONG_MAX. */ +#include +#if ULONG_MAX == 4294967295UL +#define UINT64_C(n) n##ULL +#else +#define UINT64_C(n) n##UL +#endif +#endif +#endif + +#ifndef UINT32_MAX +#define UINT32_MAX (UINT32_C(4294967295)) +#endif +#ifndef UINT64_MAX +#define UINT64_MAX (UINT64_C(18446744073709551615)) +#endif +#endif +#endif /* ifdef LZMA_MANUAL_HEADERS */ /****************** * LZMA_API macro * @@ -188,26 +187,25 @@ * omitted on Cygwin but not on MinGW. */ #ifndef LZMA_API_IMPORT -# if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__) -# define LZMA_API_IMPORT __declspec(dllimport) -# else -# define LZMA_API_IMPORT -# endif +#if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__) +#define LZMA_API_IMPORT __declspec(dllimport) +#else +#define LZMA_API_IMPORT +#endif #endif #ifndef LZMA_API_CALL -# if defined(_WIN32) && !defined(__CYGWIN__) -# define LZMA_API_CALL __cdecl -# else -# define LZMA_API_CALL -# endif +#if defined(_WIN32) && !defined(__CYGWIN__) +#define LZMA_API_CALL __cdecl +#else +#define LZMA_API_CALL +#endif #endif #ifndef LZMA_API -# define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL +#define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL #endif - /*********** * nothrow * ***********/ @@ -218,15 +216,14 @@ * because liblzma would break if a callback function threw an exception. */ #ifndef lzma_nothrow -# if defined(__cplusplus) -# define lzma_nothrow throw() -# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) -# define lzma_nothrow __attribute__((__nothrow__)) -# else -# define lzma_nothrow -# endif +#if defined(__cplusplus) +#define lzma_nothrow throw() +#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) +#define lzma_nothrow __attribute__((__nothrow__)) +#else +#define lzma_nothrow +#endif #endif - /******************** * GNU C extensions * @@ -238,38 +235,35 @@ * affects warnings and optimizations. */ #if __GNUC__ >= 3 -# ifndef lzma_attribute -# define lzma_attribute(attr) __attribute__(attr) -# endif +#ifndef lzma_attribute +#define lzma_attribute(attr) __attribute__(attr) +#endif - /* warn_unused_result was added in GCC 3.4. */ -# ifndef lzma_attr_warn_unused_result -# if __GNUC__ == 3 && __GNUC_MINOR__ < 4 -# define lzma_attr_warn_unused_result -# endif -# endif +/* warn_unused_result was added in GCC 3.4. */ +#ifndef lzma_attr_warn_unused_result +#if __GNUC__ == 3 && __GNUC_MINOR__ < 4 +#define lzma_attr_warn_unused_result +#endif +#endif #else -# ifndef lzma_attribute -# define lzma_attribute(attr) -# endif +#ifndef lzma_attribute +#define lzma_attribute(attr) +#endif #endif - #ifndef lzma_attr_pure -# define lzma_attr_pure lzma_attribute((__pure__)) +#define lzma_attr_pure lzma_attribute((__pure__)) #endif #ifndef lzma_attr_const -# define lzma_attr_const lzma_attribute((__const__)) +#define lzma_attr_const lzma_attribute((__const__)) #endif #ifndef lzma_attr_warn_unused_result -# define lzma_attr_warn_unused_result \ - lzma_attribute((__warn_unused_result__)) +#define lzma_attr_warn_unused_result lzma_attribute((__warn_unused_result__)) #endif - /************** * Subheaders * **************/ @@ -285,25 +279,25 @@ extern "C" { #define LZMA_H_INTERNAL 1 /* Basic features */ -#include "lzma/version.h" #include "lzma/base.h" -#include "lzma/vli.h" #include "lzma/check.h" +#include "lzma/version.h" +#include "lzma/vli.h" /* Filters */ -#include "lzma/filter.h" #include "lzma/bcj.h" #include "lzma/delta.h" +#include "lzma/filter.h" #include "lzma/lzma12.h" /* Container formats */ #include "lzma/container.h" /* Advanced features */ -#include "lzma/stream_flags.h" #include "lzma/block.h" #include "lzma/index.h" #include "lzma/index_hash.h" +#include "lzma/stream_flags.h" /* Hardware information */ #include "lzma/hardware.h" diff --git a/node_modules/lzma-native/deps/include/lzma/base.h b/node_modules/lzma-native/deps/include/lzma/base.h index e0405a2..76bdbfb 100644 --- a/node_modules/lzma-native/deps/include/lzma/base.h +++ b/node_modules/lzma-native/deps/include/lzma/base.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Boolean * @@ -28,7 +27,6 @@ */ typedef unsigned char lzma_bool; - /** * \brief Type of reserved enumeration variable in structures * @@ -41,10 +39,7 @@ typedef unsigned char lzma_bool; * than 128, which should guarantee that the ABI won't break even when * new constants are added to existing enumerations. */ -typedef enum { - LZMA_RESERVED_ENUM = 0 -} lzma_reserved_enum; - +typedef enum { LZMA_RESERVED_ENUM = 0 } lzma_reserved_enum; /** * \brief Return values used by several functions in liblzma @@ -55,188 +50,187 @@ typedef enum { * described per-function basis. */ typedef enum { - LZMA_OK = 0, - /**< - * \brief Operation completed successfully - */ - - LZMA_STREAM_END = 1, - /**< - * \brief End of stream was reached - * - * In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or - * LZMA_FINISH was finished. In decoder, this indicates - * that all the data was successfully decoded. - * - * In all cases, when LZMA_STREAM_END is returned, the last - * output bytes should be picked from strm->next_out. - */ - - LZMA_NO_CHECK = 2, - /**< - * \brief Input stream has no integrity check - * - * This return value can be returned only if the - * LZMA_TELL_NO_CHECK flag was used when initializing - * the decoder. LZMA_NO_CHECK is just a warning, and - * the decoding can be continued normally. - * - * It is possible to call lzma_get_check() immediately after - * lzma_code has returned LZMA_NO_CHECK. The result will - * naturally be LZMA_CHECK_NONE, but the possibility to call - * lzma_get_check() may be convenient in some applications. - */ - - LZMA_UNSUPPORTED_CHECK = 3, - /**< - * \brief Cannot calculate the integrity check - * - * The usage of this return value is different in encoders - * and decoders. - * - * Encoders can return this value only from the initialization - * function. If initialization fails with this value, the - * encoding cannot be done, because there's no way to produce - * output with the correct integrity check. - * - * Decoders can return this value only from lzma_code() and - * only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when - * initializing the decoder. The decoding can still be - * continued normally even if the check type is unsupported, - * but naturally the check will not be validated, and possible - * errors may go undetected. - * - * With decoder, it is possible to call lzma_get_check() - * immediately after lzma_code() has returned - * LZMA_UNSUPPORTED_CHECK. This way it is possible to find - * out what the unsupported Check ID was. - */ - - LZMA_GET_CHECK = 4, - /**< - * \brief Integrity check type is now available - * - * This value can be returned only by the lzma_code() function - * and only if the decoder was initialized with the - * LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the - * application that it may now call lzma_get_check() to find - * out the Check ID. This can be used, for example, to - * implement a decoder that accepts only files that have - * strong enough integrity check. - */ - - LZMA_MEM_ERROR = 5, - /**< - * \brief Cannot allocate memory - * - * Memory allocation failed, or the size of the allocation - * would be greater than SIZE_MAX. - * - * Due to internal implementation reasons, the coding cannot - * be continued even if more memory were made available after - * LZMA_MEM_ERROR. - */ - - LZMA_MEMLIMIT_ERROR = 6, - /** - * \brief Memory usage limit was reached - * - * Decoder would need more memory than allowed by the - * specified memory usage limit. To continue decoding, - * the memory usage limit has to be increased with - * lzma_memlimit_set(). - */ - - LZMA_FORMAT_ERROR = 7, - /**< - * \brief File format not recognized - * - * The decoder did not recognize the input as supported file - * format. This error can occur, for example, when trying to - * decode .lzma format file with lzma_stream_decoder, - * because lzma_stream_decoder accepts only the .xz format. - */ - - LZMA_OPTIONS_ERROR = 8, - /**< - * \brief Invalid or unsupported options - * - * Invalid or unsupported options, for example - * - unsupported filter(s) or filter options; or - * - reserved bits set in headers (decoder only). - * - * Rebuilding liblzma with more features enabled, or - * upgrading to a newer version of liblzma may help. - */ - - LZMA_DATA_ERROR = 9, - /**< - * \brief Data is corrupt - * - * The usage of this return value is different in encoders - * and decoders. In both encoder and decoder, the coding - * cannot continue after this error. - * - * Encoders return this if size limits of the target file - * format would be exceeded. These limits are huge, thus - * getting this error from an encoder is mostly theoretical. - * For example, the maximum compressed and uncompressed - * size of a .xz Stream is roughly 8 EiB (2^63 bytes). - * - * Decoders return this error if the input data is corrupt. - * This can mean, for example, invalid CRC32 in headers - * or invalid check of uncompressed data. - */ - - LZMA_BUF_ERROR = 10, - /**< - * \brief No progress is possible - * - * This error code is returned when the coder cannot consume - * any new input and produce any new output. The most common - * reason for this error is that the input stream being - * decoded is truncated or corrupt. - * - * This error is not fatal. Coding can be continued normally - * by providing more input and/or more output space, if - * possible. - * - * Typically the first call to lzma_code() that can do no - * progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only - * the second consecutive call doing no progress will return - * LZMA_BUF_ERROR. This is intentional. - * - * With zlib, Z_BUF_ERROR may be returned even if the - * application is doing nothing wrong, so apps will need - * to handle Z_BUF_ERROR specially. The above hack - * guarantees that liblzma never returns LZMA_BUF_ERROR - * to properly written applications unless the input file - * is truncated or corrupt. This should simplify the - * applications a little. - */ - - LZMA_PROG_ERROR = 11, - /**< - * \brief Programming error - * - * This indicates that the arguments given to the function are - * invalid or the internal state of the decoder is corrupt. - * - Function arguments are invalid or the structures - * pointed by the argument pointers are invalid - * e.g. if strm->next_out has been set to NULL and - * strm->avail_out > 0 when calling lzma_code(). - * - lzma_* functions have been called in wrong order - * e.g. lzma_code() was called right after lzma_end(). - * - If errors occur randomly, the reason might be flaky - * hardware. - * - * If you think that your code is correct, this error code - * can be a sign of a bug in liblzma. See the documentation - * how to report bugs. - */ + LZMA_OK = 0, + /**< + * \brief Operation completed successfully + */ + + LZMA_STREAM_END = 1, + /**< + * \brief End of stream was reached + * + * In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or + * LZMA_FINISH was finished. In decoder, this indicates + * that all the data was successfully decoded. + * + * In all cases, when LZMA_STREAM_END is returned, the last + * output bytes should be picked from strm->next_out. + */ + + LZMA_NO_CHECK = 2, + /**< + * \brief Input stream has no integrity check + * + * This return value can be returned only if the + * LZMA_TELL_NO_CHECK flag was used when initializing + * the decoder. LZMA_NO_CHECK is just a warning, and + * the decoding can be continued normally. + * + * It is possible to call lzma_get_check() immediately after + * lzma_code has returned LZMA_NO_CHECK. The result will + * naturally be LZMA_CHECK_NONE, but the possibility to call + * lzma_get_check() may be convenient in some applications. + */ + + LZMA_UNSUPPORTED_CHECK = 3, + /**< + * \brief Cannot calculate the integrity check + * + * The usage of this return value is different in encoders + * and decoders. + * + * Encoders can return this value only from the initialization + * function. If initialization fails with this value, the + * encoding cannot be done, because there's no way to produce + * output with the correct integrity check. + * + * Decoders can return this value only from lzma_code() and + * only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when + * initializing the decoder. The decoding can still be + * continued normally even if the check type is unsupported, + * but naturally the check will not be validated, and possible + * errors may go undetected. + * + * With decoder, it is possible to call lzma_get_check() + * immediately after lzma_code() has returned + * LZMA_UNSUPPORTED_CHECK. This way it is possible to find + * out what the unsupported Check ID was. + */ + + LZMA_GET_CHECK = 4, + /**< + * \brief Integrity check type is now available + * + * This value can be returned only by the lzma_code() function + * and only if the decoder was initialized with the + * LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the + * application that it may now call lzma_get_check() to find + * out the Check ID. This can be used, for example, to + * implement a decoder that accepts only files that have + * strong enough integrity check. + */ + + LZMA_MEM_ERROR = 5, + /**< + * \brief Cannot allocate memory + * + * Memory allocation failed, or the size of the allocation + * would be greater than SIZE_MAX. + * + * Due to internal implementation reasons, the coding cannot + * be continued even if more memory were made available after + * LZMA_MEM_ERROR. + */ + + LZMA_MEMLIMIT_ERROR = 6, + /** + * \brief Memory usage limit was reached + * + * Decoder would need more memory than allowed by the + * specified memory usage limit. To continue decoding, + * the memory usage limit has to be increased with + * lzma_memlimit_set(). + */ + + LZMA_FORMAT_ERROR = 7, + /**< + * \brief File format not recognized + * + * The decoder did not recognize the input as supported file + * format. This error can occur, for example, when trying to + * decode .lzma format file with lzma_stream_decoder, + * because lzma_stream_decoder accepts only the .xz format. + */ + + LZMA_OPTIONS_ERROR = 8, + /**< + * \brief Invalid or unsupported options + * + * Invalid or unsupported options, for example + * - unsupported filter(s) or filter options; or + * - reserved bits set in headers (decoder only). + * + * Rebuilding liblzma with more features enabled, or + * upgrading to a newer version of liblzma may help. + */ + + LZMA_DATA_ERROR = 9, + /**< + * \brief Data is corrupt + * + * The usage of this return value is different in encoders + * and decoders. In both encoder and decoder, the coding + * cannot continue after this error. + * + * Encoders return this if size limits of the target file + * format would be exceeded. These limits are huge, thus + * getting this error from an encoder is mostly theoretical. + * For example, the maximum compressed and uncompressed + * size of a .xz Stream is roughly 8 EiB (2^63 bytes). + * + * Decoders return this error if the input data is corrupt. + * This can mean, for example, invalid CRC32 in headers + * or invalid check of uncompressed data. + */ + + LZMA_BUF_ERROR = 10, + /**< + * \brief No progress is possible + * + * This error code is returned when the coder cannot consume + * any new input and produce any new output. The most common + * reason for this error is that the input stream being + * decoded is truncated or corrupt. + * + * This error is not fatal. Coding can be continued normally + * by providing more input and/or more output space, if + * possible. + * + * Typically the first call to lzma_code() that can do no + * progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only + * the second consecutive call doing no progress will return + * LZMA_BUF_ERROR. This is intentional. + * + * With zlib, Z_BUF_ERROR may be returned even if the + * application is doing nothing wrong, so apps will need + * to handle Z_BUF_ERROR specially. The above hack + * guarantees that liblzma never returns LZMA_BUF_ERROR + * to properly written applications unless the input file + * is truncated or corrupt. This should simplify the + * applications a little. + */ + + LZMA_PROG_ERROR = 11, + /**< + * \brief Programming error + * + * This indicates that the arguments given to the function are + * invalid or the internal state of the decoder is corrupt. + * - Function arguments are invalid or the structures + * pointed by the argument pointers are invalid + * e.g. if strm->next_out has been set to NULL and + * strm->avail_out > 0 when calling lzma_code(). + * - lzma_* functions have been called in wrong order + * e.g. lzma_code() was called right after lzma_end(). + * - If errors occur randomly, the reason might be flaky + * hardware. + * + * If you think that your code is correct, this error code + * can be a sign of a bug in liblzma. See the documentation + * how to report bugs. + */ } lzma_ret; - /** * \brief The `action' argument for lzma_code() * @@ -248,103 +242,102 @@ typedef enum { * will make lzma_code() return LZMA_PROG_ERROR. */ typedef enum { - LZMA_RUN = 0, - /**< - * \brief Continue coding - * - * Encoder: Encode as much input as possible. Some internal - * buffering will probably be done (depends on the filter - * chain in use), which causes latency: the input used won't - * usually be decodeable from the output of the same - * lzma_code() call. - * - * Decoder: Decode as much input as possible and produce as - * much output as possible. - */ - - LZMA_SYNC_FLUSH = 1, - /**< - * \brief Make all the input available at output - * - * Normally the encoder introduces some latency. - * LZMA_SYNC_FLUSH forces all the buffered data to be - * available at output without resetting the internal - * state of the encoder. This way it is possible to use - * compressed stream for example for communication over - * network. - * - * Only some filters support LZMA_SYNC_FLUSH. Trying to use - * LZMA_SYNC_FLUSH with filters that don't support it will - * make lzma_code() return LZMA_OPTIONS_ERROR. For example, - * LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does. - * - * Using LZMA_SYNC_FLUSH very often can dramatically reduce - * the compression ratio. With some filters (for example, - * LZMA2), fine-tuning the compression options may help - * mitigate this problem significantly (for example, - * match finder with LZMA2). - * - * Decoders don't support LZMA_SYNC_FLUSH. - */ - - LZMA_FULL_FLUSH = 2, - /**< - * \brief Finish encoding of the current Block - * - * All the input data going to the current Block must have - * been given to the encoder (the last bytes can still be - * pending in *next_in). Call lzma_code() with LZMA_FULL_FLUSH - * until it returns LZMA_STREAM_END. Then continue normally - * with LZMA_RUN or finish the Stream with LZMA_FINISH. - * - * This action is currently supported only by Stream encoder - * and easy encoder (which uses Stream encoder). If there is - * no unfinished Block, no empty Block is created. - */ - - LZMA_FULL_BARRIER = 4, - /**< - * \brief Finish encoding of the current Block - * - * This is like LZMA_FULL_FLUSH except that this doesn't - * necessarily wait until all the input has been made - * available via the output buffer. That is, lzma_code() - * might return LZMA_STREAM_END as soon as all the input - * has been consumed (avail_in == 0). - * - * LZMA_FULL_BARRIER is useful with a threaded encoder if - * one wants to split the .xz Stream into Blocks at specific - * offsets but doesn't care if the output isn't flushed - * immediately. Using LZMA_FULL_BARRIER allows keeping - * the threads busy while LZMA_FULL_FLUSH would make - * lzma_code() wait until all the threads have finished - * until more data could be passed to the encoder. - * - * With a lzma_stream initialized with the single-threaded - * lzma_stream_encoder() or lzma_easy_encoder(), - * LZMA_FULL_BARRIER is an alias for LZMA_FULL_FLUSH. - */ - - LZMA_FINISH = 3 - /**< - * \brief Finish the coding operation - * - * All the input data must have been given to the encoder - * (the last bytes can still be pending in next_in). - * Call lzma_code() with LZMA_FINISH until it returns - * LZMA_STREAM_END. Once LZMA_FINISH has been used, - * the amount of input must no longer be changed by - * the application. - * - * When decoding, using LZMA_FINISH is optional unless the - * LZMA_CONCATENATED flag was used when the decoder was - * initialized. When LZMA_CONCATENATED was not used, the only - * effect of LZMA_FINISH is that the amount of input must not - * be changed just like in the encoder. - */ + LZMA_RUN = 0, + /**< + * \brief Continue coding + * + * Encoder: Encode as much input as possible. Some internal + * buffering will probably be done (depends on the filter + * chain in use), which causes latency: the input used won't + * usually be decodeable from the output of the same + * lzma_code() call. + * + * Decoder: Decode as much input as possible and produce as + * much output as possible. + */ + + LZMA_SYNC_FLUSH = 1, + /**< + * \brief Make all the input available at output + * + * Normally the encoder introduces some latency. + * LZMA_SYNC_FLUSH forces all the buffered data to be + * available at output without resetting the internal + * state of the encoder. This way it is possible to use + * compressed stream for example for communication over + * network. + * + * Only some filters support LZMA_SYNC_FLUSH. Trying to use + * LZMA_SYNC_FLUSH with filters that don't support it will + * make lzma_code() return LZMA_OPTIONS_ERROR. For example, + * LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does. + * + * Using LZMA_SYNC_FLUSH very often can dramatically reduce + * the compression ratio. With some filters (for example, + * LZMA2), fine-tuning the compression options may help + * mitigate this problem significantly (for example, + * match finder with LZMA2). + * + * Decoders don't support LZMA_SYNC_FLUSH. + */ + + LZMA_FULL_FLUSH = 2, + /**< + * \brief Finish encoding of the current Block + * + * All the input data going to the current Block must have + * been given to the encoder (the last bytes can still be + * pending in *next_in). Call lzma_code() with LZMA_FULL_FLUSH + * until it returns LZMA_STREAM_END. Then continue normally + * with LZMA_RUN or finish the Stream with LZMA_FINISH. + * + * This action is currently supported only by Stream encoder + * and easy encoder (which uses Stream encoder). If there is + * no unfinished Block, no empty Block is created. + */ + + LZMA_FULL_BARRIER = 4, + /**< + * \brief Finish encoding of the current Block + * + * This is like LZMA_FULL_FLUSH except that this doesn't + * necessarily wait until all the input has been made + * available via the output buffer. That is, lzma_code() + * might return LZMA_STREAM_END as soon as all the input + * has been consumed (avail_in == 0). + * + * LZMA_FULL_BARRIER is useful with a threaded encoder if + * one wants to split the .xz Stream into Blocks at specific + * offsets but doesn't care if the output isn't flushed + * immediately. Using LZMA_FULL_BARRIER allows keeping + * the threads busy while LZMA_FULL_FLUSH would make + * lzma_code() wait until all the threads have finished + * until more data could be passed to the encoder. + * + * With a lzma_stream initialized with the single-threaded + * lzma_stream_encoder() or lzma_easy_encoder(), + * LZMA_FULL_BARRIER is an alias for LZMA_FULL_FLUSH. + */ + + LZMA_FINISH = 3 + /**< + * \brief Finish the coding operation + * + * All the input data must have been given to the encoder + * (the last bytes can still be pending in next_in). + * Call lzma_code() with LZMA_FINISH until it returns + * LZMA_STREAM_END. Once LZMA_FINISH has been used, + * the amount of input must no longer be changed by + * the application. + * + * When decoding, using LZMA_FINISH is optional unless the + * LZMA_CONCATENATED flag was used when the decoder was + * initialized. When LZMA_CONCATENATED was not used, the only + * effect of LZMA_FINISH is that the amount of input must not + * be changed just like in the encoder. + */ } lzma_action; - /** * \brief Custom functions for memory handling * @@ -370,70 +363,69 @@ typedef enum { * thus they must be thread safe. */ typedef struct { - /** - * \brief Pointer to a custom memory allocation function - * - * If you don't want a custom allocator, but still want - * custom free(), set this to NULL and liblzma will use - * the standard malloc(). - * - * \param opaque lzma_allocator.opaque (see below) - * \param nmemb Number of elements like in calloc(). liblzma - * will always set nmemb to 1, so it is safe to - * ignore nmemb in a custom allocator if you like. - * The nmemb argument exists only for - * compatibility with zlib and libbzip2. - * \param size Size of an element in bytes. - * liblzma never sets this to zero. - * - * \return Pointer to the beginning of a memory block of - * `size' bytes, or NULL if allocation fails - * for some reason. When allocation fails, functions - * of liblzma return LZMA_MEM_ERROR. - * - * The allocator should not waste time zeroing the allocated buffers. - * This is not only about speed, but also memory usage, since the - * operating system kernel doesn't necessarily allocate the requested - * memory in physical memory until it is actually used. With small - * input files, liblzma may actually need only a fraction of the - * memory that it requested for allocation. - * - * \note LZMA_MEM_ERROR is also used when the size of the - * allocation would be greater than SIZE_MAX. Thus, - * don't assume that the custom allocator must have - * returned NULL if some function from liblzma - * returns LZMA_MEM_ERROR. - */ - void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size); - - /** - * \brief Pointer to a custom memory freeing function - * - * If you don't want a custom freeing function, but still - * want a custom allocator, set this to NULL and liblzma - * will use the standard free(). - * - * \param opaque lzma_allocator.opaque (see below) - * \param ptr Pointer returned by lzma_allocator.alloc(), - * or when it is set to NULL, a pointer returned - * by the standard malloc(). - */ - void (LZMA_API_CALL *free)(void *opaque, void *ptr); - - /** - * \brief Pointer passed to .alloc() and .free() - * - * opaque is passed as the first argument to lzma_allocator.alloc() - * and lzma_allocator.free(). This intended to ease implementing - * custom memory allocation functions for use with liblzma. - * - * If you don't need this, you should set this to NULL. - */ - void *opaque; + /** + * \brief Pointer to a custom memory allocation function + * + * If you don't want a custom allocator, but still want + * custom free(), set this to NULL and liblzma will use + * the standard malloc(). + * + * \param opaque lzma_allocator.opaque (see below) + * \param nmemb Number of elements like in calloc(). liblzma + * will always set nmemb to 1, so it is safe to + * ignore nmemb in a custom allocator if you like. + * The nmemb argument exists only for + * compatibility with zlib and libbzip2. + * \param size Size of an element in bytes. + * liblzma never sets this to zero. + * + * \return Pointer to the beginning of a memory block of + * `size' bytes, or NULL if allocation fails + * for some reason. When allocation fails, functions + * of liblzma return LZMA_MEM_ERROR. + * + * The allocator should not waste time zeroing the allocated buffers. + * This is not only about speed, but also memory usage, since the + * operating system kernel doesn't necessarily allocate the requested + * memory in physical memory until it is actually used. With small + * input files, liblzma may actually need only a fraction of the + * memory that it requested for allocation. + * + * \note LZMA_MEM_ERROR is also used when the size of the + * allocation would be greater than SIZE_MAX. Thus, + * don't assume that the custom allocator must have + * returned NULL if some function from liblzma + * returns LZMA_MEM_ERROR. + */ + void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size); + + /** + * \brief Pointer to a custom memory freeing function + * + * If you don't want a custom freeing function, but still + * want a custom allocator, set this to NULL and liblzma + * will use the standard free(). + * + * \param opaque lzma_allocator.opaque (see below) + * \param ptr Pointer returned by lzma_allocator.alloc(), + * or when it is set to NULL, a pointer returned + * by the standard malloc(). + */ + void(LZMA_API_CALL *free)(void *opaque, void *ptr); + + /** + * \brief Pointer passed to .alloc() and .free() + * + * opaque is passed as the first argument to lzma_allocator.alloc() + * and lzma_allocator.free(). This intended to ease implementing + * custom memory allocation functions for use with liblzma. + * + * If you don't need this, you should set this to NULL. + */ + void *opaque; } lzma_allocator; - /** * \brief Internal data structure * @@ -441,7 +433,6 @@ typedef struct { */ typedef struct lzma_internal_s lzma_internal; - /** * \brief Passing data to and from liblzma * @@ -483,47 +474,46 @@ typedef struct lzma_internal_s lzma_internal; * values from lzma_get_progress(). */ typedef struct { - const uint8_t *next_in; /**< Pointer to the next input byte. */ - size_t avail_in; /**< Number of available input bytes in next_in. */ - uint64_t total_in; /**< Total number of bytes read by liblzma. */ - - uint8_t *next_out; /**< Pointer to the next output position. */ - size_t avail_out; /**< Amount of free space in next_out. */ - uint64_t total_out; /**< Total number of bytes written by liblzma. */ - - /** - * \brief Custom memory allocation functions - * - * In most cases this is NULL which makes liblzma use - * the standard malloc() and free(). - * - * \note In 5.0.x this is not a const pointer. - */ - const lzma_allocator *allocator; - - /** Internal state is not visible to applications. */ - lzma_internal *internal; - - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. Excluding the initialization of this structure, - * you should not touch these, because the names of these variables - * may change. - */ - void *reserved_ptr1; - void *reserved_ptr2; - void *reserved_ptr3; - void *reserved_ptr4; - uint64_t reserved_int1; - uint64_t reserved_int2; - size_t reserved_int3; - size_t reserved_int4; - lzma_reserved_enum reserved_enum1; - lzma_reserved_enum reserved_enum2; + const uint8_t *next_in; /**< Pointer to the next input byte. */ + size_t avail_in; /**< Number of available input bytes in next_in. */ + uint64_t total_in; /**< Total number of bytes read by liblzma. */ + + uint8_t *next_out; /**< Pointer to the next output position. */ + size_t avail_out; /**< Amount of free space in next_out. */ + uint64_t total_out; /**< Total number of bytes written by liblzma. */ + + /** + * \brief Custom memory allocation functions + * + * In most cases this is NULL which makes liblzma use + * the standard malloc() and free(). + * + * \note In 5.0.x this is not a const pointer. + */ + const lzma_allocator *allocator; + + /** Internal state is not visible to applications. */ + lzma_internal *internal; + + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. Excluding the initialization of this structure, + * you should not touch these, because the names of these variables + * may change. + */ + void *reserved_ptr1; + void *reserved_ptr2; + void *reserved_ptr3; + void *reserved_ptr4; + uint64_t reserved_int1; + uint64_t reserved_int2; + size_t reserved_int3; + size_t reserved_int4; + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; } lzma_stream; - /** * \brief Initialization for lzma_stream * @@ -542,11 +532,11 @@ typedef struct { * lzma_stream tmp = LZMA_STREAM_INIT; * *strm = tmp; */ -#define LZMA_STREAM_INIT \ - { NULL, 0, 0, NULL, 0, 0, NULL, NULL, \ - NULL, NULL, NULL, NULL, 0, 0, 0, 0, \ - LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM } - +#define LZMA_STREAM_INIT \ + { \ + NULL, 0, 0, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, \ + LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM \ + } /** * \brief Encode or decode data @@ -560,9 +550,9 @@ typedef struct { * See the description of the coder-specific initialization function to find * out what `action' values are supported by the coder. */ -extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_code(lzma_stream *strm, + lzma_action action) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Free memory allocated for the coder data structures @@ -579,7 +569,6 @@ extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action) */ extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow; - /** * \brief Get progress information * @@ -595,9 +584,9 @@ extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow; * single-threaded mode *progress_in and *progress_out are set to * strm->total_in and strm->total_out, respectively. */ -extern LZMA_API(void) lzma_get_progress(lzma_stream *strm, - uint64_t *progress_in, uint64_t *progress_out) lzma_nothrow; - +extern LZMA_API(void) + lzma_get_progress(lzma_stream *strm, uint64_t *progress_in, + uint64_t *progress_out) lzma_nothrow; /** * \brief Get the memory usage of decoder filter chain @@ -621,9 +610,8 @@ extern LZMA_API(void) lzma_get_progress(lzma_stream *strm, * If this function isn't supported by *strm or some other error * occurs, zero is returned. */ -extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint64_t) + lzma_memusage(const lzma_stream *strm) lzma_nothrow lzma_attr_pure; /** * \brief Get the current memory usage limit @@ -634,9 +622,8 @@ extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm) * \return On success, the current memory usage limit is returned * (always non-zero). On error, zero is returned. */ -extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint64_t) + lzma_memlimit_get(const lzma_stream *strm) lzma_nothrow lzma_attr_pure; /** * \brief Set the memory usage limit @@ -650,5 +637,5 @@ extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm) * - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't * support memory usage limit or memlimit was zero. */ -extern LZMA_API(lzma_ret) lzma_memlimit_set( - lzma_stream *strm, uint64_t memlimit) lzma_nothrow; +extern LZMA_API(lzma_ret) + lzma_memlimit_set(lzma_stream *strm, uint64_t memlimit) lzma_nothrow; diff --git a/node_modules/lzma-native/deps/include/lzma/bcj.h b/node_modules/lzma-native/deps/include/lzma/bcj.h index afb0098..6c68eb8 100644 --- a/node_modules/lzma-native/deps/include/lzma/bcj.h +++ b/node_modules/lzma-native/deps/include/lzma/bcj.h @@ -13,42 +13,40 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /* Filter IDs for lzma_filter.id */ -#define LZMA_FILTER_X86 LZMA_VLI_C(0x04) - /**< - * Filter for x86 binaries - */ - -#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05) - /**< - * Filter for Big endian PowerPC binaries - */ +#define LZMA_FILTER_X86 LZMA_VLI_C(0x04) +/**< + * Filter for x86 binaries + */ -#define LZMA_FILTER_IA64 LZMA_VLI_C(0x06) - /**< - * Filter for IA-64 (Itanium) binaries. - */ +#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05) +/**< + * Filter for Big endian PowerPC binaries + */ -#define LZMA_FILTER_ARM LZMA_VLI_C(0x07) - /**< - * Filter for ARM binaries. - */ +#define LZMA_FILTER_IA64 LZMA_VLI_C(0x06) +/**< + * Filter for IA-64 (Itanium) binaries. + */ -#define LZMA_FILTER_ARMTHUMB LZMA_VLI_C(0x08) - /**< - * Filter for ARM-Thumb binaries. - */ +#define LZMA_FILTER_ARM LZMA_VLI_C(0x07) +/**< + * Filter for ARM binaries. + */ -#define LZMA_FILTER_SPARC LZMA_VLI_C(0x09) - /**< - * Filter for SPARC binaries. - */ +#define LZMA_FILTER_ARMTHUMB LZMA_VLI_C(0x08) +/**< + * Filter for ARM-Thumb binaries. + */ +#define LZMA_FILTER_SPARC LZMA_VLI_C(0x09) +/**< + * Filter for SPARC binaries. + */ /** * \brief Options for BCJ filters @@ -71,20 +69,20 @@ * LZMA_SYNC_FLUSH predictably. */ typedef struct { - /** - * \brief Start offset for conversions - * - * This setting is useful only when the same filter is used - * _separately_ for multiple sections of the same executable file, - * and the sections contain cross-section branch/call/jump - * instructions. In that case it is beneficial to set the start - * offset of the non-first sections so that the relative addresses - * of the cross-section branch/call/jump instructions will use the - * same absolute addresses as in the first section. - * - * When the pointer to options is NULL, the default value (zero) - * is used. - */ - uint32_t start_offset; + /** + * \brief Start offset for conversions + * + * This setting is useful only when the same filter is used + * _separately_ for multiple sections of the same executable file, + * and the sections contain cross-section branch/call/jump + * instructions. In that case it is beneficial to set the start + * offset of the non-first sections so that the relative addresses + * of the cross-section branch/call/jump instructions will use the + * same absolute addresses as in the first section. + * + * When the pointer to options is NULL, the default value (zero) + * is used. + */ + uint32_t start_offset; } lzma_options_bcj; diff --git a/node_modules/lzma-native/deps/include/lzma/block.h b/node_modules/lzma-native/deps/include/lzma/block.h index 5f39b3e..5841956 100644 --- a/node_modules/lzma-native/deps/include/lzma/block.h +++ b/node_modules/lzma-native/deps/include/lzma/block.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Options for the Block and Block Header encoders and decoders * @@ -28,249 +27,248 @@ * later calls to lzma_code(). */ typedef struct { - /** - * \brief Block format version - * - * To prevent API and ABI breakages when new features are needed, - * a version number is used to indicate which fields in this - * structure are in use: - * - liblzma >= 5.0.0: version = 0 is supported. - * - liblzma >= 5.1.4beta: Support for version = 1 was added, - * which adds the ignore_check field. - * - * If version is greater than one, most Block related functions - * will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works - * with any version value). - * - * Read by: - * - All functions that take pointer to lzma_block as argument, - * including lzma_block_header_decode(). - * - * Written by: - * - lzma_block_header_decode() - */ - uint32_t version; - - /** - * \brief Size of the Block Header field - * - * This is always a multiple of four. - * - * Read by: - * - lzma_block_header_encode() - * - lzma_block_header_decode() - * - lzma_block_compressed_size() - * - lzma_block_unpadded_size() - * - lzma_block_total_size() - * - lzma_block_decoder() - * - lzma_block_buffer_decode() - * - * Written by: - * - lzma_block_header_size() - * - lzma_block_buffer_encode() - */ - uint32_t header_size; -# define LZMA_BLOCK_HEADER_SIZE_MIN 8 -# define LZMA_BLOCK_HEADER_SIZE_MAX 1024 - - /** - * \brief Type of integrity Check - * - * The Check ID is not stored into the Block Header, thus its value - * must be provided also when decoding. - * - * Read by: - * - lzma_block_header_encode() - * - lzma_block_header_decode() - * - lzma_block_compressed_size() - * - lzma_block_unpadded_size() - * - lzma_block_total_size() - * - lzma_block_encoder() - * - lzma_block_decoder() - * - lzma_block_buffer_encode() - * - lzma_block_buffer_decode() - */ - lzma_check check; - - /** - * \brief Size of the Compressed Data in bytes - * - * Encoding: If this is not LZMA_VLI_UNKNOWN, Block Header encoder - * will store this value to the Block Header. Block encoder doesn't - * care about this value, but will set it once the encoding has been - * finished. - * - * Decoding: If this is not LZMA_VLI_UNKNOWN, Block decoder will - * verify that the size of the Compressed Data field matches - * compressed_size. - * - * Usually you don't know this value when encoding in streamed mode, - * and thus cannot write this field into the Block Header. - * - * In non-streamed mode you can reserve space for this field before - * encoding the actual Block. After encoding the data, finish the - * Block by encoding the Block Header. Steps in detail: - * - * - Set compressed_size to some big enough value. If you don't know - * better, use LZMA_VLI_MAX, but remember that bigger values take - * more space in Block Header. - * - * - Call lzma_block_header_size() to see how much space you need to - * reserve for the Block Header. - * - * - Encode the Block using lzma_block_encoder() and lzma_code(). - * It sets compressed_size to the correct value. - * - * - Use lzma_block_header_encode() to encode the Block Header. - * Because space was reserved in the first step, you don't need - * to call lzma_block_header_size() anymore, because due to - * reserving, header_size has to be big enough. If it is "too big", - * lzma_block_header_encode() will add enough Header Padding to - * make Block Header to match the size specified by header_size. - * - * Read by: - * - lzma_block_header_size() - * - lzma_block_header_encode() - * - lzma_block_compressed_size() - * - lzma_block_unpadded_size() - * - lzma_block_total_size() - * - lzma_block_decoder() - * - lzma_block_buffer_decode() - * - * Written by: - * - lzma_block_header_decode() - * - lzma_block_compressed_size() - * - lzma_block_encoder() - * - lzma_block_decoder() - * - lzma_block_buffer_encode() - * - lzma_block_buffer_decode() - */ - lzma_vli compressed_size; - - /** - * \brief Uncompressed Size in bytes - * - * This is handled very similarly to compressed_size above. - * - * uncompressed_size is needed by fewer functions than - * compressed_size. This is because uncompressed_size isn't - * needed to validate that Block stays within proper limits. - * - * Read by: - * - lzma_block_header_size() - * - lzma_block_header_encode() - * - lzma_block_decoder() - * - lzma_block_buffer_decode() - * - * Written by: - * - lzma_block_header_decode() - * - lzma_block_encoder() - * - lzma_block_decoder() - * - lzma_block_buffer_encode() - * - lzma_block_buffer_decode() - */ - lzma_vli uncompressed_size; - - /** - * \brief Array of filters - * - * There can be 1-4 filters. The end of the array is marked with - * .id = LZMA_VLI_UNKNOWN. - * - * Read by: - * - lzma_block_header_size() - * - lzma_block_header_encode() - * - lzma_block_encoder() - * - lzma_block_decoder() - * - lzma_block_buffer_encode() - * - lzma_block_buffer_decode() - * - * Written by: - * - lzma_block_header_decode(): Note that this does NOT free() - * the old filter options structures. All unused filters[] will - * have .id == LZMA_VLI_UNKNOWN and .options == NULL. If - * decoding fails, all filters[] are guaranteed to be - * LZMA_VLI_UNKNOWN and NULL. - * - * \note Because of the array is terminated with - * .id = LZMA_VLI_UNKNOWN, the actual array must - * have LZMA_FILTERS_MAX + 1 members or the Block - * Header decoder will overflow the buffer. - */ - lzma_filter *filters; - - /** - * \brief Raw value stored in the Check field - * - * After successful coding, the first lzma_check_size(check) bytes - * of this array contain the raw value stored in the Check field. - * - * Note that CRC32 and CRC64 are stored in little endian byte order. - * Take it into account if you display the Check values to the user. - * - * Written by: - * - lzma_block_encoder() - * - lzma_block_decoder() - * - lzma_block_buffer_encode() - * - lzma_block_buffer_decode() - */ - uint8_t raw_check[LZMA_CHECK_SIZE_MAX]; - - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. You should not touch these, because the names - * of these variables may change. These are and will never be used - * with the currently supported options, so it is safe to leave these - * uninitialized. - */ - void *reserved_ptr1; - void *reserved_ptr2; - void *reserved_ptr3; - uint32_t reserved_int1; - uint32_t reserved_int2; - lzma_vli reserved_int3; - lzma_vli reserved_int4; - lzma_vli reserved_int5; - lzma_vli reserved_int6; - lzma_vli reserved_int7; - lzma_vli reserved_int8; - lzma_reserved_enum reserved_enum1; - lzma_reserved_enum reserved_enum2; - lzma_reserved_enum reserved_enum3; - lzma_reserved_enum reserved_enum4; - - /** - * \brief A flag to Block decoder to not verify the Check field - * - * This field is supported by liblzma >= 5.1.4beta if .version >= 1. - * - * If this is set to true, the integrity check won't be calculated - * and verified. Unless you know what you are doing, you should - * leave this to false. (A reason to set this to true is when the - * file integrity is verified externally anyway and you want to - * speed up the decompression, which matters mostly when using - * SHA-256 as the integrity check.) - * - * If .version >= 1, read by: - * - lzma_block_decoder() - * - lzma_block_buffer_decode() - * - * Written by (.version is ignored): - * - lzma_block_header_decode() always sets this to false - */ - lzma_bool ignore_check; - - lzma_bool reserved_bool2; - lzma_bool reserved_bool3; - lzma_bool reserved_bool4; - lzma_bool reserved_bool5; - lzma_bool reserved_bool6; - lzma_bool reserved_bool7; - lzma_bool reserved_bool8; + /** + * \brief Block format version + * + * To prevent API and ABI breakages when new features are needed, + * a version number is used to indicate which fields in this + * structure are in use: + * - liblzma >= 5.0.0: version = 0 is supported. + * - liblzma >= 5.1.4beta: Support for version = 1 was added, + * which adds the ignore_check field. + * + * If version is greater than one, most Block related functions + * will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works + * with any version value). + * + * Read by: + * - All functions that take pointer to lzma_block as argument, + * including lzma_block_header_decode(). + * + * Written by: + * - lzma_block_header_decode() + */ + uint32_t version; + + /** + * \brief Size of the Block Header field + * + * This is always a multiple of four. + * + * Read by: + * - lzma_block_header_encode() + * - lzma_block_header_decode() + * - lzma_block_compressed_size() + * - lzma_block_unpadded_size() + * - lzma_block_total_size() + * - lzma_block_decoder() + * - lzma_block_buffer_decode() + * + * Written by: + * - lzma_block_header_size() + * - lzma_block_buffer_encode() + */ + uint32_t header_size; +#define LZMA_BLOCK_HEADER_SIZE_MIN 8 +#define LZMA_BLOCK_HEADER_SIZE_MAX 1024 + + /** + * \brief Type of integrity Check + * + * The Check ID is not stored into the Block Header, thus its value + * must be provided also when decoding. + * + * Read by: + * - lzma_block_header_encode() + * - lzma_block_header_decode() + * - lzma_block_compressed_size() + * - lzma_block_unpadded_size() + * - lzma_block_total_size() + * - lzma_block_encoder() + * - lzma_block_decoder() + * - lzma_block_buffer_encode() + * - lzma_block_buffer_decode() + */ + lzma_check check; + + /** + * \brief Size of the Compressed Data in bytes + * + * Encoding: If this is not LZMA_VLI_UNKNOWN, Block Header encoder + * will store this value to the Block Header. Block encoder doesn't + * care about this value, but will set it once the encoding has been + * finished. + * + * Decoding: If this is not LZMA_VLI_UNKNOWN, Block decoder will + * verify that the size of the Compressed Data field matches + * compressed_size. + * + * Usually you don't know this value when encoding in streamed mode, + * and thus cannot write this field into the Block Header. + * + * In non-streamed mode you can reserve space for this field before + * encoding the actual Block. After encoding the data, finish the + * Block by encoding the Block Header. Steps in detail: + * + * - Set compressed_size to some big enough value. If you don't know + * better, use LZMA_VLI_MAX, but remember that bigger values take + * more space in Block Header. + * + * - Call lzma_block_header_size() to see how much space you need to + * reserve for the Block Header. + * + * - Encode the Block using lzma_block_encoder() and lzma_code(). + * It sets compressed_size to the correct value. + * + * - Use lzma_block_header_encode() to encode the Block Header. + * Because space was reserved in the first step, you don't need + * to call lzma_block_header_size() anymore, because due to + * reserving, header_size has to be big enough. If it is "too big", + * lzma_block_header_encode() will add enough Header Padding to + * make Block Header to match the size specified by header_size. + * + * Read by: + * - lzma_block_header_size() + * - lzma_block_header_encode() + * - lzma_block_compressed_size() + * - lzma_block_unpadded_size() + * - lzma_block_total_size() + * - lzma_block_decoder() + * - lzma_block_buffer_decode() + * + * Written by: + * - lzma_block_header_decode() + * - lzma_block_compressed_size() + * - lzma_block_encoder() + * - lzma_block_decoder() + * - lzma_block_buffer_encode() + * - lzma_block_buffer_decode() + */ + lzma_vli compressed_size; + + /** + * \brief Uncompressed Size in bytes + * + * This is handled very similarly to compressed_size above. + * + * uncompressed_size is needed by fewer functions than + * compressed_size. This is because uncompressed_size isn't + * needed to validate that Block stays within proper limits. + * + * Read by: + * - lzma_block_header_size() + * - lzma_block_header_encode() + * - lzma_block_decoder() + * - lzma_block_buffer_decode() + * + * Written by: + * - lzma_block_header_decode() + * - lzma_block_encoder() + * - lzma_block_decoder() + * - lzma_block_buffer_encode() + * - lzma_block_buffer_decode() + */ + lzma_vli uncompressed_size; + + /** + * \brief Array of filters + * + * There can be 1-4 filters. The end of the array is marked with + * .id = LZMA_VLI_UNKNOWN. + * + * Read by: + * - lzma_block_header_size() + * - lzma_block_header_encode() + * - lzma_block_encoder() + * - lzma_block_decoder() + * - lzma_block_buffer_encode() + * - lzma_block_buffer_decode() + * + * Written by: + * - lzma_block_header_decode(): Note that this does NOT free() + * the old filter options structures. All unused filters[] will + * have .id == LZMA_VLI_UNKNOWN and .options == NULL. If + * decoding fails, all filters[] are guaranteed to be + * LZMA_VLI_UNKNOWN and NULL. + * + * \note Because of the array is terminated with + * .id = LZMA_VLI_UNKNOWN, the actual array must + * have LZMA_FILTERS_MAX + 1 members or the Block + * Header decoder will overflow the buffer. + */ + lzma_filter *filters; + + /** + * \brief Raw value stored in the Check field + * + * After successful coding, the first lzma_check_size(check) bytes + * of this array contain the raw value stored in the Check field. + * + * Note that CRC32 and CRC64 are stored in little endian byte order. + * Take it into account if you display the Check values to the user. + * + * Written by: + * - lzma_block_encoder() + * - lzma_block_decoder() + * - lzma_block_buffer_encode() + * - lzma_block_buffer_decode() + */ + uint8_t raw_check[LZMA_CHECK_SIZE_MAX]; + + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. You should not touch these, because the names + * of these variables may change. These are and will never be used + * with the currently supported options, so it is safe to leave these + * uninitialized. + */ + void *reserved_ptr1; + void *reserved_ptr2; + void *reserved_ptr3; + uint32_t reserved_int1; + uint32_t reserved_int2; + lzma_vli reserved_int3; + lzma_vli reserved_int4; + lzma_vli reserved_int5; + lzma_vli reserved_int6; + lzma_vli reserved_int7; + lzma_vli reserved_int8; + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; + lzma_reserved_enum reserved_enum3; + lzma_reserved_enum reserved_enum4; + + /** + * \brief A flag to Block decoder to not verify the Check field + * + * This field is supported by liblzma >= 5.1.4beta if .version >= 1. + * + * If this is set to true, the integrity check won't be calculated + * and verified. Unless you know what you are doing, you should + * leave this to false. (A reason to set this to true is when the + * file integrity is verified externally anyway and you want to + * speed up the decompression, which matters mostly when using + * SHA-256 as the integrity check.) + * + * If .version >= 1, read by: + * - lzma_block_decoder() + * - lzma_block_buffer_decode() + * + * Written by (.version is ignored): + * - lzma_block_header_decode() always sets this to false + */ + lzma_bool ignore_check; + + lzma_bool reserved_bool2; + lzma_bool reserved_bool3; + lzma_bool reserved_bool4; + lzma_bool reserved_bool5; + lzma_bool reserved_bool6; + lzma_bool reserved_bool7; + lzma_bool reserved_bool8; } lzma_block; - /** * \brief Decode the Block Header Size field * @@ -284,7 +282,6 @@ typedef struct { */ #define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4) - /** * \brief Calculate Block Header Size * @@ -307,8 +304,7 @@ typedef struct { * a side-effect validates the filter chain. */ extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block) - lzma_nothrow lzma_attr_warn_unused_result; - + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Encode Block Header @@ -328,10 +324,9 @@ extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block) * - LZMA_PROG_ERROR: Invalid arguments, for example * block->header_size is invalid or block->filters is NULL. */ -extern LZMA_API(lzma_ret) lzma_block_header_encode( - const lzma_block *block, uint8_t *out) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_block_header_encode(const lzma_block *block, uint8_t *out) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Decode Block Header @@ -373,10 +368,9 @@ extern LZMA_API(lzma_ret) lzma_block_header_encode( * - LZMA_PROG_ERROR: Invalid arguments, for example * block->header_size is invalid or block->filters is NULL. */ -extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block, - const lzma_allocator *allocator, const uint8_t *in) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) lzma_block_header_decode( + lzma_block *block, const lzma_allocator *allocator, + const uint8_t *in) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Validate and set Compressed Size according to Unpadded Size @@ -405,10 +399,9 @@ extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block, * block->header_size must be a multiple of four and * between 8 and 1024 inclusive. */ -extern LZMA_API(lzma_ret) lzma_block_compressed_size( - lzma_block *block, lzma_vli unpadded_size) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Calculate Unpadded Size @@ -422,8 +415,7 @@ extern LZMA_API(lzma_ret) lzma_block_compressed_size( * \return Unpadded Size on success, or zero on error. */ extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block) - lzma_nothrow lzma_attr_pure; - + lzma_nothrow lzma_attr_pure; /** * \brief Calculate the total encoded size of a Block @@ -434,9 +426,8 @@ extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block) * \return On success, total encoded size of the Block. On error, * zero is returned. */ -extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_block_total_size(const lzma_block *block) lzma_nothrow lzma_attr_pure; /** * \brief Initialize .xz Block encoder @@ -452,10 +443,9 @@ extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block) * the encoder failed. * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_block_encoder( - lzma_stream *strm, lzma_block *block) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_block_encoder(lzma_stream *strm, lzma_block *block) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Initialize .xz Block decoder @@ -470,10 +460,9 @@ extern LZMA_API(lzma_ret) lzma_block_encoder( * - LZMA_PROG_ERROR * - LZMA_MEM_ERROR */ -extern LZMA_API(lzma_ret) lzma_block_decoder( - lzma_stream *strm, lzma_block *block) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_block_decoder(lzma_stream *strm, lzma_block *block) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Calculate maximum output size for single-call Block encoding @@ -481,9 +470,8 @@ extern LZMA_API(lzma_ret) lzma_block_decoder( * This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks. * See the documentation of lzma_stream_buffer_bound(). */ -extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size) - lzma_nothrow; - +extern LZMA_API(size_t) + lzma_block_buffer_bound(size_t uncompressed_size) lzma_nothrow; /** * \brief Single-call .xz Block encoder @@ -523,11 +511,9 @@ extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size) * - LZMA_PROG_ERROR */ extern LZMA_API(lzma_ret) lzma_block_buffer_encode( - lzma_block *block, const lzma_allocator *allocator, - const uint8_t *in, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) - lzma_nothrow lzma_attr_warn_unused_result; - + lzma_block *block, const lzma_allocator *allocator, const uint8_t *in, + size_t in_size, uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Single-call uncompressed .xz Block encoder @@ -541,11 +527,9 @@ extern LZMA_API(lzma_ret) lzma_block_buffer_encode( * This function doesn't take lzma_allocator because this function doesn't * allocate any memory from the heap. */ -extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block, - const uint8_t *in, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) lzma_block_uncomp_encode( + lzma_block *block, const uint8_t *in, size_t in_size, uint8_t *out, + size_t *out_pos, size_t out_size) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Single-call .xz Block decoder @@ -574,8 +558,8 @@ extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block, * - LZMA_BUF_ERROR: Output buffer was too small. * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_block_buffer_decode( - lzma_block *block, const lzma_allocator *allocator, - const uint8_t *in, size_t *in_pos, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) - lzma_nothrow; +extern LZMA_API(lzma_ret) + lzma_block_buffer_decode(lzma_block *block, const lzma_allocator *allocator, + const uint8_t *in, size_t *in_pos, size_t in_size, + uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow; diff --git a/node_modules/lzma-native/deps/include/lzma/check.h b/node_modules/lzma-native/deps/include/lzma/check.h index 1fdd56d..59317a1 100644 --- a/node_modules/lzma-native/deps/include/lzma/check.h +++ b/node_modules/lzma-native/deps/include/lzma/check.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Type of the integrity check (Check ID) * @@ -25,36 +24,35 @@ * detect errors. */ typedef enum { - LZMA_CHECK_NONE = 0, - /**< - * No Check is calculated. - * - * Size of the Check field: 0 bytes - */ - - LZMA_CHECK_CRC32 = 1, - /**< - * CRC32 using the polynomial from the IEEE 802.3 standard - * - * Size of the Check field: 4 bytes - */ - - LZMA_CHECK_CRC64 = 4, - /**< - * CRC64 using the polynomial from the ECMA-182 standard - * - * Size of the Check field: 8 bytes - */ - - LZMA_CHECK_SHA256 = 10 - /**< - * SHA-256 - * - * Size of the Check field: 32 bytes - */ + LZMA_CHECK_NONE = 0, + /**< + * No Check is calculated. + * + * Size of the Check field: 0 bytes + */ + + LZMA_CHECK_CRC32 = 1, + /**< + * CRC32 using the polynomial from the IEEE 802.3 standard + * + * Size of the Check field: 4 bytes + */ + + LZMA_CHECK_CRC64 = 4, + /**< + * CRC64 using the polynomial from the ECMA-182 standard + * + * Size of the Check field: 8 bytes + */ + + LZMA_CHECK_SHA256 = 10 + /**< + * SHA-256 + * + * Size of the Check field: 32 bytes + */ } lzma_check; - /** * \brief Maximum valid Check ID * @@ -67,7 +65,6 @@ typedef enum { */ #define LZMA_CHECK_ID_MAX 15 - /** * \brief Test if the given Check ID is supported * @@ -78,9 +75,8 @@ typedef enum { * You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always * supported (even if liblzma is built with limited features). */ -extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check) - lzma_nothrow lzma_attr_const; - +extern LZMA_API(lzma_bool) + lzma_check_is_supported(lzma_check check) lzma_nothrow lzma_attr_const; /** * \brief Get the size of the Check field with the given Check ID @@ -92,16 +88,14 @@ extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check) * * If the argument is not in the range [0, 15], UINT32_MAX is returned. */ -extern LZMA_API(uint32_t) lzma_check_size(lzma_check check) - lzma_nothrow lzma_attr_const; - +extern LZMA_API(uint32_t) + lzma_check_size(lzma_check check) lzma_nothrow lzma_attr_const; /** * \brief Maximum size of a Check field */ #define LZMA_CHECK_SIZE_MAX 64 - /** * \brief Calculate CRC32 * @@ -116,10 +110,8 @@ extern LZMA_API(uint32_t) lzma_check_size(lzma_check check) * \return Updated CRC value, which can be passed to this function * again to continue CRC calculation. */ -extern LZMA_API(uint32_t) lzma_crc32( - const uint8_t *buf, size_t size, uint32_t crc) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint32_t) lzma_crc32(const uint8_t *buf, size_t size, + uint32_t crc) lzma_nothrow lzma_attr_pure; /** * \brief Calculate CRC64 @@ -128,17 +120,14 @@ extern LZMA_API(uint32_t) lzma_crc32( * * This function is used similarly to lzma_crc32(). See its documentation. */ -extern LZMA_API(uint64_t) lzma_crc64( - const uint8_t *buf, size_t size, uint64_t crc) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint64_t) lzma_crc64(const uint8_t *buf, size_t size, + uint64_t crc) lzma_nothrow lzma_attr_pure; /* * SHA-256 functions are currently not exported to public API. * Contact Lasse Collin if you think it should be. */ - /** * \brief Get the type of the integrity check * @@ -146,5 +135,5 @@ extern LZMA_API(uint64_t) lzma_crc64( * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK. * Calling this function in any other situation has undefined behavior. */ -extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm) - lzma_nothrow; +extern LZMA_API(lzma_check) + lzma_get_check(const lzma_stream *strm) lzma_nothrow; diff --git a/node_modules/lzma-native/deps/include/lzma/container.h b/node_modules/lzma-native/deps/include/lzma/container.h index a4ab998..b469585 100644 --- a/node_modules/lzma-native/deps/include/lzma/container.h +++ b/node_modules/lzma-native/deps/include/lzma/container.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /************ * Encoding * ************/ @@ -28,8 +27,7 @@ * cases keeping the resource usage relatively low is more important that * getting the maximum compression ratio. */ -#define LZMA_PRESET_DEFAULT UINT32_C(6) - +#define LZMA_PRESET_DEFAULT UINT32_C(6) /** * \brief Mask for preset level @@ -37,8 +35,7 @@ * This is useful only if you need to extract the level from the preset * variable. That should be rare. */ -#define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F) - +#define LZMA_PRESET_LEVEL_MASK UINT32_C(0x1F) /* * Preset flags @@ -57,134 +54,132 @@ * least not significantly). The memory usage of the encoder may be increased * a little but only at the lowest preset levels (0-3). */ -#define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) - +#define LZMA_PRESET_EXTREME (UINT32_C(1) << 31) /** * \brief Multithreading options */ typedef struct { - /** - * \brief Flags - * - * Set this to zero if no flags are wanted. - * - * No flags are currently supported. - */ - uint32_t flags; - - /** - * \brief Number of worker threads to use - */ - uint32_t threads; - - /** - * \brief Maximum uncompressed size of a Block - * - * The encoder will start a new .xz Block every block_size bytes. - * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code() - * the caller may tell liblzma to start a new Block earlier. - * - * With LZMA2, a recommended block size is 2-4 times the LZMA2 - * dictionary size. With very small dictionaries, it is recommended - * to use at least 1 MiB block size for good compression ratio, even - * if this is more than four times the dictionary size. Note that - * these are only recommendations for typical use cases; feel free - * to use other values. Just keep in mind that using a block size - * less than the LZMA2 dictionary size is waste of RAM. - * - * Set this to 0 to let liblzma choose the block size depending - * on the compression options. For LZMA2 it will be 3*dict_size - * or 1 MiB, whichever is more. - * - * For each thread, about 3 * block_size bytes of memory will be - * allocated. This may change in later liblzma versions. If so, - * the memory usage will probably be reduced, not increased. - */ - uint64_t block_size; - - /** - * \brief Timeout to allow lzma_code() to return early - * - * Multithreading can make liblzma to consume input and produce - * output in a very bursty way: it may first read a lot of input - * to fill internal buffers, then no input or output occurs for - * a while. - * - * In single-threaded mode, lzma_code() won't return until it has - * either consumed all the input or filled the output buffer. If - * this is done in multithreaded mode, it may cause a call - * lzma_code() to take even tens of seconds, which isn't acceptable - * in all applications. - * - * To avoid very long blocking times in lzma_code(), a timeout - * (in milliseconds) may be set here. If lzma_code() would block - * longer than this number of milliseconds, it will return with - * LZMA_OK. Reasonable values are 100 ms or more. The xz command - * line tool uses 300 ms. - * - * If long blocking times are fine for you, set timeout to a special - * value of 0, which will disable the timeout mechanism and will make - * lzma_code() block until all the input is consumed or the output - * buffer has been filled. - * - * \note Even with a timeout, lzma_code() might sometimes take - * somewhat long time to return. No timing guarantees - * are made. - */ - uint32_t timeout; - - /** - * \brief Compression preset (level and possible flags) - * - * The preset is set just like with lzma_easy_encoder(). - * The preset is ignored if filters below is non-NULL. - */ - uint32_t preset; - - /** - * \brief Filter chain (alternative to a preset) - * - * If this is NULL, the preset above is used. Otherwise the preset - * is ignored and the filter chain specified here is used. - */ - const lzma_filter *filters; - - /** - * \brief Integrity check type - * - * See check.h for available checks. The xz command line tool - * defaults to LZMA_CHECK_CRC64, which is a good choice if you - * are unsure. - */ - lzma_check check; - - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. You should not touch these, because the names - * of these variables may change. These are and will never be used - * with the currently supported options, so it is safe to leave these - * uninitialized. - */ - lzma_reserved_enum reserved_enum1; - lzma_reserved_enum reserved_enum2; - lzma_reserved_enum reserved_enum3; - uint32_t reserved_int1; - uint32_t reserved_int2; - uint32_t reserved_int3; - uint32_t reserved_int4; - uint64_t reserved_int5; - uint64_t reserved_int6; - uint64_t reserved_int7; - uint64_t reserved_int8; - void *reserved_ptr1; - void *reserved_ptr2; - void *reserved_ptr3; - void *reserved_ptr4; + /** + * \brief Flags + * + * Set this to zero if no flags are wanted. + * + * No flags are currently supported. + */ + uint32_t flags; + + /** + * \brief Number of worker threads to use + */ + uint32_t threads; + + /** + * \brief Maximum uncompressed size of a Block + * + * The encoder will start a new .xz Block every block_size bytes. + * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code() + * the caller may tell liblzma to start a new Block earlier. + * + * With LZMA2, a recommended block size is 2-4 times the LZMA2 + * dictionary size. With very small dictionaries, it is recommended + * to use at least 1 MiB block size for good compression ratio, even + * if this is more than four times the dictionary size. Note that + * these are only recommendations for typical use cases; feel free + * to use other values. Just keep in mind that using a block size + * less than the LZMA2 dictionary size is waste of RAM. + * + * Set this to 0 to let liblzma choose the block size depending + * on the compression options. For LZMA2 it will be 3*dict_size + * or 1 MiB, whichever is more. + * + * For each thread, about 3 * block_size bytes of memory will be + * allocated. This may change in later liblzma versions. If so, + * the memory usage will probably be reduced, not increased. + */ + uint64_t block_size; + + /** + * \brief Timeout to allow lzma_code() to return early + * + * Multithreading can make liblzma to consume input and produce + * output in a very bursty way: it may first read a lot of input + * to fill internal buffers, then no input or output occurs for + * a while. + * + * In single-threaded mode, lzma_code() won't return until it has + * either consumed all the input or filled the output buffer. If + * this is done in multithreaded mode, it may cause a call + * lzma_code() to take even tens of seconds, which isn't acceptable + * in all applications. + * + * To avoid very long blocking times in lzma_code(), a timeout + * (in milliseconds) may be set here. If lzma_code() would block + * longer than this number of milliseconds, it will return with + * LZMA_OK. Reasonable values are 100 ms or more. The xz command + * line tool uses 300 ms. + * + * If long blocking times are fine for you, set timeout to a special + * value of 0, which will disable the timeout mechanism and will make + * lzma_code() block until all the input is consumed or the output + * buffer has been filled. + * + * \note Even with a timeout, lzma_code() might sometimes take + * somewhat long time to return. No timing guarantees + * are made. + */ + uint32_t timeout; + + /** + * \brief Compression preset (level and possible flags) + * + * The preset is set just like with lzma_easy_encoder(). + * The preset is ignored if filters below is non-NULL. + */ + uint32_t preset; + + /** + * \brief Filter chain (alternative to a preset) + * + * If this is NULL, the preset above is used. Otherwise the preset + * is ignored and the filter chain specified here is used. + */ + const lzma_filter *filters; + + /** + * \brief Integrity check type + * + * See check.h for available checks. The xz command line tool + * defaults to LZMA_CHECK_CRC64, which is a good choice if you + * are unsure. + */ + lzma_check check; + + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. You should not touch these, because the names + * of these variables may change. These are and will never be used + * with the currently supported options, so it is safe to leave these + * uninitialized. + */ + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; + lzma_reserved_enum reserved_enum3; + uint32_t reserved_int1; + uint32_t reserved_int2; + uint32_t reserved_int3; + uint32_t reserved_int4; + uint64_t reserved_int5; + uint64_t reserved_int6; + uint64_t reserved_int7; + uint64_t reserved_int8; + void *reserved_ptr1; + void *reserved_ptr2; + void *reserved_ptr3; + void *reserved_ptr4; } lzma_mt; - /** * \brief Calculate approximate memory usage of easy encoder * @@ -196,9 +191,8 @@ typedef struct { * preset when encoding. If an error occurs, for example * due to unsupported preset, UINT64_MAX is returned. */ -extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint64_t) + lzma_easy_encoder_memusage(uint32_t preset) lzma_nothrow lzma_attr_pure; /** * \brief Calculate approximate decoder memory usage of a preset @@ -212,9 +206,8 @@ extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) * occurs, for example due to unsupported preset, UINT64_MAX * is returned. */ -extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint64_t) + lzma_easy_decoder_memusage(uint32_t preset) lzma_nothrow lzma_attr_pure; /** * \brief Initialize .xz Stream encoder using a preset number @@ -255,10 +248,9 @@ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future, * there may be compression levels or flags that don't support LZMA_SYNC_FLUSH. */ -extern LZMA_API(lzma_ret) lzma_easy_encoder( - lzma_stream *strm, uint32_t preset, lzma_check check) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Single-call .xz Stream encoding using a preset number @@ -288,12 +280,11 @@ extern LZMA_API(lzma_ret) lzma_easy_encoder( * - LZMA_DATA_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_easy_buffer_encode( - uint32_t preset, lzma_check check, - const lzma_allocator *allocator, - const uint8_t *in, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_easy_buffer_encode(uint32_t preset, lzma_check check, + const lzma_allocator *allocator, const uint8_t *in, + size_t in_size, uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow; /** * \brief Initialize .xz Stream encoder using a custom filter chain @@ -311,10 +302,9 @@ extern LZMA_API(lzma_ret) lzma_easy_buffer_encode( * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm, - const lzma_filter *filters, lzma_check check) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) lzma_stream_encoder( + lzma_stream *strm, const lzma_filter *filters, + lzma_check check) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Calculate approximate memory usage of multithreaded .xz encoder @@ -332,8 +322,7 @@ extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm, * unsupported preset or filter chain, UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage( - const lzma_mt *options) lzma_nothrow lzma_attr_pure; - + const lzma_mt *options) lzma_nothrow lzma_attr_pure; /** * \brief Initialize multithreaded .xz Stream encoder @@ -354,10 +343,9 @@ extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage( * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_stream_encoder_mt( - lzma_stream *strm, const lzma_mt *options) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_stream_encoder_mt(lzma_stream *strm, const lzma_mt *options) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Initialize .lzma encoder (legacy file format) @@ -379,10 +367,9 @@ extern LZMA_API(lzma_ret) lzma_stream_encoder_mt( * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_alone_encoder( - lzma_stream *strm, const lzma_options_lzma *options) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Calculate output buffer size for single-call Stream encoder @@ -406,9 +393,8 @@ extern LZMA_API(lzma_ret) lzma_alone_encoder( * uncompressible data. Currently there is no function to * calculate the maximum expansion of multi-call encoding. */ -extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) - lzma_nothrow; - +extern LZMA_API(size_t) + lzma_stream_buffer_bound(size_t uncompressed_size) lzma_nothrow; /** * \brief Single-call .xz Stream encoder @@ -437,12 +423,9 @@ extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) * - LZMA_PROG_ERROR */ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( - lzma_filter *filters, lzma_check check, - const lzma_allocator *allocator, - const uint8_t *in, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) - lzma_nothrow lzma_attr_warn_unused_result; - + lzma_filter *filters, lzma_check check, const lzma_allocator *allocator, + const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow lzma_attr_warn_unused_result; /************ * Decoding * @@ -454,8 +437,7 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( * lzma_auto_decoder(), all .lzma files will trigger LZMA_NO_CHECK * if LZMA_TELL_NO_CHECK is used. */ -#define LZMA_TELL_NO_CHECK UINT32_C(0x01) - +#define LZMA_TELL_NO_CHECK UINT32_C(0x01) /** * This flag makes lzma_code() return LZMA_UNSUPPORTED_CHECK if the input @@ -463,16 +445,14 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( * supported by this liblzma version or build. Such files can still be * decoded, but the integrity check cannot be verified. */ -#define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02) - +#define LZMA_TELL_UNSUPPORTED_CHECK UINT32_C(0x02) /** * This flag makes lzma_code() return LZMA_GET_CHECK as soon as the type * of the integrity check is known. The type can then be got with * lzma_get_check(). */ -#define LZMA_TELL_ANY_CHECK UINT32_C(0x04) - +#define LZMA_TELL_ANY_CHECK UINT32_C(0x04) /** * This flag makes lzma_code() not calculate and verify the integrity check @@ -495,8 +475,7 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( * * Support for this flag was added in liblzma 5.1.4beta. */ -#define LZMA_IGNORE_CHECK UINT32_C(0x10) - +#define LZMA_IGNORE_CHECK UINT32_C(0x10) /** * This flag enables decoding of concatenated files with file formats that @@ -512,8 +491,7 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( * If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH * as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required. */ -#define LZMA_CONCATENATED UINT32_C(0x08) - +#define LZMA_CONCATENATED UINT32_C(0x08) /** * \brief Initialize .xz Stream decoder @@ -530,10 +508,9 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode( * - LZMA_OPTIONS_ERROR: Unsupported flags * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_stream_decoder( - lzma_stream *strm, uint64_t memlimit, uint32_t flags) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Decode .xz Streams and .lzma files with autodetection @@ -552,10 +529,9 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder( * - LZMA_OPTIONS_ERROR: Unsupported flags * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_auto_decoder( - lzma_stream *strm, uint64_t memlimit, uint32_t flags) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_auto_decoder(lzma_stream *strm, uint64_t memlimit, + uint32_t flags) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Initialize .lzma decoder (legacy file format) @@ -568,10 +544,9 @@ extern LZMA_API(lzma_ret) lzma_auto_decoder( * - LZMA_MEM_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_alone_decoder( - lzma_stream *strm, uint64_t memlimit) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Single-call .xz Stream decoder @@ -612,8 +587,6 @@ extern LZMA_API(lzma_ret) lzma_alone_decoder( * - LZMA_PROG_ERROR */ extern LZMA_API(lzma_ret) lzma_stream_buffer_decode( - uint64_t *memlimit, uint32_t flags, - const lzma_allocator *allocator, - const uint8_t *in, size_t *in_pos, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) - lzma_nothrow lzma_attr_warn_unused_result; + uint64_t *memlimit, uint32_t flags, const lzma_allocator *allocator, + const uint8_t *in, size_t *in_pos, size_t in_size, uint8_t *out, + size_t *out_pos, size_t out_size) lzma_nothrow lzma_attr_warn_unused_result; diff --git a/node_modules/lzma-native/deps/include/lzma/delta.h b/node_modules/lzma-native/deps/include/lzma/delta.h index f949750..5f13fab 100644 --- a/node_modules/lzma-native/deps/include/lzma/delta.h +++ b/node_modules/lzma-native/deps/include/lzma/delta.h @@ -13,17 +13,15 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Filter ID * * Filter ID of the Delta filter. This is used as lzma_filter.id. */ -#define LZMA_FILTER_DELTA LZMA_VLI_C(0x03) - +#define LZMA_FILTER_DELTA LZMA_VLI_C(0x03) /** * \brief Type of the delta calculation @@ -32,10 +30,7 @@ * be, for example, delta of 16/32/64-bit little/big endian integers, but * these are not currently planned since byte-wise delta is almost as good. */ -typedef enum { - LZMA_DELTA_TYPE_BYTE -} lzma_delta_type; - +typedef enum { LZMA_DELTA_TYPE_BYTE } lzma_delta_type; /** * \brief Options for the Delta filter @@ -43,35 +38,35 @@ typedef enum { * These options are needed by both encoder and decoder. */ typedef struct { - /** For now, this must always be LZMA_DELTA_TYPE_BYTE. */ - lzma_delta_type type; + /** For now, this must always be LZMA_DELTA_TYPE_BYTE. */ + lzma_delta_type type; - /** - * \brief Delta distance - * - * With the only currently supported type, LZMA_DELTA_TYPE_BYTE, - * the distance is as bytes. - * - * Examples: - * - 16-bit stereo audio: distance = 4 bytes - * - 24-bit RGB image data: distance = 3 bytes - */ - uint32_t dist; -# define LZMA_DELTA_DIST_MIN 1 -# define LZMA_DELTA_DIST_MAX 256 + /** + * \brief Delta distance + * + * With the only currently supported type, LZMA_DELTA_TYPE_BYTE, + * the distance is as bytes. + * + * Examples: + * - 16-bit stereo audio: distance = 4 bytes + * - 24-bit RGB image data: distance = 3 bytes + */ + uint32_t dist; +#define LZMA_DELTA_DIST_MIN 1 +#define LZMA_DELTA_DIST_MAX 256 - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. You should not touch these, because the names - * of these variables may change. These are and will never be used - * when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these - * uninitialized. - */ - uint32_t reserved_int1; - uint32_t reserved_int2; - uint32_t reserved_int3; - uint32_t reserved_int4; - void *reserved_ptr1; - void *reserved_ptr2; + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. You should not touch these, because the names + * of these variables may change. These are and will never be used + * when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these + * uninitialized. + */ + uint32_t reserved_int1; + uint32_t reserved_int2; + uint32_t reserved_int3; + uint32_t reserved_int4; + void *reserved_ptr1; + void *reserved_ptr2; } lzma_options_delta; diff --git a/node_modules/lzma-native/deps/include/lzma/filter.h b/node_modules/lzma-native/deps/include/lzma/filter.h index 1c3dccb..c548b1b 100644 --- a/node_modules/lzma-native/deps/include/lzma/filter.h +++ b/node_modules/lzma-native/deps/include/lzma/filter.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Maximum number of filters in a chain * @@ -25,7 +24,6 @@ */ #define LZMA_FILTERS_MAX 4 - /** * \brief Filter options * @@ -41,30 +39,29 @@ * array would make liblzma write past the end of the filters array. */ typedef struct { - /** - * \brief Filter ID - * - * Use constants whose name begin with `LZMA_FILTER_' to specify - * different filters. In an array of lzma_filter structures, use - * LZMA_VLI_UNKNOWN to indicate end of filters. - * - * \note This is not an enum, because on some systems enums - * cannot be 64-bit. - */ - lzma_vli id; - - /** - * \brief Pointer to filter-specific options structure - * - * If the filter doesn't need options, set this to NULL. If id is - * set to LZMA_VLI_UNKNOWN, options is ignored, and thus - * doesn't need be initialized. - */ - void *options; + /** + * \brief Filter ID + * + * Use constants whose name begin with `LZMA_FILTER_' to specify + * different filters. In an array of lzma_filter structures, use + * LZMA_VLI_UNKNOWN to indicate end of filters. + * + * \note This is not an enum, because on some systems enums + * cannot be 64-bit. + */ + lzma_vli id; + + /** + * \brief Pointer to filter-specific options structure + * + * If the filter doesn't need options, set this to NULL. If id is + * set to LZMA_VLI_UNKNOWN, options is ignored, and thus + * doesn't need be initialized. + */ + void *options; } lzma_filter; - /** * \brief Test if the given Filter ID is supported for encoding * @@ -75,9 +72,8 @@ typedef struct { * liblzma version and build. It would be useless, because the application * couldn't know what kind of options the filter would need. */ -extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id) - lzma_nothrow lzma_attr_const; - +extern LZMA_API(lzma_bool) + lzma_filter_encoder_is_supported(lzma_vli id) lzma_nothrow lzma_attr_const; /** * \brief Test if the given Filter ID is supported for decoding @@ -85,9 +81,8 @@ extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id) * Return true if the give Filter ID is supported for decoding by this * liblzma build. Otherwise false is returned. */ -extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id) - lzma_nothrow lzma_attr_const; - +extern LZMA_API(lzma_bool) + lzma_filter_decoder_is_supported(lzma_vli id) lzma_nothrow lzma_attr_const; /** * \brief Copy the filters array @@ -116,10 +111,9 @@ extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id) * is not NULL. * - LZMA_PROG_ERROR: src or dest is NULL. */ -extern LZMA_API(lzma_ret) lzma_filters_copy( - const lzma_filter *src, lzma_filter *dest, - const lzma_allocator *allocator) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_filters_copy(const lzma_filter *src, lzma_filter *dest, + const lzma_allocator *allocator) lzma_nothrow; /** * \brief Calculate approximate memory requirements for raw encoder @@ -137,8 +131,7 @@ extern LZMA_API(lzma_ret) lzma_filters_copy( * UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) - lzma_nothrow lzma_attr_pure; - + lzma_nothrow lzma_attr_pure; /** * \brief Calculate approximate memory requirements for raw decoder @@ -156,8 +149,7 @@ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) * UINT64_MAX is returned. */ extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters) - lzma_nothrow lzma_attr_pure; - + lzma_nothrow lzma_attr_pure; /** * \brief Initialize raw encoder @@ -176,10 +168,9 @@ extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters) * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_raw_encoder( - lzma_stream *strm, const lzma_filter *filters) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_raw_encoder(lzma_stream *strm, const lzma_filter *filters) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Initialize raw decoder @@ -194,10 +185,9 @@ extern LZMA_API(lzma_ret) lzma_raw_encoder( * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_raw_decoder( - lzma_stream *strm, const lzma_filter *filters) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_raw_decoder(lzma_stream *strm, const lzma_filter *filters) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Update the filter chain in the encoder @@ -225,9 +215,9 @@ extern LZMA_API(lzma_ret) lzma_raw_decoder( * - LZMA_OPTIONS_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_filters_update( - lzma_stream *strm, const lzma_filter *filters) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_filters_update(lzma_stream *strm, + const lzma_filter *filters) lzma_nothrow; /** * \brief Single-call raw encoder @@ -256,11 +246,11 @@ extern LZMA_API(lzma_ret) lzma_filters_update( * works only for lzma_stream_buffer_encode(); raw encoder * won't necessarily meet that bound.) */ -extern LZMA_API(lzma_ret) lzma_raw_buffer_encode( - const lzma_filter *filters, const lzma_allocator *allocator, - const uint8_t *in, size_t in_size, uint8_t *out, - size_t *out_pos, size_t out_size) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_raw_buffer_encode(const lzma_filter *filters, + const lzma_allocator *allocator, const uint8_t *in, + size_t in_size, uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow; /** * \brief Single-call raw decoder @@ -280,11 +270,11 @@ extern LZMA_API(lzma_ret) lzma_raw_buffer_encode( * \param out_size Size of the out buffer; the first byte into * which no data is written to is out[out_size]. */ -extern LZMA_API(lzma_ret) lzma_raw_buffer_decode( - const lzma_filter *filters, const lzma_allocator *allocator, - const uint8_t *in, size_t *in_pos, size_t in_size, - uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_raw_buffer_decode(const lzma_filter *filters, + const lzma_allocator *allocator, const uint8_t *in, + size_t *in_pos, size_t in_size, uint8_t *out, + size_t *out_pos, size_t out_size) lzma_nothrow; /** * \brief Get the size of the Filter Properties field @@ -305,9 +295,9 @@ extern LZMA_API(lzma_ret) lzma_raw_buffer_decode( * that this returns LZMA_OK while the following call to * lzma_properties_encode() returns LZMA_OPTIONS_ERROR. */ -extern LZMA_API(lzma_ret) lzma_properties_size( - uint32_t *size, const lzma_filter *filter) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_properties_size(uint32_t *size, + const lzma_filter *filter) lzma_nothrow; /** * \brief Encode the Filter Properties field @@ -331,9 +321,8 @@ extern LZMA_API(lzma_ret) lzma_properties_size( * lzma_properties_encode() is not required, but it * won't do any harm either. */ -extern LZMA_API(lzma_ret) lzma_properties_encode( - const lzma_filter *filter, uint8_t *props) lzma_nothrow; - +extern LZMA_API(lzma_ret) lzma_properties_encode(const lzma_filter *filter, + uint8_t *props) lzma_nothrow; /** * \brief Decode the Filter Properties field @@ -356,10 +345,10 @@ extern LZMA_API(lzma_ret) lzma_properties_encode( * - LZMA_OPTIONS_ERROR * - LZMA_MEM_ERROR */ -extern LZMA_API(lzma_ret) lzma_properties_decode( - lzma_filter *filter, const lzma_allocator *allocator, - const uint8_t *props, size_t props_size) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_properties_decode(lzma_filter *filter, const lzma_allocator *allocator, + const uint8_t *props, + size_t props_size) lzma_nothrow; /** * \brief Calculate encoded size of a Filter Flags field @@ -380,10 +369,9 @@ extern LZMA_API(lzma_ret) lzma_properties_decode( * \note If you need to calculate size of List of Filter Flags, * you need to loop over every lzma_filter entry. */ -extern LZMA_API(lzma_ret) lzma_filter_flags_size( - uint32_t *size, const lzma_filter *filter) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_filter_flags_size(uint32_t *size, const lzma_filter *filter) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Encode Filter Flags into given buffer @@ -403,10 +391,9 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_size( * buffer space (you should have checked it with * lzma_filter_flags_size()). */ -extern LZMA_API(lzma_ret) lzma_filter_flags_encode(const lzma_filter *filter, - uint8_t *out, size_t *out_pos, size_t out_size) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) lzma_filter_flags_encode( + const lzma_filter *filter, uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Decode Filter Flags from given buffer @@ -420,6 +407,5 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_encode(const lzma_filter *filter, * - LZMA_PROG_ERROR */ extern LZMA_API(lzma_ret) lzma_filter_flags_decode( - lzma_filter *filter, const lzma_allocator *allocator, - const uint8_t *in, size_t *in_pos, size_t in_size) - lzma_nothrow lzma_attr_warn_unused_result; + lzma_filter *filter, const lzma_allocator *allocator, const uint8_t *in, + size_t *in_pos, size_t in_size) lzma_nothrow lzma_attr_warn_unused_result; diff --git a/node_modules/lzma-native/deps/include/lzma/hardware.h b/node_modules/lzma-native/deps/include/lzma/hardware.h index 75d9b44..995246b 100644 --- a/node_modules/lzma-native/deps/include/lzma/hardware.h +++ b/node_modules/lzma-native/deps/include/lzma/hardware.h @@ -30,10 +30,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Get the total amount of physical memory (RAM) in bytes * @@ -49,7 +48,6 @@ */ extern LZMA_API(uint64_t) lzma_physmem(void) lzma_nothrow; - /** * \brief Get the number of processor cores or threads * diff --git a/node_modules/lzma-native/deps/include/lzma/index.h b/node_modules/lzma-native/deps/include/lzma/index.h index d7da2f4..6e58311 100644 --- a/node_modules/lzma-native/deps/include/lzma/index.h +++ b/node_modules/lzma-native/deps/include/lzma/index.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Opaque data type to hold the Index(es) and other information * @@ -36,238 +35,235 @@ */ typedef struct lzma_index_s lzma_index; - /** * \brief Iterator to get information about Blocks and Streams */ typedef struct { - struct { - /** - * \brief Pointer to Stream Flags - * - * This is NULL if Stream Flags have not been set for - * this Stream with lzma_index_stream_flags(). - */ - const lzma_stream_flags *flags; - - const void *reserved_ptr1; - const void *reserved_ptr2; - const void *reserved_ptr3; - - /** - * \brief Stream number in the lzma_index - * - * The first Stream is 1. - */ - lzma_vli number; - - /** - * \brief Number of Blocks in the Stream - * - * If this is zero, the block structure below has - * undefined values. - */ - lzma_vli block_count; - - /** - * \brief Compressed start offset of this Stream - * - * The offset is relative to the beginning of the lzma_index - * (i.e. usually the beginning of the .xz file). - */ - lzma_vli compressed_offset; - - /** - * \brief Uncompressed start offset of this Stream - * - * The offset is relative to the beginning of the lzma_index - * (i.e. usually the beginning of the .xz file). - */ - lzma_vli uncompressed_offset; - - /** - * \brief Compressed size of this Stream - * - * This includes all headers except the possible - * Stream Padding after this Stream. - */ - lzma_vli compressed_size; - - /** - * \brief Uncompressed size of this Stream - */ - lzma_vli uncompressed_size; - - /** - * \brief Size of Stream Padding after this Stream - * - * If it hasn't been set with lzma_index_stream_padding(), - * this defaults to zero. Stream Padding is always - * a multiple of four bytes. - */ - lzma_vli padding; - - lzma_vli reserved_vli1; - lzma_vli reserved_vli2; - lzma_vli reserved_vli3; - lzma_vli reserved_vli4; - } stream; - - struct { - /** - * \brief Block number in the file - * - * The first Block is 1. - */ - lzma_vli number_in_file; - - /** - * \brief Compressed start offset of this Block - * - * This offset is relative to the beginning of the - * lzma_index (i.e. usually the beginning of the .xz file). - * Normally this is where you should seek in the .xz file - * to start decompressing this Block. - */ - lzma_vli compressed_file_offset; - - /** - * \brief Uncompressed start offset of this Block - * - * This offset is relative to the beginning of the lzma_index - * (i.e. usually the beginning of the .xz file). - * - * When doing random-access reading, it is possible that - * the target offset is not exactly at Block boundary. One - * will need to compare the target offset against - * uncompressed_file_offset or uncompressed_stream_offset, - * and possibly decode and throw away some amount of data - * before reaching the target offset. - */ - lzma_vli uncompressed_file_offset; - - /** - * \brief Block number in this Stream - * - * The first Block is 1. - */ - lzma_vli number_in_stream; - - /** - * \brief Compressed start offset of this Block - * - * This offset is relative to the beginning of the Stream - * containing this Block. - */ - lzma_vli compressed_stream_offset; - - /** - * \brief Uncompressed start offset of this Block - * - * This offset is relative to the beginning of the Stream - * containing this Block. - */ - lzma_vli uncompressed_stream_offset; - - /** - * \brief Uncompressed size of this Block - * - * You should pass this to the Block decoder if you will - * decode this Block. It will allow the Block decoder to - * validate the uncompressed size. - */ - lzma_vli uncompressed_size; - - /** - * \brief Unpadded size of this Block - * - * You should pass this to the Block decoder if you will - * decode this Block. It will allow the Block decoder to - * validate the unpadded size. - */ - lzma_vli unpadded_size; - - /** - * \brief Total compressed size - * - * This includes all headers and padding in this Block. - * This is useful if you need to know how many bytes - * the Block decoder will actually read. - */ - lzma_vli total_size; - - lzma_vli reserved_vli1; - lzma_vli reserved_vli2; - lzma_vli reserved_vli3; - lzma_vli reserved_vli4; - - const void *reserved_ptr1; - const void *reserved_ptr2; - const void *reserved_ptr3; - const void *reserved_ptr4; - } block; - - /* - * Internal data which is used to store the state of the iterator. - * The exact format may vary between liblzma versions, so don't - * touch these in any way. - */ - union { - const void *p; - size_t s; - lzma_vli v; - } internal[6]; + struct { + /** + * \brief Pointer to Stream Flags + * + * This is NULL if Stream Flags have not been set for + * this Stream with lzma_index_stream_flags(). + */ + const lzma_stream_flags *flags; + + const void *reserved_ptr1; + const void *reserved_ptr2; + const void *reserved_ptr3; + + /** + * \brief Stream number in the lzma_index + * + * The first Stream is 1. + */ + lzma_vli number; + + /** + * \brief Number of Blocks in the Stream + * + * If this is zero, the block structure below has + * undefined values. + */ + lzma_vli block_count; + + /** + * \brief Compressed start offset of this Stream + * + * The offset is relative to the beginning of the lzma_index + * (i.e. usually the beginning of the .xz file). + */ + lzma_vli compressed_offset; + + /** + * \brief Uncompressed start offset of this Stream + * + * The offset is relative to the beginning of the lzma_index + * (i.e. usually the beginning of the .xz file). + */ + lzma_vli uncompressed_offset; + + /** + * \brief Compressed size of this Stream + * + * This includes all headers except the possible + * Stream Padding after this Stream. + */ + lzma_vli compressed_size; + + /** + * \brief Uncompressed size of this Stream + */ + lzma_vli uncompressed_size; + + /** + * \brief Size of Stream Padding after this Stream + * + * If it hasn't been set with lzma_index_stream_padding(), + * this defaults to zero. Stream Padding is always + * a multiple of four bytes. + */ + lzma_vli padding; + + lzma_vli reserved_vli1; + lzma_vli reserved_vli2; + lzma_vli reserved_vli3; + lzma_vli reserved_vli4; + } stream; + + struct { + /** + * \brief Block number in the file + * + * The first Block is 1. + */ + lzma_vli number_in_file; + + /** + * \brief Compressed start offset of this Block + * + * This offset is relative to the beginning of the + * lzma_index (i.e. usually the beginning of the .xz file). + * Normally this is where you should seek in the .xz file + * to start decompressing this Block. + */ + lzma_vli compressed_file_offset; + + /** + * \brief Uncompressed start offset of this Block + * + * This offset is relative to the beginning of the lzma_index + * (i.e. usually the beginning of the .xz file). + * + * When doing random-access reading, it is possible that + * the target offset is not exactly at Block boundary. One + * will need to compare the target offset against + * uncompressed_file_offset or uncompressed_stream_offset, + * and possibly decode and throw away some amount of data + * before reaching the target offset. + */ + lzma_vli uncompressed_file_offset; + + /** + * \brief Block number in this Stream + * + * The first Block is 1. + */ + lzma_vli number_in_stream; + + /** + * \brief Compressed start offset of this Block + * + * This offset is relative to the beginning of the Stream + * containing this Block. + */ + lzma_vli compressed_stream_offset; + + /** + * \brief Uncompressed start offset of this Block + * + * This offset is relative to the beginning of the Stream + * containing this Block. + */ + lzma_vli uncompressed_stream_offset; + + /** + * \brief Uncompressed size of this Block + * + * You should pass this to the Block decoder if you will + * decode this Block. It will allow the Block decoder to + * validate the uncompressed size. + */ + lzma_vli uncompressed_size; + + /** + * \brief Unpadded size of this Block + * + * You should pass this to the Block decoder if you will + * decode this Block. It will allow the Block decoder to + * validate the unpadded size. + */ + lzma_vli unpadded_size; + + /** + * \brief Total compressed size + * + * This includes all headers and padding in this Block. + * This is useful if you need to know how many bytes + * the Block decoder will actually read. + */ + lzma_vli total_size; + + lzma_vli reserved_vli1; + lzma_vli reserved_vli2; + lzma_vli reserved_vli3; + lzma_vli reserved_vli4; + + const void *reserved_ptr1; + const void *reserved_ptr2; + const void *reserved_ptr3; + const void *reserved_ptr4; + } block; + + /* + * Internal data which is used to store the state of the iterator. + * The exact format may vary between liblzma versions, so don't + * touch these in any way. + */ + union { + const void *p; + size_t s; + lzma_vli v; + } internal[6]; } lzma_index_iter; - /** * \brief Operation mode for lzma_index_iter_next() */ typedef enum { - LZMA_INDEX_ITER_ANY = 0, - /**< - * \brief Get the next Block or Stream - * - * Go to the next Block if the current Stream has at least - * one Block left. Otherwise go to the next Stream even if - * it has no Blocks. If the Stream has no Blocks - * (lzma_index_iter.stream.block_count == 0), - * lzma_index_iter.block will have undefined values. - */ - - LZMA_INDEX_ITER_STREAM = 1, - /**< - * \brief Get the next Stream - * - * Go to the next Stream even if the current Stream has - * unread Blocks left. If the next Stream has at least one - * Block, the iterator will point to the first Block. - * If there are no Blocks, lzma_index_iter.block will have - * undefined values. - */ - - LZMA_INDEX_ITER_BLOCK = 2, - /**< - * \brief Get the next Block - * - * Go to the next Block if the current Stream has at least - * one Block left. If the current Stream has no Blocks left, - * the next Stream with at least one Block is located and - * the iterator will be made to point to the first Block of - * that Stream. - */ - - LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3 - /**< - * \brief Get the next non-empty Block - * - * This is like LZMA_INDEX_ITER_BLOCK except that it will - * skip Blocks whose Uncompressed Size is zero. - */ + LZMA_INDEX_ITER_ANY = 0, + /**< + * \brief Get the next Block or Stream + * + * Go to the next Block if the current Stream has at least + * one Block left. Otherwise go to the next Stream even if + * it has no Blocks. If the Stream has no Blocks + * (lzma_index_iter.stream.block_count == 0), + * lzma_index_iter.block will have undefined values. + */ + + LZMA_INDEX_ITER_STREAM = 1, + /**< + * \brief Get the next Stream + * + * Go to the next Stream even if the current Stream has + * unread Blocks left. If the next Stream has at least one + * Block, the iterator will point to the first Block. + * If there are no Blocks, lzma_index_iter.block will have + * undefined values. + */ + + LZMA_INDEX_ITER_BLOCK = 2, + /**< + * \brief Get the next Block + * + * Go to the next Block if the current Stream has at least + * one Block left. If the current Stream has no Blocks left, + * the next Stream with at least one Block is located and + * the iterator will be made to point to the first Block of + * that Stream. + */ + + LZMA_INDEX_ITER_NONEMPTY_BLOCK = 3 + /**< + * \brief Get the next non-empty Block + * + * This is like LZMA_INDEX_ITER_BLOCK except that it will + * skip Blocks whose Uncompressed Size is zero. + */ } lzma_index_iter_mode; - /** * \brief Calculate memory usage of lzma_index * @@ -283,9 +279,8 @@ typedef enum { * value may vary between CPU architectures and also between liblzma versions * if the internal implementation is modified. */ -extern LZMA_API(uint64_t) lzma_index_memusage( - lzma_vli streams, lzma_vli blocks) lzma_nothrow; - +extern LZMA_API(uint64_t) + lzma_index_memusage(lzma_vli streams, lzma_vli blocks) lzma_nothrow; /** * \brief Calculate the memory usage of an existing lzma_index @@ -293,9 +288,7 @@ extern LZMA_API(uint64_t) lzma_index_memusage( * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), * lzma_index_block_count(i)). */ -extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i) - lzma_nothrow; - +extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i) lzma_nothrow; /** * \brief Allocate and initialize a new lzma_index structure @@ -303,18 +296,16 @@ extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i) * \return On success, a pointer to an empty initialized lzma_index is * returned. If allocation fails, NULL is returned. */ -extern LZMA_API(lzma_index *) lzma_index_init(const lzma_allocator *allocator) - lzma_nothrow; - +extern LZMA_API(lzma_index *) + lzma_index_init(const lzma_allocator *allocator) lzma_nothrow; /** * \brief Deallocate lzma_index * * If i is NULL, this does nothing. */ -extern LZMA_API(void) lzma_index_end( - lzma_index *i, const lzma_allocator *allocator) lzma_nothrow; - +extern LZMA_API(void) + lzma_index_end(lzma_index *i, const lzma_allocator *allocator) lzma_nothrow; /** * \brief Add a new Block to lzma_index @@ -341,10 +332,8 @@ extern LZMA_API(void) lzma_index_end( * - LZMA_PROG_ERROR */ extern LZMA_API(lzma_ret) lzma_index_append( - lzma_index *i, const lzma_allocator *allocator, - lzma_vli unpadded_size, lzma_vli uncompressed_size) - lzma_nothrow lzma_attr_warn_unused_result; - + lzma_index *i, const lzma_allocator *allocator, lzma_vli unpadded_size, + lzma_vli uncompressed_size) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Set the Stream Flags @@ -362,10 +351,10 @@ extern LZMA_API(lzma_ret) lzma_index_append( * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version. * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_index_stream_flags( - lzma_index *i, const lzma_stream_flags *stream_flags) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_index_stream_flags(lzma_index *i, + const lzma_stream_flags *stream_flags) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Get the types of integrity Checks @@ -377,9 +366,8 @@ extern LZMA_API(lzma_ret) lzma_index_stream_flags( * * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10. */ -extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(uint32_t) + lzma_index_checks(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Set the amount of Stream Padding @@ -394,17 +382,15 @@ extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i) * - LZMA_DATA_ERROR: The file size would grow too big. * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_index_stream_padding( - lzma_index *i, lzma_vli stream_padding) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_index_stream_padding(lzma_index *i, lzma_vli stream_padding) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Get the number of Streams */ -extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_index_stream_count(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Get the number of Blocks @@ -412,18 +398,16 @@ extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i) * This returns the total number of Blocks in lzma_index. To get number * of Blocks in individual Streams, use lzma_index_iter. */ -extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_index_block_count(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Get the size of the Index field as bytes * * This is needed to verify the Backward Size field in the Stream Footer. */ -extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_index_size(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Get the total size of the Stream @@ -432,9 +416,8 @@ extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i) * were in a single Stream. This is useful if you are going to combine * Blocks from multiple Streams into a single new Stream. */ -extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_index_stream_size(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Get the total size of the Blocks @@ -442,9 +425,8 @@ extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i) * This doesn't include the Stream Header, Stream Footer, Stream Padding, * or Index fields. */ -extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_index_total_size(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Get the total size of the file @@ -454,16 +436,14 @@ extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i) * If multiple lzma_indexes have been combined, this includes also the headers * of each separate Stream and the possible Stream Padding fields. */ -extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - +extern LZMA_API(lzma_vli) + lzma_index_file_size(const lzma_index *i) lzma_nothrow lzma_attr_pure; /** * \brief Get the uncompressed size of the file */ extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i) - lzma_nothrow lzma_attr_pure; - + lzma_nothrow lzma_attr_pure; /** * \brief Initialize an iterator @@ -484,9 +464,8 @@ extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i) * It is safe to make copies of an initialized lzma_index_iter, for example, * to easily restart reading at some particular position. */ -extern LZMA_API(void) lzma_index_iter_init( - lzma_index_iter *iter, const lzma_index *i) lzma_nothrow; - +extern LZMA_API(void) lzma_index_iter_init(lzma_index_iter *iter, + const lzma_index *i) lzma_nothrow; /** * \brief Rewind the iterator @@ -494,9 +473,8 @@ extern LZMA_API(void) lzma_index_iter_init( * Rewind the iterator so that next call to lzma_index_iter_next() will * return the first Block or Stream. */ -extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter) - lzma_nothrow; - +extern LZMA_API(void) + lzma_index_iter_rewind(lzma_index_iter *iter) lzma_nothrow; /** * \brief Get the next Block or Stream @@ -511,10 +489,9 @@ extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter) * and this function returns true. If mode is set to an unknown * value, *iter is not modified and this function returns true. */ -extern LZMA_API(lzma_bool) lzma_index_iter_next( - lzma_index_iter *iter, lzma_index_iter_mode mode) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_bool) + lzma_index_iter_next(lzma_index_iter *iter, lzma_index_iter_mode mode) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Locate a Block @@ -539,9 +516,8 @@ extern LZMA_API(lzma_bool) lzma_index_iter_next( * If target is greater than the uncompressed size of the Stream, *iter * is not modified, and this function returns true. */ -extern LZMA_API(lzma_bool) lzma_index_iter_locate( - lzma_index_iter *iter, lzma_vli target) lzma_nothrow; - +extern LZMA_API(lzma_bool) + lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli target) lzma_nothrow; /** * \brief Concatenate lzma_indexes @@ -565,19 +541,17 @@ extern LZMA_API(lzma_bool) lzma_index_iter_locate( * - LZMA_PROG_ERROR */ extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *dest, lzma_index *src, - const lzma_allocator *allocator) - lzma_nothrow lzma_attr_warn_unused_result; - + const lzma_allocator *allocator) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Duplicate lzma_index * * \return A copy of the lzma_index, or NULL if memory allocation failed. */ -extern LZMA_API(lzma_index *) lzma_index_dup( - const lzma_index *i, const lzma_allocator *allocator) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_index *) + lzma_index_dup(const lzma_index *i, const lzma_allocator *allocator) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Initialize .xz Index encoder @@ -593,10 +567,9 @@ extern LZMA_API(lzma_index *) lzma_index_dup( * - LZMA_MEM_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_index_encoder( - lzma_stream *strm, const lzma_index *i) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_index_encoder(lzma_stream *strm, const lzma_index *i) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Initialize .xz Index decoder @@ -621,10 +594,9 @@ extern LZMA_API(lzma_ret) lzma_index_encoder( * - LZMA_MEMLIMIT_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_index_decoder( - lzma_stream *strm, lzma_index **i, uint64_t memlimit) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_index_decoder(lzma_stream *strm, lzma_index **i, uint64_t memlimit) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Single-call .xz Index encoder @@ -645,9 +617,9 @@ extern LZMA_API(lzma_ret) lzma_index_decoder( * \note This function doesn't take allocator argument since all * the internal data is allocated on stack. */ -extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i, - uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_index_buffer_encode(const lzma_index *i, uint8_t *out, size_t *out_pos, + size_t out_size) lzma_nothrow; /** * \brief Single-call .xz Index decoder @@ -676,7 +648,7 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i, * - LZMA_DATA_ERROR * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i, - uint64_t *memlimit, const lzma_allocator *allocator, - const uint8_t *in, size_t *in_pos, size_t in_size) - lzma_nothrow; +extern LZMA_API(lzma_ret) + lzma_index_buffer_decode(lzma_index **i, uint64_t *memlimit, + const lzma_allocator *allocator, const uint8_t *in, + size_t *in_pos, size_t in_size) lzma_nothrow; diff --git a/node_modules/lzma-native/deps/include/lzma/index_hash.h b/node_modules/lzma-native/deps/include/lzma/index_hash.h index 1d0688d..de398ce 100644 --- a/node_modules/lzma-native/deps/include/lzma/index_hash.h +++ b/node_modules/lzma-native/deps/include/lzma/index_hash.h @@ -16,7 +16,7 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif /** @@ -24,7 +24,6 @@ */ typedef struct lzma_index_hash_s lzma_index_hash; - /** * \brief Allocate and initialize a new lzma_index_hash structure * @@ -37,17 +36,15 @@ typedef struct lzma_index_hash_s lzma_index_hash; * pointer than the index_hash that was given as an argument. */ extern LZMA_API(lzma_index_hash *) lzma_index_hash_init( - lzma_index_hash *index_hash, const lzma_allocator *allocator) - lzma_nothrow lzma_attr_warn_unused_result; - + lzma_index_hash *index_hash, + const lzma_allocator *allocator) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Deallocate lzma_index_hash structure */ -extern LZMA_API(void) lzma_index_hash_end( - lzma_index_hash *index_hash, const lzma_allocator *allocator) - lzma_nothrow; - +extern LZMA_API(void) + lzma_index_hash_end(lzma_index_hash *index_hash, + const lzma_allocator *allocator) lzma_nothrow; /** * \brief Add a new Record to an Index hash @@ -62,10 +59,9 @@ extern LZMA_API(void) lzma_index_hash_end( * - LZMA_PROG_ERROR: Invalid arguments or this function is being * used when lzma_index_hash_decode() has already been used. */ -extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash, - lzma_vli unpadded_size, lzma_vli uncompressed_size) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) lzma_index_hash_append( + lzma_index_hash *index_hash, lzma_vli unpadded_size, + lzma_vli uncompressed_size) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Decode and validate the Index field @@ -92,10 +88,9 @@ extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash, * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size. * - LZMA_PROG_ERROR */ -extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash, - const uint8_t *in, size_t *in_pos, size_t in_size) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) lzma_index_hash_decode( + lzma_index_hash *index_hash, const uint8_t *in, size_t *in_pos, + size_t in_size) lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Get the size of the Index field as bytes @@ -103,5 +98,4 @@ extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash, * This is needed to verify the Backward Size field in the Stream Footer. */ extern LZMA_API(lzma_vli) lzma_index_hash_size( - const lzma_index_hash *index_hash) - lzma_nothrow lzma_attr_pure; + const lzma_index_hash *index_hash) lzma_nothrow lzma_attr_pure; diff --git a/node_modules/lzma-native/deps/include/lzma/lzma12.h b/node_modules/lzma-native/deps/include/lzma/lzma12.h index cbb4cc7..db0b712 100644 --- a/node_modules/lzma-native/deps/include/lzma/lzma12.h +++ b/node_modules/lzma-native/deps/include/lzma/lzma12.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief LZMA1 Filter ID * @@ -27,7 +26,7 @@ * LZMA1 shouldn't be used for new applications unless you _really_ know * what you are doing. LZMA2 is almost always a better choice. */ -#define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001) +#define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001) /** * \brief LZMA2 Filter ID @@ -37,8 +36,7 @@ * when trying to compress uncompressible data), possibility to change * lc/lp/pb in the middle of encoding, and some other internal improvements. */ -#define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21) - +#define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21) /** * \brief Match finders @@ -56,61 +54,60 @@ * lzma_raw_encoder_memusage() to get more accurate estimate of memory usage. */ typedef enum { - LZMA_MF_HC3 = 0x03, - /**< - * \brief Hash Chain with 2- and 3-byte hashing - * - * Minimum nice_len: 3 - * - * Memory usage: - * - dict_size <= 16 MiB: dict_size * 7.5 - * - dict_size > 16 MiB: dict_size * 5.5 + 64 MiB - */ - - LZMA_MF_HC4 = 0x04, - /**< - * \brief Hash Chain with 2-, 3-, and 4-byte hashing - * - * Minimum nice_len: 4 - * - * Memory usage: - * - dict_size <= 32 MiB: dict_size * 7.5 - * - dict_size > 32 MiB: dict_size * 6.5 - */ - - LZMA_MF_BT2 = 0x12, - /**< - * \brief Binary Tree with 2-byte hashing - * - * Minimum nice_len: 2 - * - * Memory usage: dict_size * 9.5 - */ - - LZMA_MF_BT3 = 0x13, - /**< - * \brief Binary Tree with 2- and 3-byte hashing - * - * Minimum nice_len: 3 - * - * Memory usage: - * - dict_size <= 16 MiB: dict_size * 11.5 - * - dict_size > 16 MiB: dict_size * 9.5 + 64 MiB - */ - - LZMA_MF_BT4 = 0x14 - /**< - * \brief Binary Tree with 2-, 3-, and 4-byte hashing - * - * Minimum nice_len: 4 - * - * Memory usage: - * - dict_size <= 32 MiB: dict_size * 11.5 - * - dict_size > 32 MiB: dict_size * 10.5 - */ + LZMA_MF_HC3 = 0x03, + /**< + * \brief Hash Chain with 2- and 3-byte hashing + * + * Minimum nice_len: 3 + * + * Memory usage: + * - dict_size <= 16 MiB: dict_size * 7.5 + * - dict_size > 16 MiB: dict_size * 5.5 + 64 MiB + */ + + LZMA_MF_HC4 = 0x04, + /**< + * \brief Hash Chain with 2-, 3-, and 4-byte hashing + * + * Minimum nice_len: 4 + * + * Memory usage: + * - dict_size <= 32 MiB: dict_size * 7.5 + * - dict_size > 32 MiB: dict_size * 6.5 + */ + + LZMA_MF_BT2 = 0x12, + /**< + * \brief Binary Tree with 2-byte hashing + * + * Minimum nice_len: 2 + * + * Memory usage: dict_size * 9.5 + */ + + LZMA_MF_BT3 = 0x13, + /**< + * \brief Binary Tree with 2- and 3-byte hashing + * + * Minimum nice_len: 3 + * + * Memory usage: + * - dict_size <= 16 MiB: dict_size * 11.5 + * - dict_size > 16 MiB: dict_size * 9.5 + 64 MiB + */ + + LZMA_MF_BT4 = 0x14 + /**< + * \brief Binary Tree with 2-, 3-, and 4-byte hashing + * + * Minimum nice_len: 4 + * + * Memory usage: + * - dict_size <= 32 MiB: dict_size * 11.5 + * - dict_size > 32 MiB: dict_size * 10.5 + */ } lzma_match_finder; - /** * \brief Test if given match finder is supported * @@ -126,8 +123,7 @@ typedef enum { * match finders don't need. */ extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder) - lzma_nothrow lzma_attr_const; - + lzma_nothrow lzma_attr_const; /** * \brief Compression modes @@ -136,25 +132,24 @@ extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder) * finder. */ typedef enum { - LZMA_MODE_FAST = 1, - /**< - * \brief Fast compression - * - * Fast mode is usually at its best when combined with - * a hash chain match finder. - */ - - LZMA_MODE_NORMAL = 2 - /**< - * \brief Normal compression - * - * This is usually notably slower than fast mode. Use this - * together with binary tree match finders to expose the - * full potential of the LZMA1 or LZMA2 encoder. - */ + LZMA_MODE_FAST = 1, + /**< + * \brief Fast compression + * + * Fast mode is usually at its best when combined with + * a hash chain match finder. + */ + + LZMA_MODE_NORMAL = 2 + /**< + * \brief Normal compression + * + * This is usually notably slower than fast mode. Use this + * together with binary tree match finders to expose the + * full potential of the LZMA1 or LZMA2 encoder. + */ } lzma_mode; - /** * \brief Test if given compression mode is supported * @@ -167,9 +162,8 @@ typedef enum { * mode, which the application developer wasn't aware, could require giving * additional options to the encoder that the older modes don't need. */ -extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode) - lzma_nothrow lzma_attr_const; - +extern LZMA_API(lzma_bool) + lzma_mode_is_supported(lzma_mode mode) lzma_nothrow lzma_attr_const; /** * \brief Options specific to the LZMA1 and LZMA2 filters @@ -183,222 +177,221 @@ extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode) * preset_dict_size (if preset_dict != NULL). LZMA1 needs also lc, lp, and pb. */ typedef struct { - /** - * \brief Dictionary size in bytes - * - * Dictionary size indicates how many bytes of the recently processed - * uncompressed data is kept in memory. One method to reduce size of - * the uncompressed data is to store distance-length pairs, which - * indicate what data to repeat from the dictionary buffer. Thus, - * the bigger the dictionary, the better the compression ratio - * usually is. - * - * Maximum size of the dictionary depends on multiple things: - * - Memory usage limit - * - Available address space (not a problem on 64-bit systems) - * - Selected match finder (encoder only) - * - * Currently the maximum dictionary size for encoding is 1.5 GiB - * (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit - * systems for certain match finder implementation reasons. In the - * future, there may be match finders that support bigger - * dictionaries. - * - * Decoder already supports dictionaries up to 4 GiB - 1 B (i.e. - * UINT32_MAX), so increasing the maximum dictionary size of the - * encoder won't cause problems for old decoders. - * - * Because extremely small dictionaries sizes would have unneeded - * overhead in the decoder, the minimum dictionary size is 4096 bytes. - * - * \note When decoding, too big dictionary does no other harm - * than wasting memory. - */ - uint32_t dict_size; -# define LZMA_DICT_SIZE_MIN UINT32_C(4096) -# define LZMA_DICT_SIZE_DEFAULT (UINT32_C(1) << 23) - - /** - * \brief Pointer to an initial dictionary - * - * It is possible to initialize the LZ77 history window using - * a preset dictionary. It is useful when compressing many - * similar, relatively small chunks of data independently from - * each other. The preset dictionary should contain typical - * strings that occur in the files being compressed. The most - * probable strings should be near the end of the preset dictionary. - * - * This feature should be used only in special situations. For - * now, it works correctly only with raw encoding and decoding. - * Currently none of the container formats supported by - * liblzma allow preset dictionary when decoding, thus if - * you create a .xz or .lzma file with preset dictionary, it - * cannot be decoded with the regular decoder functions. In the - * future, the .xz format will likely get support for preset - * dictionary though. - */ - const uint8_t *preset_dict; - - /** - * \brief Size of the preset dictionary - * - * Specifies the size of the preset dictionary. If the size is - * bigger than dict_size, only the last dict_size bytes are - * processed. - * - * This variable is read only when preset_dict is not NULL. - * If preset_dict is not NULL but preset_dict_size is zero, - * no preset dictionary is used (identical to only setting - * preset_dict to NULL). - */ - uint32_t preset_dict_size; - - /** - * \brief Number of literal context bits - * - * How many of the highest bits of the previous uncompressed - * eight-bit byte (also known as `literal') are taken into - * account when predicting the bits of the next literal. - * - * E.g. in typical English text, an upper-case letter is - * often followed by a lower-case letter, and a lower-case - * letter is usually followed by another lower-case letter. - * In the US-ASCII character set, the highest three bits are 010 - * for upper-case letters and 011 for lower-case letters. - * When lc is at least 3, the literal coding can take advantage of - * this property in the uncompressed data. - * - * There is a limit that applies to literal context bits and literal - * position bits together: lc + lp <= 4. Without this limit the - * decoding could become very slow, which could have security related - * results in some cases like email servers doing virus scanning. - * This limit also simplifies the internal implementation in liblzma. - * - * There may be LZMA1 streams that have lc + lp > 4 (maximum possible - * lc would be 8). It is not possible to decode such streams with - * liblzma. - */ - uint32_t lc; -# define LZMA_LCLP_MIN 0 -# define LZMA_LCLP_MAX 4 -# define LZMA_LC_DEFAULT 3 - - /** - * \brief Number of literal position bits - * - * lp affects what kind of alignment in the uncompressed data is - * assumed when encoding literals. A literal is a single 8-bit byte. - * See pb below for more information about alignment. - */ - uint32_t lp; -# define LZMA_LP_DEFAULT 0 - - /** - * \brief Number of position bits - * - * pb affects what kind of alignment in the uncompressed data is - * assumed in general. The default means four-byte alignment - * (2^ pb =2^2=4), which is often a good choice when there's - * no better guess. - * - * When the aligment is known, setting pb accordingly may reduce - * the file size a little. E.g. with text files having one-byte - * alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can - * improve compression slightly. For UTF-16 text, pb=1 is a good - * choice. If the alignment is an odd number like 3 bytes, pb=0 - * might be the best choice. - * - * Even though the assumed alignment can be adjusted with pb and - * lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment. - * It might be worth taking into account when designing file formats - * that are likely to be often compressed with LZMA1 or LZMA2. - */ - uint32_t pb; -# define LZMA_PB_MIN 0 -# define LZMA_PB_MAX 4 -# define LZMA_PB_DEFAULT 2 - - /** Compression mode */ - lzma_mode mode; - - /** - * \brief Nice length of a match - * - * This determines how many bytes the encoder compares from the match - * candidates when looking for the best match. Once a match of at - * least nice_len bytes long is found, the encoder stops looking for - * better candidates and encodes the match. (Naturally, if the found - * match is actually longer than nice_len, the actual length is - * encoded; it's not truncated to nice_len.) - * - * Bigger values usually increase the compression ratio and - * compression time. For most files, 32 to 128 is a good value, - * which gives very good compression ratio at good speed. - * - * The exact minimum value depends on the match finder. The maximum - * is 273, which is the maximum length of a match that LZMA1 and - * LZMA2 can encode. - */ - uint32_t nice_len; - - /** Match finder ID */ - lzma_match_finder mf; - - /** - * \brief Maximum search depth in the match finder - * - * For every input byte, match finder searches through the hash chain - * or binary tree in a loop, each iteration going one step deeper in - * the chain or tree. The searching stops if - * - a match of at least nice_len bytes long is found; - * - all match candidates from the hash chain or binary tree have - * been checked; or - * - maximum search depth is reached. - * - * Maximum search depth is needed to prevent the match finder from - * wasting too much time in case there are lots of short match - * candidates. On the other hand, stopping the search before all - * candidates have been checked can reduce compression ratio. - * - * Setting depth to zero tells liblzma to use an automatic default - * value, that depends on the selected match finder and nice_len. - * The default is in the range [4, 200] or so (it may vary between - * liblzma versions). - * - * Using a bigger depth value than the default can increase - * compression ratio in some cases. There is no strict maximum value, - * but high values (thousands or millions) should be used with care: - * the encoder could remain fast enough with typical input, but - * malicious input could cause the match finder to slow down - * dramatically, possibly creating a denial of service attack. - */ - uint32_t depth; - - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. You should not touch these, because the names - * of these variables may change. These are and will never be used - * with the currently supported options, so it is safe to leave these - * uninitialized. - */ - uint32_t reserved_int1; - uint32_t reserved_int2; - uint32_t reserved_int3; - uint32_t reserved_int4; - uint32_t reserved_int5; - uint32_t reserved_int6; - uint32_t reserved_int7; - uint32_t reserved_int8; - lzma_reserved_enum reserved_enum1; - lzma_reserved_enum reserved_enum2; - lzma_reserved_enum reserved_enum3; - lzma_reserved_enum reserved_enum4; - void *reserved_ptr1; - void *reserved_ptr2; + /** + * \brief Dictionary size in bytes + * + * Dictionary size indicates how many bytes of the recently processed + * uncompressed data is kept in memory. One method to reduce size of + * the uncompressed data is to store distance-length pairs, which + * indicate what data to repeat from the dictionary buffer. Thus, + * the bigger the dictionary, the better the compression ratio + * usually is. + * + * Maximum size of the dictionary depends on multiple things: + * - Memory usage limit + * - Available address space (not a problem on 64-bit systems) + * - Selected match finder (encoder only) + * + * Currently the maximum dictionary size for encoding is 1.5 GiB + * (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit + * systems for certain match finder implementation reasons. In the + * future, there may be match finders that support bigger + * dictionaries. + * + * Decoder already supports dictionaries up to 4 GiB - 1 B (i.e. + * UINT32_MAX), so increasing the maximum dictionary size of the + * encoder won't cause problems for old decoders. + * + * Because extremely small dictionaries sizes would have unneeded + * overhead in the decoder, the minimum dictionary size is 4096 bytes. + * + * \note When decoding, too big dictionary does no other harm + * than wasting memory. + */ + uint32_t dict_size; +#define LZMA_DICT_SIZE_MIN UINT32_C(4096) +#define LZMA_DICT_SIZE_DEFAULT (UINT32_C(1) << 23) + + /** + * \brief Pointer to an initial dictionary + * + * It is possible to initialize the LZ77 history window using + * a preset dictionary. It is useful when compressing many + * similar, relatively small chunks of data independently from + * each other. The preset dictionary should contain typical + * strings that occur in the files being compressed. The most + * probable strings should be near the end of the preset dictionary. + * + * This feature should be used only in special situations. For + * now, it works correctly only with raw encoding and decoding. + * Currently none of the container formats supported by + * liblzma allow preset dictionary when decoding, thus if + * you create a .xz or .lzma file with preset dictionary, it + * cannot be decoded with the regular decoder functions. In the + * future, the .xz format will likely get support for preset + * dictionary though. + */ + const uint8_t *preset_dict; + + /** + * \brief Size of the preset dictionary + * + * Specifies the size of the preset dictionary. If the size is + * bigger than dict_size, only the last dict_size bytes are + * processed. + * + * This variable is read only when preset_dict is not NULL. + * If preset_dict is not NULL but preset_dict_size is zero, + * no preset dictionary is used (identical to only setting + * preset_dict to NULL). + */ + uint32_t preset_dict_size; + + /** + * \brief Number of literal context bits + * + * How many of the highest bits of the previous uncompressed + * eight-bit byte (also known as `literal') are taken into + * account when predicting the bits of the next literal. + * + * E.g. in typical English text, an upper-case letter is + * often followed by a lower-case letter, and a lower-case + * letter is usually followed by another lower-case letter. + * In the US-ASCII character set, the highest three bits are 010 + * for upper-case letters and 011 for lower-case letters. + * When lc is at least 3, the literal coding can take advantage of + * this property in the uncompressed data. + * + * There is a limit that applies to literal context bits and literal + * position bits together: lc + lp <= 4. Without this limit the + * decoding could become very slow, which could have security related + * results in some cases like email servers doing virus scanning. + * This limit also simplifies the internal implementation in liblzma. + * + * There may be LZMA1 streams that have lc + lp > 4 (maximum possible + * lc would be 8). It is not possible to decode such streams with + * liblzma. + */ + uint32_t lc; +#define LZMA_LCLP_MIN 0 +#define LZMA_LCLP_MAX 4 +#define LZMA_LC_DEFAULT 3 + + /** + * \brief Number of literal position bits + * + * lp affects what kind of alignment in the uncompressed data is + * assumed when encoding literals. A literal is a single 8-bit byte. + * See pb below for more information about alignment. + */ + uint32_t lp; +#define LZMA_LP_DEFAULT 0 + + /** + * \brief Number of position bits + * + * pb affects what kind of alignment in the uncompressed data is + * assumed in general. The default means four-byte alignment + * (2^ pb =2^2=4), which is often a good choice when there's + * no better guess. + * + * When the aligment is known, setting pb accordingly may reduce + * the file size a little. E.g. with text files having one-byte + * alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can + * improve compression slightly. For UTF-16 text, pb=1 is a good + * choice. If the alignment is an odd number like 3 bytes, pb=0 + * might be the best choice. + * + * Even though the assumed alignment can be adjusted with pb and + * lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment. + * It might be worth taking into account when designing file formats + * that are likely to be often compressed with LZMA1 or LZMA2. + */ + uint32_t pb; +#define LZMA_PB_MIN 0 +#define LZMA_PB_MAX 4 +#define LZMA_PB_DEFAULT 2 + + /** Compression mode */ + lzma_mode mode; + + /** + * \brief Nice length of a match + * + * This determines how many bytes the encoder compares from the match + * candidates when looking for the best match. Once a match of at + * least nice_len bytes long is found, the encoder stops looking for + * better candidates and encodes the match. (Naturally, if the found + * match is actually longer than nice_len, the actual length is + * encoded; it's not truncated to nice_len.) + * + * Bigger values usually increase the compression ratio and + * compression time. For most files, 32 to 128 is a good value, + * which gives very good compression ratio at good speed. + * + * The exact minimum value depends on the match finder. The maximum + * is 273, which is the maximum length of a match that LZMA1 and + * LZMA2 can encode. + */ + uint32_t nice_len; + + /** Match finder ID */ + lzma_match_finder mf; + + /** + * \brief Maximum search depth in the match finder + * + * For every input byte, match finder searches through the hash chain + * or binary tree in a loop, each iteration going one step deeper in + * the chain or tree. The searching stops if + * - a match of at least nice_len bytes long is found; + * - all match candidates from the hash chain or binary tree have + * been checked; or + * - maximum search depth is reached. + * + * Maximum search depth is needed to prevent the match finder from + * wasting too much time in case there are lots of short match + * candidates. On the other hand, stopping the search before all + * candidates have been checked can reduce compression ratio. + * + * Setting depth to zero tells liblzma to use an automatic default + * value, that depends on the selected match finder and nice_len. + * The default is in the range [4, 200] or so (it may vary between + * liblzma versions). + * + * Using a bigger depth value than the default can increase + * compression ratio in some cases. There is no strict maximum value, + * but high values (thousands or millions) should be used with care: + * the encoder could remain fast enough with typical input, but + * malicious input could cause the match finder to slow down + * dramatically, possibly creating a denial of service attack. + */ + uint32_t depth; + + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. You should not touch these, because the names + * of these variables may change. These are and will never be used + * with the currently supported options, so it is safe to leave these + * uninitialized. + */ + uint32_t reserved_int1; + uint32_t reserved_int2; + uint32_t reserved_int3; + uint32_t reserved_int4; + uint32_t reserved_int5; + uint32_t reserved_int6; + uint32_t reserved_int7; + uint32_t reserved_int8; + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; + lzma_reserved_enum reserved_enum3; + lzma_reserved_enum reserved_enum4; + void *reserved_ptr1; + void *reserved_ptr2; } lzma_options_lzma; - /** * \brief Set a compression preset to lzma_options_lzma structure * @@ -416,5 +409,5 @@ typedef struct { * \return On success, false is returned. If the preset is not * supported, true is returned. */ -extern LZMA_API(lzma_bool) lzma_lzma_preset( - lzma_options_lzma *options, uint32_t preset) lzma_nothrow; +extern LZMA_API(lzma_bool) + lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset) lzma_nothrow; diff --git a/node_modules/lzma-native/deps/include/lzma/stream_flags.h b/node_modules/lzma-native/deps/include/lzma/stream_flags.h index 8454658..1214909 100644 --- a/node_modules/lzma-native/deps/include/lzma/stream_flags.h +++ b/node_modules/lzma-native/deps/include/lzma/stream_flags.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Size of Stream Header and Stream Footer * @@ -26,85 +25,83 @@ */ #define LZMA_STREAM_HEADER_SIZE 12 - /** * \brief Options for encoding/decoding Stream Header and Stream Footer */ typedef struct { - /** - * \brief Stream Flags format version - * - * To prevent API and ABI breakages if new features are needed in - * Stream Header or Stream Footer, a version number is used to - * indicate which fields in this structure are in use. For now, - * version must always be zero. With non-zero version, the - * lzma_stream_header_encode() and lzma_stream_footer_encode() - * will return LZMA_OPTIONS_ERROR. - * - * lzma_stream_header_decode() and lzma_stream_footer_decode() - * will always set this to the lowest value that supports all the - * features indicated by the Stream Flags field. The application - * must check that the version number set by the decoding functions - * is supported by the application. Otherwise it is possible that - * the application will decode the Stream incorrectly. - */ - uint32_t version; - - /** - * \brief Backward Size - * - * Backward Size must be a multiple of four bytes. In this Stream - * format version, Backward Size is the size of the Index field. - * - * Backward Size isn't actually part of the Stream Flags field, but - * it is convenient to include in this structure anyway. Backward - * Size is present only in the Stream Footer. There is no need to - * initialize backward_size when encoding Stream Header. - * - * lzma_stream_header_decode() always sets backward_size to - * LZMA_VLI_UNKNOWN so that it is convenient to use - * lzma_stream_flags_compare() when both Stream Header and Stream - * Footer have been decoded. - */ - lzma_vli backward_size; -# define LZMA_BACKWARD_SIZE_MIN 4 -# define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34) - - /** - * \brief Check ID - * - * This indicates the type of the integrity check calculated from - * uncompressed data. - */ - lzma_check check; - - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. You should not touch these, because the - * names of these variables may change. - * - * (We will never be able to use all of these since Stream Flags - * is just two bytes plus Backward Size of four bytes. But it's - * nice to have the proper types when they are needed.) - */ - lzma_reserved_enum reserved_enum1; - lzma_reserved_enum reserved_enum2; - lzma_reserved_enum reserved_enum3; - lzma_reserved_enum reserved_enum4; - lzma_bool reserved_bool1; - lzma_bool reserved_bool2; - lzma_bool reserved_bool3; - lzma_bool reserved_bool4; - lzma_bool reserved_bool5; - lzma_bool reserved_bool6; - lzma_bool reserved_bool7; - lzma_bool reserved_bool8; - uint32_t reserved_int1; - uint32_t reserved_int2; + /** + * \brief Stream Flags format version + * + * To prevent API and ABI breakages if new features are needed in + * Stream Header or Stream Footer, a version number is used to + * indicate which fields in this structure are in use. For now, + * version must always be zero. With non-zero version, the + * lzma_stream_header_encode() and lzma_stream_footer_encode() + * will return LZMA_OPTIONS_ERROR. + * + * lzma_stream_header_decode() and lzma_stream_footer_decode() + * will always set this to the lowest value that supports all the + * features indicated by the Stream Flags field. The application + * must check that the version number set by the decoding functions + * is supported by the application. Otherwise it is possible that + * the application will decode the Stream incorrectly. + */ + uint32_t version; + + /** + * \brief Backward Size + * + * Backward Size must be a multiple of four bytes. In this Stream + * format version, Backward Size is the size of the Index field. + * + * Backward Size isn't actually part of the Stream Flags field, but + * it is convenient to include in this structure anyway. Backward + * Size is present only in the Stream Footer. There is no need to + * initialize backward_size when encoding Stream Header. + * + * lzma_stream_header_decode() always sets backward_size to + * LZMA_VLI_UNKNOWN so that it is convenient to use + * lzma_stream_flags_compare() when both Stream Header and Stream + * Footer have been decoded. + */ + lzma_vli backward_size; +#define LZMA_BACKWARD_SIZE_MIN 4 +#define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34) + + /** + * \brief Check ID + * + * This indicates the type of the integrity check calculated from + * uncompressed data. + */ + lzma_check check; + + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. You should not touch these, because the + * names of these variables may change. + * + * (We will never be able to use all of these since Stream Flags + * is just two bytes plus Backward Size of four bytes. But it's + * nice to have the proper types when they are needed.) + */ + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; + lzma_reserved_enum reserved_enum3; + lzma_reserved_enum reserved_enum4; + lzma_bool reserved_bool1; + lzma_bool reserved_bool2; + lzma_bool reserved_bool3; + lzma_bool reserved_bool4; + lzma_bool reserved_bool5; + lzma_bool reserved_bool6; + lzma_bool reserved_bool7; + lzma_bool reserved_bool8; + uint32_t reserved_int1; + uint32_t reserved_int2; } lzma_stream_flags; - /** * \brief Encode Stream Header * @@ -119,10 +116,9 @@ typedef struct { * this liblzma version. * - LZMA_PROG_ERROR: Invalid options. */ -extern LZMA_API(lzma_ret) lzma_stream_header_encode( - const lzma_stream_flags *options, uint8_t *out) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Encode Stream Footer @@ -136,10 +132,9 @@ extern LZMA_API(lzma_ret) lzma_stream_header_encode( * this liblzma version. * - LZMA_PROG_ERROR: Invalid options. */ -extern LZMA_API(lzma_ret) lzma_stream_footer_encode( - const lzma_stream_flags *options, uint8_t *out) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Decode Stream Header @@ -171,10 +166,9 @@ extern LZMA_API(lzma_ret) lzma_stream_footer_encode( * LZMA_FORMAT_ERROR is returned by lzma_stream_header_decode() * when decoding non-first Stream. */ -extern LZMA_API(lzma_ret) lzma_stream_header_decode( - lzma_stream_flags *options, const uint8_t *in) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_stream_header_decode(lzma_stream_flags *options, const uint8_t *in) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Decode Stream Footer @@ -198,10 +192,9 @@ extern LZMA_API(lzma_ret) lzma_stream_header_decode( * is corrupt (possibly truncated). Stream decoder in liblzma * uses LZMA_DATA_ERROR in this situation. */ -extern LZMA_API(lzma_ret) lzma_stream_footer_decode( - lzma_stream_flags *options, const uint8_t *in) - lzma_nothrow lzma_attr_warn_unused_result; - +extern LZMA_API(lzma_ret) + lzma_stream_footer_decode(lzma_stream_flags *options, const uint8_t *in) + lzma_nothrow lzma_attr_warn_unused_result; /** * \brief Compare two lzma_stream_flags structures @@ -218,6 +211,6 @@ extern LZMA_API(lzma_ret) lzma_stream_footer_decode( * - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or * backward_size. */ -extern LZMA_API(lzma_ret) lzma_stream_flags_compare( - const lzma_stream_flags *a, const lzma_stream_flags *b) - lzma_nothrow lzma_attr_pure; +extern LZMA_API(lzma_ret) lzma_stream_flags_compare(const lzma_stream_flags *a, + const lzma_stream_flags *b) + lzma_nothrow lzma_attr_pure; diff --git a/node_modules/lzma-native/deps/include/lzma/version.h b/node_modules/lzma-native/deps/include/lzma/version.h index 6db2efb..f918477 100644 --- a/node_modules/lzma-native/deps/include/lzma/version.h +++ b/node_modules/lzma-native/deps/include/lzma/version.h @@ -13,10 +13,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /* * Version number split into components */ @@ -26,10 +25,9 @@ #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE #ifndef LZMA_VERSION_COMMIT -# define LZMA_VERSION_COMMIT "" +#define LZMA_VERSION_COMMIT "" #endif - /* * Map symbolic stability levels to integers. */ @@ -37,7 +35,6 @@ #define LZMA_VERSION_STABILITY_BETA 1 #define LZMA_VERSION_STABILITY_STABLE 2 - /** * \brief Compile-time version number * @@ -54,31 +51,29 @@ * \note The version number of liblzma has nothing to with * the version number of Igor Pavlov's LZMA SDK. */ -#define LZMA_VERSION (LZMA_VERSION_MAJOR * UINT32_C(10000000) \ - + LZMA_VERSION_MINOR * UINT32_C(10000) \ - + LZMA_VERSION_PATCH * UINT32_C(10) \ - + LZMA_VERSION_STABILITY) - +#define LZMA_VERSION \ + (LZMA_VERSION_MAJOR * UINT32_C(10000000) + \ + LZMA_VERSION_MINOR * UINT32_C(10000) + LZMA_VERSION_PATCH * UINT32_C(10) + \ + LZMA_VERSION_STABILITY) /* * Macros to construct the compile-time version string */ #if LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_ALPHA -# define LZMA_VERSION_STABILITY_STRING "alpha" +#define LZMA_VERSION_STABILITY_STRING "alpha" #elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_BETA -# define LZMA_VERSION_STABILITY_STRING "beta" +#define LZMA_VERSION_STABILITY_STRING "beta" #elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_STABLE -# define LZMA_VERSION_STABILITY_STRING "" +#define LZMA_VERSION_STABILITY_STRING "" #else -# error Incorrect LZMA_VERSION_STABILITY +#error Incorrect LZMA_VERSION_STABILITY #endif -#define LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) \ - #major "." #minor "." #patch stability commit - -#define LZMA_VERSION_STRING_C(major, minor, patch, stability, commit) \ - LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) +#define LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) \ + #major "." #minor "." #patch stability commit +#define LZMA_VERSION_STRING_C(major, minor, patch, stability, commit) \ + LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) /** * \brief Compile-time version as a string @@ -89,11 +84,10 @@ * "4.999.8beta-21-g1d92". The commit ID won't be available in numeric form * in LZMA_VERSION macro. */ -#define LZMA_VERSION_STRING LZMA_VERSION_STRING_C( \ - LZMA_VERSION_MAJOR, LZMA_VERSION_MINOR, \ - LZMA_VERSION_PATCH, LZMA_VERSION_STABILITY_STRING, \ - LZMA_VERSION_COMMIT) - +#define LZMA_VERSION_STRING \ + LZMA_VERSION_STRING_C(LZMA_VERSION_MAJOR, LZMA_VERSION_MINOR, \ + LZMA_VERSION_PATCH, LZMA_VERSION_STABILITY_STRING, \ + LZMA_VERSION_COMMIT) /* #ifndef is needed for use with windres (MinGW or Cygwin). */ #ifndef LZMA_H_INTERNAL_RC @@ -105,9 +99,8 @@ * This allows the application to compare if it was built against the same, * older, or newer version of liblzma that is currently running. */ -extern LZMA_API(uint32_t) lzma_version_number(void) - lzma_nothrow lzma_attr_const; - +extern LZMA_API(uint32_t) + lzma_version_number(void) lzma_nothrow lzma_attr_const; /** * \brief Run-time version as a string @@ -115,7 +108,7 @@ extern LZMA_API(uint32_t) lzma_version_number(void) * This function may be useful if you want to display which version of * liblzma your application is currently using. */ -extern LZMA_API(const char *) lzma_version_string(void) - lzma_nothrow lzma_attr_const; +extern LZMA_API(const char *) + lzma_version_string(void) lzma_nothrow lzma_attr_const; #endif diff --git a/node_modules/lzma-native/deps/include/lzma/vli.h b/node_modules/lzma-native/deps/include/lzma/vli.h index bcb7b2d..142f1c4 100644 --- a/node_modules/lzma-native/deps/include/lzma/vli.h +++ b/node_modules/lzma-native/deps/include/lzma/vli.h @@ -24,10 +24,9 @@ */ #ifndef LZMA_H_INTERNAL -# error Never include this file directly. Use instead. +#error Never include this file directly. Use instead. #endif - /** * \brief Maximum supported value of a variable-length integer */ @@ -48,7 +47,6 @@ */ #define LZMA_VLI_C(n) UINT64_C(n) - /** * \brief Variable-length integer type * @@ -62,7 +60,6 @@ */ typedef uint64_t lzma_vli; - /** * \brief Validate a variable-length integer * @@ -72,9 +69,8 @@ typedef uint64_t lzma_vli; * \return True if the integer is representable as VLI or if it * indicates unknown value. */ -#define lzma_vli_is_valid(vli) \ - ((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN) - +#define lzma_vli_is_valid(vli) \ + ((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN) /** * \brief Encode a variable-length integer @@ -112,9 +108,9 @@ typedef uint64_t lzma_vli; * - LZMA_BUF_ERROR: No output space was provided. * - LZMA_PROG_ERROR: Arguments are not sane. */ -extern LZMA_API(lzma_ret) lzma_vli_encode(lzma_vli vli, size_t *vli_pos, - uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_vli_encode(lzma_vli vli, size_t *vli_pos, uint8_t *out, + size_t *out_pos, size_t out_size) lzma_nothrow; /** * \brief Decode a variable-length integer @@ -151,10 +147,9 @@ extern LZMA_API(lzma_ret) lzma_vli_encode(lzma_vli vli, size_t *vli_pos, * - LZMA_BUF_ERROR: No input was provided. * - LZMA_PROG_ERROR: Arguments are not sane. */ -extern LZMA_API(lzma_ret) lzma_vli_decode(lzma_vli *vli, size_t *vli_pos, - const uint8_t *in, size_t *in_pos, size_t in_size) - lzma_nothrow; - +extern LZMA_API(lzma_ret) + lzma_vli_decode(lzma_vli *vli, size_t *vli_pos, const uint8_t *in, + size_t *in_pos, size_t in_size) lzma_nothrow; /** * \brief Get the number of bytes required to encode a VLI @@ -162,5 +157,5 @@ extern LZMA_API(lzma_ret) lzma_vli_decode(lzma_vli *vli, size_t *vli_pos, * \return Number of bytes on success (1-9). If vli isn't valid, * zero is returned. */ -extern LZMA_API(uint32_t) lzma_vli_size(lzma_vli vli) - lzma_nothrow lzma_attr_pure; +extern LZMA_API(uint32_t) + lzma_vli_size(lzma_vli vli) lzma_nothrow lzma_attr_pure; diff --git a/node_modules/lzma-native/src/filter-array.cpp b/node_modules/lzma-native/src/filter-array.cpp index 4e2219d..7034899 100644 --- a/node_modules/lzma-native/src/filter-array.cpp +++ b/node_modules/lzma-native/src/filter-array.cpp @@ -4,59 +4,65 @@ namespace lzma { FilterArray::FilterArray(Local arr) : ok_(false) { Nan::HandleScope(); - + if (!arr->IsArray() || arr.IsEmpty()) { Nan::ThrowTypeError("Filter array expected"); return; } - + size_t len = arr->Length(); - + Local id_ = NewString("id"); Local options_ = NewString("options"); - + for (size_t i = 0; i < len; ++i) { - Local entry = Local::Cast(EmptyToUndefined(Nan::Get(arr, i))); - if (entry.IsEmpty() || entry->IsUndefined() || entry->IsNull() || !Nan::Has(entry, id_).ToChecked()) { + Local entry = + Local::Cast(EmptyToUndefined(Nan::Get(arr, i))); + if (entry.IsEmpty() || entry->IsUndefined() || entry->IsNull() || + !Nan::Has(entry, id_).ToChecked()) { Nan::ThrowTypeError("Filter array needs object entries"); return; } - - Local id = Local::Cast(EmptyToUndefined(Nan::Get(entry, id_))); - Local opt = Local::Cast(EmptyToUndefined(Nan::Get(entry, options_))); - + + Local id = + Local::Cast(EmptyToUndefined(Nan::Get(entry, id_))); + Local opt = + Local::Cast(EmptyToUndefined(Nan::Get(entry, options_))); + lzma_filter f; f.id = FilterByName(id); f.options = NULL; - + if ((opt.IsEmpty() || opt->IsUndefined() || opt->IsNull()) && - (f.id != LZMA_FILTER_LZMA1 && f.id != LZMA_FILTER_LZMA2)) { + (f.id != LZMA_FILTER_LZMA1 && f.id != LZMA_FILTER_LZMA2)) { filters.push_back(f); continue; } - + optbuf.push_back(options()); - union options& bopt = optbuf.back(); - + union options &bopt = optbuf.back(); + switch (f.id) { - case LZMA_FILTER_DELTA: - bopt.delta.type = (lzma_delta_type) GetIntegerProperty(opt, "type", LZMA_DELTA_TYPE_BYTE); - bopt.delta.dist = GetIntegerProperty(opt, "dist", 1); - f.options = &bopt.delta; - break; - case LZMA_FILTER_LZMA1: - case LZMA_FILTER_LZMA2: - bopt.lzma = parseOptionsLZMA(opt); - f.options = &bopt.lzma; - break; - default: - Nan::ThrowTypeError("LZMA wrapper library understands .options only for DELTA and LZMA1, LZMA2 filters"); - return; + case LZMA_FILTER_DELTA: + bopt.delta.type = (lzma_delta_type)GetIntegerProperty( + opt, "type", LZMA_DELTA_TYPE_BYTE); + bopt.delta.dist = GetIntegerProperty(opt, "dist", 1); + f.options = &bopt.delta; + break; + case LZMA_FILTER_LZMA1: + case LZMA_FILTER_LZMA2: + bopt.lzma = parseOptionsLZMA(opt); + f.options = &bopt.lzma; + break; + default: + Nan::ThrowTypeError("LZMA wrapper library understands .options only for " + "DELTA and LZMA1, LZMA2 filters"); + return; } - + filters.push_back(f); } - + finish(); } @@ -67,4 +73,4 @@ void FilterArray::finish() { ok_ = true; } -} +} // namespace lzma diff --git a/node_modules/lzma-native/src/index-parser.cpp b/node_modules/lzma-native/src/index-parser.cpp index ca88c56..df40509 100644 --- a/node_modules/lzma-native/src/index-parser.cpp +++ b/node_modules/lzma-native/src/index-parser.cpp @@ -11,421 +11,400 @@ namespace lzma { -void * -lzma_alloc(size_t size, const lzma_allocator *allocator) -{ - // Some malloc() variants return NULL if called with size == 0. - if (size == 0) - size = 1; +void *lzma_alloc(size_t size, const lzma_allocator *allocator) { + // Some malloc() variants return NULL if called with size == 0. + if (size == 0) + size = 1; - void *ptr; + void *ptr; - if (allocator != NULL && allocator->alloc != NULL) - ptr = allocator->alloc(allocator->opaque, 1, size); - else - ptr = malloc(size); + if (allocator != NULL && allocator->alloc != NULL) + ptr = allocator->alloc(allocator->opaque, 1, size); + else + ptr = malloc(size); - return ptr; + return ptr; } -void -lzma_free(void *ptr, const lzma_allocator *allocator) -{ - if (allocator != NULL && allocator->free != NULL) - allocator->free(allocator->opaque, ptr); - else - free(ptr); +void lzma_free(void *ptr, const lzma_allocator *allocator) { + if (allocator != NULL && allocator->free != NULL) + allocator->free(allocator->opaque, ptr); + else + free(ptr); - return; + return; } enum lip_state { - PARSE_INDEX_INITED, - PARSE_INDEX_READ_FOOTER, - PARSE_INDEX_READ_INDEX, - PARSE_INDEX_READ_STREAM_HEADER + PARSE_INDEX_INITED, + PARSE_INDEX_READ_FOOTER, + PARSE_INDEX_READ_INDEX, + PARSE_INDEX_READ_STREAM_HEADER }; struct lzma_index_parser_internal_s { - /// Current state. - lip_state state; + /// Current state. + lip_state state; - /// Current position in the file. We parse the file backwards so - /// initialize it to point to the end of the file. - int64_t pos; + /// Current position in the file. We parse the file backwards so + /// initialize it to point to the end of the file. + int64_t pos; - /// The footer flags of the current XZ stream. - lzma_stream_flags footer_flags; + /// The footer flags of the current XZ stream. + lzma_stream_flags footer_flags; - /// All Indexes decoded so far. - lzma_index *combined_index; + /// All Indexes decoded so far. + lzma_index *combined_index; - /// The Index currently being decoded. - lzma_index *this_index; + /// The Index currently being decoded. + lzma_index *this_index; - /// Padding of the stream currently being decoded. - lzma_vli stream_padding; + /// Padding of the stream currently being decoded. + lzma_vli stream_padding; - /// Size of the Index currently being decoded. - lzma_vli index_size; + /// Size of the Index currently being decoded. + lzma_vli index_size; - /// Keep track of how much memory is being used for Index decoding. - uint64_t memused; + /// Keep track of how much memory is being used for Index decoding. + uint64_t memused; - /// lzma_stream for the Index decoder. - lzma_stream strm; + /// lzma_stream for the Index decoder. + lzma_stream strm; - /// Keep the buffer coming as the last member to so all data that is - /// ever actually used fits in a few cache lines. - uint8_t buf[8192]; + /// Keep the buffer coming as the last member to so all data that is + /// ever actually used fits in a few cache lines. + uint8_t buf[8192]; }; -static lzma_ret -parse_indexes_read(lzma_index_parser_data *info, - uint8_t *buf, - size_t size, - int64_t pos) -{ - int64_t read = info->read_callback(info->opaque, buf, size, pos); +static lzma_ret parse_indexes_read(lzma_index_parser_data *info, uint8_t *buf, + size_t size, int64_t pos) { + int64_t read = info->read_callback(info->opaque, buf, size, pos); - if (read < 0) { - return LZMA_DATA_ERROR; - } + if (read < 0) { + return LZMA_DATA_ERROR; + } - if ((size_t)read != size) { - info->message = "Unexpected end of file"; - return LZMA_DATA_ERROR; - } + if ((size_t)read != size) { + info->message = "Unexpected end of file"; + return LZMA_DATA_ERROR; + } - return LZMA_OK; + return LZMA_OK; } extern lzma_ret -my_lzma_parse_indexes_from_file(lzma_index_parser_data *info) lzma_nothrow -{ - lzma_ret ret; - lzma_index_parser_internal *internal = info->internal; - info->message = NULL; - - // Apparently, we are already done. - if (info->index != NULL) { - ret = LZMA_PROG_ERROR; - goto error; - } - - // Passing file_size == SIZE_MAX can be used to safely clean up - // everything when I/O failed asynchronously. - if (info->file_size == SIZE_MAX) { - ret = LZMA_OPTIONS_ERROR; - goto error; - } - - if (info->memlimit == 0) { - info->memlimit = UINT64_MAX; - } - - if (internal == NULL) { - if (info->memlimit <= sizeof(lzma_index_parser_internal)) { - // We don't really have a good figure for how much - // memory may be necessary. Set memlimit to 0 to - // indicate that something is obviously inacceptable. - info->memlimit = 0; - return LZMA_MEMLIMIT_ERROR; - } - - internal = (lzma_index_parser_internal*)lzma_alloc(sizeof(lzma_index_parser_internal), - info->allocator); - - if (internal == NULL) - return LZMA_MEM_ERROR; - - internal->state = PARSE_INDEX_INITED; - internal->pos = info->file_size; - internal->combined_index = NULL; - internal->this_index = NULL; - info->internal = internal; - - lzma_stream strm_ = LZMA_STREAM_INIT; - memcpy(&internal->strm, &strm_, sizeof(lzma_stream)); - internal->strm.allocator = info->allocator; - } - - // The header flags of the current stream are only ever used within a - // call and don't need to go into the internals struct. - lzma_stream_flags header_flags; - - int i; - uint64_t memlimit; - - switch (internal->state) { -case PARSE_INDEX_INITED: - if (info->file_size <= 0) { - // These strings are fixed so they can be translated by the xz - // command line utility. - info->message = "File is empty"; - return LZMA_DATA_ERROR; - } - - if (info->file_size < 2 * LZMA_STREAM_HEADER_SIZE) { - info->message = "Too small to be a valid .xz file"; - return LZMA_DATA_ERROR; - } - - // Each loop iteration decodes one Index. - do { - // Check that there is enough data left to contain at least - // the Stream Header and Stream Footer. This check cannot - // fail in the first pass of this loop. - if (internal->pos < 2 * LZMA_STREAM_HEADER_SIZE) { - ret = LZMA_DATA_ERROR; - goto error; - } - - internal->pos -= LZMA_STREAM_HEADER_SIZE; - internal->stream_padding = 0; - - // Locate the Stream Footer. There may be Stream Padding which - // we must skip when reading backwards. - while (true) { - if (internal->pos < LZMA_STREAM_HEADER_SIZE) { - ret = LZMA_DATA_ERROR; - goto error; - } - - ret = parse_indexes_read(info, - internal->buf, - LZMA_STREAM_HEADER_SIZE, - internal->pos); - - if (ret != LZMA_OK) - goto error; - internal->state = PARSE_INDEX_READ_FOOTER; - if (info->async) return LZMA_OK; -case PARSE_INDEX_READ_FOOTER: - - // Stream Padding is always a multiple of four bytes. - i = 2; - if (((uint32_t *)internal->buf)[i] != 0) - break; - - // To avoid calling the read callback for every four - // bytes of Stream Padding, take advantage that we - // read 12 bytes (LZMA_STREAM_HEADER_SIZE) already - // and check them too before calling the read - // callback again. - do { - internal->stream_padding += 4; - internal->pos -= 4; - --i; - } while (i >= 0 && ((uint32_t *)internal->buf)[i] == 0); - } - - // Decode the Stream Footer. - ret = lzma_stream_footer_decode(&internal->footer_flags, - internal->buf); - if (ret != LZMA_OK) { - goto error; - } - - // Check that the Stream Footer doesn't specify something - // that we don't support. This can only happen if the xz - // version is older than liblzma and liblzma supports - // something new. - // - // It is enough to check Stream Footer. Stream Header must - // match when it is compared against Stream Footer with - // lzma_stream_flags_compare(). - if (internal->footer_flags.version != 0) { - ret = LZMA_OPTIONS_ERROR; - goto error; - } - - // Check that the size of the Index field looks sane. - internal->index_size = internal->footer_flags.backward_size; - if ((lzma_vli)(internal->pos) < - internal->index_size + - LZMA_STREAM_HEADER_SIZE) { - ret = LZMA_DATA_ERROR; - goto error; - } - - // Set pos to the beginning of the Index. - internal->pos -= internal->index_size; - - // See how much memory we can use for decoding this Index. - memlimit = info->memlimit; - internal->memused = sizeof(lzma_index_parser_internal); - if (internal->combined_index != NULL) { - internal->memused = lzma_index_memused( - internal->combined_index); - assert(internal->memused <= memlimit); - - memlimit -= internal->memused; - } - - // Decode the Index. - ret = lzma_index_decoder(&internal->strm, - &internal->this_index, - memlimit); - if (ret != LZMA_OK) { - goto error; - } - - do { - // Don't give the decoder more input than the - // Index size. - internal->strm.avail_in = my_min(sizeof(internal->buf), - internal->index_size); - - ret = parse_indexes_read(info, - internal->buf, - internal->strm.avail_in, - internal->pos); - - if (ret != LZMA_OK) - goto error; - internal->state = PARSE_INDEX_READ_INDEX; - if (info->async) return LZMA_OK; -case PARSE_INDEX_READ_INDEX: - - internal->pos += internal->strm.avail_in; - internal->index_size -= internal->strm.avail_in; - - internal->strm.next_in = internal->buf; - ret = lzma_code(&internal->strm, LZMA_RUN); - - } while (ret == LZMA_OK); - - // If the decoding seems to be successful, check also that - // the Index decoder consumed as much input as indicated - // by the Backward Size field. - if (ret == LZMA_STREAM_END && ( - internal->index_size != 0 || - internal->strm.avail_in != 0)) { - ret = LZMA_DATA_ERROR; - } - - if (ret != LZMA_STREAM_END) { - // LZMA_BUFFER_ERROR means that the Index decoder - // would have liked more input than what the Index - // size should be according to Stream Footer. - // The message for LZMA_DATA_ERROR makes more - // sense in that case. - if (ret == LZMA_BUF_ERROR) - ret = LZMA_DATA_ERROR; - - // If the error was too low memory usage limit, - // indicate also how much memory would have been needed. - if (ret == LZMA_MEMLIMIT_ERROR) { - uint64_t needed = lzma_memusage( - &internal->strm); - if (UINT64_MAX - needed < internal->memused) - needed = UINT64_MAX; - else - needed += internal->memused; - - info->memlimit = needed; - } - - goto error; - } - - // Decode the Stream Header and check that its Stream Flags - // match the Stream Footer. - internal->pos -= internal->footer_flags.backward_size; - internal->pos -= LZMA_STREAM_HEADER_SIZE; - if ((lzma_vli)(internal->pos) < - lzma_index_total_size(internal->this_index)) { - ret = LZMA_DATA_ERROR; - goto error; - } - - internal->pos -= lzma_index_total_size(internal->this_index); - - ret = parse_indexes_read(info, - internal->buf, - LZMA_STREAM_HEADER_SIZE, - internal->pos); - - if (ret != LZMA_OK) - goto error; - - internal->state = PARSE_INDEX_READ_STREAM_HEADER; - if (info->async) return LZMA_OK; -case PARSE_INDEX_READ_STREAM_HEADER: - - ret = lzma_stream_header_decode(&header_flags, internal->buf); - if (ret != LZMA_OK) { - goto error; - } - - ret = lzma_stream_flags_compare(&header_flags, - &internal->footer_flags); - if (ret != LZMA_OK) { - goto error; - } - - // Store the decoded Stream Flags into this_index. This is - // needed so that we can print which Check is used in each - // Stream. - ret = lzma_index_stream_flags(internal->this_index, - &internal->footer_flags); - assert(ret == LZMA_OK); - - // Store also the size of the Stream Padding field. It is - // needed to show the offsets of the Streams correctly. - ret = lzma_index_stream_padding(internal->this_index, - internal->stream_padding); - assert(ret == LZMA_OK); - - if (internal->combined_index != NULL) { - // Append the earlier decoded Indexes - // after this_index. - ret = lzma_index_cat( - internal->this_index, - internal->combined_index, - info->allocator); - if (ret != LZMA_OK) { - goto error; - } - } - - internal->combined_index = internal->this_index; - internal->this_index = NULL; - - info->stream_padding += internal->stream_padding; - - } while (internal->pos > 0); - - lzma_end(&internal->strm); - - // All OK. Make combined_index available to the caller. - info->index = internal->combined_index; - - lzma_free(internal, info->allocator); - info->internal = NULL; - return LZMA_STREAM_END; -} // end switch(internal->state) +my_lzma_parse_indexes_from_file(lzma_index_parser_data *info) lzma_nothrow { + lzma_ret ret; + lzma_index_parser_internal *internal = info->internal; + info->message = NULL; + + // Apparently, we are already done. + if (info->index != NULL) { + ret = LZMA_PROG_ERROR; + goto error; + } + + // Passing file_size == SIZE_MAX can be used to safely clean up + // everything when I/O failed asynchronously. + if (info->file_size == SIZE_MAX) { + ret = LZMA_OPTIONS_ERROR; + goto error; + } + + if (info->memlimit == 0) { + info->memlimit = UINT64_MAX; + } + + if (internal == NULL) { + if (info->memlimit <= sizeof(lzma_index_parser_internal)) { + // We don't really have a good figure for how much + // memory may be necessary. Set memlimit to 0 to + // indicate that something is obviously inacceptable. + info->memlimit = 0; + return LZMA_MEMLIMIT_ERROR; + } + + internal = (lzma_index_parser_internal *)lzma_alloc( + sizeof(lzma_index_parser_internal), info->allocator); + + if (internal == NULL) + return LZMA_MEM_ERROR; + + internal->state = PARSE_INDEX_INITED; + internal->pos = info->file_size; + internal->combined_index = NULL; + internal->this_index = NULL; + info->internal = internal; + + lzma_stream strm_ = LZMA_STREAM_INIT; + memcpy(&internal->strm, &strm_, sizeof(lzma_stream)); + internal->strm.allocator = info->allocator; + } + + // The header flags of the current stream are only ever used within a + // call and don't need to go into the internals struct. + lzma_stream_flags header_flags; + + int i; + uint64_t memlimit; + + switch (internal->state) { + case PARSE_INDEX_INITED: + if (info->file_size <= 0) { + // These strings are fixed so they can be translated by the xz + // command line utility. + info->message = "File is empty"; + return LZMA_DATA_ERROR; + } + + if (info->file_size < 2 * LZMA_STREAM_HEADER_SIZE) { + info->message = "Too small to be a valid .xz file"; + return LZMA_DATA_ERROR; + } + + // Each loop iteration decodes one Index. + do { + // Check that there is enough data left to contain at least + // the Stream Header and Stream Footer. This check cannot + // fail in the first pass of this loop. + if (internal->pos < 2 * LZMA_STREAM_HEADER_SIZE) { + ret = LZMA_DATA_ERROR; + goto error; + } + + internal->pos -= LZMA_STREAM_HEADER_SIZE; + internal->stream_padding = 0; + + // Locate the Stream Footer. There may be Stream Padding which + // we must skip when reading backwards. + while (true) { + if (internal->pos < LZMA_STREAM_HEADER_SIZE) { + ret = LZMA_DATA_ERROR; + goto error; + } + + ret = parse_indexes_read(info, internal->buf, LZMA_STREAM_HEADER_SIZE, + internal->pos); + + if (ret != LZMA_OK) + goto error; + internal->state = PARSE_INDEX_READ_FOOTER; + if (info->async) + return LZMA_OK; + case PARSE_INDEX_READ_FOOTER: + + // Stream Padding is always a multiple of four bytes. + i = 2; + if (((uint32_t *)internal->buf)[i] != 0) + break; + + // To avoid calling the read callback for every four + // bytes of Stream Padding, take advantage that we + // read 12 bytes (LZMA_STREAM_HEADER_SIZE) already + // and check them too before calling the read + // callback again. + do { + internal->stream_padding += 4; + internal->pos -= 4; + --i; + } while (i >= 0 && ((uint32_t *)internal->buf)[i] == 0); + } + + // Decode the Stream Footer. + ret = lzma_stream_footer_decode(&internal->footer_flags, internal->buf); + if (ret != LZMA_OK) { + goto error; + } + + // Check that the Stream Footer doesn't specify something + // that we don't support. This can only happen if the xz + // version is older than liblzma and liblzma supports + // something new. + // + // It is enough to check Stream Footer. Stream Header must + // match when it is compared against Stream Footer with + // lzma_stream_flags_compare(). + if (internal->footer_flags.version != 0) { + ret = LZMA_OPTIONS_ERROR; + goto error; + } + + // Check that the size of the Index field looks sane. + internal->index_size = internal->footer_flags.backward_size; + if ((lzma_vli)(internal->pos) < + internal->index_size + LZMA_STREAM_HEADER_SIZE) { + ret = LZMA_DATA_ERROR; + goto error; + } + + // Set pos to the beginning of the Index. + internal->pos -= internal->index_size; + + // See how much memory we can use for decoding this Index. + memlimit = info->memlimit; + internal->memused = sizeof(lzma_index_parser_internal); + if (internal->combined_index != NULL) { + internal->memused = lzma_index_memused(internal->combined_index); + assert(internal->memused <= memlimit); + + memlimit -= internal->memused; + } + + // Decode the Index. + ret = + lzma_index_decoder(&internal->strm, &internal->this_index, memlimit); + if (ret != LZMA_OK) { + goto error; + } + + do { + // Don't give the decoder more input than the + // Index size. + internal->strm.avail_in = + my_min(sizeof(internal->buf), internal->index_size); + + ret = parse_indexes_read(info, internal->buf, internal->strm.avail_in, + internal->pos); + + if (ret != LZMA_OK) + goto error; + internal->state = PARSE_INDEX_READ_INDEX; + if (info->async) + return LZMA_OK; + case PARSE_INDEX_READ_INDEX: + + internal->pos += internal->strm.avail_in; + internal->index_size -= internal->strm.avail_in; + + internal->strm.next_in = internal->buf; + ret = lzma_code(&internal->strm, LZMA_RUN); + + } while (ret == LZMA_OK); + + // If the decoding seems to be successful, check also that + // the Index decoder consumed as much input as indicated + // by the Backward Size field. + if (ret == LZMA_STREAM_END && + (internal->index_size != 0 || internal->strm.avail_in != 0)) { + ret = LZMA_DATA_ERROR; + } + + if (ret != LZMA_STREAM_END) { + // LZMA_BUFFER_ERROR means that the Index decoder + // would have liked more input than what the Index + // size should be according to Stream Footer. + // The message for LZMA_DATA_ERROR makes more + // sense in that case. + if (ret == LZMA_BUF_ERROR) + ret = LZMA_DATA_ERROR; + + // If the error was too low memory usage limit, + // indicate also how much memory would have been needed. + if (ret == LZMA_MEMLIMIT_ERROR) { + uint64_t needed = lzma_memusage(&internal->strm); + if (UINT64_MAX - needed < internal->memused) + needed = UINT64_MAX; + else + needed += internal->memused; + + info->memlimit = needed; + } + + goto error; + } + + // Decode the Stream Header and check that its Stream Flags + // match the Stream Footer. + internal->pos -= internal->footer_flags.backward_size; + internal->pos -= LZMA_STREAM_HEADER_SIZE; + if ((lzma_vli)(internal->pos) < + lzma_index_total_size(internal->this_index)) { + ret = LZMA_DATA_ERROR; + goto error; + } + + internal->pos -= lzma_index_total_size(internal->this_index); + + ret = parse_indexes_read(info, internal->buf, LZMA_STREAM_HEADER_SIZE, + internal->pos); + + if (ret != LZMA_OK) + goto error; + + internal->state = PARSE_INDEX_READ_STREAM_HEADER; + if (info->async) + return LZMA_OK; + case PARSE_INDEX_READ_STREAM_HEADER: + + ret = lzma_stream_header_decode(&header_flags, internal->buf); + if (ret != LZMA_OK) { + goto error; + } + + ret = lzma_stream_flags_compare(&header_flags, &internal->footer_flags); + if (ret != LZMA_OK) { + goto error; + } + + // Store the decoded Stream Flags into this_index. This is + // needed so that we can print which Check is used in each + // Stream. + ret = lzma_index_stream_flags(internal->this_index, + &internal->footer_flags); + assert(ret == LZMA_OK); + + // Store also the size of the Stream Padding field. It is + // needed to show the offsets of the Streams correctly. + ret = lzma_index_stream_padding(internal->this_index, + internal->stream_padding); + assert(ret == LZMA_OK); + + if (internal->combined_index != NULL) { + // Append the earlier decoded Indexes + // after this_index. + ret = lzma_index_cat(internal->this_index, internal->combined_index, + info->allocator); + if (ret != LZMA_OK) { + goto error; + } + } + + internal->combined_index = internal->this_index; + internal->this_index = NULL; + + info->stream_padding += internal->stream_padding; + + } while (internal->pos > 0); + + lzma_end(&internal->strm); + + // All OK. Make combined_index available to the caller. + info->index = internal->combined_index; + + lzma_free(internal, info->allocator); + info->internal = NULL; + return LZMA_STREAM_END; + } // end switch(internal->state) error: - // Something went wrong, free the allocated memory. - if (internal) { - lzma_end(&internal->strm); - lzma_index_end(internal->combined_index, info->allocator); - lzma_index_end(internal->this_index, info->allocator); - lzma_free(internal, info->allocator); - } - - info->internal = NULL; - - // Doing this will prevent people from calling lzma_parse_indexes_from_file() - // again without re-initializing. - info->file_size = SIZE_MAX; - return ret; -} + // Something went wrong, free the allocated memory. + if (internal) { + lzma_end(&internal->strm); + lzma_index_end(internal->combined_index, info->allocator); + lzma_index_end(internal->this_index, info->allocator); + lzma_free(internal, info->allocator); + } + + info->internal = NULL; + // Doing this will prevent people from calling lzma_parse_indexes_from_file() + // again without re-initializing. + info->file_size = SIZE_MAX; + return ret; } +} // namespace lzma + #include "liblzma-node.hpp" namespace lzma { @@ -434,76 +413,77 @@ void IndexParser::Init(Local exports) { Local tpl = Nan::New(New); tpl->SetClassName(NewString("IndexParser")); tpl->InstanceTemplate()->SetInternalFieldCount(1); - + Nan::SetPrototypeMethod(tpl, "init", Init); Nan::SetPrototypeMethod(tpl, "feed", Feed); Nan::SetPrototypeMethod(tpl, "parse", Parse); - + constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked()); Nan::Set(exports, NewString("IndexParser"), Nan::New(constructor)); } NAN_METHOD(IndexParser::New) { if (info.IsConstructCall()) { - IndexParser* self = new IndexParser(); + IndexParser *self = new IndexParser(); if (!self) { Nan::ThrowRangeError("Out of memory, cannot create IndexParser"); info.GetReturnValue().SetUndefined(); return; } - + self->Wrap(info.This()); - + info.GetReturnValue().Set(info.This()); } else { - info.GetReturnValue().Set(Nan::NewInstance(Nan::New(constructor), 0, NULL).ToLocalChecked()); + info.GetReturnValue().Set( + Nan::NewInstance(Nan::New(constructor), 0, NULL) + .ToLocalChecked()); } } namespace { - extern "C" int64_t LZMA_API_CALL - read_cb(void* opaque, uint8_t* buf, size_t count, int64_t offset) { - IndexParser* p = static_cast(opaque); - return p->readCallback(opaque, buf, count, offset); - } - - extern "C" void* LZMA_API_CALL - alloc_for_lzma_index(void *opaque, size_t nmemb, size_t size) { - size_t nBytes = nmemb * size + sizeof(size_t); - - size_t* result = static_cast(::malloc(nBytes)); - if (!result) - return result; - - *result = nBytes; - Nan::AdjustExternalMemory(static_cast(nBytes)); - return static_cast(result + 1); - } - - extern "C" void LZMA_API_CALL - free_for_lzma_index(void *opaque, void *ptr) { - if (!ptr) - return; - - size_t* orig = static_cast(ptr) - 1; - - Nan::AdjustExternalMemory(-static_cast(*orig)); - return ::free(static_cast(orig)); - } +extern "C" int64_t LZMA_API_CALL read_cb(void *opaque, uint8_t *buf, + size_t count, int64_t offset) { + IndexParser *p = static_cast(opaque); + return p->readCallback(opaque, buf, count, offset); +} + +extern "C" void *LZMA_API_CALL alloc_for_lzma_index(void *opaque, size_t nmemb, + size_t size) { + size_t nBytes = nmemb * size + sizeof(size_t); + + size_t *result = static_cast(::malloc(nBytes)); + if (!result) + return result; + + *result = nBytes; + Nan::AdjustExternalMemory(static_cast(nBytes)); + return static_cast(result + 1); } -int64_t IndexParser::readCallback(void* opaque, uint8_t* buf, size_t count, int64_t offset) { +extern "C" void LZMA_API_CALL free_for_lzma_index(void *opaque, void *ptr) { + if (!ptr) + return; + + size_t *orig = static_cast(ptr) - 1; + + Nan::AdjustExternalMemory(-static_cast(*orig)); + return ::free(static_cast(orig)); +} +} // namespace + +int64_t IndexParser::readCallback(void *opaque, uint8_t *buf, size_t count, + int64_t offset) { currentReadBuffer = buf; currentReadSize = count; - - Local argv[2] = { - Uint64ToNumberMaxNull(count), - Uint64ToNumberMaxNull(offset) - }; - - Local read_cb = Local::Cast(EmptyToUndefined(Nan::Get(handle(), NewString("read_cb")))); + + Local argv[2] = {Uint64ToNumberMaxNull(count), + Uint64ToNumberMaxNull(offset)}; + + Local read_cb = Local::Cast( + EmptyToUndefined(Nan::Get(handle(), NewString("read_cb")))); Local ret = Nan::MakeCallback(handle(), read_cb, 2, argv); - + if (currentReadBuffer) { info.async = true; return count; @@ -517,49 +497,55 @@ int64_t IndexParser::readCallback(void* opaque, uint8_t* buf, size_t count, int6 IndexParser::IndexParser() : isCurrentlyInParseCall(false) { lzma_index_parser_data info_ = LZMA_INDEX_PARSER_DATA_INIT; info = info_; - + allocator.alloc = alloc_for_lzma_index; allocator.free = free_for_lzma_index; - allocator.opaque = static_cast(this); - + allocator.opaque = static_cast(this); + info.read_callback = read_cb; - info.opaque = static_cast(this); + info.opaque = static_cast(this); info.allocator = &allocator; } NAN_METHOD(IndexParser::Init) { - IndexParser* p = Nan::ObjectWrap::Unwrap(info.This()); - + IndexParser *p = Nan::ObjectWrap::Unwrap(info.This()); + p->info.file_size = NumberToUint64ClampNullMax(info[0]); p->info.memlimit = NumberToUint64ClampNullMax(info[1]); } Local IndexParser::getObject() const { Local obj = Nan::New(); - - Nan::Set(obj, NewString("streamPadding"), Uint64ToNumberMaxNull(info.stream_padding)); + + Nan::Set(obj, NewString("streamPadding"), + Uint64ToNumberMaxNull(info.stream_padding)); Nan::Set(obj, NewString("memlimit"), Uint64ToNumberMaxNull(info.memlimit)); - Nan::Set(obj, NewString("streams"), Uint64ToNumberMaxNull(lzma_index_stream_count(info.index))); - Nan::Set(obj, NewString("blocks"), Uint64ToNumberMaxNull(lzma_index_block_count(info.index))); - Nan::Set(obj, NewString("fileSize"), Uint64ToNumberMaxNull(lzma_index_file_size(info.index))); - Nan::Set(obj, NewString("uncompressedSize"), Uint64ToNumberMaxNull(lzma_index_uncompressed_size(info.index))); - Nan::Set(obj, NewString("checks"), Uint64ToNumberMaxNull(lzma_index_checks(info.index))); - + Nan::Set(obj, NewString("streams"), + Uint64ToNumberMaxNull(lzma_index_stream_count(info.index))); + Nan::Set(obj, NewString("blocks"), + Uint64ToNumberMaxNull(lzma_index_block_count(info.index))); + Nan::Set(obj, NewString("fileSize"), + Uint64ToNumberMaxNull(lzma_index_file_size(info.index))); + Nan::Set(obj, NewString("uncompressedSize"), + Uint64ToNumberMaxNull(lzma_index_uncompressed_size(info.index))); + Nan::Set(obj, NewString("checks"), + Uint64ToNumberMaxNull(lzma_index_checks(info.index))); + return obj; } NAN_METHOD(IndexParser::Parse) { - IndexParser* p = Nan::ObjectWrap::Unwrap(info.This()); + IndexParser *p = Nan::ObjectWrap::Unwrap(info.This()); if (p->isCurrentlyInParseCall) { Nan::ThrowError("Cannot call IndexParser::Parse recursively"); return; } - + lzma_ret ret; p->isCurrentlyInParseCall = true; ret = my_lzma_parse_indexes_from_file(&p->info); p->isCurrentlyInParseCall = false; - + if (ret == LZMA_OK) { info.GetReturnValue().Set(true); return; @@ -567,7 +553,7 @@ NAN_METHOD(IndexParser::Parse) { info.GetReturnValue().Set(p->getObject()); return; } - + Local error = lzmaRetError(ret); if (p->info.message) { Nan::Set(error, NewString("message"), NewString(p->info.message)); @@ -581,21 +567,21 @@ NAN_METHOD(IndexParser::Feed) { Nan::ThrowTypeError("Expected Buffer as input"); return; } - - IndexParser* p = Nan::ObjectWrap::Unwrap(info.This()); - + + IndexParser *p = Nan::ObjectWrap::Unwrap(info.This()); + if (p->currentReadBuffer == NULL) { Nan::ThrowError("No input data was expected"); return; } size_t length = node::Buffer::Length(value); - + if (length > p->currentReadSize) length = p->currentReadSize; - + memcpy(p->currentReadBuffer, node::Buffer::Data(value), length); p->currentReadBuffer = NULL; - + info.GetReturnValue().Set(Uint64ToNumberMaxNull(length)); } @@ -611,4 +597,4 @@ IndexParser::~IndexParser() { Nan::Persistent IndexParser::constructor; -} +} // namespace lzma diff --git a/node_modules/lzma-native/src/index-parser.h b/node_modules/lzma-native/src/index-parser.h index b4d3811..8a1b357 100644 --- a/node_modules/lzma-native/src/index-parser.h +++ b/node_modules/lzma-native/src/index-parser.h @@ -4,9 +4,9 @@ #ifndef INDEX_PARSER_H #define INDEX_PARSER_H +#include #include #include -#include namespace lzma { @@ -40,129 +40,127 @@ typedef struct lzma_index_parser_internal_s lzma_index_parser_internal; * asynchronously, see the description of the read_callback(). */ typedef struct { - /** - * \brief Combined Index of all Streams in the file - * - * This will be set to an lzma_index * when parsing the file was - * successful, as indicated by a LZMA_STREAM_END return status. - */ - lzma_index *index; - - /** - * \brief Total amount of Stream Padding - * - * This will be set when the file was successfully read. - */ - size_t stream_padding; - - /** - * \brief Callback for reading data from the input file - * - * This member needs to be set to a function that provides a slice of - * the input file. - * - * The opaque pointer will have the same value as the opaque pointer - * set on this struct. - * - * When being invoked, it should read count bytes from the underlying - * file, starting at the specified offset, into buf. - * The return value may be -1, in which case - * lzma_parse_indexes_from_file() will return with LZMA_DATA_ERROR. - * Otherwise, the number of read bytes should be returned. If this is - * not the number of requested bytes, it will be assumed that the file - * was truncated, and lzma_parse_indexes_from_file() will fail with - * LZMA_DATA_ERROR. - * - * It is possible to perform the underlying I/O operations in an - * asynchronous manner. To do so, set the async flag on this struct - * to true. After read_callback() is invoked, - * lzma_parse_indexes_from_file() will return immediately with - * LZMA_OK (unless the read_callback() return value indicates failure), - * and you are expected to call lzma_parse_indexes_from_file() with - * the same struct as soon as the buffer has been filled. - * - * If asynchronous reading is used and the underlying read operation - * fails, you should set file_size to SIZE_MAX and call - * lzma_parse_indexes_from_file() to trigger an error clean up all - * remaining internal state. - * - * You should not perform any operations on this structure until - * the data has been read in any case. - * - * This function is modelled after pread(2), which is a available on - * some platforms and can be easily wrapped to be used here. - */ - int64_t (LZMA_API_CALL *read_callback)(void *opaque, - uint8_t *buf, - size_t count, - int64_t offset); - - /// Opaque pointer that is passed to read_callback. - void *opaque; - - /// Whether to return after calling read_callback and wait for - /// another call. Defaults to synchronous operations. - lzma_bool async; - - /** \brief Callback for reading data from the input file - * - * This needs to be set to the size of the input file before all - * other operations. If this is set to SIZE_MAX, the parser will - * fail with LZMA_OPTIONS_ERROR. This can be used to clean up - * after a failed asynchronous read_callback(). - * - * On error, this will be set to SIZE_MAX. - */ - size_t file_size; - - /** \brief Memory limit for decoding the indexes. - * - * Set a memory limit for decoding. Default to UINT64_MAX for no limit. - * If this is set too low to allocate the internal data structure - * that is minimally required for parsing, this will be set to 0. - * If this is set too low to parse the underlying .xz file, - * this will be set to the amount of memory that would have - * been necessary for parsing the file. - */ - uint64_t memlimit; - - /// Message that may be set when additional information is available - /// on error. - const char *message; - - /** - * \brief Custom memory allocation functions - * - * In most cases this is NULL which makes liblzma use - * the standard malloc() and free(). - */ - const lzma_allocator *allocator; - - /** - * \brief Data which is internal to the index parser. - * - * Do not touch. You can check whether this is NULL to see if this - * structure currently holds external resources, not counting the - * possible index member that is set on success. - */ - lzma_index_parser_internal* internal; - - /* - * Reserved space to allow possible future extensions without - * breaking the ABI. Excluding the initialization of this structure, - * you should not touch these, because the names of these variables - * may change. - */ - void *reserved_ptr1; - void *reserved_ptr2; - void *reserved_ptr3; - void *reserved_ptr4; - uint64_t reserved_int1; - uint64_t reserved_int2; - size_t reserved_int3; - size_t reserved_int4; - lzma_reserved_enum reserved_enum1; - lzma_reserved_enum reserved_enum2; + /** + * \brief Combined Index of all Streams in the file + * + * This will be set to an lzma_index * when parsing the file was + * successful, as indicated by a LZMA_STREAM_END return status. + */ + lzma_index *index; + + /** + * \brief Total amount of Stream Padding + * + * This will be set when the file was successfully read. + */ + size_t stream_padding; + + /** + * \brief Callback for reading data from the input file + * + * This member needs to be set to a function that provides a slice of + * the input file. + * + * The opaque pointer will have the same value as the opaque pointer + * set on this struct. + * + * When being invoked, it should read count bytes from the underlying + * file, starting at the specified offset, into buf. + * The return value may be -1, in which case + * lzma_parse_indexes_from_file() will return with LZMA_DATA_ERROR. + * Otherwise, the number of read bytes should be returned. If this is + * not the number of requested bytes, it will be assumed that the file + * was truncated, and lzma_parse_indexes_from_file() will fail with + * LZMA_DATA_ERROR. + * + * It is possible to perform the underlying I/O operations in an + * asynchronous manner. To do so, set the async flag on this struct + * to true. After read_callback() is invoked, + * lzma_parse_indexes_from_file() will return immediately with + * LZMA_OK (unless the read_callback() return value indicates failure), + * and you are expected to call lzma_parse_indexes_from_file() with + * the same struct as soon as the buffer has been filled. + * + * If asynchronous reading is used and the underlying read operation + * fails, you should set file_size to SIZE_MAX and call + * lzma_parse_indexes_from_file() to trigger an error clean up all + * remaining internal state. + * + * You should not perform any operations on this structure until + * the data has been read in any case. + * + * This function is modelled after pread(2), which is a available on + * some platforms and can be easily wrapped to be used here. + */ + int64_t(LZMA_API_CALL *read_callback)(void *opaque, uint8_t *buf, + size_t count, int64_t offset); + + /// Opaque pointer that is passed to read_callback. + void *opaque; + + /// Whether to return after calling read_callback and wait for + /// another call. Defaults to synchronous operations. + lzma_bool async; + + /** \brief Callback for reading data from the input file + * + * This needs to be set to the size of the input file before all + * other operations. If this is set to SIZE_MAX, the parser will + * fail with LZMA_OPTIONS_ERROR. This can be used to clean up + * after a failed asynchronous read_callback(). + * + * On error, this will be set to SIZE_MAX. + */ + size_t file_size; + + /** \brief Memory limit for decoding the indexes. + * + * Set a memory limit for decoding. Default to UINT64_MAX for no limit. + * If this is set too low to allocate the internal data structure + * that is minimally required for parsing, this will be set to 0. + * If this is set too low to parse the underlying .xz file, + * this will be set to the amount of memory that would have + * been necessary for parsing the file. + */ + uint64_t memlimit; + + /// Message that may be set when additional information is available + /// on error. + const char *message; + + /** + * \brief Custom memory allocation functions + * + * In most cases this is NULL which makes liblzma use + * the standard malloc() and free(). + */ + const lzma_allocator *allocator; + + /** + * \brief Data which is internal to the index parser. + * + * Do not touch. You can check whether this is NULL to see if this + * structure currently holds external resources, not counting the + * possible index member that is set on success. + */ + lzma_index_parser_internal *internal; + + /* + * Reserved space to allow possible future extensions without + * breaking the ABI. Excluding the initialization of this structure, + * you should not touch these, because the names of these variables + * may change. + */ + void *reserved_ptr1; + void *reserved_ptr2; + void *reserved_ptr3; + void *reserved_ptr4; + uint64_t reserved_int1; + uint64_t reserved_int2; + size_t reserved_int3; + size_t reserved_int4; + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; } lzma_index_parser_data; /** @@ -175,10 +173,11 @@ typedef struct { * * Anything which applies for LZMA_STREAM_INIT applies here, too. */ -#define LZMA_INDEX_PARSER_DATA_INIT \ - { NULL, 0, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, \ - NULL, NULL, NULL, NULL, 0, 0, 0, 0, \ - LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM } +#define LZMA_INDEX_PARSER_DATA_INIT \ + { \ + NULL, 0, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, \ + 0, 0, 0, LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM \ + } /** \brief Parse the Index(es) from the given .xz file * @@ -203,6 +202,6 @@ typedef struct { extern lzma_ret my_lzma_parse_indexes_from_file(lzma_index_parser_data *info) lzma_nothrow; -} +} // namespace lzma #endif diff --git a/node_modules/lzma-native/src/liblzma-functions.cpp b/node_modules/lzma-native/src/liblzma-functions.cpp index d180bf9..037cfd8 100644 --- a/node_modules/lzma-native/src/liblzma-functions.cpp +++ b/node_modules/lzma-native/src/liblzma-functions.cpp @@ -7,98 +7,110 @@ NAN_METHOD(lzmaVersionNumber) { } NAN_METHOD(lzmaVersionString) { - info.GetReturnValue().Set(Nan::New(lzma_version_string()).ToLocalChecked()); + info.GetReturnValue().Set( + Nan::New(lzma_version_string()).ToLocalChecked()); } NAN_METHOD(lzmaCheckIsSupported) { Local arg = Local::Cast(info[0]); - - info.GetReturnValue().Set((bool)lzma_check_is_supported((lzma_check) arg->Value())); + + info.GetReturnValue().Set( + (bool)lzma_check_is_supported((lzma_check)arg->Value())); } NAN_METHOD(lzmaCheckSize) { Local arg = Local::Cast(info[0]); - - info.GetReturnValue().Set(Nan::New(lzma_check_size((lzma_check) arg->Value()))); + + info.GetReturnValue().Set( + Nan::New(lzma_check_size((lzma_check)arg->Value()))); } NAN_METHOD(lzmaFilterEncoderIsSupported) { uint64_t arg = FilterByName(info[0]); - + info.GetReturnValue().Set((bool)lzma_filter_encoder_is_supported(arg)); } NAN_METHOD(lzmaFilterDecoderIsSupported) { uint64_t arg = FilterByName(info[0]); - + info.GetReturnValue().Set((bool)lzma_filter_decoder_is_supported(arg)); } NAN_METHOD(lzmaMfIsSupported) { Local arg = Local::Cast(info[0]); - - info.GetReturnValue().Set((bool)lzma_mf_is_supported((lzma_match_finder) arg->Value())); + + info.GetReturnValue().Set( + (bool)lzma_mf_is_supported((lzma_match_finder)arg->Value())); } NAN_METHOD(lzmaModeIsSupported) { Local arg = Local::Cast(info[0]); - - info.GetReturnValue().Set((bool)lzma_mode_is_supported((lzma_mode) arg->Value())); + + info.GetReturnValue().Set( + (bool)lzma_mode_is_supported((lzma_mode)arg->Value())); } NAN_METHOD(lzmaEasyEncoderMemusage) { Local arg = Local::Cast(info[0]); - - info.GetReturnValue().Set(Uint64ToNumberMaxNull(lzma_easy_encoder_memusage(arg->Value()))); + + info.GetReturnValue().Set( + Uint64ToNumberMaxNull(lzma_easy_encoder_memusage(arg->Value()))); } NAN_METHOD(lzmaEasyDecoderMemusage) { Local arg = Local::Cast(info[0]); - - info.GetReturnValue().Set(Uint64ToNumberMaxNull(lzma_easy_decoder_memusage(arg->Value()))); + + info.GetReturnValue().Set( + Uint64ToNumberMaxNull(lzma_easy_decoder_memusage(arg->Value()))); } NAN_METHOD(lzmaCRC32) { Local arg = Local::Cast(info[1]); - + if (arg.IsEmpty() || info[1]->IsUndefined()) arg = Nan::New(0); - + std::vector data; - + if (!readBufferFromObj(info[0], data)) { Nan::ThrowTypeError("CRC32 expects Buffer as input"); info.GetReturnValue().SetUndefined(); return; } - - info.GetReturnValue().Set(Nan::New(lzma_crc32(data.data(), data.size(), arg->Value()))); + + info.GetReturnValue().Set( + Nan::New(lzma_crc32(data.data(), data.size(), arg->Value()))); } NAN_METHOD(lzmaRawEncoderMemusage) { Local arg = Local::Cast(info[0]); - + const FilterArray filters(arg); if (!filters.ok()) { - Nan::ThrowTypeError("rawEncoderMemusage requires filter array as arguments"); + Nan::ThrowTypeError( + "rawEncoderMemusage requires filter array as arguments"); info.GetReturnValue().SetUndefined(); return; } - - info.GetReturnValue().Set(Uint64ToNumberMaxNull(lzma_raw_encoder_memusage(filters.array()))); + + info.GetReturnValue().Set( + Uint64ToNumberMaxNull(lzma_raw_encoder_memusage(filters.array()))); } NAN_METHOD(lzmaRawDecoderMemusage) { Local arg = Local::Cast(info[0]); - + const FilterArray filters(arg); if (!filters.ok()) { - Nan::ThrowTypeError("rawDecoderMemusage requires filter array as arguments"); + Nan::ThrowTypeError( + "rawDecoderMemusage requires filter array as arguments"); info.GetReturnValue().SetUndefined(); return; } - - info.GetReturnValue().Set(Uint64ToNumberMaxNull(lzma_raw_decoder_memusage(filters.array()))); -} + info.GetReturnValue().Set( + Uint64ToNumberMaxNull(lzma_raw_decoder_memusage(filters.array()))); } + +} // namespace lzma diff --git a/node_modules/lzma-native/src/liblzma-node.hpp b/node_modules/lzma-native/src/liblzma-node.hpp index 94cfae7..1c280b4 100644 --- a/node_modules/lzma-native/src/liblzma-node.hpp +++ b/node_modules/lzma-native/src/liblzma-node.hpp @@ -5,31 +5,32 @@ #ifndef LIBLZMA_NODE_HPP #define LIBLZMA_NODE_HPP +#include #include #include #include -#include -#include #include "index-parser.h" +#include -#include #include -#include #include +#include #include #include +#include // C++11 features in libstdc++ shipped with Apple Clang // See e.g. http://svn.boost.org/trac/boost/ticket/8092 -#if __cplusplus <= 199711L || (__APPLE__ && (__GNUC_LIBSTD__ <= 4) && (__GNUC_LIBSTD_MINOR__ <= 2)) -# define LZMA_NO_CXX11_RVALUE_REFERENCES +#if __cplusplus <= 199711L || \ + (__APPLE__ && (__GNUC_LIBSTD__ <= 4) && (__GNUC_LIBSTD_MINOR__ <= 2)) +#define LZMA_NO_CXX11_RVALUE_REFERENCES #endif #ifndef LZMA_NO_CXX11_RVALUE_REFERENCES -# define LZMA_NATIVE_MOVE std::move +#define LZMA_NATIVE_MOVE std::move #else -# define LZMA_NATIVE_MOVE +#define LZMA_NATIVE_MOVE #endif #if NODE_MODULE_VERSION >= 11 @@ -37,305 +38,305 @@ #endif namespace lzma { - using namespace v8; - - /* internal util */ +using namespace v8; + +/* internal util */ #ifdef LZMA_ASYNC_AVAILABLE - struct uv_mutex_guard { - explicit uv_mutex_guard(uv_mutex_t& m_, bool autolock = true) - : locked(false), m(m_) - { - if (autolock) - lock(); - } - - ~uv_mutex_guard() { - if (locked) - unlock(); - } - - inline void lock () { - uv_mutex_lock(&m); - locked = true; - } - - inline void unlock () { - uv_mutex_unlock(&m); - locked = false; - } - - bool locked; - uv_mutex_t& m; - }; -#endif - - /* util */ - /** - * Return the filter constant associated with a v8 String handle - */ - lzma_vli FilterByName(Local v); - - /** - * If rv represents an error, throw a javascript exception representing it. - * Always returns rv as a v8 Integer. - */ - Local lzmaRet(lzma_ret rv); - - /** - * Return a javascript exception representing rv. - */ - Local lzmaRetError(lzma_ret rv); - - /** - * Takes a Node.js SlowBuffer or Buffer as input and populates data accordingly. - * Returns true on success, false on failure. - */ - bool readBufferFromObj(Local value, std::vector& data); - - /** - * Return a lzma_options_lzma struct as described by the v8 Object obj. - */ - lzma_options_lzma parseOptionsLZMA (Local obj); - - /** - * Return a v8 Number representation of an uint64_t where UINT64_MAX will be mapped to null - */ - Local Uint64ToNumberMaxNull(uint64_t in); - - /** - * Return a v8 Number representation of an uint64_t where 0 will be mapped to null - */ - Local Uint64ToNumber0Null(uint64_t in); - - /** - * Return a uint64_t representation of a v8 Number, - * where values above UINT64_MAX map to UINT64_MAX and null to UINT64_MAX. - * Throws an TypeError if the input is not a number. - */ - uint64_t NumberToUint64ClampNullMax(Local in); - - /** - * Convert Nan MaybeLocal values to Local, replacing - * empty values with undefined - */ - inline Local EmptyToUndefined(Nan::MaybeLocal v) { - if (v.IsEmpty()) - return Nan::Undefined(); - - return v.ToLocalChecked(); +struct uv_mutex_guard { + explicit uv_mutex_guard(uv_mutex_t &m_, bool autolock = true) + : locked(false), m(m_) { + if (autolock) + lock(); } - - /** - * Create a new v8 String - */ - template - inline Local NewString(T value) { - return Nan::New(value).ToLocalChecked(); + + ~uv_mutex_guard() { + if (locked) + unlock(); } - - /** - * Return an integer property of an object (which can be passed to Nan::Get), - * providing a default value if no such property is present - */ - template - inline uint64_t GetIntegerProperty(T& obj, const char* name, uint64_t def) { - Local v = EmptyToUndefined(Nan::Get(obj, NewString(name))); - - if (v->IsUndefined()) - return def; - - Nan::MaybeLocal i = Nan::To(v); - return i.IsEmpty() ? def : i.ToLocalChecked()->Value(); + + inline void lock() { + uv_mutex_lock(&m); + locked = true; } - - /* bindings in one-to-one correspondence to the lzma functions */ - NAN_METHOD(lzmaVersionNumber); - NAN_METHOD(lzmaVersionString); - NAN_METHOD(lzmaCheckIsSupported); - NAN_METHOD(lzmaCheckSize); - NAN_METHOD(lzmaFilterEncoderIsSupported); - NAN_METHOD(lzmaFilterDecoderIsSupported); - NAN_METHOD(lzmaMfIsSupported); - NAN_METHOD(lzmaModeIsSupported); - NAN_METHOD(lzmaEasyEncoderMemusage); - NAN_METHOD(lzmaEasyDecoderMemusage); - NAN_METHOD(lzmaCRC32); - NAN_METHOD(lzmaRawEncoderMemusage); - NAN_METHOD(lzmaRawDecoderMemusage); - - /* wrappers */ - /** - * List of liblzma filters with corresponding options - */ - class FilterArray { - public: - FilterArray() : ok_(false) { finish(); } - explicit FilterArray(Local arr); - - lzma_filter* array() { return filters.data(); } - const lzma_filter* array() const { return filters.data(); } - bool ok() const { return ok_; } - private: - FilterArray(const FilterArray&); - FilterArray& operator=(const FilterArray&); - - void finish(); - - union options { - lzma_options_delta delta; - lzma_options_lzma lzma; - }; - - bool ok_; - std::vector filters; - std::list optbuf; - }; - /** - * Wrapper for lzma_mt (multi-threading options). - */ - class MTOptions { - public: - MTOptions(); - explicit MTOptions(Local opt); - ~MTOptions(); - - lzma_mt* opts() { return &opts_; } - const lzma_mt* opts() const { return &opts_; } - bool ok() const { return ok_; } - private: - MTOptions(const MTOptions&); - MTOptions& operator=(const MTOptions&); - - FilterArray* filters_; - lzma_mt opts_; - bool ok_; + inline void unlock() { + uv_mutex_unlock(&m); + locked = false; + } + + bool locked; + uv_mutex_t &m; +}; +#endif + +/* util */ +/** + * Return the filter constant associated with a v8 String handle + */ +lzma_vli FilterByName(Local v); + +/** + * If rv represents an error, throw a javascript exception representing it. + * Always returns rv as a v8 Integer. + */ +Local lzmaRet(lzma_ret rv); + +/** + * Return a javascript exception representing rv. + */ +Local lzmaRetError(lzma_ret rv); + +/** + * Takes a Node.js SlowBuffer or Buffer as input and populates data accordingly. + * Returns true on success, false on failure. + */ +bool readBufferFromObj(Local value, std::vector &data); + +/** + * Return a lzma_options_lzma struct as described by the v8 Object obj. + */ +lzma_options_lzma parseOptionsLZMA(Local obj); + +/** + * Return a v8 Number representation of an uint64_t where UINT64_MAX will be + * mapped to null + */ +Local Uint64ToNumberMaxNull(uint64_t in); + +/** + * Return a v8 Number representation of an uint64_t where 0 will be mapped to + * null + */ +Local Uint64ToNumber0Null(uint64_t in); + +/** + * Return a uint64_t representation of a v8 Number, + * where values above UINT64_MAX map to UINT64_MAX and null to UINT64_MAX. + * Throws an TypeError if the input is not a number. + */ +uint64_t NumberToUint64ClampNullMax(Local in); + +/** + * Convert Nan MaybeLocal values to Local, replacing + * empty values with undefined + */ +inline Local EmptyToUndefined(Nan::MaybeLocal v) { + if (v.IsEmpty()) + return Nan::Undefined(); + + return v.ToLocalChecked(); +} + +/** + * Create a new v8 String + */ +template inline Local NewString(T value) { + return Nan::New(value).ToLocalChecked(); +} + +/** + * Return an integer property of an object (which can be passed to Nan::Get), + * providing a default value if no such property is present + */ +template +inline uint64_t GetIntegerProperty(T &obj, const char *name, uint64_t def) { + Local v = EmptyToUndefined(Nan::Get(obj, NewString(name))); + + if (v->IsUndefined()) + return def; + + Nan::MaybeLocal i = Nan::To(v); + return i.IsEmpty() ? def : i.ToLocalChecked()->Value(); +} + +/* bindings in one-to-one correspondence to the lzma functions */ +NAN_METHOD(lzmaVersionNumber); +NAN_METHOD(lzmaVersionString); +NAN_METHOD(lzmaCheckIsSupported); +NAN_METHOD(lzmaCheckSize); +NAN_METHOD(lzmaFilterEncoderIsSupported); +NAN_METHOD(lzmaFilterDecoderIsSupported); +NAN_METHOD(lzmaMfIsSupported); +NAN_METHOD(lzmaModeIsSupported); +NAN_METHOD(lzmaEasyEncoderMemusage); +NAN_METHOD(lzmaEasyDecoderMemusage); +NAN_METHOD(lzmaCRC32); +NAN_METHOD(lzmaRawEncoderMemusage); +NAN_METHOD(lzmaRawDecoderMemusage); + +/* wrappers */ +/** + * List of liblzma filters with corresponding options + */ +class FilterArray { +public: + FilterArray() : ok_(false) { finish(); } + explicit FilterArray(Local arr); + + lzma_filter *array() { return filters.data(); } + const lzma_filter *array() const { return filters.data(); } + bool ok() const { return ok_; } + +private: + FilterArray(const FilterArray &); + FilterArray &operator=(const FilterArray &); + + void finish(); + + union options { + lzma_options_delta delta; + lzma_options_lzma lzma; }; - /** - * Node.js object wrap for lzma_stream wrapper. Corresponds to exports.Stream - */ - class LZMAStream : public Nan::ObjectWrap { - public: - static void Init(Local exports); - static const bool asyncCodeAvailable; - - /* regard as private: */ - void doLZMACodeFromAsync(); - void invokeBufferHandlers(bool hasLock); - void* alloc(size_t nmemb, size_t size); - void free(void* ptr); - private: - void resetUnderlying(); - void doLZMACode(); - - explicit LZMAStream(); - ~LZMAStream(); - - static Nan::Persistent constructor; - static NAN_METHOD(New); - - static void _failMissingSelf(const Nan::FunctionCallbackInfo& info); - - void adjustExternalMemory(int64_t bytesChange); - void reportAdjustedExternalMemoryToV8(); - + bool ok_; + std::vector filters; + std::list optbuf; +}; + +/** + * Wrapper for lzma_mt (multi-threading options). + */ +class MTOptions { +public: + MTOptions(); + explicit MTOptions(Local opt); + ~MTOptions(); + + lzma_mt *opts() { return &opts_; } + const lzma_mt *opts() const { return &opts_; } + bool ok() const { return ok_; } + +private: + MTOptions(const MTOptions &); + MTOptions &operator=(const MTOptions &); + + FilterArray *filters_; + lzma_mt opts_; + bool ok_; +}; + +/** + * Node.js object wrap for lzma_stream wrapper. Corresponds to exports.Stream + */ +class LZMAStream : public Nan::ObjectWrap { +public: + static void Init(Local exports); + static const bool asyncCodeAvailable; + + /* regard as private: */ + void doLZMACodeFromAsync(); + void invokeBufferHandlers(bool hasLock); + void *alloc(size_t nmemb, size_t size); + void free(void *ptr); + +private: + void resetUnderlying(); + void doLZMACode(); + + explicit LZMAStream(); + ~LZMAStream(); + + static Nan::Persistent constructor; + static NAN_METHOD(New); + + static void _failMissingSelf(const Nan::FunctionCallbackInfo &info); + + void adjustExternalMemory(int64_t bytesChange); + void reportAdjustedExternalMemoryToV8(); + #ifdef LZMA_ASYNC_AVAILABLE - int64_t nonAdjustedExternalMemory; - - uv_mutex_t mutex; - -#define LZMA_ASYNC_LOCK(strm) uv_mutex_guard lock(strm->mutex) + int64_t nonAdjustedExternalMemory; + + uv_mutex_t mutex; + +#define LZMA_ASYNC_LOCK(strm) uv_mutex_guard lock(strm->mutex) #else #define LZMA_ASYNC_LOCK(strm) #endif - static NAN_METHOD(ResetUnderlying); - static NAN_METHOD(SetBufsize); - static NAN_METHOD(Code); - static NAN_METHOD(Memusage); - static NAN_METHOD(MemlimitGet); - static NAN_METHOD(MemlimitSet); - static NAN_METHOD(RawEncoder); - static NAN_METHOD(RawDecoder); - static NAN_METHOD(FiltersUpdate); - static NAN_METHOD(EasyEncoder); - static NAN_METHOD(StreamEncoder); - static NAN_METHOD(AloneEncoder); - static NAN_METHOD(MTEncoder); - static NAN_METHOD(StreamDecoder); - static NAN_METHOD(AutoDecoder); - static NAN_METHOD(AloneDecoder); - - lzma_allocator allocator; - lzma_stream _; - size_t bufsize; - std::string error; - - bool shouldFinish; - size_t processedChunks; - lzma_ret lastCodeResult; - std::queue > inbufs; - std::queue > outbufs; - }; + static NAN_METHOD(ResetUnderlying); + static NAN_METHOD(SetBufsize); + static NAN_METHOD(Code); + static NAN_METHOD(Memusage); + static NAN_METHOD(MemlimitGet); + static NAN_METHOD(MemlimitSet); + static NAN_METHOD(RawEncoder); + static NAN_METHOD(RawDecoder); + static NAN_METHOD(FiltersUpdate); + static NAN_METHOD(EasyEncoder); + static NAN_METHOD(StreamEncoder); + static NAN_METHOD(AloneEncoder); + static NAN_METHOD(MTEncoder); + static NAN_METHOD(StreamDecoder); + static NAN_METHOD(AutoDecoder); + static NAN_METHOD(AloneDecoder); - /** - * Async worker for a single coding step. - */ - class LZMAStreamCodingWorker : public Nan::AsyncWorker { - public: - LZMAStreamCodingWorker(/*Nan::Callback* callback_, */LZMAStream* stream_) - : Nan::AsyncWorker(NULL/*callback_*/), stream(stream_) { - SaveToPersistent(static_cast(0), stream->handle()); - } - - ~LZMAStreamCodingWorker() {} - - void Execute() { - stream->doLZMACodeFromAsync(); - } - private: - void HandleOKCallback() { - stream->invokeBufferHandlers(false); - } - - void HandleErrorCallback() { - stream->invokeBufferHandlers(false); - } - - LZMAStream* stream; - }; - - class IndexParser : public Nan::ObjectWrap { - public: - static void Init(Local exports); - - /* regard as private: */ - int64_t readCallback(void* opaque, uint8_t* buf, size_t count, int64_t offset); - private: - explicit IndexParser(); - ~IndexParser(); - - lzma_index_parser_data info; - lzma_allocator allocator; - - uint8_t* currentReadBuffer; - size_t currentReadSize; - bool isCurrentlyInParseCall; - - Local getObject() const; - - static Nan::Persistent constructor; - static NAN_METHOD(New); - static NAN_METHOD(Init); - static NAN_METHOD(Feed); - static NAN_METHOD(Parse); - }; - - /** - * Node.js addon init function - */ - void moduleInit(Local exports); -} + lzma_allocator allocator; + lzma_stream _; + size_t bufsize; + std::string error; + + bool shouldFinish; + size_t processedChunks; + lzma_ret lastCodeResult; + std::queue> inbufs; + std::queue> outbufs; +}; + +/** + * Async worker for a single coding step. + */ +class LZMAStreamCodingWorker : public Nan::AsyncWorker { +public: + LZMAStreamCodingWorker(/*Nan::Callback* callback_, */ LZMAStream *stream_) + : Nan::AsyncWorker(NULL /*callback_*/), stream(stream_) { + SaveToPersistent(static_cast(0), stream->handle()); + } + + ~LZMAStreamCodingWorker() {} + + void Execute() { stream->doLZMACodeFromAsync(); } + +private: + void HandleOKCallback() { stream->invokeBufferHandlers(false); } + + void HandleErrorCallback() { stream->invokeBufferHandlers(false); } + + LZMAStream *stream; +}; + +class IndexParser : public Nan::ObjectWrap { +public: + static void Init(Local exports); + + /* regard as private: */ + int64_t readCallback(void *opaque, uint8_t *buf, size_t count, + int64_t offset); + +private: + explicit IndexParser(); + ~IndexParser(); + + lzma_index_parser_data info; + lzma_allocator allocator; + + uint8_t *currentReadBuffer; + size_t currentReadSize; + bool isCurrentlyInParseCall; + + Local getObject() const; + + static Nan::Persistent constructor; + static NAN_METHOD(New); + static NAN_METHOD(Init); + static NAN_METHOD(Feed); + static NAN_METHOD(Parse); +}; + +/** + * Node.js addon init function + */ +void moduleInit(Local exports); +} // namespace lzma #endif diff --git a/node_modules/lzma-native/src/lzma-stream.cpp b/node_modules/lzma-native/src/lzma-stream.cpp index c06fa87..8a811e2 100644 --- a/node_modules/lzma-native/src/lzma-stream.cpp +++ b/node_modules/lzma-native/src/lzma-stream.cpp @@ -1,8 +1,8 @@ #include "liblzma-node.hpp" -#include -#include -#include #include +#include +#include +#include namespace lzma { #ifdef LZMA_ASYNC_AVAILABLE @@ -12,38 +12,34 @@ const bool LZMAStream::asyncCodeAvailable = false; #endif namespace { - extern "C" void* LZMA_API_CALL - alloc_for_lzma(void *opaque, size_t nmemb, size_t size) { - LZMAStream* strm = static_cast(opaque); - - return strm->alloc(nmemb, size); - } - - extern "C" void LZMA_API_CALL - free_for_lzma(void *opaque, void *ptr) { - LZMAStream* strm = static_cast(opaque); - - return strm->free(ptr); - } +extern "C" void *LZMA_API_CALL alloc_for_lzma(void *opaque, size_t nmemb, + size_t size) { + LZMAStream *strm = static_cast(opaque); + + return strm->alloc(nmemb, size); +} + +extern "C" void LZMA_API_CALL free_for_lzma(void *opaque, void *ptr) { + LZMAStream *strm = static_cast(opaque); + + return strm->free(ptr); } +} // namespace Nan::Persistent LZMAStream::constructor; -LZMAStream::LZMAStream() : - bufsize(65536), - shouldFinish(false), - processedChunks(0), - lastCodeResult(LZMA_OK) -{ +LZMAStream::LZMAStream() + : bufsize(65536), shouldFinish(false), processedChunks(0), + lastCodeResult(LZMA_OK) { std::memset(&_, 0, sizeof(lzma_stream)); - + allocator.alloc = alloc_for_lzma; allocator.free = free_for_lzma; - allocator.opaque = static_cast(this); + allocator.opaque = static_cast(this); _.allocator = &allocator; #ifdef LZMA_ASYNC_AVAILABLE uv_mutex_init(&mutex); - + nonAdjustedExternalMemory = 0; #endif } @@ -51,7 +47,7 @@ LZMAStream::LZMAStream() : void LZMAStream::resetUnderlying() { if (_.internal) lzma_end(&_); - + reportAdjustedExternalMemoryToV8(); std::memset(&_, 0, sizeof(lzma_stream)); _.allocator = &allocator; @@ -61,7 +57,7 @@ void LZMAStream::resetUnderlying() { LZMAStream::~LZMAStream() { resetUnderlying(); - + #ifdef LZMA_ASYNC_AVAILABLE uv_mutex_destroy(&mutex); #endif @@ -69,33 +65,33 @@ LZMAStream::~LZMAStream() { Nan::AdjustExternalMemory(-int64_t(sizeof(LZMAStream))); } -void* LZMAStream::alloc(size_t nmemb, size_t size) { +void *LZMAStream::alloc(size_t nmemb, size_t size) { size_t nBytes = nmemb * size + sizeof(size_t); - - size_t* result = static_cast(::malloc(nBytes)); + + size_t *result = static_cast(::malloc(nBytes)); if (!result) return result; - + *result = nBytes; adjustExternalMemory(static_cast(nBytes)); - return static_cast(result + 1); + return static_cast(result + 1); } -void LZMAStream::free(void* ptr) { +void LZMAStream::free(void *ptr) { if (!ptr) return; - - size_t* orig = static_cast(ptr) - 1; - + + size_t *orig = static_cast(ptr) - 1; + adjustExternalMemory(-static_cast(*orig)); - return ::free(static_cast(orig)); + return ::free(static_cast(orig)); } void LZMAStream::reportAdjustedExternalMemoryToV8() { #ifdef LZMA_ASYNC_AVAILABLE if (nonAdjustedExternalMemory == 0) return; - + Nan::AdjustExternalMemory(nonAdjustedExternalMemory); nonAdjustedExternalMemory = 0; #endif @@ -109,57 +105,55 @@ void LZMAStream::adjustExternalMemory(int64_t bytesChange) { #endif } -#define LZMA_FETCH_SELF() \ - LZMAStream* self = NULL; \ - if (!info.This().IsEmpty() && info.This()->InternalFieldCount() > 0) { \ - self = Nan::ObjectWrap::Unwrap(info.This()); \ - } \ - if (!self) { \ - _failMissingSelf(info); \ - return; \ - } \ - struct _MemScopeGuard { \ - _MemScopeGuard(LZMAStream* self_) : self(self_) {} \ - ~_MemScopeGuard() { \ - self->reportAdjustedExternalMemoryToV8(); \ - } \ - \ - LZMAStream* self; \ - }; \ +#define LZMA_FETCH_SELF() \ + LZMAStream *self = NULL; \ + if (!info.This().IsEmpty() && info.This()->InternalFieldCount() > 0) { \ + self = Nan::ObjectWrap::Unwrap(info.This()); \ + } \ + if (!self) { \ + _failMissingSelf(info); \ + return; \ + } \ + struct _MemScopeGuard { \ + _MemScopeGuard(LZMAStream *self_) : self(self_) {} \ + ~_MemScopeGuard() { self->reportAdjustedExternalMemoryToV8(); } \ + \ + LZMAStream *self; \ + }; \ _MemScopeGuard guard(self); NAN_METHOD(LZMAStream::ResetUnderlying) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + self->resetUnderlying(); - + info.GetReturnValue().SetUndefined(); } NAN_METHOD(LZMAStream::SetBufsize) { size_t oldBufsize, newBufsize = NumberToUint64ClampNullMax(info[0]); - + { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + oldBufsize = self->bufsize; - + if (newBufsize && newBufsize != UINT_MAX) self->bufsize = newBufsize; } - + info.GetReturnValue().Set(double(oldBufsize)); } NAN_METHOD(LZMAStream::Code) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + self->reportAdjustedExternalMemoryToV8(); std::vector inputData; - + Local bufarg = Local::Cast(info[0]); if (bufarg.IsEmpty() || bufarg->IsUndefined() || bufarg->IsNull()) { self->shouldFinish = true; @@ -168,15 +162,15 @@ NAN_METHOD(LZMAStream::Code) { info.GetReturnValue().SetUndefined(); return; } - + if (inputData.empty()) self->shouldFinish = true; } - + self->inbufs.push(LZMA_NATIVE_MOVE(inputData)); - + bool async = Nan::To(info[1]).ToChecked(); - + if (async) { #ifdef LZMA_ASYNC_AVAILABLE Nan::AsyncQueueWorker(new LZMAStreamCodingWorker(self)); @@ -187,76 +181,87 @@ NAN_METHOD(LZMAStream::Code) { self->doLZMACode(); self->invokeBufferHandlers(true); } - + info.GetReturnValue().SetUndefined(); } void LZMAStream::invokeBufferHandlers(bool hasLock) { #ifdef LZMA_ASYNC_AVAILABLE uv_mutex_guard lock(mutex, !hasLock); -#define POSSIBLY_LOCK_MX do { if (!hasLock) lock.lock(); } while(0) -#define POSSIBLY_UNLOCK_MX do { if (!hasLock) lock.unlock(); } while(0) +#define POSSIBLY_LOCK_MX \ + do { \ + if (!hasLock) \ + lock.lock(); \ + } while (0) +#define POSSIBLY_UNLOCK_MX \ + do { \ + if (!hasLock) \ + lock.unlock(); \ + } while (0) #else #define POSSIBLY_LOCK_MX #define POSSIBLY_UNLOCK_MX #endif - + Nan::HandleScope scope; - + reportAdjustedExternalMemoryToV8(); - Local bufferHandler = Local::Cast(EmptyToUndefined(Nan::Get(handle(), NewString("bufferHandler")))); + Local bufferHandler = Local::Cast( + EmptyToUndefined(Nan::Get(handle(), NewString("bufferHandler")))); std::vector outbuf; - -#define CALL_BUFFER_HANDLER_WITH_ARGV \ - POSSIBLY_UNLOCK_MX; \ - Nan::MakeCallback(handle(), bufferHandler, 5, argv); \ + +#define CALL_BUFFER_HANDLER_WITH_ARGV \ + POSSIBLY_UNLOCK_MX; \ + Nan::MakeCallback(handle(), bufferHandler, 5, argv); \ POSSIBLY_LOCK_MX; - + uint64_t in = UINT64_MAX, out = UINT64_MAX; if (_.internal) lzma_get_progress(&_, &in, &out); - Local in_ = Uint64ToNumberMaxNull(in); - Local out_ = Uint64ToNumberMaxNull(out); - + Local in_ = Uint64ToNumberMaxNull(in); + Local out_ = Uint64ToNumberMaxNull(out); + while (outbufs.size() > 0) { outbuf = LZMA_NATIVE_MOVE(outbufs.front()); outbufs.pop(); - + Local argv[5] = { - Nan::CopyBuffer(reinterpret_cast(outbuf.data()), outbuf.size()).ToLocalChecked(), - Nan::Undefined(), Nan::Undefined(), in_, out_ - }; + Nan::CopyBuffer(reinterpret_cast(outbuf.data()), + outbuf.size()) + .ToLocalChecked(), + Nan::Undefined(), Nan::Undefined(), in_, out_}; CALL_BUFFER_HANDLER_WITH_ARGV } - + bool reset = false; if (lastCodeResult != LZMA_OK) { Local errorArg = Local(Nan::Null()); - + if (lastCodeResult != LZMA_STREAM_END) errorArg = lzmaRetError(lastCodeResult); - + reset = true; - - Local argv[5] = { Nan::Null(), Nan::Undefined(), errorArg, in_, out_ }; + + Local argv[5] = {Nan::Null(), Nan::Undefined(), errorArg, in_, out_}; CALL_BUFFER_HANDLER_WITH_ARGV } - + if (processedChunks) { size_t pc = processedChunks; processedChunks = 0; - - Local argv[5] = { Nan::Undefined(), Nan::New(uint32_t(pc)), Nan::Undefined(), in_, out_ }; + + Local argv[5] = {Nan::Undefined(), Nan::New(uint32_t(pc)), + Nan::Undefined(), in_, out_}; CALL_BUFFER_HANDLER_WITH_ARGV } - + if (reset) resetUnderlying(); // resets lastCodeResult! } void LZMAStream::doLZMACodeFromAsync() { LZMA_ASYNC_LOCK(this); - + doLZMACode(); } @@ -267,9 +272,9 @@ void LZMAStream::doLZMACode() { _.avail_in = 0; lzma_action action = LZMA_RUN; - + size_t readChunks = 0; - + // _.internal is set to NULL when lzma_end() is called via resetUnderlying() while (_.internal) { if (_.avail_in == 0) { // more input neccessary? @@ -277,53 +282,54 @@ void LZMAStream::doLZMACode() { inbuf = LZMA_NATIVE_MOVE(inbufs.front()); inbufs.pop(); readChunks++; - + _.next_in = inbuf.data(); _.avail_in = inbuf.size(); } } - + if (shouldFinish && inbufs.empty()) action = LZMA_FINISH; - + _.next_out = outbuf.data(); _.avail_out = outbuf.size(); - + lastCodeResult = lzma_code(&_, action); - + if (lastCodeResult != LZMA_OK && lastCodeResult != LZMA_STREAM_END) { processedChunks += readChunks; readChunks = 0; - + break; } - - if (_.avail_out == 0 || _.avail_in == 0 || lastCodeResult == LZMA_STREAM_END) { + + if (_.avail_out == 0 || _.avail_in == 0 || + lastCodeResult == LZMA_STREAM_END) { size_t outsz = outbuf.size() - _.avail_out; - + if (outsz > 0) { #ifndef LZMA_NO_CXX11_RVALUE_REFERENCES // C++11 outbufs.emplace(outbuf.data(), outbuf.data() + outsz); #else - outbufs.push(std::vector(outbuf.data(), outbuf.data() + outsz)); + outbufs.push( + std::vector(outbuf.data(), outbuf.data() + outsz)); #endif } if (lastCodeResult == LZMA_STREAM_END) { processedChunks += readChunks; readChunks = 0; - + break; } } - + if (_.avail_out == outbuf.size()) { // no progress was made if (!shouldFinish) { processedChunks += readChunks; readChunks = 0; } - if (!shouldFinish) break; } @@ -334,7 +340,7 @@ void LZMAStream::Init(Local exports) { Local tpl = Nan::New(New); tpl->SetClassName(NewString("LZMAStream")); tpl->InstanceTemplate()->SetInternalFieldCount(1); - + Nan::SetPrototypeMethod(tpl, "setBufsize", SetBufsize); Nan::SetPrototypeMethod(tpl, "resetUnderlying", ResetUnderlying); Nan::SetPrototypeMethod(tpl, "code", Code); @@ -351,161 +357,174 @@ void LZMAStream::Init(Local exports) { Nan::SetPrototypeMethod(tpl, "streamDecoder_", StreamDecoder); Nan::SetPrototypeMethod(tpl, "autoDecoder_", AutoDecoder); Nan::SetPrototypeMethod(tpl, "aloneDecoder_", AloneDecoder); - + constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked()); Nan::Set(exports, NewString("Stream"), Nan::New(constructor)); } NAN_METHOD(LZMAStream::New) { if (info.IsConstructCall()) { - LZMAStream* self = new LZMAStream(); + LZMAStream *self = new LZMAStream(); if (!self) { Nan::ThrowRangeError("Out of memory, cannot create LZMAStream"); info.GetReturnValue().SetUndefined(); return; } - + self->Wrap(info.This()); Nan::AdjustExternalMemory(sizeof(LZMAStream)); - + info.GetReturnValue().Set(info.This()); } else { - info.GetReturnValue().Set(Nan::NewInstance(Nan::New(constructor), 0, NULL).ToLocalChecked()); + info.GetReturnValue().Set( + Nan::NewInstance(Nan::New(constructor), 0, NULL) + .ToLocalChecked()); } } -void LZMAStream::_failMissingSelf(const Nan::FunctionCallbackInfo& info) { - Nan::ThrowTypeError("LZMAStream methods need to be called on an LZMAStream object"); +void LZMAStream::_failMissingSelf( + const Nan::FunctionCallbackInfo &info) { + Nan::ThrowTypeError( + "LZMAStream methods need to be called on an LZMAStream object"); info.GetReturnValue().SetUndefined(); } NAN_METHOD(LZMAStream::Memusage) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + info.GetReturnValue().Set(Uint64ToNumber0Null(lzma_memusage(&self->_))); } NAN_METHOD(LZMAStream::MemlimitGet) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + info.GetReturnValue().Set(Uint64ToNumber0Null(lzma_memlimit_get(&self->_))); } NAN_METHOD(LZMAStream::MemlimitSet) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + Local arg = Local::Cast(info[0]); if (info[0]->IsUndefined() || arg.IsEmpty()) { Nan::ThrowTypeError("memlimitSet() needs a numerical argument"); info.GetReturnValue().SetUndefined(); return; } - - info.GetReturnValue().Set(lzmaRet(lzma_memlimit_set(&self->_, NumberToUint64ClampNullMax(arg)))); + + info.GetReturnValue().Set( + lzmaRet(lzma_memlimit_set(&self->_, NumberToUint64ClampNullMax(arg)))); } NAN_METHOD(LZMAStream::RawEncoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + const FilterArray filters(Local::Cast(info[0])); - - info.GetReturnValue().Set(lzmaRet(lzma_raw_encoder(&self->_, filters.array()))); + + info.GetReturnValue().Set( + lzmaRet(lzma_raw_encoder(&self->_, filters.array()))); } NAN_METHOD(LZMAStream::RawDecoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + const FilterArray filters(Local::Cast(info[0])); - - info.GetReturnValue().Set(lzmaRet(lzma_raw_decoder(&self->_, filters.array()))); + + info.GetReturnValue().Set( + lzmaRet(lzma_raw_decoder(&self->_, filters.array()))); } NAN_METHOD(LZMAStream::FiltersUpdate) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + const FilterArray filters(Local::Cast(info[0])); - - info.GetReturnValue().Set(lzmaRet(lzma_filters_update(&self->_, filters.array()))); + + info.GetReturnValue().Set( + lzmaRet(lzma_filters_update(&self->_, filters.array()))); } NAN_METHOD(LZMAStream::EasyEncoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + Local preset = Local::Cast(info[0]); Local check = Local::Cast(info[1]); - - info.GetReturnValue().Set(lzmaRet(lzma_easy_encoder(&self->_, preset->Value(), (lzma_check) check->Value()))); + + info.GetReturnValue().Set(lzmaRet(lzma_easy_encoder( + &self->_, preset->Value(), (lzma_check)check->Value()))); } NAN_METHOD(LZMAStream::StreamEncoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + const FilterArray filters(Local::Cast(info[0])); Local check = Local::Cast(info[1]); if (!filters.ok()) return; - - info.GetReturnValue().Set(lzmaRet(lzma_stream_encoder(&self->_, filters.array(), (lzma_check) check->Value()))); + + info.GetReturnValue().Set(lzmaRet(lzma_stream_encoder( + &self->_, filters.array(), (lzma_check)check->Value()))); } NAN_METHOD(LZMAStream::MTEncoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + const MTOptions mt(Local::Cast(info[0])); if (!mt.ok()) return; - - info.GetReturnValue().Set(lzmaRet(lzma_stream_encoder_mt(&self->_, mt.opts()))); + + info.GetReturnValue().Set( + lzmaRet(lzma_stream_encoder_mt(&self->_, mt.opts()))); } NAN_METHOD(LZMAStream::AloneEncoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + Local opt = Local::Cast(info[0]); lzma_options_lzma o = parseOptionsLZMA(opt); - + info.GetReturnValue().Set(lzmaRet(lzma_alone_encoder(&self->_, &o))); } NAN_METHOD(LZMAStream::StreamDecoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + uint64_t memlimit = NumberToUint64ClampNullMax(info[0]); Local flags = Local::Cast(info[1]); - - info.GetReturnValue().Set(lzmaRet(lzma_stream_decoder(&self->_, memlimit, flags->Value()))); + + info.GetReturnValue().Set( + lzmaRet(lzma_stream_decoder(&self->_, memlimit, flags->Value()))); } NAN_METHOD(LZMAStream::AutoDecoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + uint64_t memlimit = NumberToUint64ClampNullMax(info[0]); Local flags = Local::Cast(info[1]); - - info.GetReturnValue().Set(lzmaRet(lzma_auto_decoder(&self->_, memlimit, flags->Value()))); + + info.GetReturnValue().Set( + lzmaRet(lzma_auto_decoder(&self->_, memlimit, flags->Value()))); } NAN_METHOD(LZMAStream::AloneDecoder) { LZMA_FETCH_SELF(); LZMA_ASYNC_LOCK(self); - + uint64_t memlimit = NumberToUint64ClampNullMax(info[0]); - + info.GetReturnValue().Set(lzmaRet(lzma_alone_decoder(&self->_, memlimit))); } -} +} // namespace lzma diff --git a/node_modules/lzma-native/src/module.cpp b/node_modules/lzma-native/src/module.cpp index 3001af1..b320556 100644 --- a/node_modules/lzma-native/src/module.cpp +++ b/node_modules/lzma-native/src/module.cpp @@ -5,96 +5,153 @@ namespace lzma { void moduleInit(Local exports) { LZMAStream::Init(exports); IndexParser::Init(exports); - - Nan::Set(exports, NewString("versionNumber"), Nan::GetFunction(Nan::New(lzmaVersionNumber)).ToLocalChecked()); - Nan::Set(exports, NewString("versionString"), Nan::GetFunction(Nan::New(lzmaVersionString)).ToLocalChecked()); - Nan::Set(exports, NewString("checkIsSupported"), Nan::GetFunction(Nan::New(lzmaCheckIsSupported)).ToLocalChecked()); - Nan::Set(exports, NewString("checkSize"), Nan::GetFunction(Nan::New(lzmaCheckSize)).ToLocalChecked()); - Nan::Set(exports, NewString("crc32_"), Nan::GetFunction(Nan::New(lzmaCRC32)).ToLocalChecked()); - Nan::Set(exports, NewString("filterEncoderIsSupported"), Nan::GetFunction(Nan::New(lzmaFilterEncoderIsSupported)).ToLocalChecked()); - Nan::Set(exports, NewString("filterDecoderIsSupported"), Nan::GetFunction(Nan::New(lzmaFilterDecoderIsSupported)).ToLocalChecked()); - Nan::Set(exports, NewString("rawEncoderMemusage"), Nan::GetFunction(Nan::New(lzmaRawEncoderMemusage)).ToLocalChecked()); - Nan::Set(exports, NewString("rawDecoderMemusage"), Nan::GetFunction(Nan::New(lzmaRawDecoderMemusage)).ToLocalChecked()); - Nan::Set(exports, NewString("mfIsSupported"), Nan::GetFunction(Nan::New(lzmaMfIsSupported)).ToLocalChecked()); - Nan::Set(exports, NewString("modeIsSupported"), Nan::GetFunction(Nan::New(lzmaModeIsSupported)).ToLocalChecked()); - Nan::Set(exports, NewString("easyEncoderMemusage"), Nan::GetFunction(Nan::New(lzmaEasyEncoderMemusage)).ToLocalChecked()); - Nan::Set(exports, NewString("easyDecoderMemusage"), Nan::GetFunction(Nan::New(lzmaEasyDecoderMemusage)).ToLocalChecked()); - + + Nan::Set(exports, NewString("versionNumber"), + Nan::GetFunction(Nan::New(lzmaVersionNumber)) + .ToLocalChecked()); + Nan::Set(exports, NewString("versionString"), + Nan::GetFunction(Nan::New(lzmaVersionString)) + .ToLocalChecked()); + Nan::Set(exports, NewString("checkIsSupported"), + Nan::GetFunction(Nan::New(lzmaCheckIsSupported)) + .ToLocalChecked()); + Nan::Set(exports, NewString("checkSize"), + Nan::GetFunction(Nan::New(lzmaCheckSize)) + .ToLocalChecked()); + Nan::Set( + exports, NewString("crc32_"), + Nan::GetFunction(Nan::New(lzmaCRC32)).ToLocalChecked()); + Nan::Set( + exports, NewString("filterEncoderIsSupported"), + Nan::GetFunction(Nan::New(lzmaFilterEncoderIsSupported)) + .ToLocalChecked()); + Nan::Set( + exports, NewString("filterDecoderIsSupported"), + Nan::GetFunction(Nan::New(lzmaFilterDecoderIsSupported)) + .ToLocalChecked()); + Nan::Set(exports, NewString("rawEncoderMemusage"), + Nan::GetFunction(Nan::New(lzmaRawEncoderMemusage)) + .ToLocalChecked()); + Nan::Set(exports, NewString("rawDecoderMemusage"), + Nan::GetFunction(Nan::New(lzmaRawDecoderMemusage)) + .ToLocalChecked()); + Nan::Set(exports, NewString("mfIsSupported"), + Nan::GetFunction(Nan::New(lzmaMfIsSupported)) + .ToLocalChecked()); + Nan::Set(exports, NewString("modeIsSupported"), + Nan::GetFunction(Nan::New(lzmaModeIsSupported)) + .ToLocalChecked()); + Nan::Set(exports, NewString("easyEncoderMemusage"), + Nan::GetFunction(Nan::New(lzmaEasyEncoderMemusage)) + .ToLocalChecked()); + Nan::Set(exports, NewString("easyDecoderMemusage"), + Nan::GetFunction(Nan::New(lzmaEasyDecoderMemusage)) + .ToLocalChecked()); + // enum lzma_ret - Nan::Set(exports, NewString("OK"), Nan::New(LZMA_OK)); - Nan::Set(exports, NewString("STREAM_END"), Nan::New(LZMA_STREAM_END)); - Nan::Set(exports, NewString("NO_CHECK"), Nan::New(LZMA_NO_CHECK)); - Nan::Set(exports, NewString("UNSUPPORTED_CHECK"), Nan::New(LZMA_UNSUPPORTED_CHECK)); - Nan::Set(exports, NewString("GET_CHECK"), Nan::New(LZMA_GET_CHECK)); - Nan::Set(exports, NewString("MEM_ERROR"), Nan::New(LZMA_MEM_ERROR)); - Nan::Set(exports, NewString("MEMLIMIT_ERROR"), Nan::New(LZMA_MEMLIMIT_ERROR)); - Nan::Set(exports, NewString("FORMAT_ERROR"), Nan::New(LZMA_FORMAT_ERROR)); - Nan::Set(exports, NewString("OPTIONS_ERROR"), Nan::New(LZMA_OPTIONS_ERROR)); - Nan::Set(exports, NewString("DATA_ERROR"), Nan::New(LZMA_DATA_ERROR)); - Nan::Set(exports, NewString("BUF_ERROR"), Nan::New(LZMA_BUF_ERROR)); - Nan::Set(exports, NewString("PROG_ERROR"), Nan::New(LZMA_PROG_ERROR)); - + Nan::Set(exports, NewString("OK"), Nan::New(LZMA_OK)); + Nan::Set(exports, NewString("STREAM_END"), Nan::New(LZMA_STREAM_END)); + Nan::Set(exports, NewString("NO_CHECK"), Nan::New(LZMA_NO_CHECK)); + Nan::Set(exports, NewString("UNSUPPORTED_CHECK"), + Nan::New(LZMA_UNSUPPORTED_CHECK)); + Nan::Set(exports, NewString("GET_CHECK"), Nan::New(LZMA_GET_CHECK)); + Nan::Set(exports, NewString("MEM_ERROR"), Nan::New(LZMA_MEM_ERROR)); + Nan::Set(exports, NewString("MEMLIMIT_ERROR"), + Nan::New(LZMA_MEMLIMIT_ERROR)); + Nan::Set(exports, NewString("FORMAT_ERROR"), + Nan::New(LZMA_FORMAT_ERROR)); + Nan::Set(exports, NewString("OPTIONS_ERROR"), + Nan::New(LZMA_OPTIONS_ERROR)); + Nan::Set(exports, NewString("DATA_ERROR"), Nan::New(LZMA_DATA_ERROR)); + Nan::Set(exports, NewString("BUF_ERROR"), Nan::New(LZMA_BUF_ERROR)); + Nan::Set(exports, NewString("PROG_ERROR"), Nan::New(LZMA_PROG_ERROR)); + // enum lzma_action - Nan::Set(exports, NewString("RUN"), Nan::New(LZMA_RUN)); + Nan::Set(exports, NewString("RUN"), Nan::New(LZMA_RUN)); Nan::Set(exports, NewString("SYNC_FLUSH"), Nan::New(LZMA_SYNC_FLUSH)); Nan::Set(exports, NewString("FULL_FLUSH"), Nan::New(LZMA_FULL_FLUSH)); - Nan::Set(exports, NewString("FINISH"), Nan::New(LZMA_FINISH)); - + Nan::Set(exports, NewString("FINISH"), Nan::New(LZMA_FINISH)); + // enum lzma_check - Nan::Set(exports, NewString("CHECK_NONE"), Nan::New(LZMA_CHECK_NONE)); - Nan::Set(exports, NewString("CHECK_CRC32"), Nan::New(LZMA_CHECK_CRC32)); - Nan::Set(exports, NewString("CHECK_CRC64"), Nan::New(LZMA_CHECK_CRC64)); - Nan::Set(exports, NewString("CHECK_SHA256"), Nan::New(LZMA_CHECK_SHA256)); - + Nan::Set(exports, NewString("CHECK_NONE"), Nan::New(LZMA_CHECK_NONE)); + Nan::Set(exports, NewString("CHECK_CRC32"), + Nan::New(LZMA_CHECK_CRC32)); + Nan::Set(exports, NewString("CHECK_CRC64"), + Nan::New(LZMA_CHECK_CRC64)); + Nan::Set(exports, NewString("CHECK_SHA256"), + Nan::New(LZMA_CHECK_SHA256)); + // lzma_match_finder Nan::Set(exports, NewString("MF_HC3"), Nan::New(LZMA_MF_HC3)); Nan::Set(exports, NewString("MF_HC4"), Nan::New(LZMA_MF_HC4)); Nan::Set(exports, NewString("MF_BT2"), Nan::New(LZMA_MF_BT2)); Nan::Set(exports, NewString("MF_BT3"), Nan::New(LZMA_MF_BT3)); Nan::Set(exports, NewString("MF_BT4"), Nan::New(LZMA_MF_BT4)); - + // lzma_mode - Nan::Set(exports, NewString("MODE_FAST"), Nan::New(LZMA_MODE_FAST)); - Nan::Set(exports, NewString("MODE_NORMAL"), Nan::New(LZMA_MODE_NORMAL)); - + Nan::Set(exports, NewString("MODE_FAST"), Nan::New(LZMA_MODE_FAST)); + Nan::Set(exports, NewString("MODE_NORMAL"), + Nan::New(LZMA_MODE_NORMAL)); + // defines - Nan::Set(exports, NewString("FILTER_X86"), NewString("LZMA_FILTER_X86")); - Nan::Set(exports, NewString("FILTER_POWERPC"), NewString("LZMA_FILTER_POWERPC")); - Nan::Set(exports, NewString("FILTER_IA64"), NewString("LZMA_FILTER_IA64")); - Nan::Set(exports, NewString("FILTER_ARM"), NewString("LZMA_FILTER_ARM")); - Nan::Set(exports, NewString("FILTER_ARMTHUMB"), NewString("LZMA_FILTER_ARMTHUMB")); - Nan::Set(exports, NewString("FILTER_SPARC"), NewString("LZMA_FILTER_SPARC")); - Nan::Set(exports, NewString("FILTER_DELTA"), NewString("LZMA_FILTER_DELTA")); - Nan::Set(exports, NewString("FILTERS_MAX"), NewString("LZMA_FILTERS_MAX")); - Nan::Set(exports, NewString("FILTER_LZMA1"), NewString("LZMA_FILTER_LZMA1")); - Nan::Set(exports, NewString("FILTER_LZMA2"), NewString("LZMA_FILTER_LZMA2")); - Nan::Set(exports, NewString("VLI_UNKNOWN"), NewString("LZMA_VLI_UNKNOWN")); - - Nan::Set(exports, NewString("VLI_BYTES_MAX"), Nan::New(LZMA_VLI_BYTES_MAX)); - Nan::Set(exports, NewString("CHECK_ID_MAX"), Nan::New(LZMA_CHECK_ID_MAX)); - Nan::Set(exports, NewString("CHECK_SIZE_MAX"), Nan::New(LZMA_CHECK_SIZE_MAX)); - Nan::Set(exports, NewString("PRESET_DEFAULT"), Nan::New(LZMA_PRESET_DEFAULT)); - Nan::Set(exports, NewString("PRESET_LEVEL_MASK"), Nan::New(LZMA_PRESET_LEVEL_MASK)); - Nan::Set(exports, NewString("PRESET_EXTREME"), Nan::New(LZMA_PRESET_EXTREME)); - Nan::Set(exports, NewString("TELL_NO_CHECK"), Nan::New(LZMA_TELL_NO_CHECK)); - Nan::Set(exports, NewString("TELL_UNSUPPORTED_CHECK"), Nan::New(LZMA_TELL_UNSUPPORTED_CHECK)); - Nan::Set(exports, NewString("TELL_ANY_CHECK"), Nan::New(LZMA_TELL_ANY_CHECK)); - Nan::Set(exports, NewString("CONCATENATED"), Nan::New(LZMA_CONCATENATED)); - Nan::Set(exports, NewString("STREAM_HEADER_SIZE"), Nan::New(LZMA_STREAM_HEADER_SIZE)); - Nan::Set(exports, NewString("VERSION_MAJOR"), Nan::New(LZMA_VERSION_MAJOR)); - Nan::Set(exports, NewString("VERSION_MINOR"), Nan::New(LZMA_VERSION_MINOR)); - Nan::Set(exports, NewString("VERSION_PATCH"), Nan::New(LZMA_VERSION_PATCH)); - Nan::Set(exports, NewString("VERSION_STABILITY"), Nan::New(LZMA_VERSION_STABILITY)); - Nan::Set(exports, NewString("VERSION_STABILITY_ALPHA"), Nan::New(LZMA_VERSION_STABILITY_ALPHA)); - Nan::Set(exports, NewString("VERSION_STABILITY_BETA"), Nan::New(LZMA_VERSION_STABILITY_BETA)); - Nan::Set(exports, NewString("VERSION_STABILITY_STABLE"), Nan::New(LZMA_VERSION_STABILITY_STABLE)); - Nan::Set(exports, NewString("VERSION"), Nan::New(LZMA_VERSION)); - Nan::Set(exports, NewString("VERSION_STRING"), NewString(LZMA_VERSION_STRING)); - - Nan::Set(exports, NewString("asyncCodeAvailable"), Nan::New(LZMAStream::asyncCodeAvailable)); -} + Nan::Set(exports, NewString("FILTER_X86"), NewString("LZMA_FILTER_X86")); + Nan::Set(exports, NewString("FILTER_POWERPC"), + NewString("LZMA_FILTER_POWERPC")); + Nan::Set(exports, NewString("FILTER_IA64"), NewString("LZMA_FILTER_IA64")); + Nan::Set(exports, NewString("FILTER_ARM"), NewString("LZMA_FILTER_ARM")); + Nan::Set(exports, NewString("FILTER_ARMTHUMB"), + NewString("LZMA_FILTER_ARMTHUMB")); + Nan::Set(exports, NewString("FILTER_SPARC"), NewString("LZMA_FILTER_SPARC")); + Nan::Set(exports, NewString("FILTER_DELTA"), NewString("LZMA_FILTER_DELTA")); + Nan::Set(exports, NewString("FILTERS_MAX"), NewString("LZMA_FILTERS_MAX")); + Nan::Set(exports, NewString("FILTER_LZMA1"), NewString("LZMA_FILTER_LZMA1")); + Nan::Set(exports, NewString("FILTER_LZMA2"), NewString("LZMA_FILTER_LZMA2")); + Nan::Set(exports, NewString("VLI_UNKNOWN"), NewString("LZMA_VLI_UNKNOWN")); + + Nan::Set(exports, NewString("VLI_BYTES_MAX"), + Nan::New(LZMA_VLI_BYTES_MAX)); + Nan::Set(exports, NewString("CHECK_ID_MAX"), + Nan::New(LZMA_CHECK_ID_MAX)); + Nan::Set(exports, NewString("CHECK_SIZE_MAX"), + Nan::New(LZMA_CHECK_SIZE_MAX)); + Nan::Set(exports, NewString("PRESET_DEFAULT"), + Nan::New(LZMA_PRESET_DEFAULT)); + Nan::Set(exports, NewString("PRESET_LEVEL_MASK"), + Nan::New(LZMA_PRESET_LEVEL_MASK)); + Nan::Set(exports, NewString("PRESET_EXTREME"), + Nan::New(LZMA_PRESET_EXTREME)); + Nan::Set(exports, NewString("TELL_NO_CHECK"), + Nan::New(LZMA_TELL_NO_CHECK)); + Nan::Set(exports, NewString("TELL_UNSUPPORTED_CHECK"), + Nan::New(LZMA_TELL_UNSUPPORTED_CHECK)); + Nan::Set(exports, NewString("TELL_ANY_CHECK"), + Nan::New(LZMA_TELL_ANY_CHECK)); + Nan::Set(exports, NewString("CONCATENATED"), + Nan::New(LZMA_CONCATENATED)); + Nan::Set(exports, NewString("STREAM_HEADER_SIZE"), + Nan::New(LZMA_STREAM_HEADER_SIZE)); + Nan::Set(exports, NewString("VERSION_MAJOR"), + Nan::New(LZMA_VERSION_MAJOR)); + Nan::Set(exports, NewString("VERSION_MINOR"), + Nan::New(LZMA_VERSION_MINOR)); + Nan::Set(exports, NewString("VERSION_PATCH"), + Nan::New(LZMA_VERSION_PATCH)); + Nan::Set(exports, NewString("VERSION_STABILITY"), + Nan::New(LZMA_VERSION_STABILITY)); + Nan::Set(exports, NewString("VERSION_STABILITY_ALPHA"), + Nan::New(LZMA_VERSION_STABILITY_ALPHA)); + Nan::Set(exports, NewString("VERSION_STABILITY_BETA"), + Nan::New(LZMA_VERSION_STABILITY_BETA)); + Nan::Set(exports, NewString("VERSION_STABILITY_STABLE"), + Nan::New(LZMA_VERSION_STABILITY_STABLE)); + Nan::Set(exports, NewString("VERSION"), Nan::New(LZMA_VERSION)); + Nan::Set(exports, NewString("VERSION_STRING"), + NewString(LZMA_VERSION_STRING)); + Nan::Set(exports, NewString("asyncCodeAvailable"), + Nan::New(LZMAStream::asyncCodeAvailable)); } -NODE_MODULE(lzma_native, lzma::moduleInit) +} // namespace lzma +NODE_MODULE(lzma_native, lzma::moduleInit) diff --git a/node_modules/lzma-native/src/mt-options.cpp b/node_modules/lzma-native/src/mt-options.cpp index d37bb59..ccb39ed 100644 --- a/node_modules/lzma-native/src/mt-options.cpp +++ b/node_modules/lzma-native/src/mt-options.cpp @@ -2,25 +2,29 @@ namespace lzma { -MTOptions::MTOptions() : filters_(NULL), ok_(false) { } +MTOptions::MTOptions() : filters_(NULL), ok_(false) {} -MTOptions::~MTOptions() { - delete filters_; -} +MTOptions::~MTOptions() { delete filters_; } MTOptions::MTOptions(Local opt) : filters_(NULL), ok_(true) { opts_.flags = 0; opts_.filters = NULL; - - opts_.block_size = Nan::To(Nan::Get(opt, NewString("blockSize")).ToLocalChecked()).ToChecked(); - opts_.timeout = Nan::To(Nan::Get(opt, NewString("timeout")).ToLocalChecked()) - .FromMaybe(0); - opts_.preset = Nan::To(Nan::Get(opt, NewString("preset")).ToLocalChecked()) - .FromMaybe(LZMA_PRESET_DEFAULT); - opts_.check = (lzma_check)Nan::To(Nan::Get(opt, NewString("check")).ToLocalChecked()) - .FromMaybe((int)LZMA_CHECK_CRC64); - opts_.threads = Nan::To(Nan::Get(opt, NewString("threads")).ToLocalChecked()) - .FromMaybe(0); + + opts_.block_size = + Nan::To(Nan::Get(opt, NewString("blockSize")).ToLocalChecked()) + .ToChecked(); + opts_.timeout = + Nan::To(Nan::Get(opt, NewString("timeout")).ToLocalChecked()) + .FromMaybe(0); + opts_.preset = + Nan::To(Nan::Get(opt, NewString("preset")).ToLocalChecked()) + .FromMaybe(LZMA_PRESET_DEFAULT); + opts_.check = (lzma_check)Nan::To( + Nan::Get(opt, NewString("check")).ToLocalChecked()) + .FromMaybe((int)LZMA_CHECK_CRC64); + opts_.threads = + Nan::To(Nan::Get(opt, NewString("threads")).ToLocalChecked()) + .FromMaybe(0); if (opts_.threads == 0) { opts_.threads = lzma_cputhreads(); @@ -37,4 +41,4 @@ MTOptions::MTOptions(Local opt) : filters_(NULL), ok_(true) { } } -} +} // namespace lzma diff --git a/node_modules/lzma-native/src/util.cpp b/node_modules/lzma-native/src/util.cpp index b97fe54..ef24ddd 100644 --- a/node_modules/lzma-native/src/util.cpp +++ b/node_modules/lzma-native/src/util.cpp @@ -1,6 +1,6 @@ #include "liblzma-node.hpp" -#include #include +#include namespace lzma { @@ -8,27 +8,26 @@ lzma_vli FilterByName(Local v) { Nan::Utf8String cmpto(v); if (cmpto.length() == 0) return LZMA_VLI_UNKNOWN; - + struct searchEntry { - const char* str; + const char *str; lzma_vli value; }; - + static const struct searchEntry search[] = { - { "LZMA_FILTER_X86", LZMA_FILTER_X86 }, - { "LZMA_FILTER_POWERPC", LZMA_FILTER_POWERPC }, - { "LZMA_FILTER_IA64", LZMA_FILTER_IA64 }, - { "LZMA_FILTER_ARM", LZMA_FILTER_ARM }, - { "LZMA_FILTER_ARMTHUMB", LZMA_FILTER_ARMTHUMB }, - { "LZMA_FILTER_SPARC", LZMA_FILTER_SPARC }, - { "LZMA_FILTER_DELTA", LZMA_FILTER_DELTA }, - { "LZMA_FILTER_LZMA1", LZMA_FILTER_LZMA1 }, - { "LZMA_FILTER_LZMA2", LZMA_FILTER_LZMA2 }, - { "LZMA_FILTERS_MAX", LZMA_FILTERS_MAX }, - { "LZMA_VLI_UNKNOWN", LZMA_VLI_UNKNOWN } - }; - - for (const struct searchEntry* p = search; ; ++p) + {"LZMA_FILTER_X86", LZMA_FILTER_X86}, + {"LZMA_FILTER_POWERPC", LZMA_FILTER_POWERPC}, + {"LZMA_FILTER_IA64", LZMA_FILTER_IA64}, + {"LZMA_FILTER_ARM", LZMA_FILTER_ARM}, + {"LZMA_FILTER_ARMTHUMB", LZMA_FILTER_ARMTHUMB}, + {"LZMA_FILTER_SPARC", LZMA_FILTER_SPARC}, + {"LZMA_FILTER_DELTA", LZMA_FILTER_DELTA}, + {"LZMA_FILTER_LZMA1", LZMA_FILTER_LZMA1}, + {"LZMA_FILTER_LZMA2", LZMA_FILTER_LZMA2}, + {"LZMA_FILTERS_MAX", LZMA_FILTERS_MAX}, + {"LZMA_VLI_UNKNOWN", LZMA_VLI_UNKNOWN}}; + + for (const struct searchEntry *p = search;; ++p) if (p->value == LZMA_VLI_UNKNOWN || std::strcmp(*cmpto, p->str) == 0) return p->value; } @@ -36,83 +35,88 @@ lzma_vli FilterByName(Local v) { Local lzmaRetError(lzma_ret rv) { struct errorInfo { lzma_ret code; - const char* name; - const char* desc; + const char *name; + const char *desc; }; - + /* description strings taken from liblzma/…/api/base.h */ static const struct errorInfo searchErrorInfo[] = { - { LZMA_OK, "LZMA_OK", "Operation completed successfully" }, - { LZMA_STREAM_END, "LZMA_STREAM_END", "End of stream was reached" }, - { LZMA_NO_CHECK, "LZMA_NO_CHECK", "Input stream has no integrity check" }, - { LZMA_UNSUPPORTED_CHECK, "LZMA_UNSUPPORTED_CHECK", "Cannot calculate the integrity check" }, - { LZMA_GET_CHECK, "LZMA_GET_CHECK", "Integrity check type is now available" }, - { LZMA_MEM_ERROR, "LZMA_MEM_ERROR", "Cannot allocate memory" }, - { LZMA_MEMLIMIT_ERROR, "LZMA_MEMLIMIT_ERROR", "Memory usage limit was reached" }, - { LZMA_FORMAT_ERROR, "LZMA_FORMAT_ERROR", "File format not recognized" }, - { LZMA_OPTIONS_ERROR, "LZMA_OPTIONS_ERROR", "Invalid or unsupported options" }, - { LZMA_DATA_ERROR, "LZMA_DATA_ERROR", "Data is corrupt" }, - { LZMA_PROG_ERROR, "LZMA_PROG_ERROR", "Programming error" }, - { LZMA_BUF_ERROR, "LZMA_BUF_ERROR", "No progress is possible" }, - { (lzma_ret)-1, "LZMA_UNKNOWN_ERROR", "Unknown error code" } - }; - - const struct errorInfo* p = searchErrorInfo; + {LZMA_OK, "LZMA_OK", "Operation completed successfully"}, + {LZMA_STREAM_END, "LZMA_STREAM_END", "End of stream was reached"}, + {LZMA_NO_CHECK, "LZMA_NO_CHECK", "Input stream has no integrity check"}, + {LZMA_UNSUPPORTED_CHECK, "LZMA_UNSUPPORTED_CHECK", + "Cannot calculate the integrity check"}, + {LZMA_GET_CHECK, "LZMA_GET_CHECK", + "Integrity check type is now available"}, + {LZMA_MEM_ERROR, "LZMA_MEM_ERROR", "Cannot allocate memory"}, + {LZMA_MEMLIMIT_ERROR, "LZMA_MEMLIMIT_ERROR", + "Memory usage limit was reached"}, + {LZMA_FORMAT_ERROR, "LZMA_FORMAT_ERROR", "File format not recognized"}, + {LZMA_OPTIONS_ERROR, "LZMA_OPTIONS_ERROR", + "Invalid or unsupported options"}, + {LZMA_DATA_ERROR, "LZMA_DATA_ERROR", "Data is corrupt"}, + {LZMA_PROG_ERROR, "LZMA_PROG_ERROR", "Programming error"}, + {LZMA_BUF_ERROR, "LZMA_BUF_ERROR", "No progress is possible"}, + {(lzma_ret)-1, "LZMA_UNKNOWN_ERROR", "Unknown error code"}}; + + const struct errorInfo *p = searchErrorInfo; while (p->code != rv && p->code != (lzma_ret)-1) ++p; - + Local e = Local::Cast(Nan::Error(p->desc)); Nan::Set(e, NewString("code"), Nan::New(rv)); Nan::Set(e, NewString("name"), NewString(p->name)); Nan::Set(e, NewString("desc"), NewString(p->desc)); - + return e; } Local lzmaRet(lzma_ret rv) { if (rv != LZMA_OK && rv != LZMA_STREAM_END) Nan::ThrowError(Local(lzmaRetError(rv))); - + return Nan::New(rv); } -bool readBufferFromObj(Local buf_, std::vector& data) { +bool readBufferFromObj(Local buf_, std::vector &data) { if (buf_.IsEmpty() || !node::Buffer::HasInstance(buf_)) { Nan::ThrowTypeError("Expected Buffer as input"); return false; } - + Local buf = Local::Cast(buf_); size_t len = node::Buffer::Length(buf); - const uint8_t* ptr = reinterpret_cast(len > 0 ? node::Buffer::Data(buf) : ""); - + const uint8_t *ptr = + reinterpret_cast(len > 0 ? node::Buffer::Data(buf) : ""); + data = std::vector(ptr, ptr + len); - + return true; } -lzma_options_lzma parseOptionsLZMA (Local obj) { +lzma_options_lzma parseOptionsLZMA(Local obj) { Nan::HandleScope(); lzma_options_lzma r; - + if (obj.IsEmpty() || obj->IsUndefined()) obj = Nan::New(); - + r.dict_size = GetIntegerProperty(obj, "dictSize", LZMA_DICT_SIZE_DEFAULT); r.lp = GetIntegerProperty(obj, "lp", LZMA_LP_DEFAULT); r.lc = GetIntegerProperty(obj, "lc", LZMA_LC_DEFAULT); r.pb = GetIntegerProperty(obj, "pb", LZMA_PB_DEFAULT); r.mode = (lzma_mode)GetIntegerProperty(obj, "mode", (uint64_t)LZMA_MODE_FAST); r.nice_len = GetIntegerProperty(obj, "niceLen", 64); - r.mf = (lzma_match_finder)GetIntegerProperty(obj, "mf", (uint64_t)LZMA_MF_HC4); + r.mf = + (lzma_match_finder)GetIntegerProperty(obj, "mf", (uint64_t)LZMA_MF_HC4); r.depth = GetIntegerProperty(obj, "depth", 0); uint64_t preset_ = GetIntegerProperty(obj, "preset", UINT64_MAX); - + r.preset_dict = NULL; - - if (preset_ != UINT64_MAX) + + if (preset_ != UINT64_MAX) lzma_lzma_preset(&r, preset_); - + return r; } @@ -133,18 +137,18 @@ Local Uint64ToNumber0Null(uint64_t in) { uint64_t NumberToUint64ClampNullMax(Local in) { if (in->IsNull() || in->IsUndefined()) return UINT64_MAX; - + Local n = Local::Cast(in); if (n.IsEmpty() && !in.IsEmpty()) { Nan::ThrowTypeError("Number required"); return UINT64_MAX; } - + Local integer = Local::Cast(n); if (!integer.IsEmpty()) return integer->Value(); - + return n->Value(); } -} +} // namespace lzma diff --git a/node_modules/nan/nan.h b/node_modules/nan/nan.h index 1ac7f74..3550426 100644 --- a/node_modules/nan/nan.h +++ b/node_modules/nan/nan.h @@ -13,7 +13,8 @@ * * MIT License * - * Version 2.22.0: current Node 22.9.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1 + * Version 2.22.0: current Node 22.9.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, + *iojs: 3.3.1 * * See https://github.com/nodejs/nan for the latest update to this file **********************************************************************************/ @@ -26,16 +27,16 @@ #define NODE_0_10_MODULE_VERSION 11 #define NODE_0_12_MODULE_VERSION 14 #define ATOM_0_21_MODULE_VERSION 41 -#define IOJS_1_0_MODULE_VERSION 42 -#define IOJS_1_1_MODULE_VERSION 43 -#define IOJS_2_0_MODULE_VERSION 44 -#define IOJS_3_0_MODULE_VERSION 45 -#define NODE_4_0_MODULE_VERSION 46 -#define NODE_5_0_MODULE_VERSION 47 -#define NODE_6_0_MODULE_VERSION 48 -#define NODE_7_0_MODULE_VERSION 51 -#define NODE_8_0_MODULE_VERSION 57 -#define NODE_9_0_MODULE_VERSION 59 +#define IOJS_1_0_MODULE_VERSION 42 +#define IOJS_1_1_MODULE_VERSION 43 +#define IOJS_2_0_MODULE_VERSION 44 +#define IOJS_3_0_MODULE_VERSION 45 +#define NODE_4_0_MODULE_VERSION 46 +#define NODE_5_0_MODULE_VERSION 47 +#define NODE_6_0_MODULE_VERSION 48 +#define NODE_7_0_MODULE_VERSION 51 +#define NODE_8_0_MODULE_VERSION 57 +#define NODE_9_0_MODULE_VERSION 59 #define NODE_10_0_MODULE_VERSION 64 #define NODE_11_0_MODULE_VERSION 67 #define NODE_12_0_MODULE_VERSION 72 @@ -49,55 +50,54 @@ #define NODE_20_0_MODULE_VERSION 115 #ifdef _MSC_VER -# define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800) +#define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800) #else -# define NAN_HAS_CPLUSPLUS_11 (__cplusplus >= 201103L) +#define NAN_HAS_CPLUSPLUS_11 (__cplusplus >= 201103L) #endif #if NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION && !NAN_HAS_CPLUSPLUS_11 -# error This version of node/NAN/v8 requires a C++11 compiler +#error This version of node/NAN/v8 requires a C++11 compiler #endif -#include -#include -#include -#include #include -#include #include #include +#include +#include +#include +#include #include +#include #if defined(_MSC_VER) -# pragma warning( push ) -# pragma warning( disable : 4530 ) -# include -# include -# include -# pragma warning( pop ) +#pragma warning(push) +#pragma warning(disable : 4530) +#include +#include +#include +#pragma warning(pop) #else -# include -# include -# include +#include +#include +#include #endif // uv helpers #ifdef UV_VERSION_MAJOR -# ifndef UV_VERSION_PATCH -# define UV_VERSION_PATCH 0 -# endif -# define NAUV_UVVERSION ((UV_VERSION_MAJOR << 16) | \ - (UV_VERSION_MINOR << 8) | \ - (UV_VERSION_PATCH)) +#ifndef UV_VERSION_PATCH +#define UV_VERSION_PATCH 0 +#endif +#define NAUV_UVVERSION \ + ((UV_VERSION_MAJOR << 16) | (UV_VERSION_MINOR << 8) | (UV_VERSION_PATCH)) #else -# define NAUV_UVVERSION 0x000b00 +#define NAUV_UVVERSION 0x000b00 #endif #if NAUV_UVVERSION < 0x000b0b -# ifdef WIN32 -# include -# else -# include -# endif +#ifdef WIN32 +#include +#else +#include +#endif #endif namespace Nan { @@ -105,231 +105,213 @@ namespace Nan { #define NAN_CONCAT(a, b) NAN_CONCAT_HELPER(a, b) #define NAN_CONCAT_HELPER(a, b) a##b -#define NAN_INLINE inline // TODO(bnoordhuis) Remove in v3.0.0. +#define NAN_INLINE inline // TODO(bnoordhuis) Remove in v3.0.0. -#if defined(__GNUC__) && \ +#if defined(__GNUC__) && \ !(defined(V8_DISABLE_DEPRECATIONS) && V8_DISABLE_DEPRECATIONS) -# define NAN_DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) && \ +#define NAN_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) && \ !(defined(V8_DISABLE_DEPRECATIONS) && V8_DISABLE_DEPRECATIONS) -# define NAN_DEPRECATED __declspec(deprecated) +#define NAN_DEPRECATED __declspec(deprecated) #else -# define NAN_DEPRECATED +#define NAN_DEPRECATED #endif #if NAN_HAS_CPLUSPLUS_11 -# define NAN_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS&) = delete; -# define NAN_DISALLOW_COPY(CLASS) CLASS(const CLASS&) = delete; -# define NAN_DISALLOW_MOVE(CLASS) \ - CLASS(CLASS&&) = delete; /* NOLINT(build/c++11) */ \ - void operator=(CLASS&&) = delete; +#define NAN_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS &) = delete; +#define NAN_DISALLOW_COPY(CLASS) CLASS(const CLASS &) = delete; +#define NAN_DISALLOW_MOVE(CLASS) \ + CLASS(CLASS &&) = delete; /* NOLINT(build/c++11) */ \ + void operator=(CLASS &&) = delete; #else -# define NAN_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS&); -# define NAN_DISALLOW_COPY(CLASS) CLASS(const CLASS&); -# define NAN_DISALLOW_MOVE(CLASS) +#define NAN_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS &); +#define NAN_DISALLOW_COPY(CLASS) CLASS(const CLASS &); +#define NAN_DISALLOW_MOVE(CLASS) #endif #define NAN_DISALLOW_ASSIGN_COPY(CLASS) \ - NAN_DISALLOW_ASSIGN(CLASS) \ - NAN_DISALLOW_COPY(CLASS) + NAN_DISALLOW_ASSIGN(CLASS) \ + NAN_DISALLOW_COPY(CLASS) #define NAN_DISALLOW_ASSIGN_MOVE(CLASS) \ - NAN_DISALLOW_ASSIGN(CLASS) \ - NAN_DISALLOW_MOVE(CLASS) + NAN_DISALLOW_ASSIGN(CLASS) \ + NAN_DISALLOW_MOVE(CLASS) #define NAN_DISALLOW_COPY_MOVE(CLASS) \ - NAN_DISALLOW_COPY(CLASS) \ - NAN_DISALLOW_MOVE(CLASS) + NAN_DISALLOW_COPY(CLASS) \ + NAN_DISALLOW_MOVE(CLASS) #define NAN_DISALLOW_ASSIGN_COPY_MOVE(CLASS) \ - NAN_DISALLOW_ASSIGN(CLASS) \ - NAN_DISALLOW_COPY(CLASS) \ - NAN_DISALLOW_MOVE(CLASS) + NAN_DISALLOW_ASSIGN(CLASS) \ + NAN_DISALLOW_COPY(CLASS) \ + NAN_DISALLOW_MOVE(CLASS) #define TYPE_CHECK(T, S) \ - while (false) { \ - *(static_cast(0)) = static_cast(0); \ - } + while (false) { \ + *(static_cast(0)) = static_cast(0); \ + } //=== RegistrationFunction ===================================================== #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - typedef v8::Handle ADDON_REGISTER_FUNCTION_ARGS_TYPE; +typedef v8::Handle ADDON_REGISTER_FUNCTION_ARGS_TYPE; #else - typedef v8::Local ADDON_REGISTER_FUNCTION_ARGS_TYPE; +typedef v8::Local ADDON_REGISTER_FUNCTION_ARGS_TYPE; #endif #define NAN_MODULE_INIT(name) \ - void name(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target) + void name(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target) -#if NODE_MAJOR_VERSION >= 10 || \ +#if NODE_MAJOR_VERSION >= 10 || \ NODE_MAJOR_VERSION == 9 && NODE_MINOR_VERSION >= 3 #define NAN_MODULE_WORKER_ENABLED(module_name, registration) \ - extern "C" NODE_MODULE_EXPORT void \ - NAN_CONCAT(node_register_module_v, NODE_MODULE_VERSION)( \ - v8::Local exports, v8::Local module, \ - v8::Local context) \ - { \ - registration(exports); \ - } + extern "C" NODE_MODULE_EXPORT void NAN_CONCAT(node_register_module_v, \ + NODE_MODULE_VERSION)( \ + v8::Local exports, v8::Local module, \ + v8::Local context) { \ + registration(exports); \ + } #else #define NAN_MODULE_WORKER_ENABLED(module_name, registration) \ - NODE_MODULE(module_name, registration) + NODE_MODULE(module_name, registration) #endif //=== CallbackInfo ============================================================= -#include "nan_callbacks.h" // NOLINT(build/include) +#include "nan_callbacks.h" // NOLINT(build/include) //============================================================================== #if (NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION) -typedef v8::Script UnboundScript; -typedef v8::Script BoundScript; +typedef v8::Script UnboundScript; +typedef v8::Script BoundScript; #else -typedef v8::UnboundScript UnboundScript; -typedef v8::Script BoundScript; +typedef v8::UnboundScript UnboundScript; +typedef v8::Script BoundScript; #endif #if (NODE_MODULE_VERSION < ATOM_0_21_MODULE_VERSION) -typedef v8::String::ExternalAsciiStringResource - ExternalOneByteStringResource; +typedef v8::String::ExternalAsciiStringResource ExternalOneByteStringResource; #else -typedef v8::String::ExternalOneByteStringResource - ExternalOneByteStringResource; +typedef v8::String::ExternalOneByteStringResource ExternalOneByteStringResource; #endif #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) -template -class NonCopyablePersistentTraits : - public v8::NonCopyablePersistentTraits {}; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 10 || \ - (V8_MAJOR_VERSION == 10 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5)) -template struct CopyablePersistentTraits { - typedef v8::Persistent > CopyablePersistent; +template +class NonCopyablePersistentTraits : public v8::NonCopyablePersistentTraits { +}; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 10 || \ + (V8_MAJOR_VERSION == 10 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 5)) +template struct CopyablePersistentTraits { + typedef v8::Persistent> CopyablePersistent; static const bool kResetInDestructor = true; template static NAN_INLINE void Copy(const v8::Persistent &source, - CopyablePersistent *dest) { - } + CopyablePersistent *dest) {} }; #else -template -class CopyablePersistentTraits : - public v8::CopyablePersistentTraits {}; +template +class CopyablePersistentTraits : public v8::CopyablePersistentTraits {}; #endif -template -class PersistentBase : - public v8::PersistentBase {}; +template class PersistentBase : public v8::PersistentBase {}; -template > +template > class Persistent; #else -template class NonCopyablePersistentTraits; -template class PersistentBase; -template class WeakCallbackData; -template > +template class NonCopyablePersistentTraits; +template class PersistentBase; +template class WeakCallbackData; +template > class Persistent; -#endif // NODE_MODULE_VERSION +#endif // NODE_MODULE_VERSION -template -class Maybe { - public: +template class Maybe { +public: inline bool IsNothing() const { return !has_value_; } inline bool IsJust() const { return has_value_; } inline T ToChecked() const { return FromJust(); } inline void Check() const { FromJust(); } - inline bool To(T* out) const { - if (IsJust()) *out = value_; + inline bool To(T *out) const { + if (IsJust()) + *out = value_; return IsJust(); } inline T FromJust() const { #if defined(V8_ENABLE_CHECKS) assert(IsJust() && "FromJust is Nothing"); -#endif // V8_ENABLE_CHECKS +#endif // V8_ENABLE_CHECKS return value_; } - inline T FromMaybe(const T& default_value) const { + inline T FromMaybe(const T &default_value) const { return has_value_ ? value_ : default_value; } inline bool operator==(const Maybe &other) const { return (IsJust() == other.IsJust()) && - (!IsJust() || FromJust() == other.FromJust()); + (!IsJust() || FromJust() == other.FromJust()); } inline bool operator!=(const Maybe &other) const { return !operator==(other); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) // Allow implicit conversions from v8::Maybe to Nan::Maybe. - Maybe(const v8::Maybe& that) // NOLINT(runtime/explicit) - : has_value_(that.IsJust()) - , value_(that.FromMaybe(T())) {} + Maybe(const v8::Maybe &that) // NOLINT(runtime/explicit) + : has_value_(that.IsJust()), value_(that.FromMaybe(T())) {} #endif - private: +private: Maybe() : has_value_(false) {} - explicit Maybe(const T& t) : has_value_(true), value_(t) {} + explicit Maybe(const T &t) : has_value_(true), value_(t) {} bool has_value_; T value_; - template - friend Maybe Nothing(); - template - friend Maybe Just(const U& u); + template friend Maybe Nothing(); + template friend Maybe Just(const U &u); }; -template -inline Maybe Nothing() { - return Maybe(); -} +template inline Maybe Nothing() { return Maybe(); } -template -inline Maybe Just(const T& t) { - return Maybe(t); -} +template inline Maybe Just(const T &t) { return Maybe(t); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -# include "nan_maybe_43_inl.h" // NOLINT(build/include) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +#include "nan_maybe_43_inl.h" // NOLINT(build/include) #else -# include "nan_maybe_pre_43_inl.h" // NOLINT(build/include) +#include "nan_maybe_pre_43_inl.h" // NOLINT(build/include) #endif -#include "nan_converters.h" // NOLINT(build/include) -#include "nan_new.h" // NOLINT(build/include) +#include "nan_converters.h" // NOLINT(build/include) +#include "nan_new.h" // NOLINT(build/include) #if NAUV_UVVERSION < 0x000b17 -#define NAUV_WORK_CB(func) \ - void func(uv_async_t *async, int) +#define NAUV_WORK_CB(func) void func(uv_async_t *async, int) #else -#define NAUV_WORK_CB(func) \ - void func(uv_async_t *async) +#define NAUV_WORK_CB(func) void func(uv_async_t *async) #endif #if NAUV_UVVERSION >= 0x000b0b typedef uv_key_t nauv_key_t; -inline int nauv_key_create(nauv_key_t *key) { - return uv_key_create(key); -} +inline int nauv_key_create(nauv_key_t *key) { return uv_key_create(key); } -inline void nauv_key_delete(nauv_key_t *key) { - uv_key_delete(key); -} +inline void nauv_key_delete(nauv_key_t *key) { uv_key_delete(key); } -inline void* nauv_key_get(nauv_key_t *key) { - return uv_key_get(key); -} +inline void *nauv_key_get(nauv_key_t *key) { return uv_key_get(key); } inline void nauv_key_set(nauv_key_t *key, void *value) { uv_key_set(key, value); @@ -346,20 +328,18 @@ inline void nauv_key_set(nauv_key_t *key, void *value) { typedef pthread_key_t nauv_key_t; -inline int nauv_key_create(nauv_key_t* key) { +inline int nauv_key_create(nauv_key_t *key) { return -pthread_key_create(key, NULL); } -inline void nauv_key_delete(nauv_key_t* key) { +inline void nauv_key_delete(nauv_key_t *key) { if (pthread_key_delete(*key)) abort(); } -inline void* nauv_key_get(nauv_key_t* key) { - return pthread_getspecific(*key); -} +inline void *nauv_key_get(nauv_key_t *key) { return pthread_getspecific(*key); } -inline void nauv_key_set(nauv_key_t* key, void* value) { +inline void nauv_key_set(nauv_key_t *key, void *value) { if (pthread_setspecific(*key, value)) abort(); } @@ -370,28 +350,28 @@ typedef struct { DWORD tls_index; } nauv_key_t; -inline int nauv_key_create(nauv_key_t* key) { +inline int nauv_key_create(nauv_key_t *key) { key->tls_index = TlsAlloc(); if (key->tls_index == TLS_OUT_OF_INDEXES) return UV_ENOMEM; return 0; } -inline void nauv_key_delete(nauv_key_t* key) { +inline void nauv_key_delete(nauv_key_t *key) { if (TlsFree(key->tls_index) == FALSE) abort(); key->tls_index = TLS_OUT_OF_INDEXES; } -inline void* nauv_key_get(nauv_key_t* key) { - void* value = TlsGetValue(key->tls_index); +inline void *nauv_key_get(nauv_key_t *key) { + void *value = TlsGetValue(key->tls_index); if (value == NULL) if (GetLastError() != ERROR_SUCCESS) abort(); return value; } -inline void nauv_key_set(nauv_key_t* key, void* value) { +inline void nauv_key_set(nauv_key_t *key, void *value) { if (TlsSetValue(key->tls_index, value) == FALSE) abort(); } @@ -400,51 +380,51 @@ inline void nauv_key_set(nauv_key_t* key, void* value) { #endif #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION -template -v8::Local New(v8::Handle); +template v8::Local New(v8::Handle); #endif -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) - typedef v8::WeakCallbackType WeakCallbackType; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +typedef v8::WeakCallbackType WeakCallbackType; #else struct WeakCallbackType { - enum E {kParameter, kInternalFields}; + enum E { kParameter, kInternalFields }; E type; - WeakCallbackType(E other) : type(other) {} // NOLINT(runtime/explicit) + WeakCallbackType(E other) : type(other) {} // NOLINT(runtime/explicit) inline bool operator==(E other) { return other == this->type; } inline bool operator!=(E other) { return !operator==(other); } }; #endif -template class WeakCallbackInfo; +template class WeakCallbackInfo; #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION -# include "nan_persistent_12_inl.h" // NOLINT(build/include) +#include "nan_persistent_12_inl.h" // NOLINT(build/include) #else -# include "nan_persistent_pre_12_inl.h" // NOLINT(build/include) +#include "nan_persistent_pre_12_inl.h" // NOLINT(build/include) #endif namespace imp { - static const size_t kMaxLength = 0x3fffffff; - // v8::String::REPLACE_INVALID_UTF8 was introduced - // in node.js v0.10.29 and v0.8.27. -#if NODE_MAJOR_VERSION > 0 || \ - NODE_MINOR_VERSION > 10 || \ - NODE_MINOR_VERSION == 10 && NODE_PATCH_VERSION >= 29 || \ +static const size_t kMaxLength = 0x3fffffff; +// v8::String::REPLACE_INVALID_UTF8 was introduced +// in node.js v0.10.29 and v0.8.27. +#if NODE_MAJOR_VERSION > 0 || NODE_MINOR_VERSION > 10 || \ + NODE_MINOR_VERSION == 10 && NODE_PATCH_VERSION >= 29 || \ NODE_MINOR_VERSION == 8 && NODE_PATCH_VERSION >= 27 - static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8; +static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8; #else - static const unsigned kReplaceInvalidUtf8 = 0; +static const unsigned kReplaceInvalidUtf8 = 0; #endif -} // end of namespace imp +} // end of namespace imp //=== HandleScope ============================================================== class HandleScope { v8::HandleScope scope; - public: +public: #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION inline HandleScope() : scope(v8::Isolate::GetCurrent()) {} inline static int NumberOfHandles() { @@ -457,19 +437,17 @@ class HandleScope { } #endif - private: +private: // Make it hard to create heap-allocated or illegal handle scopes by // disallowing certain operations. HandleScope(const HandleScope &); void operator=(const HandleScope &); void *operator new(size_t size); - void operator delete(void *, size_t) { - abort(); - } + void operator delete(void *, size_t) { abort(); } }; class EscapableHandleScope { - public: +public: #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION inline EscapableHandleScope() : scope(v8::Isolate::GetCurrent()) {} @@ -477,12 +455,11 @@ class EscapableHandleScope { return v8::EscapableHandleScope::NumberOfHandles(v8::Isolate::GetCurrent()); } - template - inline v8::Local Escape(v8::Local value) { + template inline v8::Local Escape(v8::Local value) { return scope.Escape(value); } - private: +private: v8::EscapableHandleScope scope; #else inline EscapableHandleScope() : scope() {} @@ -491,33 +468,30 @@ class EscapableHandleScope { return v8::HandleScope::NumberOfHandles(); } - template - inline v8::Local Escape(v8::Local value) { + template inline v8::Local Escape(v8::Local value) { return scope.Close(value); } - private: +private: v8::HandleScope scope; #endif - private: +private: // Make it hard to create heap-allocated or illegal handle scopes by // disallowing certain operations. EscapableHandleScope(const EscapableHandleScope &); void operator=(const EscapableHandleScope &); void *operator new(size_t size); - void operator delete(void *, size_t) { - abort(); - } + void operator delete(void *, size_t) { abort(); } }; //=== TryCatch ================================================================= class TryCatch { v8::TryCatch try_catch_; - friend void FatalException(const TryCatch&); + friend void FatalException(const TryCatch &); - public: +public: #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION TryCatch() : try_catch_(v8::Isolate::GetCurrent()) {} #endif @@ -538,8 +512,10 @@ class TryCatch { return try_catch_.Exception(); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) inline v8::MaybeLocal StackTrace() const { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); @@ -552,9 +528,7 @@ class TryCatch { } #endif - inline v8::Local Message() const { - return try_catch_.Message(); - } + inline v8::Local Message() const { return try_catch_.Message(); } inline void Reset() { try_catch_.Reset(); } @@ -566,27 +540,23 @@ class TryCatch { }; v8::Local MakeCallback(v8::Local target, - v8::Local func, - int argc, - v8::Local* argv); + v8::Local func, int argc, + v8::Local *argv); v8::Local MakeCallback(v8::Local target, - v8::Local symbol, - int argc, - v8::Local* argv); + v8::Local symbol, int argc, + v8::Local *argv); v8::Local MakeCallback(v8::Local target, - const char* method, - int argc, - v8::Local* argv); + const char *method, int argc, + v8::Local *argv); // === AsyncResource =========================================================== class AsyncResource { - public: - AsyncResource( - v8::Local name - , v8::Local resource = New()) { +public: + AsyncResource(v8::Local name, + v8::Local resource = New()) { #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); if (resource.IsEmpty()) { resource = New(); @@ -596,82 +566,76 @@ class AsyncResource { #endif } - AsyncResource( - const char* name - , v8::Local resource = New()) { + AsyncResource(const char *name, + v8::Local resource = New()) { #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); if (resource.IsEmpty()) { resource = New(); } - v8::Local name_string = - New(name).ToLocalChecked(); + v8::Local name_string = New(name).ToLocalChecked(); context = node::EmitAsyncInit(isolate, resource, name_string); #endif } ~AsyncResource() { #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); node::EmitAsyncDestroy(isolate, context); #endif } - inline MaybeLocal runInAsyncScope( - v8::Local target - , v8::Local func - , int argc - , v8::Local* argv) { + inline MaybeLocal runInAsyncScope(v8::Local target, + v8::Local func, + int argc, + v8::Local *argv) { #if NODE_MODULE_VERSION < NODE_9_0_MODULE_VERSION return MakeCallback(target, func, argc, argv); #else - return node::MakeCallback( - v8::Isolate::GetCurrent(), target, func, argc, argv, context); + return node::MakeCallback(v8::Isolate::GetCurrent(), target, func, argc, + argv, context); #endif } - inline MaybeLocal runInAsyncScope( - v8::Local target - , v8::Local symbol - , int argc - , v8::Local* argv) { + inline MaybeLocal runInAsyncScope(v8::Local target, + v8::Local symbol, + int argc, + v8::Local *argv) { #if NODE_MODULE_VERSION < NODE_9_0_MODULE_VERSION return MakeCallback(target, symbol, argc, argv); #else - return node::MakeCallback( - v8::Isolate::GetCurrent(), target, symbol, argc, argv, context); + return node::MakeCallback(v8::Isolate::GetCurrent(), target, symbol, argc, + argv, context); #endif } - inline MaybeLocal runInAsyncScope( - v8::Local target - , const char* method - , int argc - , v8::Local* argv) { + inline MaybeLocal runInAsyncScope(v8::Local target, + const char *method, int argc, + v8::Local *argv) { #if NODE_MODULE_VERSION < NODE_9_0_MODULE_VERSION return MakeCallback(target, method, argc, argv); #else - return node::MakeCallback( - v8::Isolate::GetCurrent(), target, method, argc, argv, context); + return node::MakeCallback(v8::Isolate::GetCurrent(), target, method, argc, + argv, context); #endif } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(AsyncResource) #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION node::async_context context; #endif }; -inline uv_loop_t* GetCurrentEventLoop() { -#if NODE_MAJOR_VERSION >= 10 || \ - NODE_MAJOR_VERSION == 9 && NODE_MINOR_VERSION >= 3 || \ - NODE_MAJOR_VERSION == 8 && NODE_MINOR_VERSION >= 10 - return node::GetCurrentEventLoop(v8::Isolate::GetCurrent()); +inline uv_loop_t *GetCurrentEventLoop() { +#if NODE_MAJOR_VERSION >= 10 || \ + NODE_MAJOR_VERSION == 9 && NODE_MINOR_VERSION >= 3 || \ + NODE_MAJOR_VERSION == 8 && NODE_MINOR_VERSION >= 10 + return node::GetCurrentEventLoop(v8::Isolate::GetCurrent()); #else - return uv_default_loop(); + return uv_default_loop(); #endif } @@ -679,478 +643,418 @@ inline uv_loop_t* GetCurrentEventLoop() { /* node 0.12 */ #if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION - inline - void SetCounterFunction(v8::CounterLookupCallback cb) { - v8::Isolate::GetCurrent()->SetCounterFunction(cb); - } +inline void SetCounterFunction(v8::CounterLookupCallback cb) { + v8::Isolate::GetCurrent()->SetCounterFunction(cb); +} - inline - void SetCreateHistogramFunction(v8::CreateHistogramCallback cb) { - v8::Isolate::GetCurrent()->SetCreateHistogramFunction(cb); - } +inline void SetCreateHistogramFunction(v8::CreateHistogramCallback cb) { + v8::Isolate::GetCurrent()->SetCreateHistogramFunction(cb); +} - inline - void SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { - v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb); - } +inline void SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { + v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb); +} #if defined(V8_MAJOR_VERSION) && \ - (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ - V8_MINOR_VERSION >= 7)) - NAN_DEPRECATED inline bool IdleNotification(int) { - return true; - } -# elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) - NAN_DEPRECATED inline bool IdleNotification(int idle_time_in_ms) { - return v8::Isolate::GetCurrent()->IdleNotificationDeadline( - idle_time_in_ms * 0.001); - } -# else - NAN_DEPRECATED inline bool IdleNotification(int idle_time_in_ms) { - return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms); - } + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 7)) +NAN_DEPRECATED inline bool IdleNotification(int) { return true; } +#elif defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +NAN_DEPRECATED inline bool IdleNotification(int idle_time_in_ms) { + return v8::Isolate::GetCurrent()->IdleNotificationDeadline(idle_time_in_ms * + 0.001); +} +#else +NAN_DEPRECATED inline bool IdleNotification(int idle_time_in_ms) { + return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms); +} #endif - inline void LowMemoryNotification() { - v8::Isolate::GetCurrent()->LowMemoryNotification(); - } +inline void LowMemoryNotification() { + v8::Isolate::GetCurrent()->LowMemoryNotification(); +} - inline void ContextDisposedNotification() { - v8::Isolate::GetCurrent()->ContextDisposedNotification(); - } +inline void ContextDisposedNotification() { + v8::Isolate::GetCurrent()->ContextDisposedNotification(); +} #else - inline - void SetCounterFunction(v8::CounterLookupCallback cb) { - v8::V8::SetCounterFunction(cb); - } +inline void SetCounterFunction(v8::CounterLookupCallback cb) { + v8::V8::SetCounterFunction(cb); +} - inline - void SetCreateHistogramFunction(v8::CreateHistogramCallback cb) { - v8::V8::SetCreateHistogramFunction(cb); - } +inline void SetCreateHistogramFunction(v8::CreateHistogramCallback cb) { + v8::V8::SetCreateHistogramFunction(cb); +} - inline - void SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { - v8::V8::SetAddHistogramSampleFunction(cb); - } +inline void SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { + v8::V8::SetAddHistogramSampleFunction(cb); +} - inline bool IdleNotification(int idle_time_in_ms) { - return v8::V8::IdleNotification(idle_time_in_ms); - } +inline bool IdleNotification(int idle_time_in_ms) { + return v8::V8::IdleNotification(idle_time_in_ms); +} - inline void LowMemoryNotification() { - v8::V8::LowMemoryNotification(); - } +inline void LowMemoryNotification() { v8::V8::LowMemoryNotification(); } - inline void ContextDisposedNotification() { - v8::V8::ContextDisposedNotification(); - } +inline void ContextDisposedNotification() { + v8::V8::ContextDisposedNotification(); +} #endif -#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) // Node 0.12 - inline v8::Local Undefined() { -# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(v8::Undefined(v8::Isolate::GetCurrent()))); -# else - return v8::Undefined(v8::Isolate::GetCurrent()); -# endif - } +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) // Node 0.12 +inline v8::Local Undefined() { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::Undefined(v8::Isolate::GetCurrent()))); +#else + return v8::Undefined(v8::Isolate::GetCurrent()); +#endif +} - inline v8::Local Null() { -# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(v8::Null(v8::Isolate::GetCurrent()))); -# else - return v8::Null(v8::Isolate::GetCurrent()); -# endif - } +inline v8::Local Null() { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::Null(v8::Isolate::GetCurrent()))); +#else + return v8::Null(v8::Isolate::GetCurrent()); +#endif +} - inline v8::Local True() { -# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(v8::True(v8::Isolate::GetCurrent()))); -# else - return v8::True(v8::Isolate::GetCurrent()); -# endif - } +inline v8::Local True() { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::True(v8::Isolate::GetCurrent()))); +#else + return v8::True(v8::Isolate::GetCurrent()); +#endif +} - inline v8::Local False() { -# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(v8::False(v8::Isolate::GetCurrent()))); -# else - return v8::False(v8::Isolate::GetCurrent()); -# endif - } +inline v8::Local False() { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + return scope.Escape(New(v8::False(v8::Isolate::GetCurrent()))); +#else + return v8::False(v8::Isolate::GetCurrent()); +#endif +} - inline v8::Local EmptyString() { - return v8::String::Empty(v8::Isolate::GetCurrent()); - } +inline v8::Local EmptyString() { + return v8::String::Empty(v8::Isolate::GetCurrent()); +} - inline int AdjustExternalMemory(int bc) { - return static_cast( - v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(bc)); - } +inline int AdjustExternalMemory(int bc) { + return static_cast( + v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(bc)); +} - inline void SetTemplate( - v8::Local templ - , const char *name - , v8::Local value) { - templ->Set(v8::Isolate::GetCurrent(), name, value); - } +inline void SetTemplate(v8::Local templ, const char *name, + v8::Local value) { + templ->Set(v8::Isolate::GetCurrent(), name, value); +} - inline void SetTemplate( - v8::Local templ - , v8::Local name - , v8::Local value - , v8::PropertyAttribute attributes) { - templ->Set(name, value, attributes); - } +inline void SetTemplate(v8::Local templ, + v8::Local name, v8::Local value, + v8::PropertyAttribute attributes) { + templ->Set(name, value, attributes); +} - inline v8::Local GetCurrentContext() { - return v8::Isolate::GetCurrent()->GetCurrentContext(); - } +inline v8::Local GetCurrentContext() { + return v8::Isolate::GetCurrent()->GetCurrentContext(); +} - inline void* GetInternalFieldPointer( - v8::Local object - , int index) { - return object->GetAlignedPointerFromInternalField(index); - } +inline void *GetInternalFieldPointer(v8::Local object, int index) { + return object->GetAlignedPointerFromInternalField(index); +} - inline void SetInternalFieldPointer( - v8::Local object - , int index - , void* value) { - object->SetAlignedPointerInInternalField(index, value); - } +inline void SetInternalFieldPointer(v8::Local object, int index, + void *value) { + object->SetAlignedPointerInInternalField(index, value); +} -# define NAN_GC_CALLBACK(name) \ - void name(v8::Isolate *isolate, v8::GCType type, v8::GCCallbackFlags flags) +#define NAN_GC_CALLBACK(name) \ + void name(v8::Isolate *isolate, v8::GCType type, v8::GCCallbackFlags flags) #if NODE_MODULE_VERSION <= NODE_4_0_MODULE_VERSION - typedef v8::Isolate::GCEpilogueCallback GCEpilogueCallback; - typedef v8::Isolate::GCPrologueCallback GCPrologueCallback; +typedef v8::Isolate::GCEpilogueCallback GCEpilogueCallback; +typedef v8::Isolate::GCPrologueCallback GCPrologueCallback; #else - typedef v8::Isolate::GCCallback GCEpilogueCallback; - typedef v8::Isolate::GCCallback GCPrologueCallback; +typedef v8::Isolate::GCCallback GCEpilogueCallback; +typedef v8::Isolate::GCCallback GCPrologueCallback; #endif - inline void AddGCEpilogueCallback( - GCEpilogueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::Isolate::GetCurrent()->AddGCEpilogueCallback(callback, gc_type_filter); - } +inline void AddGCEpilogueCallback(GCEpilogueCallback callback, + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::Isolate::GetCurrent()->AddGCEpilogueCallback(callback, gc_type_filter); +} - inline void RemoveGCEpilogueCallback( - GCEpilogueCallback callback) { - v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback(callback); - } +inline void RemoveGCEpilogueCallback(GCEpilogueCallback callback) { + v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback(callback); +} - inline void AddGCPrologueCallback( - GCPrologueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::Isolate::GetCurrent()->AddGCPrologueCallback(callback, gc_type_filter); - } +inline void AddGCPrologueCallback(GCPrologueCallback callback, + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::Isolate::GetCurrent()->AddGCPrologueCallback(callback, gc_type_filter); +} - inline void RemoveGCPrologueCallback( - GCPrologueCallback callback) { - v8::Isolate::GetCurrent()->RemoveGCPrologueCallback(callback); - } +inline void RemoveGCPrologueCallback(GCPrologueCallback callback) { + v8::Isolate::GetCurrent()->RemoveGCPrologueCallback(callback); +} - inline void GetHeapStatistics( - v8::HeapStatistics *heap_statistics) { - v8::Isolate::GetCurrent()->GetHeapStatistics(heap_statistics); - } +inline void GetHeapStatistics(v8::HeapStatistics *heap_statistics) { + v8::Isolate::GetCurrent()->GetHeapStatistics(heap_statistics); +} -# define X(NAME) \ - inline v8::Local NAME(const char *msg) { \ - EscapableHandleScope scope; \ - return scope.Escape(v8::Exception::NAME(New(msg).ToLocalChecked())); \ - } \ +#define X(NAME) \ + inline v8::Local NAME(const char *msg) { \ + EscapableHandleScope scope; \ + return scope.Escape(v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ \ - inline \ - v8::Local NAME(v8::Local msg) { \ - return v8::Exception::NAME(msg); \ - } \ + inline v8::Local NAME(v8::Local msg) { \ + return v8::Exception::NAME(msg); \ + } \ \ - inline void Throw ## NAME(const char *msg) { \ - HandleScope scope; \ - v8::Isolate::GetCurrent()->ThrowException( \ - v8::Exception::NAME(New(msg).ToLocalChecked())); \ - } \ + inline void Throw##NAME(const char *msg) { \ + HandleScope scope; \ + v8::Isolate::GetCurrent()->ThrowException( \ + v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ \ - inline void Throw ## NAME(v8::Local msg) { \ - HandleScope scope; \ - v8::Isolate::GetCurrent()->ThrowException( \ - v8::Exception::NAME(msg)); \ - } + inline void Throw##NAME(v8::Local msg) { \ + HandleScope scope; \ + v8::Isolate::GetCurrent()->ThrowException(v8::Exception::NAME(msg)); \ + } - X(Error) - X(RangeError) - X(ReferenceError) - X(SyntaxError) - X(TypeError) +X(Error) +X(RangeError) +X(ReferenceError) +X(SyntaxError) +X(TypeError) -# undef X +#undef X - inline void ThrowError(v8::Local error) { - v8::Isolate::GetCurrent()->ThrowException(error); - } +inline void ThrowError(v8::Local error) { + v8::Isolate::GetCurrent()->ThrowException(error); +} - inline MaybeLocal NewBuffer( - char *data - , size_t length +inline MaybeLocal NewBuffer(char *data, size_t length #if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION - , node::Buffer::FreeCallback callback + , + node::Buffer::FreeCallback callback #else - , node::smalloc::FreeCallback callback + , + node::smalloc::FreeCallback callback #endif - , void *hint - ) { - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(length <= imp::kMaxLength && "too large buffer"); + , + void *hint) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(length <= imp::kMaxLength && "too large buffer"); #if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION - return node::Buffer::New( - v8::Isolate::GetCurrent(), data, length, callback, hint); + return node::Buffer::New(v8::Isolate::GetCurrent(), data, length, callback, + hint); #else - return node::Buffer::New(v8::Isolate::GetCurrent(), data, length, callback, - hint); + return node::Buffer::New(v8::Isolate::GetCurrent(), data, length, callback, + hint); #endif - } +} - inline MaybeLocal CopyBuffer( - const char *data - , uint32_t size - ) { - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(size <= imp::kMaxLength && "too large buffer"); +inline MaybeLocal CopyBuffer(const char *data, uint32_t size) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); #if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION - return node::Buffer::Copy( - v8::Isolate::GetCurrent(), data, size); + return node::Buffer::Copy(v8::Isolate::GetCurrent(), data, size); #else - return node::Buffer::New(v8::Isolate::GetCurrent(), data, size); + return node::Buffer::New(v8::Isolate::GetCurrent(), data, size); #endif - } +} - inline MaybeLocal NewBuffer(uint32_t size) { - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(size <= imp::kMaxLength && "too large buffer"); +inline MaybeLocal NewBuffer(uint32_t size) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); #if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION - return node::Buffer::New( - v8::Isolate::GetCurrent(), size); + return node::Buffer::New(v8::Isolate::GetCurrent(), size); #else - return node::Buffer::New(v8::Isolate::GetCurrent(), size); + return node::Buffer::New(v8::Isolate::GetCurrent(), size); #endif - } +} - inline MaybeLocal NewBuffer( - char* data - , uint32_t size - ) { - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(size <= imp::kMaxLength && "too large buffer"); +inline MaybeLocal NewBuffer(char *data, uint32_t size) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); #if NODE_MODULE_VERSION > IOJS_2_0_MODULE_VERSION - return node::Buffer::New(v8::Isolate::GetCurrent(), data, size); + return node::Buffer::New(v8::Isolate::GetCurrent(), data, size); #else - return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size); + return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size); #endif - } +} -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) - inline MaybeLocal - NewOneByteString(const uint8_t * value, int length = -1) { - return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value, - v8::NewStringType::kNormal, length); - } +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +inline MaybeLocal NewOneByteString(const uint8_t *value, + int length = -1) { + return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value, + v8::NewStringType::kNormal, length); +} - inline MaybeLocal CompileScript( - v8::Local s - , const v8::ScriptOrigin& origin - ) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::EscapableHandleScope scope(isolate); - v8::ScriptCompiler::Source source(s, origin); - return scope.Escape( - v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &source) - .FromMaybe(v8::Local())); - } +inline MaybeLocal CompileScript(v8::Local s, + const v8::ScriptOrigin &origin) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::EscapableHandleScope scope(isolate); + v8::ScriptCompiler::Source source(s, origin); + return scope.Escape( + v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &source) + .FromMaybe(v8::Local())); +} - inline MaybeLocal CompileScript( - v8::Local s - ) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::EscapableHandleScope scope(isolate); - v8::ScriptCompiler::Source source(s); - return scope.Escape( - v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &source) - .FromMaybe(v8::Local())); - } +inline MaybeLocal CompileScript(v8::Local s) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::EscapableHandleScope scope(isolate); + v8::ScriptCompiler::Source source(s); + return scope.Escape( + v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &source) + .FromMaybe(v8::Local())); +} - inline MaybeLocal RunScript( - v8::Local script - ) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::EscapableHandleScope scope(isolate); - return scope.Escape(script->BindToCurrentContext() - ->Run(isolate->GetCurrentContext()) - .FromMaybe(v8::Local())); - } +inline MaybeLocal RunScript(v8::Local script) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::EscapableHandleScope scope(isolate); + return scope.Escape(script->BindToCurrentContext() + ->Run(isolate->GetCurrentContext()) + .FromMaybe(v8::Local())); +} - inline MaybeLocal RunScript( - v8::Local script - ) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::EscapableHandleScope scope(isolate); - return scope.Escape(script->Run(isolate->GetCurrentContext()) - .FromMaybe(v8::Local())); - } +inline MaybeLocal RunScript(v8::Local script) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::EscapableHandleScope scope(isolate); + return scope.Escape(script->Run(isolate->GetCurrentContext()) + .FromMaybe(v8::Local())); +} #else - inline MaybeLocal - NewOneByteString(const uint8_t * value, int length = -1) { - return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value, - v8::String::kNormalString, length); - } +inline MaybeLocal NewOneByteString(const uint8_t *value, + int length = -1) { + return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value, + v8::String::kNormalString, length); +} - inline MaybeLocal CompileScript( - v8::Local s - , const v8::ScriptOrigin& origin - ) { - v8::ScriptCompiler::Source source(s, origin); - return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source); - } +inline MaybeLocal CompileScript(v8::Local s, + const v8::ScriptOrigin &origin) { + v8::ScriptCompiler::Source source(s, origin); + return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source); +} - inline MaybeLocal CompileScript( - v8::Local s - ) { - v8::ScriptCompiler::Source source(s); - return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source); - } +inline MaybeLocal CompileScript(v8::Local s) { + v8::ScriptCompiler::Source source(s); + return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source); +} - inline MaybeLocal RunScript( - v8::Local script - ) { - EscapableHandleScope scope; - return scope.Escape(script->BindToCurrentContext()->Run()); - } +inline MaybeLocal RunScript(v8::Local script) { + EscapableHandleScope scope; + return scope.Escape(script->BindToCurrentContext()->Run()); +} - inline MaybeLocal RunScript( - v8::Local script - ) { - return script->Run(); - } +inline MaybeLocal RunScript(v8::Local script) { + return script->Run(); +} #endif - NAN_DEPRECATED inline v8::Local MakeCallback( - v8::Local target - , v8::Local func - , int argc - , v8::Local* argv) { +NAN_DEPRECATED inline v8::Local +MakeCallback(v8::Local target, v8::Local func, + int argc, v8::Local *argv) { #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(node::MakeCallback( - v8::Isolate::GetCurrent(), target, func, argc, argv))); + EscapableHandleScope scope; + return scope.Escape(New( + node::MakeCallback(v8::Isolate::GetCurrent(), target, func, argc, argv))); #else -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - AsyncResource res("nan:makeCallback"); - return res.runInAsyncScope(target, func, argc, argv) - .FromMaybe(v8::Local()); -# else - return node::MakeCallback( - v8::Isolate::GetCurrent(), target, func, argc, argv); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION -#endif // NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - } - - NAN_DEPRECATED inline v8::Local MakeCallback( - v8::Local target - , v8::Local symbol - , int argc - , v8::Local* argv) { +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION + AsyncResource res("nan:makeCallback"); + return res.runInAsyncScope(target, func, argc, argv) + .FromMaybe(v8::Local()); +#else + return node::MakeCallback(v8::Isolate::GetCurrent(), target, func, argc, + argv); +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION +} + +NAN_DEPRECATED inline v8::Local +MakeCallback(v8::Local target, v8::Local symbol, + int argc, v8::Local *argv) { #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(node::MakeCallback( - v8::Isolate::GetCurrent(), target, symbol, argc, argv))); + EscapableHandleScope scope; + return scope.Escape(New(node::MakeCallback(v8::Isolate::GetCurrent(), target, + symbol, argc, argv))); #else -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - AsyncResource res("nan:makeCallback"); - return res.runInAsyncScope(target, symbol, argc, argv) - .FromMaybe(v8::Local()); -# else - return node::MakeCallback( - v8::Isolate::GetCurrent(), target, symbol, argc, argv); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION -#endif // NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - } - - NAN_DEPRECATED inline v8::Local MakeCallback( - v8::Local target - , const char* method - , int argc - , v8::Local* argv) { +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION + AsyncResource res("nan:makeCallback"); + return res.runInAsyncScope(target, symbol, argc, argv) + .FromMaybe(v8::Local()); +#else + return node::MakeCallback(v8::Isolate::GetCurrent(), target, symbol, argc, + argv); +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION +} + +NAN_DEPRECATED inline v8::Local +MakeCallback(v8::Local target, const char *method, int argc, + v8::Local *argv) { #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - return scope.Escape(New(node::MakeCallback( - v8::Isolate::GetCurrent(), target, method, argc, argv))); + EscapableHandleScope scope; + return scope.Escape(New(node::MakeCallback(v8::Isolate::GetCurrent(), target, + method, argc, argv))); #else -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - AsyncResource res("nan:makeCallback"); - return res.runInAsyncScope(target, method, argc, argv) - .FromMaybe(v8::Local()); -# else - return node::MakeCallback( - v8::Isolate::GetCurrent(), target, method, argc, argv); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION -#endif // NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - } +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION + AsyncResource res("nan:makeCallback"); + return res.runInAsyncScope(target, method, argc, argv) + .FromMaybe(v8::Local()); +#else + return node::MakeCallback(v8::Isolate::GetCurrent(), target, method, argc, + argv); +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION +} - inline void FatalException(const TryCatch& try_catch) { - node::FatalException(v8::Isolate::GetCurrent(), try_catch.try_catch_); - } +inline void FatalException(const TryCatch &try_catch) { + node::FatalException(v8::Isolate::GetCurrent(), try_catch.try_catch_); +} - inline v8::Local ErrnoException( - int errorno - , const char* syscall = NULL - , const char* message = NULL - , const char* path = NULL) { - return node::ErrnoException(v8::Isolate::GetCurrent(), errorno, syscall, - message, path); - } +inline v8::Local ErrnoException(int errorno, + const char *syscall = NULL, + const char *message = NULL, + const char *path = NULL) { + return node::ErrnoException(v8::Isolate::GetCurrent(), errorno, syscall, + message, path); +} - NAN_DEPRECATED inline v8::Local NanErrnoException( - int errorno - , const char* syscall = NULL - , const char* message = NULL - , const char* path = NULL) { - return ErrnoException(errorno, syscall, message, path); - } +NAN_DEPRECATED inline v8::Local +NanErrnoException(int errorno, const char *syscall = NULL, + const char *message = NULL, const char *path = NULL) { + return ErrnoException(errorno, syscall, message, path); +} - template - inline void SetIsolateData( - v8::Isolate *isolate - , T *data - ) { - isolate->SetData(0, data); - } +template +inline void SetIsolateData(v8::Isolate *isolate, T *data) { + isolate->SetData(0, data); +} - template - inline T *GetIsolateData( - v8::Isolate *isolate - ) { - return static_cast(isolate->GetData(0)); - } +template inline T *GetIsolateData(v8::Isolate *isolate) { + return static_cast(isolate->GetData(0)); +} class Utf8String { - public: - inline explicit Utf8String(v8::Local from) : - length_(0), str_(str_st_) { +public: + inline explicit Utf8String(v8::Local from) + : length_(0), str_(str_st_) { HandleScope scope; if (!from.IsEmpty()) { #if NODE_MAJOR_VERSION >= 10 @@ -1163,8 +1067,8 @@ class Utf8String { if (!string.IsEmpty()) { size_t len = 3 * string->Length() + 1; assert(len <= INT_MAX); - if (len > sizeof (str_st_)) { - str_ = static_cast(malloc(len)); + if (len > sizeof(str_st_)) { + str_ = static_cast(malloc(len)); assert(str_ != 0); } const int flags = @@ -1190,18 +1094,16 @@ class Utf8String { #ifdef _MSC_VER #pragma warning(pop) #endif -#endif // NODE_MAJOR_VERSION < 11 +#endif // NODE_MAJOR_VERSION < 11 str_[length_] = '\0'; } } } - inline int length() const { - return length_; - } + inline int length() const { return length_; } - inline char* operator*() { return str_; } - inline const char* operator*() const { return str_; } + inline char *operator*() { return str_; } + inline const char *operator*() const { return str_; } inline ~Utf8String() { if (str_ != str_st_) { @@ -1209,7 +1111,7 @@ class Utf8String { } } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(Utf8String) int length_; @@ -1217,296 +1119,248 @@ class Utf8String { char str_st_[1024]; }; -#else // Node 0.8 and 0.10 - inline v8::Local Undefined() { - EscapableHandleScope scope; - return scope.Escape(New(v8::Undefined())); - } +#else // Node 0.8 and 0.10 +inline v8::Local Undefined() { + EscapableHandleScope scope; + return scope.Escape(New(v8::Undefined())); +} - inline v8::Local Null() { - EscapableHandleScope scope; - return scope.Escape(New(v8::Null())); - } +inline v8::Local Null() { + EscapableHandleScope scope; + return scope.Escape(New(v8::Null())); +} - inline v8::Local True() { - EscapableHandleScope scope; - return scope.Escape(New(v8::True())); - } +inline v8::Local True() { + EscapableHandleScope scope; + return scope.Escape(New(v8::True())); +} - inline v8::Local False() { - EscapableHandleScope scope; - return scope.Escape(New(v8::False())); - } +inline v8::Local False() { + EscapableHandleScope scope; + return scope.Escape(New(v8::False())); +} - inline v8::Local EmptyString() { - return v8::String::Empty(); - } +inline v8::Local EmptyString() { return v8::String::Empty(); } - inline int AdjustExternalMemory(int bc) { - return static_cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(bc)); - } +inline int AdjustExternalMemory(int bc) { + return static_cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(bc)); +} - inline void SetTemplate( - v8::Local templ - , const char *name - , v8::Local value) { - templ->Set(name, value); - } +inline void SetTemplate(v8::Local templ, const char *name, + v8::Local value) { + templ->Set(name, value); +} - inline void SetTemplate( - v8::Local templ - , v8::Local name - , v8::Local value - , v8::PropertyAttribute attributes) { - templ->Set(name, value, attributes); - } +inline void SetTemplate(v8::Local templ, + v8::Local name, v8::Local value, + v8::PropertyAttribute attributes) { + templ->Set(name, value, attributes); +} - inline v8::Local GetCurrentContext() { - return v8::Context::GetCurrent(); - } +inline v8::Local GetCurrentContext() { + return v8::Context::GetCurrent(); +} - inline void* GetInternalFieldPointer( - v8::Local object - , int index) { - return object->GetPointerFromInternalField(index); - } +inline void *GetInternalFieldPointer(v8::Local object, int index) { + return object->GetPointerFromInternalField(index); +} - inline void SetInternalFieldPointer( - v8::Local object - , int index - , void* value) { - object->SetPointerInInternalField(index, value); - } +inline void SetInternalFieldPointer(v8::Local object, int index, + void *value) { + object->SetPointerInInternalField(index, value); +} -# define NAN_GC_CALLBACK(name) \ - void name(v8::GCType type, v8::GCCallbackFlags flags) +#define NAN_GC_CALLBACK(name) \ + void name(v8::GCType type, v8::GCCallbackFlags flags) - inline void AddGCEpilogueCallback( - v8::GCEpilogueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::V8::AddGCEpilogueCallback(callback, gc_type_filter); - } - inline void RemoveGCEpilogueCallback( - v8::GCEpilogueCallback callback) { - v8::V8::RemoveGCEpilogueCallback(callback); - } - inline void AddGCPrologueCallback( - v8::GCPrologueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::V8::AddGCPrologueCallback(callback, gc_type_filter); - } - inline void RemoveGCPrologueCallback( - v8::GCPrologueCallback callback) { - v8::V8::RemoveGCPrologueCallback(callback); - } - inline void GetHeapStatistics( - v8::HeapStatistics *heap_statistics) { - v8::V8::GetHeapStatistics(heap_statistics); - } +inline void AddGCEpilogueCallback(v8::GCEpilogueCallback callback, + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::V8::AddGCEpilogueCallback(callback, gc_type_filter); +} +inline void RemoveGCEpilogueCallback(v8::GCEpilogueCallback callback) { + v8::V8::RemoveGCEpilogueCallback(callback); +} +inline void AddGCPrologueCallback(v8::GCPrologueCallback callback, + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::V8::AddGCPrologueCallback(callback, gc_type_filter); +} +inline void RemoveGCPrologueCallback(v8::GCPrologueCallback callback) { + v8::V8::RemoveGCPrologueCallback(callback); +} +inline void GetHeapStatistics(v8::HeapStatistics *heap_statistics) { + v8::V8::GetHeapStatistics(heap_statistics); +} -# define X(NAME) \ - inline v8::Local NAME(const char *msg) { \ - EscapableHandleScope scope; \ - return scope.Escape(v8::Exception::NAME(New(msg).ToLocalChecked())); \ - } \ +#define X(NAME) \ + inline v8::Local NAME(const char *msg) { \ + EscapableHandleScope scope; \ + return scope.Escape(v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ \ - inline \ - v8::Local NAME(v8::Local msg) { \ - return v8::Exception::NAME(msg); \ - } \ + inline v8::Local NAME(v8::Local msg) { \ + return v8::Exception::NAME(msg); \ + } \ \ - inline void Throw ## NAME(const char *msg) { \ - HandleScope scope; \ - v8::ThrowException(v8::Exception::NAME(New(msg).ToLocalChecked())); \ - } \ + inline void Throw##NAME(const char *msg) { \ + HandleScope scope; \ + v8::ThrowException(v8::Exception::NAME(New(msg).ToLocalChecked())); \ + } \ \ - inline \ - void Throw ## NAME(v8::Local errmsg) { \ - HandleScope scope; \ - v8::ThrowException(v8::Exception::NAME(errmsg)); \ - } + inline void Throw##NAME(v8::Local errmsg) { \ + HandleScope scope; \ + v8::ThrowException(v8::Exception::NAME(errmsg)); \ + } - X(Error) - X(RangeError) - X(ReferenceError) - X(SyntaxError) - X(TypeError) +X(Error) +X(RangeError) +X(ReferenceError) +X(SyntaxError) +X(TypeError) -# undef X +#undef X - inline void ThrowError(v8::Local error) { - v8::ThrowException(error); - } +inline void ThrowError(v8::Local error) { + v8::ThrowException(error); +} - inline MaybeLocal NewBuffer( - char *data - , size_t length - , node::Buffer::free_callback callback - , void *hint - ) { - EscapableHandleScope scope; - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(length <= imp::kMaxLength && "too large buffer"); - return scope.Escape( - New(node::Buffer::New(data, length, callback, hint)->handle_)); - } +inline MaybeLocal NewBuffer(char *data, size_t length, + node::Buffer::free_callback callback, + void *hint) { + EscapableHandleScope scope; + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(length <= imp::kMaxLength && "too large buffer"); + return scope.Escape( + New(node::Buffer::New(data, length, callback, hint)->handle_)); +} - inline MaybeLocal CopyBuffer( - const char *data - , uint32_t size - ) { - EscapableHandleScope scope; - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(size <= imp::kMaxLength && "too large buffer"); +inline MaybeLocal CopyBuffer(const char *data, uint32_t size) { + EscapableHandleScope scope; + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); #if NODE_MODULE_VERSION >= NODE_0_10_MODULE_VERSION - return scope.Escape(New(node::Buffer::New(data, size)->handle_)); + return scope.Escape(New(node::Buffer::New(data, size)->handle_)); #else - return scope.Escape( - New(node::Buffer::New(const_cast(data), size)->handle_)); + return scope.Escape( + New(node::Buffer::New(const_cast(data), size)->handle_)); #endif - } +} - inline MaybeLocal NewBuffer(uint32_t size) { - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - EscapableHandleScope scope; - assert(size <= imp::kMaxLength && "too large buffer"); - return scope.Escape(New(node::Buffer::New(size)->handle_)); - } +inline MaybeLocal NewBuffer(uint32_t size) { + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + EscapableHandleScope scope; + assert(size <= imp::kMaxLength && "too large buffer"); + return scope.Escape(New(node::Buffer::New(size)->handle_)); +} - inline void FreeData(char *data, void *hint) { - (void) hint; // unused - delete[] data; - } +inline void FreeData(char *data, void *hint) { + (void)hint; // unused + delete[] data; +} - inline MaybeLocal NewBuffer( - char* data - , uint32_t size - ) { - EscapableHandleScope scope; - // arbitrary buffer lengths requires - // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION - assert(size <= imp::kMaxLength && "too large buffer"); - return scope.Escape( - New(node::Buffer::New(data, size, FreeData, NULL)->handle_)); - } +inline MaybeLocal NewBuffer(char *data, uint32_t size) { + EscapableHandleScope scope; + // arbitrary buffer lengths requires + // NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION + assert(size <= imp::kMaxLength && "too large buffer"); + return scope.Escape( + New(node::Buffer::New(data, size, FreeData, NULL)->handle_)); +} namespace imp { -inline void -widenString(std::vector *ws, const uint8_t *s, int l) { +inline void widenString(std::vector *ws, const uint8_t *s, int l) { size_t len = static_cast(l); if (l < 0) { - len = strlen(reinterpret_cast(s)); + len = strlen(reinterpret_cast(s)); } assert(len <= INT_MAX && "string too long"); ws->resize(len); - std::copy(s, s + len, ws->begin()); // NOLINT(build/include_what_you_use) + std::copy(s, s + len, ws->begin()); // NOLINT(build/include_what_you_use) +} +} // end of namespace imp + +inline MaybeLocal NewOneByteString(const uint8_t *value, + int length = -1) { + std::vector wideString; // NOLINT(build/include_what_you_use) + imp::widenString(&wideString, value, length); + return v8::String::New(wideString.data(), + static_cast(wideString.size())); } -} // end of namespace imp - - inline MaybeLocal - NewOneByteString(const uint8_t * value, int length = -1) { - std::vector wideString; // NOLINT(build/include_what_you_use) - imp::widenString(&wideString, value, length); - return v8::String::New(wideString.data(), - static_cast(wideString.size())); - } - - inline MaybeLocal CompileScript( - v8::Local s - , const v8::ScriptOrigin& origin - ) { - return v8::Script::Compile(s, const_cast(&origin)); - } - inline MaybeLocal CompileScript( - v8::Local s - ) { - return v8::Script::Compile(s); - } +inline MaybeLocal CompileScript(v8::Local s, + const v8::ScriptOrigin &origin) { + return v8::Script::Compile(s, const_cast(&origin)); +} - inline - MaybeLocal RunScript(v8::Local script) { - return script->Run(); - } +inline MaybeLocal CompileScript(v8::Local s) { + return v8::Script::Compile(s); +} - inline v8::Local MakeCallback( - v8::Local target - , v8::Local func - , int argc - , v8::Local* argv) { - v8::HandleScope scope; - return scope.Close(New(node::MakeCallback(target, func, argc, argv))); - } +inline MaybeLocal RunScript(v8::Local script) { + return script->Run(); +} - inline v8::Local MakeCallback( - v8::Local target - , v8::Local symbol - , int argc - , v8::Local* argv) { - v8::HandleScope scope; - return scope.Close(New(node::MakeCallback(target, symbol, argc, argv))); - } +inline v8::Local MakeCallback(v8::Local target, + v8::Local func, int argc, + v8::Local *argv) { + v8::HandleScope scope; + return scope.Close(New(node::MakeCallback(target, func, argc, argv))); +} - inline v8::Local MakeCallback( - v8::Local target - , const char* method - , int argc - , v8::Local* argv) { - v8::HandleScope scope; - return scope.Close(New(node::MakeCallback(target, method, argc, argv))); - } +inline v8::Local MakeCallback(v8::Local target, + v8::Local symbol, int argc, + v8::Local *argv) { + v8::HandleScope scope; + return scope.Close(New(node::MakeCallback(target, symbol, argc, argv))); +} - inline void FatalException(const TryCatch& try_catch) { - node::FatalException(const_cast(try_catch.try_catch_)); - } +inline v8::Local MakeCallback(v8::Local target, + const char *method, int argc, + v8::Local *argv) { + v8::HandleScope scope; + return scope.Close(New(node::MakeCallback(target, method, argc, argv))); +} - inline v8::Local ErrnoException( - int errorno - , const char* syscall = NULL - , const char* message = NULL - , const char* path = NULL) { - return node::ErrnoException(errorno, syscall, message, path); - } +inline void FatalException(const TryCatch &try_catch) { + node::FatalException(const_cast(try_catch.try_catch_)); +} - NAN_DEPRECATED inline v8::Local NanErrnoException( - int errorno - , const char* syscall = NULL - , const char* message = NULL - , const char* path = NULL) { - return ErrnoException(errorno, syscall, message, path); - } +inline v8::Local ErrnoException(int errorno, + const char *syscall = NULL, + const char *message = NULL, + const char *path = NULL) { + return node::ErrnoException(errorno, syscall, message, path); +} +NAN_DEPRECATED inline v8::Local +NanErrnoException(int errorno, const char *syscall = NULL, + const char *message = NULL, const char *path = NULL) { + return ErrnoException(errorno, syscall, message, path); +} - template - inline void SetIsolateData( - v8::Isolate *isolate - , T *data - ) { - isolate->SetData(data); - } +template +inline void SetIsolateData(v8::Isolate *isolate, T *data) { + isolate->SetData(data); +} - template - inline T *GetIsolateData( - v8::Isolate *isolate - ) { - return static_cast(isolate->GetData()); - } +template inline T *GetIsolateData(v8::Isolate *isolate) { + return static_cast(isolate->GetData()); +} class Utf8String { - public: - inline explicit Utf8String(v8::Local from) : - length_(0), str_(str_st_) { +public: + inline explicit Utf8String(v8::Local from) + : length_(0), str_(str_st_) { v8::HandleScope scope; if (!from.IsEmpty()) { v8::Local string = from->ToString(); if (!string.IsEmpty()) { size_t len = 3 * string->Length() + 1; assert(len <= INT_MAX); - if (len > sizeof (str_st_)) { - str_ = static_cast(malloc(len)); + if (len > sizeof(str_st_)) { + str_ = static_cast(malloc(len)); assert(str_ != 0); } const int flags = @@ -1517,12 +1371,10 @@ class Utf8String { } } - inline int length() const { - return length_; - } + inline int length() const { return length_; } - inline char* operator*() { return str_; } - inline const char* operator*() const { return str_; } + inline char *operator*() { return str_; } + inline const char *operator*() const { return str_; } inline ~Utf8String() { if (str_ != str_st_) { @@ -1530,7 +1382,7 @@ class Utf8String { } } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(Utf8String) int length_; @@ -1538,273 +1390,251 @@ class Utf8String { char str_st_[1024]; }; -#endif // NODE_MODULE_VERSION +#endif // NODE_MODULE_VERSION typedef void (*FreeCallback)(char *data, void *hint); -typedef const FunctionCallbackInfo& NAN_METHOD_ARGS_TYPE; +typedef const FunctionCallbackInfo &NAN_METHOD_ARGS_TYPE; typedef void NAN_METHOD_RETURN_TYPE; -typedef const PropertyCallbackInfo& NAN_GETTER_ARGS_TYPE; +typedef const PropertyCallbackInfo &NAN_GETTER_ARGS_TYPE; typedef void NAN_GETTER_RETURN_TYPE; -typedef const PropertyCallbackInfo& NAN_SETTER_ARGS_TYPE; +typedef const PropertyCallbackInfo &NAN_SETTER_ARGS_TYPE; typedef void NAN_SETTER_RETURN_TYPE; -typedef const PropertyCallbackInfo& - NAN_PROPERTY_GETTER_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_PROPERTY_GETTER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_PROPERTY_GETTER_RETURN_TYPE; #else typedef void NAN_PROPERTY_GETTER_RETURN_TYPE; #endif -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -typedef const PropertyCallbackInfo& - NAN_PROPERTY_SETTER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_PROPERTY_SETTER_ARGS_TYPE; typedef v8::Intercepted NAN_PROPERTY_SETTER_RETURN_TYPE; #else -typedef const PropertyCallbackInfo& - NAN_PROPERTY_SETTER_ARGS_TYPE; +typedef const PropertyCallbackInfo &NAN_PROPERTY_SETTER_ARGS_TYPE; typedef void NAN_PROPERTY_SETTER_RETURN_TYPE; #endif -typedef const PropertyCallbackInfo& - NAN_PROPERTY_ENUMERATOR_ARGS_TYPE; +typedef const PropertyCallbackInfo + &NAN_PROPERTY_ENUMERATOR_ARGS_TYPE; typedef void NAN_PROPERTY_ENUMERATOR_RETURN_TYPE; -typedef const PropertyCallbackInfo& - NAN_PROPERTY_DELETER_ARGS_TYPE; +typedef const PropertyCallbackInfo &NAN_PROPERTY_DELETER_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_PROPERTY_DELETER_RETURN_TYPE; #else typedef void NAN_PROPERTY_DELETER_RETURN_TYPE; #endif - -typedef const PropertyCallbackInfo& - NAN_PROPERTY_QUERY_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_PROPERTY_QUERY_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_PROPERTY_QUERY_RETURN_TYPE; #else typedef void NAN_PROPERTY_QUERY_RETURN_TYPE; #endif -typedef const PropertyCallbackInfo& NAN_INDEX_GETTER_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_INDEX_GETTER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_INDEX_GETTER_RETURN_TYPE; #else typedef void NAN_INDEX_GETTER_RETURN_TYPE; #endif - -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -typedef const PropertyCallbackInfo& NAN_INDEX_SETTER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_INDEX_SETTER_ARGS_TYPE; typedef v8::Intercepted NAN_INDEX_SETTER_RETURN_TYPE; #else -typedef const PropertyCallbackInfo& NAN_INDEX_SETTER_ARGS_TYPE; +typedef const PropertyCallbackInfo &NAN_INDEX_SETTER_ARGS_TYPE; typedef void NAN_INDEX_SETTER_RETURN_TYPE; #endif -typedef const PropertyCallbackInfo& - NAN_INDEX_ENUMERATOR_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_INDEX_ENUMERATOR_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_INDEX_ENUMERATOR_RETURN_TYPE; #else typedef void NAN_INDEX_ENUMERATOR_RETURN_TYPE; #endif -typedef const PropertyCallbackInfo& - NAN_INDEX_DELETER_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_INDEX_DELETER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_INDEX_DELETER_RETURN_TYPE; #else typedef void NAN_INDEX_DELETER_RETURN_TYPE; #endif -typedef const PropertyCallbackInfo& - NAN_INDEX_QUERY_ARGS_TYPE; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo &NAN_INDEX_QUERY_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) typedef v8::Intercepted NAN_INDEX_QUERY_RETURN_TYPE; #else typedef void NAN_INDEX_QUERY_RETURN_TYPE; #endif #define NAN_METHOD(name) \ - Nan::NAN_METHOD_RETURN_TYPE name(Nan::NAN_METHOD_ARGS_TYPE info) + Nan::NAN_METHOD_RETURN_TYPE name(Nan::NAN_METHOD_ARGS_TYPE info) #define NAN_GETTER(name) \ - Nan::NAN_GETTER_RETURN_TYPE name( \ - v8::Local property \ - , Nan::NAN_GETTER_ARGS_TYPE info) + Nan::NAN_GETTER_RETURN_TYPE name(v8::Local property, \ + Nan::NAN_GETTER_ARGS_TYPE info) #define NAN_SETTER(name) \ - Nan::NAN_SETTER_RETURN_TYPE name( \ - v8::Local property \ - , v8::Local value \ - , Nan::NAN_SETTER_ARGS_TYPE info) + Nan::NAN_SETTER_RETURN_TYPE name(v8::Local property, \ + v8::Local value, \ + Nan::NAN_SETTER_ARGS_TYPE info) #define NAN_PROPERTY_GETTER(name) \ - Nan::NAN_PROPERTY_GETTER_RETURN_TYPE name( \ - v8::Local property \ - , Nan::NAN_PROPERTY_GETTER_ARGS_TYPE info) + Nan::NAN_PROPERTY_GETTER_RETURN_TYPE name( \ + v8::Local property, Nan::NAN_PROPERTY_GETTER_ARGS_TYPE info) #define NAN_PROPERTY_SETTER(name) \ - Nan::NAN_PROPERTY_SETTER_RETURN_TYPE name( \ - v8::Local property \ - , v8::Local value \ - , Nan::NAN_PROPERTY_SETTER_ARGS_TYPE info) + Nan::NAN_PROPERTY_SETTER_RETURN_TYPE name( \ + v8::Local property, v8::Local value, \ + Nan::NAN_PROPERTY_SETTER_ARGS_TYPE info) #define NAN_PROPERTY_ENUMERATOR(name) \ - Nan::NAN_PROPERTY_ENUMERATOR_RETURN_TYPE name( \ - Nan::NAN_PROPERTY_ENUMERATOR_ARGS_TYPE info) + Nan::NAN_PROPERTY_ENUMERATOR_RETURN_TYPE name( \ + Nan::NAN_PROPERTY_ENUMERATOR_ARGS_TYPE info) #define NAN_PROPERTY_DELETER(name) \ - Nan::NAN_PROPERTY_DELETER_RETURN_TYPE name( \ - v8::Local property \ - , Nan::NAN_PROPERTY_DELETER_ARGS_TYPE info) + Nan::NAN_PROPERTY_DELETER_RETURN_TYPE name( \ + v8::Local property, \ + Nan::NAN_PROPERTY_DELETER_ARGS_TYPE info) #define NAN_PROPERTY_QUERY(name) \ - Nan::NAN_PROPERTY_QUERY_RETURN_TYPE name( \ - v8::Local property \ - , Nan::NAN_PROPERTY_QUERY_ARGS_TYPE info) -# define NAN_INDEX_GETTER(name) \ - Nan::NAN_INDEX_GETTER_RETURN_TYPE name( \ - uint32_t index \ - , Nan::NAN_INDEX_GETTER_ARGS_TYPE info) + Nan::NAN_PROPERTY_QUERY_RETURN_TYPE name( \ + v8::Local property, Nan::NAN_PROPERTY_QUERY_ARGS_TYPE info) +#define NAN_INDEX_GETTER(name) \ + Nan::NAN_INDEX_GETTER_RETURN_TYPE name(uint32_t index, \ + Nan::NAN_INDEX_GETTER_ARGS_TYPE info) #define NAN_INDEX_SETTER(name) \ - Nan::NAN_INDEX_SETTER_RETURN_TYPE name( \ - uint32_t index \ - , v8::Local value \ - , Nan::NAN_INDEX_SETTER_ARGS_TYPE info) + Nan::NAN_INDEX_SETTER_RETURN_TYPE name(uint32_t index, \ + v8::Local value, \ + Nan::NAN_INDEX_SETTER_ARGS_TYPE info) #define NAN_INDEX_ENUMERATOR(name) \ - Nan::NAN_INDEX_ENUMERATOR_RETURN_TYPE \ - name(Nan::NAN_INDEX_ENUMERATOR_ARGS_TYPE info) + Nan::NAN_INDEX_ENUMERATOR_RETURN_TYPE name( \ + Nan::NAN_INDEX_ENUMERATOR_ARGS_TYPE info) #define NAN_INDEX_DELETER(name) \ - Nan::NAN_INDEX_DELETER_RETURN_TYPE name( \ - uint32_t index \ - , Nan::NAN_INDEX_DELETER_ARGS_TYPE info) + Nan::NAN_INDEX_DELETER_RETURN_TYPE name( \ + uint32_t index, Nan::NAN_INDEX_DELETER_ARGS_TYPE info) #define NAN_INDEX_QUERY(name) \ - Nan::NAN_INDEX_QUERY_RETURN_TYPE name( \ - uint32_t index \ - , Nan::NAN_INDEX_QUERY_ARGS_TYPE info) + Nan::NAN_INDEX_QUERY_RETURN_TYPE name(uint32_t index, \ + Nan::NAN_INDEX_QUERY_ARGS_TYPE info) class Callback { - public: +public: Callback() {} explicit Callback(const v8::Local &fn) : handle_(fn) {} - ~Callback() { - handle_.Reset(); - } + ~Callback() { handle_.Reset(); } bool operator==(const Callback &other) const { return handle_ == other.handle_; } - bool operator!=(const Callback &other) const { - return !operator==(other); - } + bool operator!=(const Callback &other) const { return !operator==(other); } - inline - v8::Local operator*() const { return GetFunction(); } + inline v8::Local operator*() const { return GetFunction(); } - NAN_DEPRECATED inline v8::Local operator()( - v8::Local target - , int argc = 0 - , v8::Local argv[] = 0) const { + NAN_DEPRECATED inline v8::Local + operator()(v8::Local target, int argc = 0, + v8::Local argv[] = 0) const { #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION AsyncResource async("nan:Callback:operator()"); return Call_(isolate, target, argc, argv, &async) .FromMaybe(v8::Local()); -# else +#else return Call_(isolate, target, argc, argv); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION #else return Call_(target, argc, argv); -#endif // NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +#endif // NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION } - NAN_DEPRECATED inline v8::Local operator()( - int argc = 0 - , v8::Local argv[] = 0) const { + NAN_DEPRECATED inline v8::Local + operator()(int argc = 0, v8::Local argv[] = 0) const { #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION AsyncResource async("nan:Callback:operator()"); return scope.Escape(Call_(isolate, isolate->GetCurrentContext()->Global(), argc, argv, &async) .FromMaybe(v8::Local())); -# else +#else return scope.Escape( Call_(isolate, isolate->GetCurrentContext()->Global(), argc, argv)); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION #else v8::HandleScope scope; return scope.Close(Call_(v8::Context::GetCurrent()->Global(), argc, argv)); -#endif // NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +#endif // NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION } - inline MaybeLocal operator()( - AsyncResource* resource - , int argc = 0 - , v8::Local argv[] = 0) const { + inline MaybeLocal + operator()(AsyncResource *resource, int argc = 0, + v8::Local argv[] = 0) const { return this->Call(argc, argv, resource); } - inline MaybeLocal operator()( - AsyncResource* resource - , v8::Local target - , int argc = 0 - , v8::Local argv[] = 0) const { + inline MaybeLocal + operator()(AsyncResource *resource, v8::Local target, + int argc = 0, v8::Local argv[] = 0) const { return this->Call(target, argc, argv, resource); } // TODO(kkoopa): remove - inline void SetFunction(const v8::Local &fn) { - Reset(fn); - } + inline void SetFunction(const v8::Local &fn) { Reset(fn); } - inline void Reset(const v8::Local &fn) { - handle_.Reset(fn); - } + inline void Reset(const v8::Local &fn) { handle_.Reset(fn); } - inline void Reset() { - handle_.Reset(); - } + inline void Reset() { handle_.Reset(); } - inline v8::Local GetFunction() const { - return New(handle_); - } + inline v8::Local GetFunction() const { return New(handle_); } - inline bool IsEmpty() const { - return handle_.IsEmpty(); - } + inline bool IsEmpty() const { return handle_.IsEmpty(); } // Deprecated: For async callbacks Use the versions that accept an // AsyncResource. If this callback does not correspond to an async resource, // that is, it is a synchronous function call on a non-empty JS stack, you // should Nan::Call instead. NAN_DEPRECATED inline v8::Local - Call(v8::Local target - , int argc - , v8::Local argv[]) const { + Call(v8::Local target, int argc, + v8::Local argv[]) const { #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION AsyncResource async("nan:Callback:Call"); return Call_(isolate, target, argc, argv, &async) .FromMaybe(v8::Local()); -# else +#else return Call_(isolate, target, argc, argv); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION #else return Call_(target, argc, argv); #endif @@ -1819,28 +1649,26 @@ class Callback { #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); -# if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION AsyncResource async("nan:Callback:Call"); return scope.Escape(Call_(isolate, isolate->GetCurrentContext()->Global(), argc, argv, &async) .FromMaybe(v8::Local())); -# else +#else return scope.Escape( Call_(isolate, isolate->GetCurrentContext()->Global(), argc, argv)); -# endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION #else v8::HandleScope scope; return scope.Close(Call_(v8::Context::GetCurrent()->Global(), argc, argv)); #endif } - inline MaybeLocal - Call(v8::Local target - , int argc - , v8::Local argv[] - , AsyncResource* resource) const { + inline MaybeLocal Call(v8::Local target, int argc, + v8::Local argv[], + AsyncResource *resource) const { #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); return Call_(isolate, target, argc, argv, resource); #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -1850,10 +1678,10 @@ class Callback { #endif } - inline MaybeLocal - Call(int argc, v8::Local argv[], AsyncResource* resource) const { + inline MaybeLocal Call(int argc, v8::Local argv[], + AsyncResource *resource) const { #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); return Call(isolate->GetCurrentContext()->Global(), argc, argv, resource); #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -1866,80 +1694,58 @@ class Callback { #endif } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(Callback) Persistent handle_; #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION - MaybeLocal Call_(v8::Isolate *isolate - , v8::Local target - , int argc - , v8::Local argv[] - , AsyncResource* resource) const { + MaybeLocal Call_(v8::Isolate *isolate, + v8::Local target, int argc, + v8::Local argv[], + AsyncResource *resource) const { EscapableHandleScope scope; v8::Local func = New(handle_); auto maybe = resource->runInAsyncScope(target, func, argc, argv); v8::Local local; - if (!maybe.ToLocal(&local)) return MaybeLocal(); + if (!maybe.ToLocal(&local)) + return MaybeLocal(); return scope.Escape(local); } #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION - v8::Local Call_(v8::Isolate *isolate - , v8::Local target - , int argc - , v8::Local argv[]) const { + v8::Local Call_(v8::Isolate *isolate, v8::Local target, + int argc, v8::Local argv[]) const { EscapableHandleScope scope; v8::Local callback = New(handle_); -# if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION - return scope.Escape(New(node::MakeCallback( - isolate - , target - , callback - , argc - , argv - ))); -# else - return scope.Escape(node::MakeCallback( - isolate - , target - , callback - , argc - , argv - )); -# endif - } -#else - v8::Local Call_(v8::Local target - , int argc - , v8::Local argv[]) const { +#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION + return scope.Escape( + New(node::MakeCallback(isolate, target, callback, argc, argv))); +#else + return scope.Escape( + node::MakeCallback(isolate, target, callback, argc, argv)); +#endif + } +#else + v8::Local Call_(v8::Local target, int argc, + v8::Local argv[]) const { EscapableHandleScope scope; v8::Local callback = New(handle_); - return scope.Escape(New(node::MakeCallback( - target - , callback - , argc - , argv - ))); + return scope.Escape(New(node::MakeCallback(target, callback, argc, argv))); } #endif }; -inline MaybeLocal Call( - const Nan::Callback& callback - , v8::Local recv - , int argc - , v8::Local argv[]) { +inline MaybeLocal Call(const Nan::Callback &callback, + v8::Local recv, int argc, + v8::Local argv[]) { return Call(*callback, recv, argc, argv); } -inline MaybeLocal Call( - const Nan::Callback& callback - , int argc - , v8::Local argv[]) { +inline MaybeLocal Call(const Nan::Callback &callback, int argc, + v8::Local argv[]) { #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape( Call(*callback, isolate->GetCurrentContext()->Global(), argc, argv) @@ -1952,25 +1758,22 @@ inline MaybeLocal Call( #endif } -inline MaybeLocal Call( - v8::Local symbol - , v8::Local recv - , int argc - , v8::Local argv[]) { +inline MaybeLocal Call(v8::Local symbol, + v8::Local recv, int argc, + v8::Local argv[]) { EscapableHandleScope scope; v8::Local fn_v = Get(recv, symbol).FromMaybe(v8::Local()); - if (fn_v.IsEmpty() || !fn_v->IsFunction()) return v8::Local(); + if (fn_v.IsEmpty() || !fn_v->IsFunction()) + return v8::Local(); v8::Local fn = fn_v.As(); return scope.Escape( Call(fn, recv, argc, argv).FromMaybe(v8::Local())); } -inline MaybeLocal Call( - const char* method - , v8::Local recv - , int argc - , v8::Local argv[]) { +inline MaybeLocal Call(const char *method, + v8::Local recv, int argc, + v8::Local argv[]) { EscapableHandleScope scope; v8::Local method_string = New(method).ToLocalChecked(); @@ -1979,9 +1782,9 @@ inline MaybeLocal Call( } /* abstract */ class AsyncWorker { - public: +public: explicit AsyncWorker(Callback *callback_, - const char* resource_name = "nan:AsyncWorker") + const char *resource_name = "nan:AsyncWorker") : callback(callback_), errmsg_(NULL) { request.data = this; @@ -2012,55 +1815,50 @@ inline MaybeLocal Call( callback = NULL; } - inline void SaveToPersistent( - const char *key, const v8::Local &value) { + inline void SaveToPersistent(const char *key, + const v8::Local &value) { HandleScope scope; Set(New(persistentHandle), New(key).ToLocalChecked(), value).FromJust(); } - inline void SaveToPersistent( - const v8::Local &key, const v8::Local &value) { + inline void SaveToPersistent(const v8::Local &key, + const v8::Local &value) { HandleScope scope; Set(New(persistentHandle), key, value).FromJust(); } - inline void SaveToPersistent( - uint32_t index, const v8::Local &value) { + inline void SaveToPersistent(uint32_t index, + const v8::Local &value) { HandleScope scope; Set(New(persistentHandle), index, value).FromJust(); } inline v8::Local GetFromPersistent(const char *key) const { EscapableHandleScope scope; - return scope.Escape( - Get(New(persistentHandle), New(key).ToLocalChecked()) - .FromMaybe(v8::Local())); + return scope.Escape(Get(New(persistentHandle), New(key).ToLocalChecked()) + .FromMaybe(v8::Local())); } inline v8::Local GetFromPersistent(const v8::Local &key) const { EscapableHandleScope scope; return scope.Escape( - Get(New(persistentHandle), key) - .FromMaybe(v8::Local())); + Get(New(persistentHandle), key).FromMaybe(v8::Local())); } inline v8::Local GetFromPersistent(uint32_t index) const { EscapableHandleScope scope; return scope.Escape( - Get(New(persistentHandle), index) - .FromMaybe(v8::Local())); + Get(New(persistentHandle), index).FromMaybe(v8::Local())); } virtual void Execute() = 0; uv_work_t request; - virtual void Destroy() { - delete this; - } + virtual void Destroy() { delete this; } - protected: +protected: Persistent persistentHandle; Callback *callback; AsyncResource *async_resource; @@ -2075,8 +1873,7 @@ inline MaybeLocal Call( HandleScope scope; v8::Local argv[] = { - v8::Exception::Error(New(ErrorMessage()).ToLocalChecked()) - }; + v8::Exception::Error(New(ErrorMessage()).ToLocalChecked())}; callback->Call(1, argv, async_resource); } @@ -2088,96 +1885,88 @@ inline MaybeLocal Call( memcpy(errmsg_, msg, size); } - const char* ErrorMessage() const { - return errmsg_; - } + const char *ErrorMessage() const { return errmsg_; } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(AsyncWorker) char *errmsg_; }; /* abstract */ class AsyncBareProgressWorkerBase : public AsyncWorker { - public: +public: explicit AsyncBareProgressWorkerBase( Callback *callback_, - const char* resource_name = "nan:AsyncBareProgressWorkerBase") + const char *resource_name = "nan:AsyncBareProgressWorkerBase") : AsyncWorker(callback_, resource_name) { - uv_async_init( - GetCurrentEventLoop() - , &async - , AsyncProgress_ - ); + uv_async_init(GetCurrentEventLoop(), &async, AsyncProgress_); async.data = this; } - virtual ~AsyncBareProgressWorkerBase() { - } + virtual ~AsyncBareProgressWorkerBase() {} virtual void WorkProgress() = 0; virtual void Destroy() { - uv_close(reinterpret_cast(&async), AsyncClose_); + uv_close(reinterpret_cast(&async), AsyncClose_); } - private: +private: inline static NAUV_WORK_CB(AsyncProgress_) { AsyncBareProgressWorkerBase *worker = - static_cast(async->data); + static_cast(async->data); worker->WorkProgress(); } - inline static void AsyncClose_(uv_handle_t* handle) { + inline static void AsyncClose_(uv_handle_t *handle) { AsyncBareProgressWorkerBase *worker = - static_cast(handle->data); + static_cast(handle->data); delete worker; } - protected: +protected: uv_async_t async; }; -template +template /* abstract */ class AsyncBareProgressWorker : public AsyncBareProgressWorkerBase { - public: +public: explicit AsyncBareProgressWorker( Callback *callback_, - const char* resource_name = "nan:AsyncBareProgressWorker") + const char *resource_name = "nan:AsyncBareProgressWorker") : AsyncBareProgressWorkerBase(callback_, resource_name) { uv_mutex_init(&async_lock); } - virtual ~AsyncBareProgressWorker() { - uv_mutex_destroy(&async_lock); - } + virtual ~AsyncBareProgressWorker() { uv_mutex_destroy(&async_lock); } class ExecutionProgress { friend class AsyncBareProgressWorker; - public: + + public: void Signal() const { uv_mutex_lock(&that_->async_lock); uv_async_send(&that_->async); uv_mutex_unlock(&that_->async_lock); } - void Send(const T* data, size_t count) const { + void Send(const T *data, size_t count) const { that_->SendProgress_(data, count); } - private: + private: explicit ExecutionProgress(AsyncBareProgressWorker *that) : that_(that) {} NAN_DISALLOW_ASSIGN_COPY_MOVE(ExecutionProgress) - AsyncBareProgressWorker* const that_; + AsyncBareProgressWorker *const that_; }; - virtual void Execute(const ExecutionProgress& progress) = 0; + virtual void Execute(const ExecutionProgress &progress) = 0; virtual void HandleProgressCallback(const T *data, size_t size) = 0; - protected: +protected: uv_mutex_t async_lock; - private: +private: void Execute() /*final override*/ { ExecutionProgress progress(this); Execute(progress); @@ -2186,20 +1975,17 @@ class AsyncBareProgressWorker : public AsyncBareProgressWorkerBase { virtual void SendProgress_(const T *data, size_t count) = 0; }; -template +template /* abstract */ class AsyncProgressWorkerBase : public AsyncBareProgressWorker { - public: +public: explicit AsyncProgressWorkerBase( Callback *callback_, - const char* resource_name = "nan:AsyncProgressWorkerBase") + const char *resource_name = "nan:AsyncProgressWorkerBase") : AsyncBareProgressWorker(callback_, resource_name), asyncdata_(NULL), - asyncsize_(0) { - } + asyncsize_(0) {} - virtual ~AsyncProgressWorkerBase() { - delete[] asyncdata_; - } + virtual ~AsyncProgressWorkerBase() { delete[] asyncdata_; } void WorkProgress() { uv_mutex_lock(&this->async_lock); @@ -2211,12 +1997,12 @@ class AsyncProgressWorkerBase : public AsyncBareProgressWorker { // Don't send progress events after we've already completed. if (this->callback) { - this->HandleProgressCallback(data, size); + this->HandleProgressCallback(data, size); } delete[] data; } - private: +private: void SendProgress_(const T *data, size_t count) { T *new_data = new T[count]; std::copy(data, data + count, new_data); @@ -2239,37 +2025,36 @@ class AsyncProgressWorkerBase : public AsyncBareProgressWorker { // class definition. typedef AsyncProgressWorkerBase AsyncProgressWorker; -template +template /* abstract */ class AsyncBareProgressQueueWorker : public AsyncBareProgressWorkerBase { - public: +public: explicit AsyncBareProgressQueueWorker( Callback *callback_, - const char* resource_name = "nan:AsyncBareProgressQueueWorker") - : AsyncBareProgressWorkerBase(callback_, resource_name) { - } + const char *resource_name = "nan:AsyncBareProgressQueueWorker") + : AsyncBareProgressWorkerBase(callback_, resource_name) {} - virtual ~AsyncBareProgressQueueWorker() { - } + virtual ~AsyncBareProgressQueueWorker() {} class ExecutionProgress { friend class AsyncBareProgressQueueWorker; - public: - void Send(const T* data, size_t count) const { + + public: + void Send(const T *data, size_t count) const { that_->SendProgress_(data, count); } - private: + private: explicit ExecutionProgress(AsyncBareProgressQueueWorker *that) : that_(that) {} NAN_DISALLOW_ASSIGN_COPY_MOVE(ExecutionProgress) - AsyncBareProgressQueueWorker* const that_; + AsyncBareProgressQueueWorker *const that_; }; - virtual void Execute(const ExecutionProgress& progress) = 0; + virtual void Execute(const ExecutionProgress &progress) = 0; virtual void HandleProgressCallback(const T *data, size_t size) = 0; - private: +private: void Execute() /*final override*/ { ExecutionProgress progress(this); Execute(progress); @@ -2278,13 +2063,13 @@ class AsyncBareProgressQueueWorker : public AsyncBareProgressWorkerBase { virtual void SendProgress_(const T *data, size_t count) = 0; }; -template +template /* abstract */ class AsyncProgressQueueWorker : public AsyncBareProgressQueueWorker { - public: +public: explicit AsyncProgressQueueWorker( Callback *callback_, - const char* resource_name = "nan:AsyncProgressQueueWorker") + const char *resource_name = "nan:AsyncProgressQueueWorker") : AsyncBareProgressQueueWorker(callback_) { uv_mutex_init(&async_lock); } @@ -2293,7 +2078,7 @@ class AsyncProgressQueueWorker : public AsyncBareProgressQueueWorker { uv_mutex_lock(&async_lock); while (!asyncdata_.empty()) { - std::pair &datapair = asyncdata_.front(); + std::pair &datapair = asyncdata_.front(); T *data = datapair.first; asyncdata_.pop(); @@ -2314,7 +2099,7 @@ class AsyncProgressQueueWorker : public AsyncBareProgressQueueWorker { uv_mutex_lock(&async_lock); while (!asyncdata_.empty()) { - std::pair &datapair = asyncdata_.front(); + std::pair &datapair = asyncdata_.front(); T *data = datapair.first; size_t size = datapair.second; @@ -2324,7 +2109,7 @@ class AsyncProgressQueueWorker : public AsyncBareProgressQueueWorker { // Don't send progress events after we've already completed. if (this->callback) { - this->HandleProgressCallback(data, size); + this->HandleProgressCallback(data, size); } delete[] data; @@ -2335,24 +2120,24 @@ class AsyncProgressQueueWorker : public AsyncBareProgressQueueWorker { uv_mutex_unlock(&async_lock); } - private: +private: void SendProgress_(const T *data, size_t count) { T *new_data = new T[count]; std::copy(data, data + count, new_data); uv_mutex_lock(&async_lock); - asyncdata_.push(std::pair(new_data, count)); + asyncdata_.push(std::pair(new_data, count)); uv_mutex_unlock(&async_lock); uv_async_send(&this->async); } uv_mutex_t async_lock; - std::queue > asyncdata_; + std::queue> asyncdata_; }; -inline void AsyncExecute (uv_work_t* req) { - AsyncWorker *worker = static_cast(req->data); +inline void AsyncExecute(uv_work_t *req) { + AsyncWorker *worker = static_cast(req->data); worker->Execute(); } @@ -2361,162 +2146,126 @@ inline void AsyncExecute (uv_work_t* req) { * https://github.com/libuv/libuv/commit/92fb84b751e18f032c02609467f44bfe927b80c5 */ inline void AsyncExecuteComplete(uv_work_t *req) { - AsyncWorker* worker = static_cast(req->data); + AsyncWorker *worker = static_cast(req->data); worker->WorkComplete(); worker->Destroy(); } -inline void AsyncExecuteComplete (uv_work_t* req, int status) { +inline void AsyncExecuteComplete(uv_work_t *req, int status) { AsyncExecuteComplete(req); } -inline void AsyncQueueWorker (AsyncWorker* worker) { - uv_queue_work( - GetCurrentEventLoop() - , &worker->request - , AsyncExecute - , AsyncExecuteComplete - ); +inline void AsyncQueueWorker(AsyncWorker *worker) { + uv_queue_work(GetCurrentEventLoop(), &worker->request, AsyncExecute, + AsyncExecuteComplete); } namespace imp { -inline -ExternalOneByteStringResource const* +inline ExternalOneByteStringResource const * GetExternalResource(v8::Local str) { #if NODE_MODULE_VERSION < ATOM_0_21_MODULE_VERSION - return str->GetExternalAsciiStringResource(); + return str->GetExternalAsciiStringResource(); #else - return str->GetExternalOneByteStringResource(); + return str->GetExternalOneByteStringResource(); #endif } -inline -bool -IsExternal(v8::Local str) { +inline bool IsExternal(v8::Local str) { #if NODE_MODULE_VERSION < ATOM_0_21_MODULE_VERSION - return str->IsExternalAscii(); + return str->IsExternalAscii(); #else - return str->IsExternalOneByte(); + return str->IsExternalOneByte(); #endif } -} // end of namespace imp +} // end of namespace imp -enum Encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER}; +enum Encoding { ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER }; #if NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION -# include "nan_string_bytes.h" // NOLINT(build/include) +#include "nan_string_bytes.h" // NOLINT(build/include) #endif -inline v8::Local Encode( - const void *buf, size_t len, enum Encoding encoding = BINARY) { +inline v8::Local Encode(const void *buf, size_t len, + enum Encoding encoding = BINARY) { #if (NODE_MODULE_VERSION >= ATOM_0_21_MODULE_VERSION) - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); node::encoding node_enc = static_cast(encoding); if (encoding == UCS2) { - return node::Encode( - isolate - , reinterpret_cast(buf) - , len / 2); + return node::Encode(isolate, reinterpret_cast(buf), + len / 2); } else { - return node::Encode( - isolate - , reinterpret_cast(buf) - , len - , node_enc); + return node::Encode(isolate, reinterpret_cast(buf), len, + node_enc); } #elif (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) - return node::Encode( - v8::Isolate::GetCurrent() - , buf, len - , static_cast(encoding)); + return node::Encode(v8::Isolate::GetCurrent(), buf, len, + static_cast(encoding)); #else -# if NODE_MODULE_VERSION >= NODE_0_10_MODULE_VERSION +#if NODE_MODULE_VERSION >= NODE_0_10_MODULE_VERSION return node::Encode(buf, len, static_cast(encoding)); -# else - return imp::Encode(reinterpret_cast(buf), len, encoding); -# endif +#else + return imp::Encode(reinterpret_cast(buf), len, encoding); +#endif #endif } -inline ssize_t DecodeBytes( - v8::Local val, enum Encoding encoding = BINARY) { +inline ssize_t DecodeBytes(v8::Local val, + enum Encoding encoding = BINARY) { #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) - return node::DecodeBytes( - v8::Isolate::GetCurrent() - , val - , static_cast(encoding)); + return node::DecodeBytes(v8::Isolate::GetCurrent(), val, + static_cast(encoding)); #else -# if (NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION) +#if (NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION) if (encoding == BUFFER) { return node::DecodeBytes(val, node::BINARY); } -# endif +#endif return node::DecodeBytes(val, static_cast(encoding)); #endif } -inline ssize_t DecodeWrite( - char *buf - , size_t len - , v8::Local val - , enum Encoding encoding = BINARY) { +inline ssize_t DecodeWrite(char *buf, size_t len, v8::Local val, + enum Encoding encoding = BINARY) { #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) - return node::DecodeWrite( - v8::Isolate::GetCurrent() - , buf - , len - , val - , static_cast(encoding)); -#else -# if (NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION) + return node::DecodeWrite(v8::Isolate::GetCurrent(), buf, len, val, + static_cast(encoding)); +#else +#if (NODE_MODULE_VERSION < NODE_0_10_MODULE_VERSION) if (encoding == BUFFER) { return node::DecodeWrite(buf, len, val, node::BINARY); } -# endif - return node::DecodeWrite( - buf - , len - , val - , static_cast(encoding)); +#endif + return node::DecodeWrite(buf, len, val, + static_cast(encoding)); #endif } -inline void SetPrototypeTemplate( - v8::Local templ - , const char *name - , v8::Local value -) { +inline void SetPrototypeTemplate(v8::Local templ, + const char *name, v8::Local value) { HandleScope scope; SetTemplate(templ->PrototypeTemplate(), name, value); } -inline void SetPrototypeTemplate( - v8::Local templ - , v8::Local name - , v8::Local value - , v8::PropertyAttribute attributes -) { +inline void SetPrototypeTemplate(v8::Local templ, + v8::Local name, + v8::Local value, + v8::PropertyAttribute attributes) { HandleScope scope; SetTemplate(templ->PrototypeTemplate(), name, value, attributes); } -inline void SetInstanceTemplate( - v8::Local templ - , const char *name - , v8::Local value -) { +inline void SetInstanceTemplate(v8::Local templ, + const char *name, v8::Local value) { HandleScope scope; SetTemplate(templ->InstanceTemplate(), name, value); } -inline void SetInstanceTemplate( - v8::Local templ - , v8::Local name - , v8::Local value - , v8::PropertyAttribute attributes -) { +inline void SetInstanceTemplate(v8::Local templ, + v8::Local name, + v8::Local value, + v8::PropertyAttribute attributes) { HandleScope scope; SetTemplate(templ->InstanceTemplate(), name, value, attributes); } @@ -2528,52 +2277,39 @@ namespace imp { // handles everything else. The final argument only serves as discriminator and // is unused. template -inline -void -SetMethodAux(T recv, - v8::Local name, - v8::Local tpl, - v8::Template *) { +inline void SetMethodAux(T recv, v8::Local name, + v8::Local tpl, v8::Template *) { recv->Set(name, tpl); } template -inline -void -SetMethodAux(T recv, - v8::Local name, - v8::Local tpl, - ...) { +inline void SetMethodAux(T recv, v8::Local name, + v8::Local tpl, ...) { Set(recv, name, GetFunction(tpl).ToLocalChecked()); } -} // end of namespace imp +} // end of namespace imp template class HandleType> -inline void SetMethod( - HandleType recv - , const char *name - , FunctionCallback callback - , v8::Local data = v8::Local()) { +inline void SetMethod(HandleType recv, const char *name, + FunctionCallback callback, + v8::Local data = v8::Local()) { HandleScope scope; v8::Local t = New(callback, data); v8::Local fn_name = New(name).ToLocalChecked(); t->SetClassName(fn_name); // Note(@agnat): Pass an empty T* as discriminator. See note on // SetMethodAux(...) above - imp::SetMethodAux(recv, fn_name, t, static_cast(0)); + imp::SetMethodAux(recv, fn_name, t, static_cast(0)); } -inline void SetPrototypeMethod( - v8::Local recv - , const char* name - , FunctionCallback callback - , v8::Local data = v8::Local()) { +inline void +SetPrototypeMethod(v8::Local recv, const char *name, + FunctionCallback callback, + v8::Local data = v8::Local()) { HandleScope scope; - v8::Local t = New( - callback - , data - , New(recv)); + v8::Local t = + New(callback, data, New(recv)); v8::Local fn_name = New(name).ToLocalChecked(); recv->PrototypeTemplate()->Set(fn_name, t); t->SetClassName(fn_name); @@ -2581,130 +2317,114 @@ inline void SetPrototypeMethod( //=== Accessors and Such ======================================================= -NAN_DEPRECATED inline void SetAccessor( - v8::Local tpl - , v8::Local name - , GetterCallback getter - , SetterCallback setter - , v8::Local data - , v8::AccessControl settings - , v8::PropertyAttribute attribute - , imp::Sig signature) { +NAN_DEPRECATED inline void +SetAccessor(v8::Local tpl, v8::Local name, + GetterCallback getter, SetterCallback setter, + v8::Local data, v8::AccessControl settings, + v8::PropertyAttribute attribute, imp::Sig signature) { HandleScope scope; - imp::NativeGetter getter_ = - imp::GetterCallbackWrapper; - imp::NativeSetter setter_ = - setter ? imp::SetterCallbackWrapper : 0; + imp::NativeGetter getter_ = imp::GetterCallbackWrapper; + imp::NativeSetter setter_ = setter ? imp::SetterCallbackWrapper : 0; v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kAccessorFieldCount); v8::Local obj = NewInstance(otpl).ToLocalChecked(); - obj->SetInternalField( - imp::kGetterIndex - , New(reinterpret_cast(getter))); + obj->SetInternalField(imp::kGetterIndex, + New(reinterpret_cast(getter))); if (setter != 0) { - obj->SetInternalField( - imp::kSetterIndex - , New(reinterpret_cast(setter))); + obj->SetInternalField(imp::kSetterIndex, + New(reinterpret_cast(setter))); } if (!data.IsEmpty()) { obj->SetInternalField(imp::kDataIndex, data); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 5)) tpl->SetNativeDataProperty( #else tpl->SetAccessor( #endif - name - , getter_ - , setter_ - , obj + name, getter_, setter_, obj #if !defined(V8_MAJOR_VERSION) || V8_MAJOR_VERSION < 12 - , settings + , + settings #endif - , attribute + , + attribute #if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION) - , signature + , + signature #endif ); } -inline void SetAccessor( - v8::Local tpl - , v8::Local name - , GetterCallback getter - , SetterCallback setter = 0 - , v8::Local data = v8::Local() - , v8::AccessControl settings = v8::DEFAULT - , v8::PropertyAttribute attribute = v8::None) { +inline void SetAccessor(v8::Local tpl, + v8::Local name, GetterCallback getter, + SetterCallback setter = 0, + v8::Local data = v8::Local(), + v8::AccessControl settings = v8::DEFAULT, + v8::PropertyAttribute attribute = v8::None) { HandleScope scope; - imp::NativeGetter getter_ = - imp::GetterCallbackWrapper; - imp::NativeSetter setter_ = - setter ? imp::SetterCallbackWrapper : 0; + imp::NativeGetter getter_ = imp::GetterCallbackWrapper; + imp::NativeSetter setter_ = setter ? imp::SetterCallbackWrapper : 0; v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kAccessorFieldCount); v8::Local obj = NewInstance(otpl).ToLocalChecked(); - obj->SetInternalField( - imp::kGetterIndex - , New(reinterpret_cast(getter))); + obj->SetInternalField(imp::kGetterIndex, + New(reinterpret_cast(getter))); if (setter != 0) { - obj->SetInternalField( - imp::kSetterIndex - , New(reinterpret_cast(setter))); + obj->SetInternalField(imp::kSetterIndex, + New(reinterpret_cast(setter))); } if (!data.IsEmpty()) { obj->SetInternalField(imp::kDataIndex, data); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 5)) tpl->SetNativeDataProperty( #else tpl->SetAccessor( #endif - name - , getter_ - , setter_ - , obj + name, getter_, setter_, obj #if !defined(V8_MAJOR_VERSION) || V8_MAJOR_VERSION < 12 - , settings + , + settings #endif - , attribute - ); + , + attribute); } -inline bool SetAccessor( - v8::Local obj - , v8::Local name - , GetterCallback getter - , SetterCallback setter = 0 - , v8::Local data = v8::Local() - , v8::AccessControl settings = v8::DEFAULT - , v8::PropertyAttribute attribute = v8::None) { +inline bool SetAccessor(v8::Local obj, v8::Local name, + GetterCallback getter, SetterCallback setter = 0, + v8::Local data = v8::Local(), + v8::AccessControl settings = v8::DEFAULT, + v8::PropertyAttribute attribute = v8::None) { HandleScope scope; - imp::NativeGetter getter_ = - imp::GetterCallbackWrapper; - imp::NativeSetter setter_ = - setter ? imp::SetterCallbackWrapper : 0; + imp::NativeGetter getter_ = imp::GetterCallbackWrapper; + imp::NativeSetter setter_ = setter ? imp::SetterCallbackWrapper : 0; v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kAccessorFieldCount); v8::Local dataobj = NewInstance(otpl).ToLocalChecked(); dataobj->SetInternalField( - imp::kGetterIndex - , New(reinterpret_cast(getter))); + imp::kGetterIndex, New(reinterpret_cast(getter))); if (!data.IsEmpty()) { dataobj->SetInternalField(imp::kDataIndex, data); @@ -2712,8 +2432,7 @@ inline bool SetAccessor( if (setter) { dataobj->SetInternalField( - imp::kSetterIndex - , New(reinterpret_cast(setter))); + imp::kSetterIndex, New(reinterpret_cast(setter))); } #if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) @@ -2721,46 +2440,30 @@ inline bool SetAccessor( (V8_MAJOR_VERSION > 12 || \ (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ V8_MINOR_VERSION >= 5)) - return obj->SetNativeDataProperty( - GetCurrentContext() - , name - , getter_ - , setter_ - , dataobj - , attribute).FromMaybe(false); -#else - return obj->SetAccessor( - GetCurrentContext() - , name - , getter_ - , setter_ - , dataobj - , settings - , attribute).FromMaybe(false); -#endif -#else - return obj->SetAccessor( - name - , getter_ - , setter_ - , dataobj - , settings - , attribute); + return obj + ->SetNativeDataProperty(GetCurrentContext(), name, getter_, setter_, + dataobj, attribute) + .FromMaybe(false); +#else + return obj + ->SetAccessor(GetCurrentContext(), name, getter_, setter_, dataobj, + settings, attribute) + .FromMaybe(false); +#endif +#else + return obj->SetAccessor(name, getter_, setter_, dataobj, settings, attribute); #endif } inline void SetNamedPropertyHandler( - v8::Local tpl - , PropertyGetterCallback getter - , PropertySetterCallback setter = 0 - , PropertyQueryCallback query = 0 - , PropertyDeleterCallback deleter = 0 - , PropertyEnumeratorCallback enumerator = 0 - , v8::Local data = v8::Local()) { + v8::Local tpl, PropertyGetterCallback getter, + PropertySetterCallback setter = 0, PropertyQueryCallback query = 0, + PropertyDeleterCallback deleter = 0, + PropertyEnumeratorCallback enumerator = 0, + v8::Local data = v8::Local()) { HandleScope scope; - imp::NativePropertyGetter getter_ = - imp::PropertyGetterCallbackWrapper; + imp::NativePropertyGetter getter_ = imp::PropertyGetterCallbackWrapper; imp::NativePropertySetter setter_ = setter ? imp::PropertySetterCallbackWrapper : 0; imp::NativePropertyQuery query_ = @@ -2773,32 +2476,28 @@ inline void SetNamedPropertyHandler( v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kPropertyFieldCount); v8::Local obj = NewInstance(otpl).ToLocalChecked(); - obj->SetInternalField( - imp::kPropertyGetterIndex - , New(reinterpret_cast(getter))); + obj->SetInternalField(imp::kPropertyGetterIndex, + New(reinterpret_cast(getter))); if (setter) { - obj->SetInternalField( - imp::kPropertySetterIndex - , New(reinterpret_cast(setter))); + obj->SetInternalField(imp::kPropertySetterIndex, + New(reinterpret_cast(setter))); } if (query) { - obj->SetInternalField( - imp::kPropertyQueryIndex - , New(reinterpret_cast(query))); + obj->SetInternalField(imp::kPropertyQueryIndex, + New(reinterpret_cast(query))); } if (deleter) { - obj->SetInternalField( - imp::kPropertyDeleterIndex - , New(reinterpret_cast(deleter))); + obj->SetInternalField(imp::kPropertyDeleterIndex, + New(reinterpret_cast(deleter))); } if (enumerator) { obj->SetInternalField( - imp::kPropertyEnumeratorIndex - , New(reinterpret_cast(enumerator))); + imp::kPropertyEnumeratorIndex, + New(reinterpret_cast(enumerator))); } if (!data.IsEmpty()) { @@ -2809,32 +2508,21 @@ inline void SetNamedPropertyHandler( tpl->SetHandler(v8::NamedPropertyHandlerConfiguration( getter_, setter_, query_, deleter_, enumerator_, obj)); #else - tpl->SetNamedPropertyHandler( - getter_ - , setter_ - , query_ - , deleter_ - , enumerator_ - , obj); + tpl->SetNamedPropertyHandler(getter_, setter_, query_, deleter_, enumerator_, + obj); #endif } inline void SetIndexedPropertyHandler( - v8::Local tpl - , IndexGetterCallback getter - , IndexSetterCallback setter = 0 - , IndexQueryCallback query = 0 - , IndexDeleterCallback deleter = 0 - , IndexEnumeratorCallback enumerator = 0 - , v8::Local data = v8::Local()) { + v8::Local tpl, IndexGetterCallback getter, + IndexSetterCallback setter = 0, IndexQueryCallback query = 0, + IndexDeleterCallback deleter = 0, IndexEnumeratorCallback enumerator = 0, + v8::Local data = v8::Local()) { HandleScope scope; - imp::NativeIndexGetter getter_ = - imp::IndexGetterCallbackWrapper; - imp::NativeIndexSetter setter_ = - setter ? imp::IndexSetterCallbackWrapper : 0; - imp::NativeIndexQuery query_ = - query ? imp::IndexQueryCallbackWrapper : 0; + imp::NativeIndexGetter getter_ = imp::IndexGetterCallbackWrapper; + imp::NativeIndexSetter setter_ = setter ? imp::IndexSetterCallbackWrapper : 0; + imp::NativeIndexQuery query_ = query ? imp::IndexQueryCallbackWrapper : 0; imp::NativeIndexDeleter deleter_ = deleter ? imp::IndexDeleterCallbackWrapper : 0; imp::NativeIndexEnumerator enumerator_ = @@ -2843,32 +2531,28 @@ inline void SetIndexedPropertyHandler( v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kIndexPropertyFieldCount); v8::Local obj = NewInstance(otpl).ToLocalChecked(); - obj->SetInternalField( - imp::kIndexPropertyGetterIndex - , New(reinterpret_cast(getter))); + obj->SetInternalField(imp::kIndexPropertyGetterIndex, + New(reinterpret_cast(getter))); if (setter) { - obj->SetInternalField( - imp::kIndexPropertySetterIndex - , New(reinterpret_cast(setter))); + obj->SetInternalField(imp::kIndexPropertySetterIndex, + New(reinterpret_cast(setter))); } if (query) { - obj->SetInternalField( - imp::kIndexPropertyQueryIndex - , New(reinterpret_cast(query))); + obj->SetInternalField(imp::kIndexPropertyQueryIndex, + New(reinterpret_cast(query))); } if (deleter) { - obj->SetInternalField( - imp::kIndexPropertyDeleterIndex - , New(reinterpret_cast(deleter))); + obj->SetInternalField(imp::kIndexPropertyDeleterIndex, + New(reinterpret_cast(deleter))); } if (enumerator) { obj->SetInternalField( - imp::kIndexPropertyEnumeratorIndex - , New(reinterpret_cast(enumerator))); + imp::kIndexPropertyEnumeratorIndex, + New(reinterpret_cast(enumerator))); } if (!data.IsEmpty()) { @@ -2879,29 +2563,22 @@ inline void SetIndexedPropertyHandler( tpl->SetHandler(v8::IndexedPropertyHandlerConfiguration( getter_, setter_, query_, deleter_, enumerator_, obj)); #else - tpl->SetIndexedPropertyHandler( - getter_ - , setter_ - , query_ - , deleter_ - , enumerator_ - , obj); + tpl->SetIndexedPropertyHandler(getter_, setter_, query_, deleter_, + enumerator_, obj); #endif } -inline void SetCallHandler( - v8::Local tpl - , FunctionCallback callback - , v8::Local data = v8::Local()) { +inline void SetCallHandler(v8::Local tpl, + FunctionCallback callback, + v8::Local data = v8::Local()) { HandleScope scope; v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kFunctionFieldCount); v8::Local obj = NewInstance(otpl).ToLocalChecked(); - obj->SetInternalField( - imp::kFunctionIndex - , New(reinterpret_cast(callback))); + obj->SetInternalField(imp::kFunctionIndex, + New(reinterpret_cast(callback))); if (!data.IsEmpty()) { obj->SetInternalField(imp::kDataIndex, data); @@ -2910,20 +2587,18 @@ inline void SetCallHandler( tpl->SetCallHandler(imp::FunctionCallbackWrapper, obj); } - -inline void SetCallAsFunctionHandler( - v8::Local tpl, - FunctionCallback callback, - v8::Local data = v8::Local()) { +inline void +SetCallAsFunctionHandler(v8::Local tpl, + FunctionCallback callback, + v8::Local data = v8::Local()) { HandleScope scope; v8::Local otpl = New(); otpl->SetInternalFieldCount(imp::kFunctionFieldCount); v8::Local obj = NewInstance(otpl).ToLocalChecked(); - obj->SetInternalField( - imp::kFunctionIndex - , New(reinterpret_cast(callback))); + obj->SetInternalField(imp::kFunctionIndex, + New(reinterpret_cast(callback))); if (!data.IsEmpty()) { obj->SetInternalField(imp::kDataIndex, data); @@ -2934,22 +2609,20 @@ inline void SetCallAsFunctionHandler( //=== Weak Persistent Handling ================================================= -#include "nan_weak.h" // NOLINT(build/include) +#include "nan_weak.h" // NOLINT(build/include) //=== ObjectWrap =============================================================== -#include "nan_object_wrap.h" // NOLINT(build/include) +#include "nan_object_wrap.h" // NOLINT(build/include) //=== HiddenValue/Private ====================================================== -#include "nan_private.h" // NOLINT(build/include) +#include "nan_private.h" // NOLINT(build/include) //=== Export ================================================================== -inline -void -Export(ADDON_REGISTER_FUNCTION_ARGS_TYPE target, const char *name, - FunctionCallback f) { +inline void Export(ADDON_REGISTER_FUNCTION_ARGS_TYPE target, const char *name, + FunctionCallback f) { HandleScope scope; Set(target, New(name).ToLocalChecked(), @@ -2965,7 +2638,7 @@ struct Tap { t_.Reset(To(t).ToLocalChecked()); } - ~Tap() { t_.Reset(); } // not sure if necessary + ~Tap() { t_.Reset(); } // not sure if necessary inline void plan(int i) { HandleScope scope; @@ -2977,14 +2650,16 @@ struct Tap { HandleScope scope; v8::Local args[2]; args[0] = New(isOk); - if (msg) args[1] = New(msg).ToLocalChecked(); + if (msg) + args[1] = New(msg).ToLocalChecked(); Call("ok", New(t_), msg ? 2 : 1, args); } - inline void pass(const char * msg = NULL) { + inline void pass(const char *msg = NULL) { HandleScope scope; v8::Local hmsg; - if (msg) hmsg = New(msg).ToLocalChecked(); + if (msg) + hmsg = New(msg).ToLocalChecked(); Call("pass", New(t_), msg ? 1 : 0, &hmsg); } @@ -2993,14 +2668,14 @@ struct Tap { Call("end", New(t_), 0, NULL); } - private: +private: Persistent t_; }; #define NAN_STRINGIZE2(x) #x #define NAN_STRINGIZE(x) NAN_STRINGIZE2(x) -#define NAN_TEST_EXPRESSION(expression) \ - ( expression ), __FILE__ ":" NAN_STRINGIZE(__LINE__) ": " #expression +#define NAN_TEST_EXPRESSION(expression) \ + (expression), __FILE__ ":" NAN_STRINGIZE(__LINE__) ": " #expression #define NAN_EXPORT(target, function) Export(target, #function, function) @@ -3012,38 +2687,33 @@ namespace imp { template struct Maybefier; -template struct Maybefier > { - inline static MaybeLocal convert(v8::Local v) { - return v; - } +template struct Maybefier> { + inline static MaybeLocal convert(v8::Local v) { return v; } }; -template struct Maybefier > { - inline static MaybeLocal convert(MaybeLocal v) { - return v; - } +template struct Maybefier> { + inline static MaybeLocal convert(MaybeLocal v) { return v; } }; -} // end of namespace imp +} // end of namespace imp template class MaybeMaybe> -inline MaybeLocal -MakeMaybe(MaybeMaybe v) { - return imp::Maybefier >::convert(v); +inline MaybeLocal MakeMaybe(MaybeMaybe v) { + return imp::Maybefier>::convert(v); } //=== TypedArrayContents ======================================================= -#include "nan_typedarray_contents.h" // NOLINT(build/include) +#include "nan_typedarray_contents.h" // NOLINT(build/include) //=== JSON ===================================================================== -#include "nan_json.h" // NOLINT(build/include) +#include "nan_json.h" // NOLINT(build/include) //=== ScriptOrigin ============================================================= -#include "nan_scriptorigin.h" // NOLINT(build/include) +#include "nan_scriptorigin.h" // NOLINT(build/include) -} // end of namespace Nan +} // end of namespace Nan -#endif // NAN_H_ +#endif // NAN_H_ diff --git a/node_modules/nan/nan_callbacks.h b/node_modules/nan/nan_callbacks.h index 2c54857..80a2b05 100644 --- a/node_modules/nan/nan_callbacks.h +++ b/node_modules/nan/nan_callbacks.h @@ -9,83 +9,67 @@ #ifndef NAN_CALLBACKS_H_ #define NAN_CALLBACKS_H_ -template class FunctionCallbackInfo; -template class PropertyCallbackInfo; -template class Global; +template class FunctionCallbackInfo; +template class PropertyCallbackInfo; +template class Global; -typedef void(*FunctionCallback)(const FunctionCallbackInfo&); -typedef void(*GetterCallback) - (v8::Local, const PropertyCallbackInfo&); -typedef void(*SetterCallback)( - v8::Local, - v8::Local, - const PropertyCallbackInfo&); +typedef void (*FunctionCallback)(const FunctionCallbackInfo &); +typedef void (*GetterCallback)(v8::Local, + const PropertyCallbackInfo &); +typedef void (*SetterCallback)(v8::Local, v8::Local, + const PropertyCallbackInfo &); -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -typedef v8::Intercepted(*PropertyGetterCallback)( - v8::Local, - const PropertyCallbackInfo&); -typedef v8::Intercepted(*PropertySetterCallback)( - v8::Local, - v8::Local, - const PropertyCallbackInfo&); +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +typedef v8::Intercepted (*PropertyGetterCallback)( + v8::Local, const PropertyCallbackInfo &); +typedef v8::Intercepted (*PropertySetterCallback)( + v8::Local, v8::Local, + const PropertyCallbackInfo &); #else -typedef void(*PropertyGetterCallback)( - v8::Local, - const PropertyCallbackInfo&); -typedef void(*PropertySetterCallback)( - v8::Local, - v8::Local, - const PropertyCallbackInfo&); +typedef void (*PropertyGetterCallback)(v8::Local, + const PropertyCallbackInfo &); +typedef void (*PropertySetterCallback)(v8::Local, + v8::Local, + const PropertyCallbackInfo &); #endif -typedef void(*PropertyEnumeratorCallback) - (const PropertyCallbackInfo&); -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -typedef v8::Intercepted(*PropertyDeleterCallback)( - v8::Local, - const PropertyCallbackInfo&); -typedef v8::Intercepted(*PropertyQueryCallback)( - v8::Local, - const PropertyCallbackInfo&); -typedef v8::Intercepted(*IndexGetterCallback)( - uint32_t, - const PropertyCallbackInfo&); -typedef v8::Intercepted(*IndexSetterCallback)( - uint32_t, - v8::Local, - const PropertyCallbackInfo&); -typedef v8::Intercepted(*IndexEnumeratorCallback) - (const PropertyCallbackInfo&); -typedef v8::Intercepted(*IndexDeleterCallback)( - uint32_t, - const PropertyCallbackInfo&); -typedef v8::Intercepted(*IndexQueryCallback)( - uint32_t, - const PropertyCallbackInfo&); +typedef void (*PropertyEnumeratorCallback)( + const PropertyCallbackInfo &); +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +typedef v8::Intercepted (*PropertyDeleterCallback)( + v8::Local, const PropertyCallbackInfo &); +typedef v8::Intercepted (*PropertyQueryCallback)( + v8::Local, const PropertyCallbackInfo &); +typedef v8::Intercepted (*IndexGetterCallback)( + uint32_t, const PropertyCallbackInfo &); +typedef v8::Intercepted (*IndexSetterCallback)( + uint32_t, v8::Local, const PropertyCallbackInfo &); +typedef v8::Intercepted (*IndexEnumeratorCallback)( + const PropertyCallbackInfo &); +typedef v8::Intercepted (*IndexDeleterCallback)( + uint32_t, const PropertyCallbackInfo &); +typedef v8::Intercepted (*IndexQueryCallback)( + uint32_t, const PropertyCallbackInfo &); #else -typedef void(*PropertyDeleterCallback)( - v8::Local, - const PropertyCallbackInfo&); -typedef void(*PropertyQueryCallback)( - v8::Local, - const PropertyCallbackInfo&); -typedef void(*IndexGetterCallback)( - uint32_t, - const PropertyCallbackInfo&); -typedef void(*IndexSetterCallback)( - uint32_t, - v8::Local, - const PropertyCallbackInfo&); -typedef void(*IndexEnumeratorCallback) - (const PropertyCallbackInfo&); -typedef void(*IndexDeleterCallback)( - uint32_t, - const PropertyCallbackInfo&); -typedef void(*IndexQueryCallback)( - uint32_t, - const PropertyCallbackInfo&); +typedef void (*PropertyDeleterCallback)( + v8::Local, const PropertyCallbackInfo &); +typedef void (*PropertyQueryCallback)( + v8::Local, const PropertyCallbackInfo &); +typedef void (*IndexGetterCallback)(uint32_t, + const PropertyCallbackInfo &); +typedef void (*IndexSetterCallback)(uint32_t, v8::Local, + const PropertyCallbackInfo &); +typedef void (*IndexEnumeratorCallback)( + const PropertyCallbackInfo &); +typedef void (*IndexDeleterCallback)(uint32_t, + const PropertyCallbackInfo &); +typedef void (*IndexQueryCallback)(uint32_t, + const PropertyCallbackInfo &); #endif namespace imp { #if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION) @@ -94,35 +78,35 @@ typedef v8::Local Sig; typedef v8::Local Sig; #endif -static const int kDataIndex = 0; +static const int kDataIndex = 0; -static const int kFunctionIndex = 1; -static const int kFunctionFieldCount = 2; +static const int kFunctionIndex = 1; +static const int kFunctionFieldCount = 2; -static const int kGetterIndex = 1; -static const int kSetterIndex = 2; -static const int kAccessorFieldCount = 3; +static const int kGetterIndex = 1; +static const int kSetterIndex = 2; +static const int kAccessorFieldCount = 3; -static const int kPropertyGetterIndex = 1; -static const int kPropertySetterIndex = 2; -static const int kPropertyEnumeratorIndex = 3; -static const int kPropertyDeleterIndex = 4; -static const int kPropertyQueryIndex = 5; -static const int kPropertyFieldCount = 6; +static const int kPropertyGetterIndex = 1; +static const int kPropertySetterIndex = 2; +static const int kPropertyEnumeratorIndex = 3; +static const int kPropertyDeleterIndex = 4; +static const int kPropertyQueryIndex = 5; +static const int kPropertyFieldCount = 6; -static const int kIndexPropertyGetterIndex = 1; -static const int kIndexPropertySetterIndex = 2; +static const int kIndexPropertyGetterIndex = 1; +static const int kIndexPropertySetterIndex = 2; static const int kIndexPropertyEnumeratorIndex = 3; -static const int kIndexPropertyDeleterIndex = 4; -static const int kIndexPropertyQueryIndex = 5; -static const int kIndexPropertyFieldCount = 6; +static const int kIndexPropertyDeleterIndex = 4; +static const int kIndexPropertyQueryIndex = 5; +static const int kIndexPropertyFieldCount = 6; -} // end of namespace imp +} // end of namespace imp #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION -# include "nan_callbacks_12_inl.h" // NOLINT(build/include) +#include "nan_callbacks_12_inl.h" // NOLINT(build/include) #else -# include "nan_callbacks_pre_12_inl.h" // NOLINT(build/include) +#include "nan_callbacks_pre_12_inl.h" // NOLINT(build/include) #endif -#endif // NAN_CALLBACKS_H_ +#endif // NAN_CALLBACKS_H_ diff --git a/node_modules/nan/nan_callbacks_12_inl.h b/node_modules/nan/nan_callbacks_12_inl.h index f953989..9a6eaa9 100644 --- a/node_modules/nan/nan_callbacks_12_inl.h +++ b/node_modules/nan/nan_callbacks_12_inl.h @@ -9,16 +9,15 @@ #ifndef NAN_CALLBACKS_12_INL_H_ #define NAN_CALLBACKS_12_INL_H_ -template -class ReturnValue { +template class ReturnValue { v8::ReturnValue value_; - public: +public: template - explicit inline ReturnValue(const v8::ReturnValue &value) : - value_(value) {} + explicit inline ReturnValue(const v8::ReturnValue &value) + : value_(value) {} template - explicit inline ReturnValue(const ReturnValue& that) + explicit inline ReturnValue(const ReturnValue &that) : value_(that.value_) { TYPE_CHECK(T, S); } @@ -31,13 +30,15 @@ class ReturnValue { template inline void Set(const Global &handle) { TYPE_CHECK(T, S); -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ - (V8_MINOR_VERSION > 5 || (V8_MINOR_VERSION == 5 && \ - defined(V8_BUILD_NUMBER) && V8_BUILD_NUMBER >= 8)))) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 5 || \ + (V8_MINOR_VERSION == 5 && defined(V8_BUILD_NUMBER) && \ + V8_BUILD_NUMBER >= 8)))) value_.Set(handle); #else - value_.Set(*reinterpret_cast*>(&handle)); + value_.Set(*reinterpret_cast *>(&handle)); const_cast &>(handle).Reset(); #endif } @@ -80,26 +81,22 @@ class ReturnValue { } // Convenience getter for isolate - inline v8::Isolate *GetIsolate() const { - return value_.GetIsolate(); - } + inline v8::Isolate *GetIsolate() const { return value_.GetIsolate(); } // Pointer setter: Uncompilable to prevent inadvertent misuse. - template - inline void Set(S *whatever) { TYPE_CHECK(S*, v8::Primitive); } + template inline void Set(S *whatever) { + TYPE_CHECK(S *, v8::Primitive); + } }; -template -class FunctionCallbackInfo { +template class FunctionCallbackInfo { const v8::FunctionCallbackInfo &info_; const v8::Local data_; - public: - explicit inline FunctionCallbackInfo( - const v8::FunctionCallbackInfo &info - , v8::Local data) : - info_(info) - , data_(data) {} +public: + explicit inline FunctionCallbackInfo(const v8::FunctionCallbackInfo &info, + v8::Local data) + : info_(info), data_(data) {} inline ReturnValue GetReturnValue() const { return ReturnValue(info_.GetReturnValue()); @@ -116,8 +113,7 @@ class FunctionCallbackInfo { inline v8::Local This() const { return info_.This(); } inline v8::Isolate *GetIsolate() const { return info_.GetIsolate(); } - - protected: +protected: static const int kHolderIndex = 0; static const int kIsolateIndex = 1; static const int kReturnValueDefaultValueIndex = 2; @@ -127,23 +123,20 @@ class FunctionCallbackInfo { static const int kContextSaveIndex = 6; static const int kArgsLength = 7; - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(FunctionCallbackInfo) }; -template -class PropertyCallbackInfo { +template class PropertyCallbackInfo { const v8::PropertyCallbackInfo &info_; const v8::Local data_; - public: - explicit inline PropertyCallbackInfo( - const v8::PropertyCallbackInfo &info - , const v8::Local data) : - info_(info) - , data_(data) {} +public: + explicit inline PropertyCallbackInfo(const v8::PropertyCallbackInfo &info, + const v8::Local data) + : info_(info), data_(data) {} - inline v8::Isolate* GetIsolate() const { return info_.GetIsolate(); } + inline v8::Isolate *GetIsolate() const { return info_.GetIsolate(); } inline v8::Local Data() const { return data_; } inline v8::Local This() const { return info_.This(); } inline v8::Local Holder() const { return info_.Holder(); } @@ -151,7 +144,7 @@ class PropertyCallbackInfo { return ReturnValue(info_.GetReturnValue()); } - protected: +protected: static const int kHolderIndex = 0; static const int kIsolateIndex = 1; static const int kReturnValueDefaultValueIndex = 2; @@ -160,517 +153,524 @@ class PropertyCallbackInfo { static const int kThisIndex = 5; static const int kArgsLength = 6; - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(PropertyCallbackInfo) }; namespace imp { -static -void FunctionCallbackWrapper(const v8::FunctionCallbackInfo &info) { +static void +FunctionCallbackWrapper(const v8::FunctionCallbackInfo &info) { v8::Local obj = info.Data().As(); FunctionCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kFunctionIndex) - .As().As()->Value())); - FunctionCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + reinterpret_cast(obj->GetInternalField(kFunctionIndex) + .As() + .As() + ->Value())); + FunctionCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); callback(cbinfo); } typedef void (*NativeFunction)(const v8::FunctionCallbackInfo &); #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION -static -void GetterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void +GetterCallbackWrapper(v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); GetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kGetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kGetterIndex) + .As() + .As() + ->Value())); callback(property.As(), cbinfo); } -typedef void (*NativeGetter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void (*NativeGetter)(v8::Local, + const v8::PropertyCallbackInfo &); -static -void SetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +static void SetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); SetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kSetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kSetterIndex) + .As() + .As() + ->Value())); callback(property.As(), value, cbinfo); } -typedef void (*NativeSetter)( - v8::Local - , v8::Local - , const v8::PropertyCallbackInfo &); +typedef void (*NativeSetter)(v8::Local, v8::Local, + const v8::PropertyCallbackInfo &); #else -static -void GetterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void +GetterCallbackWrapper(v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); GetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kGetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kGetterIndex) + .As() + .As() + ->Value())); callback(property, cbinfo); } -typedef void (*NativeGetter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void (*NativeGetter)(v8::Local, + const v8::PropertyCallbackInfo &); -static -void SetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +static void SetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); SetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kSetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kSetterIndex) + .As() + .As() + ->Value())); callback(property, value, cbinfo); } -typedef void (*NativeSetter)( - v8::Local - , v8::Local - , const v8::PropertyCallbackInfo &); +typedef void (*NativeSetter)(v8::Local, v8::Local, + const v8::PropertyCallbackInfo &); #endif #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -static -v8::Intercepted PropertyGetterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +static v8::Intercepted +PropertyGetterCallbackWrapper(v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyGetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyGetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyGetterIndex) + .As() + .As() + ->Value())); return callback(property.As(), cbinfo); } -typedef v8::Intercepted (*NativePropertyGetter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef v8::Intercepted (*NativePropertyGetter)( + v8::Local, const v8::PropertyCallbackInfo &); -static -v8::Intercepted PropertySetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +static v8::Intercepted +PropertySetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertySetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertySetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertySetterIndex) + .As() + .As() + ->Value())); return callback(property.As(), value, cbinfo); } typedef v8::Intercepted (*NativePropertySetter)( - v8::Local - , v8::Local - , const v8::PropertyCallbackInfo &); + v8::Local, v8::Local, + const v8::PropertyCallbackInfo &); #else -static -void PropertyGetterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void +PropertyGetterCallbackWrapper(v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyGetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyGetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyGetterIndex) + .As() + .As() + ->Value())); callback(property.As(), cbinfo); } -typedef void (*NativePropertyGetter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void (*NativePropertyGetter)( + v8::Local, const v8::PropertyCallbackInfo &); -static -void PropertySetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +static void +PropertySetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertySetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertySetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertySetterIndex) + .As() + .As() + ->Value())); callback(property.As(), value, cbinfo); } typedef void (*NativePropertySetter)( - v8::Local - , v8::Local - , const v8::PropertyCallbackInfo &); + v8::Local, v8::Local, + const v8::PropertyCallbackInfo &); #endif -static -void PropertyEnumeratorCallbackWrapper( +static void PropertyEnumeratorCallbackWrapper( const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyEnumeratorCallback callback = reinterpret_cast(reinterpret_cast( obj->GetInternalField(kPropertyEnumeratorIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); callback(cbinfo); } -typedef void (*NativePropertyEnumerator) - (const v8::PropertyCallbackInfo &); +typedef void (*NativePropertyEnumerator)( + const v8::PropertyCallbackInfo &); -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -static -v8::Intercepted PropertyDeleterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +static v8::Intercepted PropertyDeleterCallbackWrapper( + v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyDeleterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyDeleterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyDeleterIndex) + .As() + .As() + ->Value())); return callback(property.As(), cbinfo); } -typedef v8::Intercepted (NativePropertyDeleter) - (v8::Local, const v8::PropertyCallbackInfo &); - +typedef v8::Intercepted(NativePropertyDeleter)( + v8::Local, const v8::PropertyCallbackInfo &); -static -v8::Intercepted PropertyQueryCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static v8::Intercepted PropertyQueryCallbackWrapper( + v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyQueryIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyQueryIndex) + .As() + .As() + ->Value())); return callback(property.As(), cbinfo); } -typedef v8::Intercepted (*NativePropertyQuery) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef v8::Intercepted (*NativePropertyQuery)( + v8::Local, const v8::PropertyCallbackInfo &); #else -static -void PropertyDeleterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void PropertyDeleterCallbackWrapper( + v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyDeleterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyDeleterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyDeleterIndex) + .As() + .As() + ->Value())); callback(property.As(), cbinfo); } -typedef void (NativePropertyDeleter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void(NativePropertyDeleter)( + v8::Local, const v8::PropertyCallbackInfo &); -static -void PropertyQueryCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void PropertyQueryCallbackWrapper( + v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyQueryIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyQueryIndex) + .As() + .As() + ->Value())); callback(property.As(), cbinfo); } -typedef void (*NativePropertyQuery) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void (*NativePropertyQuery)( + v8::Local, const v8::PropertyCallbackInfo &); #endif #else -static -void PropertyGetterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void +PropertyGetterCallbackWrapper(v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyGetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyGetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyGetterIndex) + .As() + .As() + ->Value())); callback(property, cbinfo); } -typedef void (*NativePropertyGetter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void (*NativePropertyGetter)( + v8::Local, const v8::PropertyCallbackInfo &); -static -void PropertySetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +static void +PropertySetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertySetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertySetterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertySetterIndex) + .As() + .As() + ->Value())); callback(property, value, cbinfo); } typedef void (*NativePropertySetter)( - v8::Local - , v8::Local - , const v8::PropertyCallbackInfo &); + v8::Local, v8::Local, + const v8::PropertyCallbackInfo &); -static -void PropertyEnumeratorCallbackWrapper( +static void PropertyEnumeratorCallbackWrapper( const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyEnumeratorCallback callback = reinterpret_cast(reinterpret_cast( obj->GetInternalField(kPropertyEnumeratorIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); callback(cbinfo); } -typedef void (*NativePropertyEnumerator) - (const v8::PropertyCallbackInfo &); +typedef void (*NativePropertyEnumerator)( + const v8::PropertyCallbackInfo &); -static -void PropertyDeleterCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void PropertyDeleterCallbackWrapper( + v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyDeleterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyDeleterIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyDeleterIndex) + .As() + .As() + ->Value())); callback(property, cbinfo); } -typedef void (NativePropertyDeleter) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void(NativePropertyDeleter)( + v8::Local, const v8::PropertyCallbackInfo &); -static -void PropertyQueryCallbackWrapper( - v8::Local property - , const v8::PropertyCallbackInfo &info) { +static void PropertyQueryCallbackWrapper( + v8::Local property, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); PropertyQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyQueryIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyQueryIndex) + .As() + .As() + ->Value())); callback(property, cbinfo); } -typedef void (*NativePropertyQuery) - (v8::Local, const v8::PropertyCallbackInfo &); +typedef void (*NativePropertyQuery)( + v8::Local, const v8::PropertyCallbackInfo &); #endif -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -static -v8::Intercepted IndexGetterCallbackWrapper( - uint32_t index, const v8::PropertyCallbackInfo &info) { +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +static v8::Intercepted +IndexGetterCallbackWrapper(uint32_t index, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexGetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexGetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyGetterIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); return callback(index, cbinfo); } -typedef v8::Intercepted (*NativeIndexGetter) - (uint32_t, const v8::PropertyCallbackInfo &); +typedef v8::Intercepted (*NativeIndexGetter)( + uint32_t, const v8::PropertyCallbackInfo &); -static -v8::Intercepted IndexSetterCallbackWrapper( - uint32_t index - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +static v8::Intercepted +IndexSetterCallbackWrapper(uint32_t index, v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexSetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexSetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertySetterIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); return callback(index, value, cbinfo); } typedef v8::Intercepted (*NativeIndexSetter)( - uint32_t - , v8::Local - , const v8::PropertyCallbackInfo &); + uint32_t, v8::Local, const v8::PropertyCallbackInfo &); #else -static -void IndexGetterCallbackWrapper( - uint32_t index, const v8::PropertyCallbackInfo &info) { +static void +IndexGetterCallbackWrapper(uint32_t index, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexGetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexGetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyGetterIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); callback(index, cbinfo); } -typedef void (*NativeIndexGetter) - (uint32_t, const v8::PropertyCallbackInfo &); -static -void IndexSetterCallbackWrapper( - uint32_t index - , v8::Local value - , const v8::PropertyCallbackInfo &info) { +typedef void (*NativeIndexGetter)(uint32_t, + const v8::PropertyCallbackInfo &); +static void +IndexSetterCallbackWrapper(uint32_t index, v8::Local value, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexSetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexSetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertySetterIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); callback(index, value, cbinfo); } -typedef void (*NativeIndexSetter)( - uint32_t - , v8::Local - , const v8::PropertyCallbackInfo &); +typedef void (*NativeIndexSetter)(uint32_t, v8::Local, + const v8::PropertyCallbackInfo &); #endif -static -void IndexEnumeratorCallbackWrapper( +static void IndexEnumeratorCallbackWrapper( const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexEnumeratorCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField( - kIndexPropertyEnumeratorIndex) - .As().As()->Value())); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexEnumeratorCallback callback = + reinterpret_cast(reinterpret_cast( + obj->GetInternalField(kIndexPropertyEnumeratorIndex) + .As() + .As() + ->Value())); callback(cbinfo); } -typedef void (*NativeIndexEnumerator) - (const v8::PropertyCallbackInfo &); +typedef void (*NativeIndexEnumerator)( + const v8::PropertyCallbackInfo &); -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ - (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) -static -v8::Intercepted IndexDeleterCallbackWrapper( - uint32_t index, const v8::PropertyCallbackInfo &info) { +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 4)) +static v8::Intercepted +IndexDeleterCallbackWrapper(uint32_t index, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexDeleterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexDeleterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyDeleterIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); return callback(index, cbinfo); } -typedef v8::Intercepted (*NativeIndexDeleter) - (uint32_t, const v8::PropertyCallbackInfo &); +typedef v8::Intercepted (*NativeIndexDeleter)( + uint32_t, const v8::PropertyCallbackInfo &); -static -v8::Intercepted IndexQueryCallbackWrapper( - uint32_t index, const v8::PropertyCallbackInfo &info) { +static v8::Intercepted +IndexQueryCallbackWrapper(uint32_t index, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); IndexQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kIndexPropertyQueryIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kIndexPropertyQueryIndex) + .As() + .As() + ->Value())); return callback(index, cbinfo); } -typedef v8::Intercepted (*NativeIndexQuery) - (uint32_t, const v8::PropertyCallbackInfo &); +typedef v8::Intercepted (*NativeIndexQuery)( + uint32_t, const v8::PropertyCallbackInfo &); #else -static -void IndexDeleterCallbackWrapper( - uint32_t index, const v8::PropertyCallbackInfo &info) { +static void +IndexDeleterCallbackWrapper(uint32_t index, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); - IndexDeleterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); + IndexDeleterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyDeleterIndex) - .As().As()->Value())); + .As() + .As() + ->Value())); callback(index, cbinfo); } -typedef void (*NativeIndexDeleter) - (uint32_t, const v8::PropertyCallbackInfo &); +typedef void (*NativeIndexDeleter)( + uint32_t, const v8::PropertyCallbackInfo &); -static -void IndexQueryCallbackWrapper( - uint32_t index, const v8::PropertyCallbackInfo &info) { +static void +IndexQueryCallbackWrapper(uint32_t index, + const v8::PropertyCallbackInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyCallbackInfo cbinfo( + info, obj->GetInternalField(kDataIndex).As()); IndexQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kIndexPropertyQueryIndex) - .As().As()->Value())); + reinterpret_cast(obj->GetInternalField(kIndexPropertyQueryIndex) + .As() + .As() + ->Value())); callback(index, cbinfo); } -typedef void (*NativeIndexQuery) - (uint32_t, const v8::PropertyCallbackInfo &); +typedef void (*NativeIndexQuery)(uint32_t, + const v8::PropertyCallbackInfo &); #endif -} // end of namespace imp +} // end of namespace imp -#endif // NAN_CALLBACKS_12_INL_H_ +#endif // NAN_CALLBACKS_12_INL_H_ diff --git a/node_modules/nan/nan_callbacks_pre_12_inl.h b/node_modules/nan/nan_callbacks_pre_12_inl.h index c9ba499..78424c1 100644 --- a/node_modules/nan/nan_callbacks_pre_12_inl.h +++ b/node_modules/nan/nan_callbacks_pre_12_inl.h @@ -10,21 +10,20 @@ #define NAN_CALLBACKS_PRE_12_INL_H_ namespace imp { -template class ReturnValueImp; -} // end of namespace imp +template class ReturnValueImp; +} // end of namespace imp -template -class ReturnValue { +template class ReturnValue { v8::Isolate *isolate_; v8::Persistent *value_; friend class imp::ReturnValueImp; - public: +public: template - explicit inline ReturnValue(v8::Isolate *isolate, v8::Persistent *p) : - isolate_(isolate), value_(p) {} + explicit inline ReturnValue(v8::Isolate *isolate, v8::Persistent *p) + : isolate_(isolate), value_(p) {} template - explicit inline ReturnValue(const ReturnValue& that) + explicit inline ReturnValue(const ReturnValue &that) : isolate_(that.isolate_), value_(that.value_) { TYPE_CHECK(T, S); } @@ -102,30 +101,25 @@ class ReturnValue { } // Convenience getter for isolate - inline v8::Isolate *GetIsolate() const { - return isolate_; - } + inline v8::Isolate *GetIsolate() const { return isolate_; } // Pointer setter: Uncompilable to prevent inadvertent misuse. - template - inline void Set(S *whatever) { TYPE_CHECK(S*, v8::Primitive); } + template inline void Set(S *whatever) { + TYPE_CHECK(S *, v8::Primitive); + } }; -template -class FunctionCallbackInfo { +template class FunctionCallbackInfo { const v8::Arguments &args_; v8::Local data_; ReturnValue return_value_; v8::Persistent retval_; - public: - explicit inline FunctionCallbackInfo( - const v8::Arguments &args - , v8::Local data) : - args_(args) - , data_(data) - , return_value_(args.GetIsolate(), &retval_) - , retval_(v8::Persistent::New(v8::Undefined())) {} +public: + explicit inline FunctionCallbackInfo(const v8::Arguments &args, + v8::Local data) + : args_(args), data_(data), return_value_(args.GetIsolate(), &retval_), + retval_(v8::Persistent::New(v8::Undefined())) {} inline ~FunctionCallbackInfo() { retval_.Dispose(); @@ -145,8 +139,7 @@ class FunctionCallbackInfo { inline v8::Local This() const { return args_.This(); } inline v8::Isolate *GetIsolate() const { return args_.GetIsolate(); } - - protected: +protected: static const int kHolderIndex = 0; static const int kIsolateIndex = 1; static const int kReturnValueDefaultValueIndex = 2; @@ -156,28 +149,25 @@ class FunctionCallbackInfo { static const int kContextSaveIndex = 6; static const int kArgsLength = 7; - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(FunctionCallbackInfo) }; -template -class PropertyCallbackInfoBase { +template class PropertyCallbackInfoBase { const v8::AccessorInfo &info_; const v8::Local data_; - public: - explicit inline PropertyCallbackInfoBase( - const v8::AccessorInfo &info - , const v8::Local data) : - info_(info) - , data_(data) {} +public: + explicit inline PropertyCallbackInfoBase(const v8::AccessorInfo &info, + const v8::Local data) + : info_(info), data_(data) {} - inline v8::Isolate* GetIsolate() const { return info_.GetIsolate(); } + inline v8::Isolate *GetIsolate() const { return info_.GetIsolate(); } inline v8::Local Data() const { return data_; } inline v8::Local This() const { return info_.This(); } inline v8::Local Holder() const { return info_.Holder(); } - protected: +protected: static const int kHolderIndex = 0; static const int kIsolateIndex = 1; static const int kReturnValueDefaultValueIndex = 2; @@ -186,22 +176,21 @@ class PropertyCallbackInfoBase { static const int kThisIndex = 5; static const int kArgsLength = 6; - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(PropertyCallbackInfoBase) }; -template +template class PropertyCallbackInfo : public PropertyCallbackInfoBase { ReturnValue return_value_; v8::Persistent retval_; - public: - explicit inline PropertyCallbackInfo( - const v8::AccessorInfo &info - , const v8::Local data) : - PropertyCallbackInfoBase(info, data) - , return_value_(info.GetIsolate(), &retval_) - , retval_(v8::Persistent::New(v8::Undefined())) {} +public: + explicit inline PropertyCallbackInfo(const v8::AccessorInfo &info, + const v8::Local data) + : PropertyCallbackInfoBase(info, data), + return_value_(info.GetIsolate(), &retval_), + retval_(v8::Persistent::New(v8::Undefined())) {} inline ~PropertyCallbackInfo() { retval_.Dispose(); @@ -211,43 +200,39 @@ class PropertyCallbackInfo : public PropertyCallbackInfoBase { inline ReturnValue GetReturnValue() const { return return_value_; } }; -template<> -class PropertyCallbackInfo : - public PropertyCallbackInfoBase { +template <> +class PropertyCallbackInfo + : public PropertyCallbackInfoBase { ReturnValue return_value_; v8::Persistent retval_; - public: - explicit inline PropertyCallbackInfo( - const v8::AccessorInfo &info - , const v8::Local data) : - PropertyCallbackInfoBase(info, data) - , return_value_(info.GetIsolate(), &retval_) - , retval_(v8::Persistent::New(v8::Local())) {} +public: + explicit inline PropertyCallbackInfo(const v8::AccessorInfo &info, + const v8::Local data) + : PropertyCallbackInfoBase(info, data), + return_value_(info.GetIsolate(), &retval_), + retval_(v8::Persistent::New(v8::Local())) {} inline ~PropertyCallbackInfo() { retval_.Dispose(); retval_.Clear(); } - inline ReturnValue GetReturnValue() const { - return return_value_; - } + inline ReturnValue GetReturnValue() const { return return_value_; } }; -template<> -class PropertyCallbackInfo : - public PropertyCallbackInfoBase { +template <> +class PropertyCallbackInfo + : public PropertyCallbackInfoBase { ReturnValue return_value_; v8::Persistent retval_; - public: - explicit inline PropertyCallbackInfo( - const v8::AccessorInfo &info - , const v8::Local data) : - PropertyCallbackInfoBase(info, data) - , return_value_(info.GetIsolate(), &retval_) - , retval_(v8::Persistent::New(v8::Local())) {} +public: + explicit inline PropertyCallbackInfo(const v8::AccessorInfo &info, + const v8::Local data) + : PropertyCallbackInfoBase(info, data), + return_value_(info.GetIsolate(), &retval_), + retval_(v8::Persistent::New(v8::Local())) {} inline ~PropertyCallbackInfo() { retval_.Dispose(); @@ -259,19 +244,18 @@ class PropertyCallbackInfo : } }; -template<> -class PropertyCallbackInfo : - public PropertyCallbackInfoBase { +template <> +class PropertyCallbackInfo + : public PropertyCallbackInfoBase { ReturnValue return_value_; v8::Persistent retval_; - public: - explicit inline PropertyCallbackInfo( - const v8::AccessorInfo &info - , const v8::Local data) : - PropertyCallbackInfoBase(info, data) - , return_value_(info.GetIsolate(), &retval_) - , retval_(v8::Persistent::New(v8::Local())) {} +public: + explicit inline PropertyCallbackInfo(const v8::AccessorInfo &info, + const v8::Local data) + : PropertyCallbackInfoBase(info, data), + return_value_(info.GetIsolate(), &retval_), + retval_(v8::Persistent::New(v8::Local())) {} inline ~PropertyCallbackInfo() { retval_.Dispose(); @@ -284,237 +268,228 @@ class PropertyCallbackInfo : }; namespace imp { -template -class ReturnValueImp : public ReturnValue { - public: - explicit ReturnValueImp(ReturnValue that) : - ReturnValue(that) {} - inline v8::Handle Value() { - return *ReturnValue::value_; - } +template class ReturnValueImp : public ReturnValue { +public: + explicit ReturnValueImp(ReturnValue that) : ReturnValue(that) {} + inline v8::Handle Value() { return *ReturnValue::value_; } }; -static -v8::Handle FunctionCallbackWrapper(const v8::Arguments &args) { +static v8::Handle +FunctionCallbackWrapper(const v8::Arguments &args) { v8::Local obj = args.Data().As(); - FunctionCallback callback = reinterpret_cast( - reinterpret_cast( + FunctionCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kFunctionIndex).As()->Value())); - FunctionCallbackInfo - cbinfo(args, obj->GetInternalField(kDataIndex)); + FunctionCallbackInfo cbinfo(args, + obj->GetInternalField(kDataIndex)); callback(cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } typedef v8::Handle (*NativeFunction)(const v8::Arguments &); -static -v8::Handle GetterCallbackWrapper( - v8::Local property, const v8::AccessorInfo &info) { +static v8::Handle +GetterCallbackWrapper(v8::Local property, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); - GetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); + GetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kGetterIndex).As()->Value())); callback(property, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativeGetter) - (v8::Local, const v8::AccessorInfo &); +typedef v8::Handle (*NativeGetter)(v8::Local, + const v8::AccessorInfo &); -static -void SetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::AccessorInfo &info) { +static void SetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); - SetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo(info, obj->GetInternalField(kDataIndex)); + SetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kSetterIndex).As()->Value())); callback(property, value, cbinfo); } -typedef void (*NativeSetter) - (v8::Local, v8::Local, const v8::AccessorInfo &); +typedef void (*NativeSetter)(v8::Local, v8::Local, + const v8::AccessorInfo &); -static -v8::Handle PropertyGetterCallbackWrapper( - v8::Local property, const v8::AccessorInfo &info) { +static v8::Handle +PropertyGetterCallbackWrapper(v8::Local property, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); PropertyGetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyGetterIndex) - .As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyGetterIndex) + .As() + ->Value())); callback(property, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativePropertyGetter) - (v8::Local, const v8::AccessorInfo &); +typedef v8::Handle (*NativePropertyGetter)(v8::Local, + const v8::AccessorInfo &); -static -v8::Handle PropertySetterCallbackWrapper( - v8::Local property - , v8::Local value - , const v8::AccessorInfo &info) { +static v8::Handle +PropertySetterCallbackWrapper(v8::Local property, + v8::Local value, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); PropertySetterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertySetterIndex) - .As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertySetterIndex) + .As() + ->Value())); callback(property, value, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativePropertySetter) - (v8::Local, v8::Local, const v8::AccessorInfo &); +typedef v8::Handle (*NativePropertySetter)(v8::Local, + v8::Local, + const v8::AccessorInfo &); -static -v8::Handle PropertyEnumeratorCallbackWrapper( - const v8::AccessorInfo &info) { +static v8::Handle +PropertyEnumeratorCallbackWrapper(const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); PropertyEnumeratorCallback callback = reinterpret_cast(reinterpret_cast( obj->GetInternalField(kPropertyEnumeratorIndex) - .As()->Value())); + .As() + ->Value())); callback(cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativePropertyEnumerator) - (const v8::AccessorInfo &); +typedef v8::Handle (*NativePropertyEnumerator)( + const v8::AccessorInfo &); -static -v8::Handle PropertyDeleterCallbackWrapper( - v8::Local property - , const v8::AccessorInfo &info) { +static v8::Handle +PropertyDeleterCallbackWrapper(v8::Local property, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); PropertyDeleterCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyDeleterIndex) - .As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyDeleterIndex) + .As() + ->Value())); callback(property, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (NativePropertyDeleter) - (v8::Local, const v8::AccessorInfo &); +typedef v8::Handle(NativePropertyDeleter)( + v8::Local, const v8::AccessorInfo &); -static -v8::Handle PropertyQueryCallbackWrapper( - v8::Local property, const v8::AccessorInfo &info) { +static v8::Handle +PropertyQueryCallbackWrapper(v8::Local property, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); PropertyQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kPropertyQueryIndex) - .As()->Value())); + reinterpret_cast(obj->GetInternalField(kPropertyQueryIndex) + .As() + ->Value())); callback(property, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativePropertyQuery) - (v8::Local, const v8::AccessorInfo &); +typedef v8::Handle (*NativePropertyQuery)( + v8::Local, const v8::AccessorInfo &); -static -v8::Handle IndexGetterCallbackWrapper( - uint32_t index, const v8::AccessorInfo &info) { +static v8::Handle +IndexGetterCallbackWrapper(uint32_t index, const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); - IndexGetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); + IndexGetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyGetterIndex) - .As()->Value())); + .As() + ->Value())); callback(index, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativeIndexGetter) - (uint32_t, const v8::AccessorInfo &); +typedef v8::Handle (*NativeIndexGetter)(uint32_t, + const v8::AccessorInfo &); -static -v8::Handle IndexSetterCallbackWrapper( - uint32_t index - , v8::Local value - , const v8::AccessorInfo &info) { +static v8::Handle +IndexSetterCallbackWrapper(uint32_t index, v8::Local value, + const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); - IndexSetterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); + IndexSetterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertySetterIndex) - .As()->Value())); + .As() + ->Value())); callback(index, value, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativeIndexSetter) - (uint32_t, v8::Local, const v8::AccessorInfo &); +typedef v8::Handle (*NativeIndexSetter)(uint32_t, + v8::Local, + const v8::AccessorInfo &); -static -v8::Handle IndexEnumeratorCallbackWrapper( - const v8::AccessorInfo &info) { +static v8::Handle +IndexEnumeratorCallbackWrapper(const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); - IndexEnumeratorCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); + IndexEnumeratorCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyEnumeratorIndex) - .As()->Value())); + .As() + ->Value())); callback(cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativeIndexEnumerator) - (const v8::AccessorInfo &); +typedef v8::Handle (*NativeIndexEnumerator)( + const v8::AccessorInfo &); -static -v8::Handle IndexDeleterCallbackWrapper( - uint32_t index, const v8::AccessorInfo &info) { +static v8::Handle +IndexDeleterCallbackWrapper(uint32_t index, const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); - IndexDeleterCallback callback = reinterpret_cast( - reinterpret_cast( + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); + IndexDeleterCallback callback = + reinterpret_cast(reinterpret_cast( obj->GetInternalField(kIndexPropertyDeleterIndex) - .As()->Value())); + .As() + ->Value())); callback(index, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativeIndexDeleter) - (uint32_t, const v8::AccessorInfo &); +typedef v8::Handle (*NativeIndexDeleter)(uint32_t, + const v8::AccessorInfo &); -static -v8::Handle IndexQueryCallbackWrapper( - uint32_t index, const v8::AccessorInfo &info) { +static v8::Handle +IndexQueryCallbackWrapper(uint32_t index, const v8::AccessorInfo &info) { v8::Local obj = info.Data().As(); - PropertyCallbackInfo - cbinfo(info, obj->GetInternalField(kDataIndex)); + PropertyCallbackInfo cbinfo(info, + obj->GetInternalField(kDataIndex)); IndexQueryCallback callback = reinterpret_cast( - reinterpret_cast( - obj->GetInternalField(kIndexPropertyQueryIndex) - .As()->Value())); + reinterpret_cast(obj->GetInternalField(kIndexPropertyQueryIndex) + .As() + ->Value())); callback(index, cbinfo); return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (*NativeIndexQuery) - (uint32_t, const v8::AccessorInfo &); -} // end of namespace imp +typedef v8::Handle (*NativeIndexQuery)(uint32_t, + const v8::AccessorInfo &); +} // end of namespace imp -#endif // NAN_CALLBACKS_PRE_12_INL_H_ +#endif // NAN_CALLBACKS_PRE_12_INL_H_ diff --git a/node_modules/nan/nan_converters.h b/node_modules/nan/nan_converters.h index c0b3272..7a22e5a 100644 --- a/node_modules/nan/nan_converters.h +++ b/node_modules/nan/nan_converters.h @@ -10,26 +10,27 @@ #define NAN_CONVERTERS_H_ namespace imp { -template struct ToFactoryBase { +template struct ToFactoryBase { typedef MaybeLocal return_t; }; -template struct ValueFactoryBase { typedef Maybe return_t; }; +template struct ValueFactoryBase { + typedef Maybe return_t; +}; -template struct ToFactory; +template struct ToFactory; -template<> -struct ToFactory : ToFactoryBase { +template <> struct ToFactory : ToFactoryBase { static inline return_t convert(v8::Local val) { - if (val.IsEmpty() || !val->IsFunction()) return MaybeLocal(); + if (val.IsEmpty() || !val->IsFunction()) + return MaybeLocal(); return MaybeLocal(val.As()); } }; #define X(TYPE) \ - template<> \ - struct ToFactory : ToFactoryBase { \ - static inline return_t convert(v8::Local val); \ - }; + template <> struct ToFactory : ToFactoryBase { \ + static inline return_t convert(v8::Local val); \ + }; X(Boolean) X(Number) @@ -42,10 +43,9 @@ X(Int32) #undef X #define X(TYPE) \ - template<> \ - struct ToFactory : ValueFactoryBase { \ - static inline return_t convert(v8::Local val); \ - }; + template <> struct ToFactory : ValueFactoryBase { \ + static inline return_t convert(v8::Local val); \ + }; X(bool) X(double) @@ -54,19 +54,20 @@ X(uint32_t) X(int32_t) #undef X -} // end of namespace imp +} // end of namespace imp -template -inline -typename imp::ToFactory::return_t To(v8::Local val) { +template +inline typename imp::ToFactory::return_t To(v8::Local val) { return imp::ToFactory::convert(val); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -# include "nan_converters_43_inl.h" +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +#include "nan_converters_43_inl.h" #else -# include "nan_converters_pre_43_inl.h" +#include "nan_converters_pre_43_inl.h" #endif -#endif // NAN_CONVERTERS_H_ +#endif // NAN_CONVERTERS_H_ diff --git a/node_modules/nan/nan_converters_43_inl.h b/node_modules/nan/nan_converters_43_inl.h index 41b72de..3b41599 100644 --- a/node_modules/nan/nan_converters_43_inl.h +++ b/node_modules/nan/nan_converters_43_inl.h @@ -10,14 +10,13 @@ #define NAN_CONVERTERS_43_INL_H_ #define X(TYPE) \ -imp::ToFactory::return_t \ -imp::ToFactory::convert(v8::Local val) { \ - v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ - v8::EscapableHandleScope scope(isolate); \ - return scope.Escape( \ - val->To ## TYPE(isolate->GetCurrentContext()) \ - .FromMaybe(v8::Local())); \ -} + imp::ToFactory::return_t imp::ToFactory::convert( \ + v8::Local val) { \ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ + v8::EscapableHandleScope scope(isolate); \ + return scope.Escape(val->To##TYPE(isolate->GetCurrentContext()) \ + .FromMaybe(v8::Local())); \ + } X(Number) X(String) @@ -29,23 +28,23 @@ X(Int32) #if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0) X(Boolean) #else -imp::ToFactory::return_t \ -imp::ToFactory::convert(v8::Local val) { \ - v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ - v8::EscapableHandleScope scope(isolate); \ - return scope.Escape(val->ToBoolean(isolate)); \ +imp::ToFactory::return_t +imp::ToFactory::convert(v8::Local val) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::EscapableHandleScope scope(isolate); + return scope.Escape(val->ToBoolean(isolate)); } #endif #undef X #define X(TYPE, NAME) \ -imp::ToFactory::return_t \ -imp::ToFactory::convert(v8::Local val) { \ - v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ - v8::HandleScope scope(isolate); \ - return val->NAME ## Value(isolate->GetCurrentContext()); \ -} + imp::ToFactory::return_t imp::ToFactory::convert( \ + v8::Local val) { \ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ + v8::HandleScope scope(isolate); \ + return val->NAME##Value(isolate->GetCurrentContext()); \ + } X(double, Number) X(int64_t, Integer) @@ -55,14 +54,14 @@ X(int32_t, Int32) #if V8_MAJOR_VERSION < 7 || (V8_MAJOR_VERSION == 7 && V8_MINOR_VERSION == 0) X(bool, Boolean) #else -imp::ToFactory::return_t \ -imp::ToFactory::convert(v8::Local val) { \ - v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ - v8::HandleScope scope(isolate); \ - return Just(val->BooleanValue(isolate)); \ +imp::ToFactory::return_t +imp::ToFactory::convert(v8::Local val) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::HandleScope scope(isolate); + return Just(val->BooleanValue(isolate)); } #endif #undef X -#endif // NAN_CONVERTERS_43_INL_H_ +#endif // NAN_CONVERTERS_43_INL_H_ diff --git a/node_modules/nan/nan_converters_pre_43_inl.h b/node_modules/nan/nan_converters_pre_43_inl.h index ae0518a..3a59840 100644 --- a/node_modules/nan/nan_converters_pre_43_inl.h +++ b/node_modules/nan/nan_converters_pre_43_inl.h @@ -10,10 +10,10 @@ #define NAN_CONVERTERS_PRE_43_INL_H_ #define X(TYPE) \ -imp::ToFactory::return_t \ -imp::ToFactory::convert(v8::Local val) { \ - return val->To ## TYPE(); \ -} + imp::ToFactory::return_t imp::ToFactory::convert( \ + v8::Local val) { \ + return val->To##TYPE(); \ + } X(Boolean) X(Number) @@ -26,10 +26,10 @@ X(Int32) #undef X #define X(TYPE, NAME) \ -imp::ToFactory::return_t \ -imp::ToFactory::convert(v8::Local val) { \ - return Just(val->NAME ## Value()); \ -} + imp::ToFactory::return_t imp::ToFactory::convert( \ + v8::Local val) { \ + return Just(val->NAME##Value()); \ + } X(bool, Boolean) X(double, Number) @@ -39,4 +39,4 @@ X(int32_t, Int32) #undef X -#endif // NAN_CONVERTERS_PRE_43_INL_H_ +#endif // NAN_CONVERTERS_PRE_43_INL_H_ diff --git a/node_modules/nan/nan_define_own_property_helper.h b/node_modules/nan/nan_define_own_property_helper.h index d710ef2..45fa344 100644 --- a/node_modules/nan/nan_define_own_property_helper.h +++ b/node_modules/nan/nan_define_own_property_helper.h @@ -11,19 +11,18 @@ namespace imp { -inline Maybe DefineOwnPropertyHelper( - v8::PropertyAttribute current - , v8::Handle obj - , v8::Handle key - , v8::Handle value - , v8::PropertyAttribute attribs = v8::None) { - return !(current & v8::DontDelete) || // configurable OR - (!(current & v8::ReadOnly) && // writable AND - !((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO +inline Maybe +DefineOwnPropertyHelper(v8::PropertyAttribute current, + v8::Handle obj, v8::Handle key, + v8::Handle value, + v8::PropertyAttribute attribs = v8::None) { + return !(current & v8::DontDelete) || // configurable OR + (!(current & v8::ReadOnly) && // writable AND + !((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO ? Just(obj->ForceSet(key, value, attribs)) : Nothing(); } -} // end of namespace imp +} // end of namespace imp -#endif // NAN_DEFINE_OWN_PROPERTY_HELPER_H_ +#endif // NAN_DEFINE_OWN_PROPERTY_HELPER_H_ diff --git a/node_modules/nan/nan_implementation_12_inl.h b/node_modules/nan/nan_implementation_12_inl.h index 255293a..ba34f11 100644 --- a/node_modules/nan/nan_implementation_12_inl.h +++ b/node_modules/nan/nan_implementation_12_inl.h @@ -16,20 +16,17 @@ namespace imp { //=== Array ==================================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::Array::New(v8::Isolate::GetCurrent()); } -Factory::return_t -Factory::New(int length) { +Factory::return_t Factory::New(int length) { return v8::Array::New(v8::Isolate::GetCurrent(), length); } //=== Boolean ================================================================== -Factory::return_t -Factory::New(bool value) { +Factory::return_t Factory::New(bool value) { return v8::Boolean::New(v8::Isolate::GetCurrent(), value); } @@ -38,8 +35,8 @@ Factory::New(bool value) { Factory::return_t Factory::New(bool value) { #if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) - return v8::BooleanObject::New( - v8::Isolate::GetCurrent(), value).As(); + return v8::BooleanObject::New(v8::Isolate::GetCurrent(), value) + .As(); #else return v8::BooleanObject::New(value).As(); #endif @@ -48,42 +45,42 @@ Factory::New(bool value) { //=== Context ================================================================== Factory::return_t -Factory::New( v8::ExtensionConfiguration* extensions - , v8::Local tmpl - , v8::Local obj) { +Factory::New(v8::ExtensionConfiguration *extensions, + v8::Local tmpl, + v8::Local obj) { return v8::Context::New(v8::Isolate::GetCurrent(), extensions, tmpl, obj); } //=== Date ===================================================================== -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -Factory::return_t -Factory::New(double value) { +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +Factory::return_t Factory::New(double value) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(v8::Date::New(isolate->GetCurrentContext(), value) - .FromMaybe(v8::Local()).As()); + .FromMaybe(v8::Local()) + .As()); } #else -Factory::return_t -Factory::New(double value) { +Factory::return_t Factory::New(double value) { return v8::Date::New(v8::Isolate::GetCurrent(), value).As(); } #endif //=== External ================================================================= -Factory::return_t -Factory::New(void * value) { +Factory::return_t Factory::New(void *value) { return v8::External::New(v8::Isolate::GetCurrent(), value); } //=== Function ================================================================= Factory::return_t -Factory::New( FunctionCallback callback - , v8::Local data) { +Factory::New(FunctionCallback callback, + v8::Local data) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); v8::Local tpl = v8::ObjectTemplate::New(isolate); @@ -91,8 +88,8 @@ Factory::New( FunctionCallback callback v8::Local obj = NewInstance(tpl).ToLocalChecked(); obj->SetInternalField( - imp::kFunctionIndex - , v8::External::New(isolate, reinterpret_cast(callback))); + imp::kFunctionIndex, + v8::External::New(isolate, reinterpret_cast(callback))); v8::Local val = v8::Local::New(isolate, data); @@ -104,7 +101,7 @@ Factory::New( FunctionCallback callback v8::Local context = isolate->GetCurrentContext(); v8::Local function = v8::Function::New(context, imp::FunctionCallbackWrapper, obj) - .ToLocalChecked(); + .ToLocalChecked(); #else v8::Local function = v8::Function::New(isolate, imp::FunctionCallbackWrapper, obj); @@ -116,9 +113,9 @@ Factory::New( FunctionCallback callback //=== Function Template ======================================================== Factory::return_t -Factory::New( FunctionCallback callback - , v8::Local data - , v8::Local signature) { +Factory::New(FunctionCallback callback, + v8::Local data, + v8::Local signature) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); if (callback) { v8::EscapableHandleScope scope(isolate); @@ -127,18 +124,16 @@ Factory::New( FunctionCallback callback v8::Local obj = NewInstance(tpl).ToLocalChecked(); obj->SetInternalField( - imp::kFunctionIndex - , v8::External::New(isolate, reinterpret_cast(callback))); + imp::kFunctionIndex, + v8::External::New(isolate, reinterpret_cast(callback))); v8::Local val = v8::Local::New(isolate, data); if (!val.IsEmpty()) { obj->SetInternalField(imp::kDataIndex, val); } - return scope.Escape(v8::FunctionTemplate::New( isolate - , imp::FunctionCallbackWrapper - , obj - , signature)); + return scope.Escape(v8::FunctionTemplate::New( + isolate, imp::FunctionCallbackWrapper, obj, signature)); } else { return v8::FunctionTemplate::New(isolate, 0, data, signature); } @@ -146,8 +141,7 @@ Factory::New( FunctionCallback callback //=== Number =================================================================== -Factory::return_t -Factory::New(double value) { +Factory::return_t Factory::New(double value) { return v8::Number::New(v8::Isolate::GetCurrent(), value); } @@ -155,58 +149,53 @@ Factory::New(double value) { Factory::return_t Factory::New(double value) { - return v8::NumberObject::New( v8::Isolate::GetCurrent() - , value).As(); + return v8::NumberObject::New(v8::Isolate::GetCurrent(), value) + .As(); } //=== Integer, Int32 and Uint32 ================================================ template -typename IntegerFactory::return_t -IntegerFactory::New(int32_t value) { +typename IntegerFactory::return_t IntegerFactory::New(int32_t value) { return To(T::New(v8::Isolate::GetCurrent(), value)); } template -typename IntegerFactory::return_t -IntegerFactory::New(uint32_t value) { +typename IntegerFactory::return_t IntegerFactory::New(uint32_t value) { return To(T::NewFromUnsigned(v8::Isolate::GetCurrent(), value)); } -Factory::return_t -Factory::New(int32_t value) { +Factory::return_t Factory::New(int32_t value) { return To( v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value)); } -Factory::return_t -Factory::New(uint32_t value) { +Factory::return_t Factory::New(uint32_t value) { return To( v8::Uint32::NewFromUnsigned(v8::Isolate::GetCurrent(), value)); } //=== Object =================================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::Object::New(v8::Isolate::GetCurrent()); } //=== Object Template ========================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::ObjectTemplate::New(v8::Isolate::GetCurrent()); } //=== RegExp =================================================================== -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) Factory::return_t -Factory::New( - v8::Local pattern - , v8::RegExp::Flags flags) { +Factory::New(v8::Local pattern, + v8::RegExp::Flags flags) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape( @@ -215,19 +204,20 @@ Factory::New( } #else Factory::return_t -Factory::New( - v8::Local pattern - , v8::RegExp::Flags flags) { +Factory::New(v8::Local pattern, + v8::RegExp::Flags flags) { return v8::RegExp::New(pattern, flags); } #endif //=== Script =================================================================== -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) Factory::return_t -Factory::New( v8::Local source) { +Factory::New(v8::Local source) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); v8::ScriptCompiler::Source src(source); @@ -237,8 +227,8 @@ Factory::New( v8::Local source) { } Factory::return_t -Factory::New( v8::Local source - , v8::ScriptOrigin const& origin) { +Factory::New(v8::Local source, + v8::ScriptOrigin const &origin) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); v8::ScriptCompiler::Source src(source, origin); @@ -248,14 +238,14 @@ Factory::New( v8::Local source } #else Factory::return_t -Factory::New( v8::Local source) { +Factory::New(v8::Local source) { v8::ScriptCompiler::Source src(source); return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src); } Factory::return_t -Factory::New( v8::Local source - , v8::ScriptOrigin const& origin) { +Factory::New(v8::Local source, + v8::ScriptOrigin const &origin) { v8::ScriptCompiler::Source src(source, origin); return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src); } @@ -270,70 +260,71 @@ Factory::New(Factory::FTH receiver) { //=== String =================================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::String::Empty(v8::Isolate::GetCurrent()); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -Factory::return_t -Factory::New(const char * value, int length) { - return v8::String::NewFromUtf8( - v8::Isolate::GetCurrent(), value, v8::NewStringType::kNormal, length); +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +Factory::return_t Factory::New(const char *value, + int length) { + return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value, + v8::NewStringType::kNormal, length); } Factory::return_t -Factory::New(std::string const& value) { +Factory::New(std::string const &value) { assert(value.size() <= INT_MAX && "string too long"); - return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), - value.data(), v8::NewStringType::kNormal, static_cast(value.size())); + return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value.data(), + v8::NewStringType::kNormal, + static_cast(value.size())); } -Factory::return_t -Factory::New(const uint16_t * value, int length) { +Factory::return_t Factory::New(const uint16_t *value, + int length) { return v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), value, - v8::NewStringType::kNormal, length); + v8::NewStringType::kNormal, length); } Factory::return_t -Factory::New(v8::String::ExternalStringResource * value) { +Factory::New(v8::String::ExternalStringResource *value) { return v8::String::NewExternalTwoByte(v8::Isolate::GetCurrent(), value); } Factory::return_t -Factory::New(ExternalOneByteStringResource * value) { +Factory::New(ExternalOneByteStringResource *value) { return v8::String::NewExternalOneByte(v8::Isolate::GetCurrent(), value); } #else -Factory::return_t -Factory::New(const char * value, int length) { +Factory::return_t Factory::New(const char *value, + int length) { return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value, v8::String::kNormalString, length); } -Factory::return_t -Factory::New( - std::string const& value) /* NOLINT(build/include_what_you_use) */ { +Factory::return_t Factory::New( + std::string const &value) /* NOLINT(build/include_what_you_use) */ { assert(value.size() <= INT_MAX && "string too long"); return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value.data(), v8::String::kNormalString, static_cast(value.size())); } -Factory::return_t -Factory::New(const uint16_t * value, int length) { +Factory::return_t Factory::New(const uint16_t *value, + int length) { return v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), value, v8::String::kNormalString, length); } Factory::return_t -Factory::New(v8::String::ExternalStringResource * value) { +Factory::New(v8::String::ExternalStringResource *value) { return v8::String::NewExternal(v8::Isolate::GetCurrent(), value); } Factory::return_t -Factory::New(ExternalOneByteStringResource * value) { +Factory::New(ExternalOneByteStringResource *value) { return v8::String::NewExternal(v8::Isolate::GetCurrent(), value); } #endif @@ -370,21 +361,23 @@ Factory::New(v8::Local value) { //=== Unbound Script =========================================================== -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) Factory::return_t Factory::New(v8::Local source) { v8::ScriptCompiler::Source src(source); - return v8::ScriptCompiler::CompileUnboundScript( - v8::Isolate::GetCurrent(), &src); + return v8::ScriptCompiler::CompileUnboundScript(v8::Isolate::GetCurrent(), + &src); } Factory::return_t -Factory::New( v8::Local source - , v8::ScriptOrigin const& origin) { +Factory::New(v8::Local source, + v8::ScriptOrigin const &origin) { v8::ScriptCompiler::Source src(source, origin); - return v8::ScriptCompiler::CompileUnboundScript( - v8::Isolate::GetCurrent(), &src); + return v8::ScriptCompiler::CompileUnboundScript(v8::Isolate::GetCurrent(), + &src); } #else Factory::return_t @@ -394,37 +387,35 @@ Factory::New(v8::Local source) { } Factory::return_t -Factory::New( v8::Local source - , v8::ScriptOrigin const& origin) { +Factory::New(v8::Local source, + v8::ScriptOrigin const &origin) { v8::ScriptCompiler::Source src(source, origin); return v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src); } #endif -} // end of namespace imp +} // end of namespace imp //=== Presistents and Handles ================================================== #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION -template -inline v8::Local New(v8::Handle h) { +template inline v8::Local New(v8::Handle h) { return v8::Local::New(v8::Isolate::GetCurrent(), h); } #endif template -inline v8::Local New(v8::Persistent const& p) { +inline v8::Local New(v8::Persistent const &p) { return v8::Local::New(v8::Isolate::GetCurrent(), p); } template -inline v8::Local New(Persistent const& p) { +inline v8::Local New(Persistent const &p) { return v8::Local::New(v8::Isolate::GetCurrent(), p); } -template -inline v8::Local New(Global const& p) { +template inline v8::Local New(Global const &p) { return v8::Local::New(v8::Isolate::GetCurrent(), p); } -#endif // NAN_IMPLEMENTATION_12_INL_H_ +#endif // NAN_IMPLEMENTATION_12_INL_H_ diff --git a/node_modules/nan/nan_implementation_pre_12_inl.h b/node_modules/nan/nan_implementation_pre_12_inl.h index 1472421..df88e78 100644 --- a/node_modules/nan/nan_implementation_pre_12_inl.h +++ b/node_modules/nan/nan_implementation_pre_12_inl.h @@ -17,20 +17,17 @@ namespace imp { //=== Array ==================================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::Array::New(); } -Factory::return_t -Factory::New(int length) { +Factory::return_t Factory::New(int length) { return v8::Array::New(length); } //=== Boolean ================================================================== -Factory::return_t -Factory::New(bool value) { +Factory::return_t Factory::New(bool value) { return v8::Boolean::New(value)->ToBoolean(); } @@ -44,9 +41,9 @@ Factory::New(bool value) { //=== Context ================================================================== Factory::return_t -Factory::New( v8::ExtensionConfiguration* extensions - , v8::Local tmpl - , v8::Local obj) { +Factory::New(v8::ExtensionConfiguration *extensions, + v8::Local tmpl, + v8::Local obj) { v8::Persistent ctx = v8::Context::New(extensions, tmpl, obj); v8::Local lctx = v8::Local::New(ctx); ctx.Dispose(); @@ -55,23 +52,21 @@ Factory::New( v8::ExtensionConfiguration* extensions //=== Date ===================================================================== -Factory::return_t -Factory::New(double value) { +Factory::return_t Factory::New(double value) { return v8::Date::New(value).As(); } //=== External ================================================================= -Factory::return_t -Factory::New(void * value) { +Factory::return_t Factory::New(void *value) { return v8::External::New(value); } //=== Function ================================================================= Factory::return_t -Factory::New( FunctionCallback callback - , v8::Local data) { +Factory::New(FunctionCallback callback, + v8::Local data) { v8::HandleScope scope; return scope.Close(Factory::New( @@ -79,13 +74,12 @@ Factory::New( FunctionCallback callback ->GetFunction()); } - //=== FunctionTemplate ========================================================= Factory::return_t -Factory::New( FunctionCallback callback - , v8::Local data - , v8::Local signature) { +Factory::New(FunctionCallback callback, + v8::Local data, + v8::Local signature) { if (callback) { v8::HandleScope scope; @@ -94,8 +88,8 @@ Factory::New( FunctionCallback callback v8::Local obj = tpl->NewInstance(); obj->SetInternalField( - imp::kFunctionIndex - , v8::External::New(reinterpret_cast(callback))); + imp::kFunctionIndex, + v8::External::New(reinterpret_cast(callback))); v8::Local val = v8::Local::New(data); @@ -105,10 +99,8 @@ Factory::New( FunctionCallback callback // Note(agnat): Emulate length argument here. Unfortunately, I couldn't find // a way. Have at it though... - return scope.Close( - v8::FunctionTemplate::New(imp::FunctionCallbackWrapper - , obj - , signature)); + return scope.Close(v8::FunctionTemplate::New(imp::FunctionCallbackWrapper, + obj, signature)); } else { return v8::FunctionTemplate::New(0, data, signature); } @@ -116,8 +108,7 @@ Factory::New( FunctionCallback callback //=== Number =================================================================== -Factory::return_t -Factory::New(double value) { +Factory::return_t Factory::New(double value) { return v8::Number::New(value); } @@ -131,61 +122,53 @@ Factory::New(double value) { //=== Integer, Int32 and Uint32 ================================================ template -typename IntegerFactory::return_t -IntegerFactory::New(int32_t value) { +typename IntegerFactory::return_t IntegerFactory::New(int32_t value) { return To(T::New(value)); } template -typename IntegerFactory::return_t -IntegerFactory::New(uint32_t value) { +typename IntegerFactory::return_t IntegerFactory::New(uint32_t value) { return To(T::NewFromUnsigned(value)); } -Factory::return_t -Factory::New(int32_t value) { +Factory::return_t Factory::New(int32_t value) { return To(v8::Uint32::NewFromUnsigned(value)); } -Factory::return_t -Factory::New(uint32_t value) { +Factory::return_t Factory::New(uint32_t value) { return To(v8::Uint32::NewFromUnsigned(value)); } - //=== Object =================================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::Object::New(); } //=== Object Template ========================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::ObjectTemplate::New(); } //=== RegExp =================================================================== Factory::return_t -Factory::New( - v8::Local pattern - , v8::RegExp::Flags flags) { +Factory::New(v8::Local pattern, + v8::RegExp::Flags flags) { return v8::RegExp::New(pattern, flags); } //=== Script =================================================================== Factory::return_t -Factory::New( v8::Local source) { +Factory::New(v8::Local source) { return v8::Script::New(source); } Factory::return_t -Factory::New( v8::Local source - , v8::ScriptOrigin const& origin) { - return v8::Script::New(source, const_cast(&origin)); +Factory::New(v8::Local source, + v8::ScriptOrigin const &origin) { + return v8::Script::New(source, const_cast(&origin)); } //=== Signature ================================================================ @@ -197,35 +180,33 @@ Factory::New(Factory::FTH receiver) { //=== String =================================================================== -Factory::return_t -Factory::New() { +Factory::return_t Factory::New() { return v8::String::Empty(); } -Factory::return_t -Factory::New(const char * value, int length) { +Factory::return_t Factory::New(const char *value, + int length) { return v8::String::New(value, length); } -Factory::return_t -Factory::New( - std::string const& value) /* NOLINT(build/include_what_you_use) */ { +Factory::return_t Factory::New( + std::string const &value) /* NOLINT(build/include_what_you_use) */ { assert(value.size() <= INT_MAX && "string too long"); return v8::String::New(value.data(), static_cast(value.size())); } -Factory::return_t -Factory::New(const uint16_t * value, int length) { +Factory::return_t Factory::New(const uint16_t *value, + int length) { return v8::String::New(value, length); } Factory::return_t -Factory::New(v8::String::ExternalStringResource * value) { +Factory::New(v8::String::ExternalStringResource *value) { return v8::String::NewExternal(value); } Factory::return_t -Factory::New(v8::String::ExternalAsciiStringResource * value) { +Factory::New(v8::String::ExternalAsciiStringResource *value) { return v8::String::NewExternal(value); } @@ -236,28 +217,25 @@ Factory::New(v8::Local value) { return v8::StringObject::New(value).As(); } -} // end of namespace imp +} // end of namespace imp //=== Presistents and Handles ================================================== -template -inline v8::Local New(v8::Handle h) { +template inline v8::Local New(v8::Handle h) { return v8::Local::New(h); } -template -inline v8::Local New(v8::Persistent const& p) { +template inline v8::Local New(v8::Persistent const &p) { return v8::Local::New(p); } template -inline v8::Local New(Persistent const& p) { +inline v8::Local New(Persistent const &p) { return v8::Local::New(p.persistent); } -template -inline v8::Local New(Global const& p) { +template inline v8::Local New(Global const &p) { return v8::Local::New(p.persistent); } -#endif // NAN_IMPLEMENTATION_PRE_12_INL_H_ +#endif // NAN_IMPLEMENTATION_PRE_12_INL_H_ diff --git a/node_modules/nan/nan_json.h b/node_modules/nan/nan_json.h index 33ac8ba..8b2f824 100644 --- a/node_modules/nan/nan_json.h +++ b/node_modules/nan/nan_json.h @@ -13,123 +13,119 @@ #define NAN_JSON_H_NEED_PARSE 1 #else #define NAN_JSON_H_NEED_PARSE 0 -#endif // NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION +#endif // NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION #if NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION #define NAN_JSON_H_NEED_STRINGIFY 0 #else #define NAN_JSON_H_NEED_STRINGIFY 1 -#endif // NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION +#endif // NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION class JSON { - public: +public: JSON() { #if NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY Nan::HandleScope scope; Nan::MaybeLocal maybe_global_json = Nan::Get( - Nan::GetCurrentContext()->Global(), - Nan::New("JSON").ToLocalChecked() - ); + Nan::GetCurrentContext()->Global(), Nan::New("JSON").ToLocalChecked()); assert(!maybe_global_json.IsEmpty() && "global JSON is empty"); v8::Local val_global_json = maybe_global_json.ToLocalChecked(); assert(val_global_json->IsObject() && "global JSON is not an object"); Nan::MaybeLocal maybe_obj_global_json = - Nan::To(val_global_json); + Nan::To(val_global_json); assert(!maybe_obj_global_json.IsEmpty() && "global JSON object is empty"); v8::Local global_json = maybe_obj_global_json.ToLocalChecked(); #if NAN_JSON_H_NEED_PARSE - Nan::MaybeLocal maybe_parse_method = Nan::Get( - global_json, Nan::New("parse").ToLocalChecked() - ); + Nan::MaybeLocal maybe_parse_method = + Nan::Get(global_json, Nan::New("parse").ToLocalChecked()); assert(!maybe_parse_method.IsEmpty() && "JSON.parse is empty"); v8::Local parse_method = maybe_parse_method.ToLocalChecked(); assert(parse_method->IsFunction() && "JSON.parse is not a function"); parse_cb_.Reset(parse_method.As()); -#endif // NAN_JSON_H_NEED_PARSE +#endif // NAN_JSON_H_NEED_PARSE #if NAN_JSON_H_NEED_STRINGIFY - Nan::MaybeLocal maybe_stringify_method = Nan::Get( - global_json, Nan::New("stringify").ToLocalChecked() - ); + Nan::MaybeLocal maybe_stringify_method = + Nan::Get(global_json, Nan::New("stringify").ToLocalChecked()); assert(!maybe_stringify_method.IsEmpty() && "JSON.stringify is empty"); v8::Local stringify_method = - maybe_stringify_method.ToLocalChecked(); + maybe_stringify_method.ToLocalChecked(); - assert( - stringify_method->IsFunction() && "JSON.stringify is not a function" - ); + assert(stringify_method->IsFunction() && + "JSON.stringify is not a function"); stringify_cb_.Reset(stringify_method.As()); -#endif // NAN_JSON_H_NEED_STRINGIFY -#endif // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY +#endif // NAN_JSON_H_NEED_STRINGIFY +#endif // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY } - inline - Nan::MaybeLocal Parse(v8::Local json_string) { + inline Nan::MaybeLocal Parse(v8::Local json_string) { Nan::EscapableHandleScope scope; #if NAN_JSON_H_NEED_PARSE return scope.Escape(parse(json_string)); #else Nan::MaybeLocal result; -#if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && \ +#if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && \ NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION result = v8::JSON::Parse(json_string); #else #if NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION v8::Local context_or_isolate = Nan::GetCurrentContext(); #else - v8::Isolate* context_or_isolate = v8::Isolate::GetCurrent(); -#endif // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION + v8::Isolate *context_or_isolate = v8::Isolate::GetCurrent(); +#endif // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION result = v8::JSON::Parse(context_or_isolate, json_string); -#endif // NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && - // NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION - if (result.IsEmpty()) return v8::Local(); +#endif // NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && + // NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION + if (result.IsEmpty()) + return v8::Local(); return scope.Escape(result.ToLocalChecked()); -#endif // NAN_JSON_H_NEED_PARSE +#endif // NAN_JSON_H_NEED_PARSE } - inline - Nan::MaybeLocal Stringify(v8::Local json_object) { + inline Nan::MaybeLocal + Stringify(v8::Local json_object) { Nan::EscapableHandleScope scope; Nan::MaybeLocal result = #if NAN_JSON_H_NEED_STRINGIFY - Nan::To(stringify(json_object)); + Nan::To(stringify(json_object)); #else - v8::JSON::Stringify(Nan::GetCurrentContext(), json_object); -#endif // NAN_JSON_H_NEED_STRINGIFY - if (result.IsEmpty()) return v8::Local(); + v8::JSON::Stringify(Nan::GetCurrentContext(), json_object); +#endif // NAN_JSON_H_NEED_STRINGIFY + if (result.IsEmpty()) + return v8::Local(); return scope.Escape(result.ToLocalChecked()); } - inline - Nan::MaybeLocal Stringify(v8::Local json_object, - v8::Local gap) { + inline Nan::MaybeLocal + Stringify(v8::Local json_object, v8::Local gap) { Nan::EscapableHandleScope scope; Nan::MaybeLocal result = #if NAN_JSON_H_NEED_STRINGIFY - Nan::To(stringify(json_object, gap)); + Nan::To(stringify(json_object, gap)); #else - v8::JSON::Stringify(Nan::GetCurrentContext(), json_object, gap); -#endif // NAN_JSON_H_NEED_STRINGIFY - if (result.IsEmpty()) return v8::Local(); + v8::JSON::Stringify(Nan::GetCurrentContext(), json_object, gap); +#endif // NAN_JSON_H_NEED_STRINGIFY + if (result.IsEmpty()) + return v8::Local(); return scope.Escape(result.ToLocalChecked()); } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(JSON) #if NAN_JSON_H_NEED_PARSE Nan::Callback parse_cb_; -#endif // NAN_JSON_H_NEED_PARSE +#endif // NAN_JSON_H_NEED_PARSE #if NAN_JSON_H_NEED_STRINGIFY Nan::Callback stringify_cb_; -#endif // NAN_JSON_H_NEED_STRINGIFY +#endif // NAN_JSON_H_NEED_STRINGIFY #if NAN_JSON_H_NEED_PARSE inline v8::Local parse(v8::Local arg) { @@ -137,7 +133,7 @@ class JSON { AsyncResource resource("nan:JSON.parse"); return parse_cb_.Call(1, &arg, &resource).FromMaybe(v8::Local()); } -#endif // NAN_JSON_H_NEED_PARSE +#endif // NAN_JSON_H_NEED_PARSE #if NAN_JSON_H_NEED_STRINGIFY inline v8::Local stringify(v8::Local arg) { @@ -148,19 +144,15 @@ class JSON { } inline v8::Local stringify(v8::Local arg, - v8::Local gap) { + v8::Local gap) { assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty"); - v8::Local argv[] = { - arg, - Nan::Null(), - gap - }; + v8::Local argv[] = {arg, Nan::Null(), gap}; AsyncResource resource("nan:JSON.stringify"); return stringify_cb_.Call(3, argv, &resource) .FromMaybe(v8::Local()); } -#endif // NAN_JSON_H_NEED_STRINGIFY +#endif // NAN_JSON_H_NEED_STRINGIFY }; -#endif // NAN_JSON_H_ +#endif // NAN_JSON_H_ diff --git a/node_modules/nan/nan_maybe_43_inl.h b/node_modules/nan/nan_maybe_43_inl.h index c04ce30..be535b2 100644 --- a/node_modules/nan/nan_maybe_43_inl.h +++ b/node_modules/nan/nan_maybe_43_inl.h @@ -9,95 +9,79 @@ #ifndef NAN_MAYBE_43_INL_H_ #define NAN_MAYBE_43_INL_H_ -template -using MaybeLocal = v8::MaybeLocal; +template using MaybeLocal = v8::MaybeLocal; -inline -MaybeLocal ToDetailString(v8::Local val) { +inline MaybeLocal ToDetailString(v8::Local val) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(val->ToDetailString(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline -MaybeLocal ToArrayIndex(v8::Local val) { +inline MaybeLocal ToArrayIndex(v8::Local val) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(val->ToArrayIndex(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline -Maybe Equals(v8::Local a, v8::Local(b)) { +inline Maybe Equals(v8::Local a, v8::Local(b)) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return a->Equals(isolate->GetCurrentContext(), b); } -inline -MaybeLocal NewInstance(v8::Local h) { +inline MaybeLocal NewInstance(v8::Local h) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(h->NewInstance(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline -MaybeLocal NewInstance( - v8::Local h - , int argc - , v8::Local argv[]) { +inline MaybeLocal NewInstance(v8::Local h, int argc, + v8::Local argv[]) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(h->NewInstance(isolate->GetCurrentContext(), argc, argv) .FromMaybe(v8::Local())); } -inline -MaybeLocal NewInstance(v8::Local h) { +inline MaybeLocal NewInstance(v8::Local h) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(h->NewInstance(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } - -inline MaybeLocal GetFunction( - v8::Local t) { +inline MaybeLocal GetFunction(v8::Local t) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(t->GetFunction(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline Maybe Set( - v8::Local obj - , v8::Local key - , v8::Local value) { +inline Maybe Set(v8::Local obj, v8::Local key, + v8::Local value) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->Set(isolate->GetCurrentContext(), key, value); } -inline Maybe Set( - v8::Local obj - , uint32_t index - , v8::Local value) { +inline Maybe Set(v8::Local obj, uint32_t index, + v8::Local value) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->Set(isolate->GetCurrentContext(), index, value); } #if NODE_MODULE_VERSION < NODE_4_0_MODULE_VERSION -#include "nan_define_own_property_helper.h" // NOLINT(build/include) +#include "nan_define_own_property_helper.h" // NOLINT(build/include) #endif -inline Maybe DefineOwnProperty( - v8::Local obj - , v8::Local key - , v8::Local value - , v8::PropertyAttribute attribs = v8::None) { +inline Maybe DefineOwnProperty(v8::Local obj, + v8::Local key, + v8::Local value, + v8::PropertyAttribute attribs = v8::None) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); #if NODE_MODULE_VERSION >= NODE_4_0_MODULE_VERSION @@ -114,11 +98,9 @@ inline Maybe DefineOwnProperty( #endif } -NAN_DEPRECATED inline Maybe ForceSet( - v8::Local obj - , v8::Local key - , v8::Local value - , v8::PropertyAttribute attribs = v8::None) { +NAN_DEPRECATED inline Maybe +ForceSet(v8::Local obj, v8::Local key, + v8::Local value, v8::PropertyAttribute attribs = v8::None) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); #if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION @@ -131,35 +113,30 @@ NAN_DEPRECATED inline Maybe ForceSet( #endif } -inline MaybeLocal Get( - v8::Local obj - , v8::Local key) { +inline MaybeLocal Get(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(obj->Get(isolate->GetCurrentContext(), key) .FromMaybe(v8::Local())); } -inline -MaybeLocal Get(v8::Local obj, uint32_t index) { +inline MaybeLocal Get(v8::Local obj, uint32_t index) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(obj->Get(isolate->GetCurrentContext(), index) .FromMaybe(v8::Local())); } -inline v8::PropertyAttribute GetPropertyAttributes( - v8::Local obj - , v8::Local key) { +inline v8::PropertyAttribute GetPropertyAttributes(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->GetPropertyAttributes(isolate->GetCurrentContext(), key) .FromJust(); } -inline Maybe Has( - v8::Local obj - , v8::Local key) { +inline Maybe Has(v8::Local obj, v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->Has(isolate->GetCurrentContext(), key); @@ -171,88 +148,78 @@ inline Maybe Has(v8::Local obj, uint32_t index) { return obj->Has(isolate->GetCurrentContext(), index); } -inline Maybe Delete( - v8::Local obj - , v8::Local key) { +inline Maybe Delete(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->Delete(isolate->GetCurrentContext(), key); } -inline -Maybe Delete(v8::Local obj, uint32_t index) { +inline Maybe Delete(v8::Local obj, uint32_t index) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->Delete(isolate->GetCurrentContext(), index); } -inline -MaybeLocal GetPropertyNames(v8::Local obj) { +inline MaybeLocal GetPropertyNames(v8::Local obj) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(obj->GetPropertyNames(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline -MaybeLocal GetOwnPropertyNames(v8::Local obj) { +inline MaybeLocal GetOwnPropertyNames(v8::Local obj) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(obj->GetOwnPropertyNames(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline Maybe SetPrototype( - v8::Local obj - , v8::Local prototype) { +inline Maybe SetPrototype(v8::Local obj, + v8::Local prototype) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->SetPrototype(isolate->GetCurrentContext(), prototype); } -inline MaybeLocal ObjectProtoToString( - v8::Local obj) { +inline MaybeLocal ObjectProtoToString(v8::Local obj) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(obj->ObjectProtoToString(isolate->GetCurrentContext()) .FromMaybe(v8::Local())); } -inline Maybe HasOwnProperty( - v8::Local obj - , v8::Local key) { +inline Maybe HasOwnProperty(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->HasOwnProperty(isolate->GetCurrentContext(), key); } -inline Maybe HasRealNamedProperty( - v8::Local obj - , v8::Local key) { +inline Maybe HasRealNamedProperty(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->HasRealNamedProperty(isolate->GetCurrentContext(), key); } -inline Maybe HasRealIndexedProperty( - v8::Local obj - , uint32_t index) { +inline Maybe HasRealIndexedProperty(v8::Local obj, + uint32_t index) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->HasRealIndexedProperty(isolate->GetCurrentContext(), index); } -inline Maybe HasRealNamedCallbackProperty( - v8::Local obj - , v8::Local key) { +inline Maybe HasRealNamedCallbackProperty(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); return obj->HasRealNamedCallbackProperty(isolate->GetCurrentContext(), key); } -inline MaybeLocal GetRealNamedPropertyInPrototypeChain( - v8::Local obj - , v8::Local key) { +inline MaybeLocal +GetRealNamedPropertyInPrototypeChain(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(obj->GetRealNamedPropertyInPrototypeChain( @@ -260,9 +227,8 @@ inline MaybeLocal GetRealNamedPropertyInPrototypeChain( .FromMaybe(v8::Local())); } -inline MaybeLocal GetRealNamedProperty( - v8::Local obj - , v8::Local key) { +inline MaybeLocal GetRealNamedProperty(v8::Local obj, + v8::Local key) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape( @@ -270,11 +236,10 @@ inline MaybeLocal GetRealNamedProperty( .FromMaybe(v8::Local())); } -inline MaybeLocal CallAsFunction( - v8::Local obj - , v8::Local recv - , int argc - , v8::Local argv[]) { +inline MaybeLocal CallAsFunction(v8::Local obj, + v8::Local recv, + int argc, + v8::Local argv[]) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape( @@ -282,9 +247,9 @@ inline MaybeLocal CallAsFunction( .FromMaybe(v8::Local())); } -inline MaybeLocal CallAsConstructor( - v8::Local obj - , int argc, v8::Local argv[]) { +inline MaybeLocal CallAsConstructor(v8::Local obj, + int argc, + v8::Local argv[]) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape( @@ -292,8 +257,7 @@ inline MaybeLocal CallAsConstructor( .FromMaybe(v8::Local())); } -inline -MaybeLocal GetSourceLine(v8::Local msg) { +inline MaybeLocal GetSourceLine(v8::Local msg) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(msg->GetSourceLine(isolate->GetCurrentContext()) @@ -318,9 +282,8 @@ inline Maybe GetEndColumn(v8::Local msg) { return msg->GetEndColumn(isolate->GetCurrentContext()); } -inline MaybeLocal CloneElementAt( - v8::Local array - , uint32_t index) { +inline MaybeLocal CloneElementAt(v8::Local array, + uint32_t index) { #if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); @@ -342,15 +305,13 @@ inline MaybeLocal CloneElementAt( #endif } -inline MaybeLocal Call( - v8::Local fun - , v8::Local recv - , int argc - , v8::Local argv[]) { +inline MaybeLocal Call(v8::Local fun, + v8::Local recv, int argc, + v8::Local argv[]) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); return scope.Escape(fun->Call(isolate->GetCurrentContext(), recv, argc, argv) .FromMaybe(v8::Local())); } -#endif // NAN_MAYBE_43_INL_H_ +#endif // NAN_MAYBE_43_INL_H_ diff --git a/node_modules/nan/nan_maybe_pre_43_inl.h b/node_modules/nan/nan_maybe_pre_43_inl.h index 83325ae..65c99a4 100644 --- a/node_modules/nan/nan_maybe_pre_43_inl.h +++ b/node_modules/nan/nan_maybe_pre_43_inl.h @@ -9,25 +9,24 @@ #ifndef NAN_MAYBE_PRE_43_INL_H_ #define NAN_MAYBE_PRE_43_INL_H_ -template -class MaybeLocal { - public: +template class MaybeLocal { +public: inline MaybeLocal() : val_(v8::Local()) {} - template -# if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION - inline - MaybeLocal(v8::Local that) : val_(that) {} // NOLINT(runtime/explicit) -# else - inline - MaybeLocal(v8::Local that) : // NOLINT(runtime/explicit) - val_(*reinterpret_cast*>(&that)) {} -# endif + template +#if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION + inline MaybeLocal(v8::Local that) : val_(that) { + } // NOLINT(runtime/explicit) +#else + inline MaybeLocal(v8::Local that) + : // NOLINT(runtime/explicit) + val_(*reinterpret_cast *>(&that)) { + } +#endif inline bool IsEmpty() const { return val_.IsEmpty(); } - template - inline bool ToLocal(v8::Local *out) const { + template inline bool ToLocal(v8::Local *out) const { *out = val_; return !IsEmpty(); } @@ -35,207 +34,169 @@ class MaybeLocal { inline v8::Local ToLocalChecked() const { #if defined(V8_ENABLE_CHECKS) assert(!IsEmpty() && "ToLocalChecked is Empty"); -#endif // V8_ENABLE_CHECKS +#endif // V8_ENABLE_CHECKS return val_; } - template + template inline v8::Local FromMaybe(v8::Local default_value) const { return IsEmpty() ? default_value : v8::Local(val_); } - private: +private: v8::Local val_; }; -inline -MaybeLocal ToDetailString(v8::Handle val) { +inline MaybeLocal ToDetailString(v8::Handle val) { return MaybeLocal(val->ToDetailString()); } -inline -MaybeLocal ToArrayIndex(v8::Handle val) { +inline MaybeLocal ToArrayIndex(v8::Handle val) { return MaybeLocal(val->ToArrayIndex()); } -inline -Maybe Equals(v8::Handle a, v8::Handle(b)) { +inline Maybe Equals(v8::Handle a, v8::Handle(b)) { return Just(a->Equals(b)); } -inline -MaybeLocal NewInstance(v8::Handle h) { +inline MaybeLocal NewInstance(v8::Handle h) { return MaybeLocal(h->NewInstance()); } -inline -MaybeLocal NewInstance( - v8::Local h - , int argc - , v8::Local argv[]) { +inline MaybeLocal NewInstance(v8::Local h, int argc, + v8::Local argv[]) { return MaybeLocal(h->NewInstance(argc, argv)); } -inline -MaybeLocal NewInstance(v8::Handle h) { +inline MaybeLocal NewInstance(v8::Handle h) { return MaybeLocal(h->NewInstance()); } -inline -MaybeLocal GetFunction(v8::Handle t) { +inline MaybeLocal +GetFunction(v8::Handle t) { return MaybeLocal(t->GetFunction()); } -inline Maybe Set( - v8::Handle obj - , v8::Handle key - , v8::Handle value) { +inline Maybe Set(v8::Handle obj, v8::Handle key, + v8::Handle value) { return Just(obj->Set(key, value)); } -inline Maybe Set( - v8::Handle obj - , uint32_t index - , v8::Handle value) { +inline Maybe Set(v8::Handle obj, uint32_t index, + v8::Handle value) { return Just(obj->Set(index, value)); } -#include "nan_define_own_property_helper.h" // NOLINT(build/include) +#include "nan_define_own_property_helper.h" // NOLINT(build/include) -inline Maybe DefineOwnProperty( - v8::Handle obj - , v8::Handle key - , v8::Handle value - , v8::PropertyAttribute attribs = v8::None) { +inline Maybe DefineOwnProperty(v8::Handle obj, + v8::Handle key, + v8::Handle value, + v8::PropertyAttribute attribs = v8::None) { v8::PropertyAttribute current = obj->GetPropertyAttributes(key); return imp::DefineOwnPropertyHelper(current, obj, key, value, attribs); } -NAN_DEPRECATED inline Maybe ForceSet( - v8::Handle obj - , v8::Handle key - , v8::Handle value - , v8::PropertyAttribute attribs = v8::None) { +NAN_DEPRECATED inline Maybe +ForceSet(v8::Handle obj, v8::Handle key, + v8::Handle value, + v8::PropertyAttribute attribs = v8::None) { return Just(obj->ForceSet(key, value, attribs)); } -inline MaybeLocal Get( - v8::Handle obj - , v8::Handle key) { +inline MaybeLocal Get(v8::Handle obj, + v8::Handle key) { return MaybeLocal(obj->Get(key)); } -inline MaybeLocal Get( - v8::Handle obj - , uint32_t index) { +inline MaybeLocal Get(v8::Handle obj, uint32_t index) { return MaybeLocal(obj->Get(index)); } -inline Maybe GetPropertyAttributes( - v8::Handle obj - , v8::Handle key) { +inline Maybe +GetPropertyAttributes(v8::Handle obj, v8::Handle key) { return Just(obj->GetPropertyAttributes(key)); } -inline Maybe Has( - v8::Handle obj - , v8::Handle key) { +inline Maybe Has(v8::Handle obj, v8::Handle key) { return Just(obj->Has(key)); } -inline Maybe Has( - v8::Handle obj - , uint32_t index) { +inline Maybe Has(v8::Handle obj, uint32_t index) { return Just(obj->Has(index)); } -inline Maybe Delete( - v8::Handle obj - , v8::Handle key) { +inline Maybe Delete(v8::Handle obj, + v8::Handle key) { return Just(obj->Delete(key)); } -inline Maybe Delete( - v8::Handle obj - , uint32_t index) { +inline Maybe Delete(v8::Handle obj, uint32_t index) { return Just(obj->Delete(index)); } -inline -MaybeLocal GetPropertyNames(v8::Handle obj) { +inline MaybeLocal GetPropertyNames(v8::Handle obj) { return MaybeLocal(obj->GetPropertyNames()); } -inline -MaybeLocal GetOwnPropertyNames(v8::Handle obj) { +inline MaybeLocal GetOwnPropertyNames(v8::Handle obj) { return MaybeLocal(obj->GetOwnPropertyNames()); } -inline Maybe SetPrototype( - v8::Handle obj - , v8::Handle prototype) { +inline Maybe SetPrototype(v8::Handle obj, + v8::Handle prototype) { return Just(obj->SetPrototype(prototype)); } -inline MaybeLocal ObjectProtoToString( - v8::Handle obj) { +inline MaybeLocal ObjectProtoToString(v8::Handle obj) { return MaybeLocal(obj->ObjectProtoToString()); } -inline Maybe HasOwnProperty( - v8::Handle obj - , v8::Handle key) { +inline Maybe HasOwnProperty(v8::Handle obj, + v8::Handle key) { return Just(obj->HasOwnProperty(key)); } -inline Maybe HasRealNamedProperty( - v8::Handle obj - , v8::Handle key) { +inline Maybe HasRealNamedProperty(v8::Handle obj, + v8::Handle key) { return Just(obj->HasRealNamedProperty(key)); } -inline Maybe HasRealIndexedProperty( - v8::Handle obj - , uint32_t index) { +inline Maybe HasRealIndexedProperty(v8::Handle obj, + uint32_t index) { return Just(obj->HasRealIndexedProperty(index)); } -inline Maybe HasRealNamedCallbackProperty( - v8::Handle obj - , v8::Handle key) { +inline Maybe HasRealNamedCallbackProperty(v8::Handle obj, + v8::Handle key) { return Just(obj->HasRealNamedCallbackProperty(key)); } -inline MaybeLocal GetRealNamedPropertyInPrototypeChain( - v8::Handle obj - , v8::Handle key) { - return MaybeLocal( - obj->GetRealNamedPropertyInPrototypeChain(key)); +inline MaybeLocal +GetRealNamedPropertyInPrototypeChain(v8::Handle obj, + v8::Handle key) { + return MaybeLocal(obj->GetRealNamedPropertyInPrototypeChain(key)); } -inline MaybeLocal GetRealNamedProperty( - v8::Handle obj - , v8::Handle key) { +inline MaybeLocal GetRealNamedProperty(v8::Handle obj, + v8::Handle key) { return MaybeLocal(obj->GetRealNamedProperty(key)); } -inline MaybeLocal CallAsFunction( - v8::Handle obj - , v8::Handle recv - , int argc - , v8::Handle argv[]) { +inline MaybeLocal CallAsFunction(v8::Handle obj, + v8::Handle recv, + int argc, + v8::Handle argv[]) { return MaybeLocal(obj->CallAsFunction(recv, argc, argv)); } -inline MaybeLocal CallAsConstructor( - v8::Handle obj - , int argc - , v8::Local argv[]) { +inline MaybeLocal CallAsConstructor(v8::Handle obj, + int argc, + v8::Local argv[]) { return MaybeLocal(obj->CallAsConstructor(argc, argv)); } -inline -MaybeLocal GetSourceLine(v8::Handle msg) { +inline MaybeLocal GetSourceLine(v8::Handle msg) { return MaybeLocal(msg->GetSourceLine()); } @@ -251,18 +212,15 @@ inline Maybe GetEndColumn(v8::Handle msg) { return Just(msg->GetEndColumn()); } -inline MaybeLocal CloneElementAt( - v8::Handle array - , uint32_t index) { +inline MaybeLocal CloneElementAt(v8::Handle array, + uint32_t index) { return MaybeLocal(array->CloneElementAt(index)); } -inline MaybeLocal Call( - v8::Local fun - , v8::Local recv - , int argc - , v8::Local argv[]) { +inline MaybeLocal Call(v8::Local fun, + v8::Local recv, int argc, + v8::Local argv[]) { return MaybeLocal(fun->Call(recv, argc, argv)); } -#endif // NAN_MAYBE_PRE_43_INL_H_ +#endif // NAN_MAYBE_PRE_43_INL_H_ diff --git a/node_modules/nan/nan_new.h b/node_modules/nan/nan_new.h index cdf8bbe..384b345 100644 --- a/node_modules/nan/nan_new.h +++ b/node_modules/nan/nan_new.h @@ -9,29 +9,23 @@ #ifndef NAN_NEW_H_ #define NAN_NEW_H_ -namespace imp { // scnr +namespace imp { // scnr // TODO(agnat): Generalize template v8::Local To(v8::Local i); template <> -inline -v8::Local -To(v8::Local i) { +inline v8::Local To(v8::Local i) { return Nan::To(i).ToLocalChecked(); } template <> -inline -v8::Local -To(v8::Local i) { +inline v8::Local To(v8::Local i) { return Nan::To(i).ToLocalChecked(); } template <> -inline -v8::Local -To(v8::Local i) { +inline v8::Local To(v8::Local i) { return Nan::To(i).ToLocalChecked(); } @@ -45,89 +39,72 @@ template struct MaybeFactoryBase { template struct Factory; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(); static inline return_t New(int length); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(bool value); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(bool value); }; -template <> -struct Factory : FactoryBase { - static inline - return_t - New( v8::ExtensionConfiguration* extensions = NULL - , v8::Local tmpl = v8::Local() - , v8::Local obj = v8::Local()); +template <> struct Factory : FactoryBase { + static inline return_t + New(v8::ExtensionConfiguration *extensions = NULL, + v8::Local tmpl = v8::Local(), + v8::Local obj = v8::Local()); }; -template <> -struct Factory : MaybeFactoryBase { +template <> struct Factory : MaybeFactoryBase { static inline return_t New(double value); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(void *value); }; -template <> -struct Factory : FactoryBase { - static inline - return_t - New( FunctionCallback callback - , v8::Local data = v8::Local()); +template <> struct Factory : FactoryBase { + static inline return_t + New(FunctionCallback callback, + v8::Local data = v8::Local()); }; template <> struct Factory : FactoryBase { - static inline - return_t - New( FunctionCallback callback = NULL - , v8::Local data = v8::Local() - , v8::Local signature = v8::Local()); + static inline return_t + New(FunctionCallback callback = NULL, + v8::Local data = v8::Local(), + v8::Local signature = v8::Local()); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(double value); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(double value); }; -template -struct IntegerFactory : FactoryBase { +template struct IntegerFactory : FactoryBase { typedef typename FactoryBase::return_t return_t; static inline return_t New(int32_t value); static inline return_t New(uint32_t value); }; -template <> -struct Factory : IntegerFactory {}; +template <> struct Factory : IntegerFactory {}; -template <> -struct Factory : IntegerFactory {}; +template <> struct Factory : IntegerFactory {}; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(int32_t value); static inline return_t New(uint32_t value); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(); }; @@ -136,42 +113,37 @@ struct Factory : FactoryBase { static inline return_t New(); }; -template <> -struct Factory : MaybeFactoryBase { - static inline return_t New( - v8::Local pattern, v8::RegExp::Flags flags); +template <> struct Factory : MaybeFactoryBase { + static inline return_t New(v8::Local pattern, + v8::RegExp::Flags flags); }; -template <> -struct Factory : MaybeFactoryBase { - static inline return_t New( v8::Local source); - static inline return_t New( v8::Local source - , v8::ScriptOrigin const& origin); +template <> struct Factory : MaybeFactoryBase { + static inline return_t New(v8::Local source); + static inline return_t New(v8::Local source, + v8::ScriptOrigin const &origin); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { typedef v8::Local FTH; static inline return_t New(FTH receiver = FTH()); }; -template <> -struct Factory : MaybeFactoryBase { +template <> struct Factory : MaybeFactoryBase { static inline return_t New(); static inline return_t New(const char *value, int length = -1); static inline return_t New(const uint16_t *value, int length = -1); - static inline return_t New(std::string const& value); + static inline return_t New(std::string const &value); - static inline return_t New(v8::String::ExternalStringResource * value); - static inline return_t New(ExternalOneByteStringResource * value); + static inline return_t New(v8::String::ExternalStringResource *value); + static inline return_t New(ExternalOneByteStringResource *value); }; -template <> -struct Factory : FactoryBase { +template <> struct Factory : FactoryBase { static inline return_t New(v8::Local value); }; -} // end of namespace imp +} // end of namespace imp #if (NODE_MODULE_VERSION >= 12) @@ -179,50 +151,44 @@ namespace imp { template <> struct Factory : MaybeFactoryBase { - static inline return_t New( v8::Local source); - static inline return_t New( v8::Local source - , v8::ScriptOrigin const& origin); + static inline return_t New(v8::Local source); + static inline return_t New(v8::Local source, + v8::ScriptOrigin const &origin); }; -} // end of namespace imp +} // end of namespace imp -# include "nan_implementation_12_inl.h" +#include "nan_implementation_12_inl.h" -#else // NODE_MODULE_VERSION >= 12 +#else // NODE_MODULE_VERSION >= 12 -# include "nan_implementation_pre_12_inl.h" +#include "nan_implementation_pre_12_inl.h" #endif //=== API ====================================================================== -template -typename imp::Factory::return_t -New() { +template typename imp::Factory::return_t New() { return imp::Factory::New(); } template -typename imp::Factory::return_t -New(A0 arg0) { +typename imp::Factory::return_t New(A0 arg0) { return imp::Factory::New(arg0); } template -typename imp::Factory::return_t -New(A0 arg0, A1 arg1) { +typename imp::Factory::return_t New(A0 arg0, A1 arg1) { return imp::Factory::New(arg0, arg1); } template -typename imp::Factory::return_t -New(A0 arg0, A1 arg1, A2 arg2) { +typename imp::Factory::return_t New(A0 arg0, A1 arg1, A2 arg2) { return imp::Factory::New(arg0, arg1, arg2); } template -typename imp::Factory::return_t -New(A0 arg0, A1 arg1, A2 arg2, A3 arg3) { +typename imp::Factory::return_t New(A0 arg0, A1 arg1, A2 arg2, A3 arg3) { return imp::Factory::New(arg0, arg1, arg2, arg3); } @@ -234,18 +200,17 @@ New(A0 arg0, A1 arg1, A2 arg2, A3 arg3) { // v8::Function and v8::FunctionTemplate with one or two arguments template typename imp::Factory::return_t -New( FunctionCallback callback - , v8::Local data = v8::Local()) { - return imp::Factory::New(callback, data); +New(FunctionCallback callback, + v8::Local data = v8::Local()) { + return imp::Factory::New(callback, data); } // v8::Function and v8::FunctionTemplate with three arguments template typename imp::Factory::return_t -New( FunctionCallback callback - , v8::Local data = v8::Local() - , A2 a2 = A2()) { - return imp::Factory::New(callback, data, a2); +New(FunctionCallback callback, + v8::Local data = v8::Local(), A2 a2 = A2()) { + return imp::Factory::New(callback, data, a2); } // Convenience @@ -256,85 +221,65 @@ template inline v8::Local New(v8::Handle h); #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION template - inline v8::Local New(v8::Persistent const& p); +inline v8::Local New(v8::Persistent const &p); #else -template inline v8::Local New(v8::Persistent const& p); +template inline v8::Local New(v8::Persistent const &p); #endif template -inline v8::Local New(Persistent const& p); -template -inline v8::Local New(Global const& p); +inline v8::Local New(Persistent const &p); +template inline v8::Local New(Global const &p); -inline -imp::Factory::return_t -New(bool value) { +inline imp::Factory::return_t New(bool value) { return New(value); } -inline -imp::Factory::return_t -New(int32_t value) { +inline imp::Factory::return_t New(int32_t value) { return New(value); } -inline -imp::Factory::return_t -New(uint32_t value) { +inline imp::Factory::return_t New(uint32_t value) { return New(value); } -inline -imp::Factory::return_t -New(double value) { +inline imp::Factory::return_t New(double value) { return New(value); } -inline -imp::Factory::return_t -New(std::string const& value) { // NOLINT(build/include_what_you_use) +inline imp::Factory::return_t +New(std::string const &value) { // NOLINT(build/include_what_you_use) return New(value); } -inline -imp::Factory::return_t -New(const char * value, int length) { +inline imp::Factory::return_t New(const char *value, int length) { return New(value, length); } -inline -imp::Factory::return_t -New(const uint16_t * value, int length) { +inline imp::Factory::return_t New(const uint16_t *value, + int length) { return New(value, length); } -inline -imp::Factory::return_t -New(const char * value) { +inline imp::Factory::return_t New(const char *value) { return New(value); } -inline -imp::Factory::return_t -New(const uint16_t * value) { +inline imp::Factory::return_t New(const uint16_t *value) { return New(value); } -inline -imp::Factory::return_t -New(v8::String::ExternalStringResource * value) { +inline imp::Factory::return_t +New(v8::String::ExternalStringResource *value) { return New(value); } -inline -imp::Factory::return_t -New(ExternalOneByteStringResource * value) { +inline imp::Factory::return_t +New(ExternalOneByteStringResource *value) { return New(value); } -inline -imp::Factory::return_t -New(v8::Local pattern, v8::RegExp::Flags flags) { +inline imp::Factory::return_t New(v8::Local pattern, + v8::RegExp::Flags flags) { return New(pattern, flags); } -#endif // NAN_NEW_H_ +#endif // NAN_NEW_H_ diff --git a/node_modules/nan/nan_object_wrap.h b/node_modules/nan/nan_object_wrap.h index 78712f9..a4d1efe 100644 --- a/node_modules/nan/nan_object_wrap.h +++ b/node_modules/nan/nan_object_wrap.h @@ -10,11 +10,8 @@ #define NAN_OBJECT_WRAP_H_ class ObjectWrap { - public: - ObjectWrap() { - refs_ = 0; - } - +public: + ObjectWrap() { refs_ = 0; } virtual ~ObjectWrap() { if (persistent().IsEmpty()) { @@ -25,30 +22,21 @@ class ObjectWrap { persistent().Reset(); } - - template - static inline T* Unwrap(v8::Local object) { + template static inline T *Unwrap(v8::Local object) { assert(!object.IsEmpty()); assert(object->InternalFieldCount() > 0); // Cast to ObjectWrap before casting to T. A direct cast from void // to T won't work right when T has more than one base class. - void* ptr = GetInternalFieldPointer(object, 0); - ObjectWrap* wrap = static_cast(ptr); - return static_cast(wrap); - } - - - inline v8::Local handle() const { - return New(handle_); + void *ptr = GetInternalFieldPointer(object, 0); + ObjectWrap *wrap = static_cast(ptr); + return static_cast(wrap); } + inline v8::Local handle() const { return New(handle_); } - inline Persistent& persistent() { - return handle_; - } - + inline Persistent &persistent() { return handle_; } - protected: +protected: inline void Wrap(v8::Local object) { assert(persistent().IsEmpty()); assert(object->InternalFieldCount() > 0); @@ -57,8 +45,10 @@ class ObjectWrap { MakeWeak(); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) inline void MakeWeak() { persistent().v8::PersistentBase::SetWeak( @@ -112,16 +102,17 @@ class ObjectWrap { MakeWeak(); } - int refs_; // ro + int refs_; // ro - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(ObjectWrap) -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) - static void - WeakCallback(v8::WeakCallbackInfo const& info) { - ObjectWrap* wrap = info.GetParameter(); + static void WeakCallback(v8::WeakCallbackInfo const &info) { + ObjectWrap *wrap = info.GetParameter(); assert(wrap->refs_ == 0); wrap->handle_.Reset(); delete wrap; @@ -130,8 +121,8 @@ class ObjectWrap { #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION static void - WeakCallback(v8::WeakCallbackData const& data) { - ObjectWrap* wrap = data.GetParameter(); + WeakCallback(v8::WeakCallbackData const &data) { + ObjectWrap *wrap = data.GetParameter(); assert(wrap->refs_ == 0); assert(wrap->handle_.IsNearDeath()); wrap->handle_.Reset(); @@ -141,7 +132,7 @@ class ObjectWrap { #else static void WeakCallback(v8::Persistent value, void *data) { - ObjectWrap *wrap = static_cast(data); + ObjectWrap *wrap = static_cast(data); assert(wrap->refs_ == 0); assert(wrap->handle_.IsNearDeath()); wrap->handle_.Reset(); @@ -152,5 +143,4 @@ class ObjectWrap { Persistent handle_; }; - -#endif // NAN_OBJECT_WRAP_H_ +#endif // NAN_OBJECT_WRAP_H_ diff --git a/node_modules/nan/nan_persistent_12_inl.h b/node_modules/nan/nan_persistent_12_inl.h index d9649e8..039041c 100644 --- a/node_modules/nan/nan_persistent_12_inl.h +++ b/node_modules/nan/nan_persistent_12_inl.h @@ -9,41 +9,39 @@ #ifndef NAN_PERSISTENT_12_INL_H_ #define NAN_PERSISTENT_12_INL_H_ -template class Persistent : - public v8::Persistent { - public: +template +class Persistent : public v8::Persistent { +public: inline Persistent() : v8::Persistent() {} - template inline Persistent(v8::Local that) : - v8::Persistent(v8::Isolate::GetCurrent(), that) {} + template + inline Persistent(v8::Local that) + : v8::Persistent(v8::Isolate::GetCurrent(), that) {} - template - inline - Persistent(const v8::Persistent &that) : // NOLINT(runtime/explicit) - v8::Persistent(v8::Isolate::GetCurrent(), that) {} + template + inline Persistent(const v8::Persistent &that) + : // NOLINT(runtime/explicit) + v8::Persistent(v8::Isolate::GetCurrent(), that) {} inline void Reset() { v8::PersistentBase::Reset(); } - template - inline void Reset(const v8::Local &other) { + template inline void Reset(const v8::Local &other) { v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); } - template - inline void Reset(const v8::PersistentBase &other) { + template inline void Reset(const v8::PersistentBase &other) { v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); } - template - inline void SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type); + template + inline void SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type); - private: +private: inline T *operator*() const { return *PersistentBase::persistent; } - template + template inline void Copy(const Persistent &that) { TYPE_CHECK(T, S); @@ -56,77 +54,71 @@ template class Persistent : } }; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -template -class Global : public v8::Global { - public: +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +template class Global : public v8::Global { +public: inline Global() : v8::Global() {} - template inline Global(v8::Local that) : - v8::Global(v8::Isolate::GetCurrent(), that) {} + template + inline Global(v8::Local that) + : v8::Global(v8::Isolate::GetCurrent(), that) {} - template - inline - Global(const v8::PersistentBase &that) : // NOLINT(runtime/explicit) - v8::Global(v8::Isolate::GetCurrent(), that) {} + template + inline Global(const v8::PersistentBase &that) + : // NOLINT(runtime/explicit) + v8::Global(v8::Isolate::GetCurrent(), that) {} inline void Reset() { v8::PersistentBase::Reset(); } - template - inline void Reset(const v8::Local &other) { + template inline void Reset(const v8::Local &other) { v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); } - template - inline void Reset(const v8::PersistentBase &other) { + template inline void Reset(const v8::PersistentBase &other) { v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); } - template - inline void SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { - reinterpret_cast*>(this)->SetWeak( - parameter, callback, type); + template + inline void SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { + reinterpret_cast *>(this)->SetWeak(parameter, callback, type); } }; #else -template -class Global : public v8::UniquePersistent { - public: +template class Global : public v8::UniquePersistent { +public: inline Global() : v8::UniquePersistent() {} - template inline Global(v8::Local that) : - v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} + template + inline Global(v8::Local that) + : v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} - template - inline - Global(const v8::PersistentBase &that) : // NOLINT(runtime/explicit) - v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} + template + inline Global(const v8::PersistentBase &that) + : // NOLINT(runtime/explicit) + v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} inline void Reset() { v8::PersistentBase::Reset(); } - template - inline void Reset(const v8::Local &other) { + template inline void Reset(const v8::Local &other) { v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); } - template - inline void Reset(const v8::PersistentBase &other) { + template inline void Reset(const v8::PersistentBase &other) { v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); } - template - inline void SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { - reinterpret_cast*>(this)->SetWeak( - parameter, callback, type); + template + inline void SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { + reinterpret_cast *>(this)->SetWeak(parameter, callback, type); } }; #endif -#endif // NAN_PERSISTENT_12_INL_H_ +#endif // NAN_PERSISTENT_12_INL_H_ diff --git a/node_modules/nan/nan_persistent_pre_12_inl.h b/node_modules/nan/nan_persistent_pre_12_inl.h index 4c9c59d..ab3e5ec 100644 --- a/node_modules/nan/nan_persistent_pre_12_inl.h +++ b/node_modules/nan/nan_persistent_pre_12_inl.h @@ -9,28 +9,23 @@ #ifndef NAN_PERSISTENT_PRE_12_INL_H_ #define NAN_PERSISTENT_PRE_12_INL_H_ -template -class PersistentBase { +template class PersistentBase { v8::Persistent persistent; - template - friend v8::Local New(const PersistentBase &p); - template + template friend v8::Local New(const PersistentBase &p); + template friend v8::Local New(const Persistent &p); - template - friend v8::Local New(const Global &p); - template friend class ReturnValue; + template friend v8::Local New(const Global &p); + template friend class ReturnValue; - public: - inline PersistentBase() : - persistent() {} +public: + inline PersistentBase() : persistent() {} inline void Reset() { persistent.Dispose(); persistent.Clear(); } - template - inline void Reset(const v8::Local &other) { + template inline void Reset(const v8::Local &other) { TYPE_CHECK(T, S); if (!persistent.IsEmpty()) { @@ -44,8 +39,7 @@ class PersistentBase { } } - template - inline void Reset(const PersistentBase &other) { + template inline void Reset(const PersistentBase &other) { TYPE_CHECK(T, S); if (!persistent.IsEmpty()) { @@ -63,31 +57,28 @@ class PersistentBase { inline void Empty() { persistent.Clear(); } - template + template inline bool operator==(const PersistentBase &that) const { return this->persistent == that.persistent; } - template - inline bool operator==(const v8::Local &that) const { + template inline bool operator==(const v8::Local &that) const { return this->persistent == that; } - template + template inline bool operator!=(const PersistentBase &that) const { return !operator==(that); } - template - inline bool operator!=(const v8::Local &that) const { + template inline bool operator!=(const v8::Local &that) const { return !operator==(that); } - template - inline void SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type); + template + inline void SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type); inline void ClearWeak() { persistent.ClearWeak(); } @@ -99,47 +90,43 @@ class PersistentBase { inline bool IsWeak() const { return persistent.IsWeak(); } - private: - inline explicit PersistentBase(v8::Persistent that) : - persistent(that) { } +private: + inline explicit PersistentBase(v8::Persistent that) : persistent(that) {} inline explicit PersistentBase(T *val) : persistent(val) {} - template friend class Persistent; - template friend class Global; + template friend class Persistent; + template friend class Global; friend class ObjectWrap; }; -template -class NonCopyablePersistentTraits { - public: - typedef Persistent > - NonCopyablePersistent; +template class NonCopyablePersistentTraits { +public: + typedef Persistent> NonCopyablePersistent; static const bool kResetInDestructor = false; - template + template inline static void Copy(const Persistent &source, - NonCopyablePersistent *dest) { + NonCopyablePersistent *dest) { Uncompilable(); } - template inline static void Uncompilable() { + template inline static void Uncompilable() { TYPE_CHECK(O, v8::Primitive); } }; -template -struct CopyablePersistentTraits { - typedef Persistent > CopyablePersistent; +template struct CopyablePersistentTraits { + typedef Persistent> CopyablePersistent; static const bool kResetInDestructor = true; - template + template static inline void Copy(const Persistent &source, - CopyablePersistent *dest) {} + CopyablePersistent *dest) {} }; -template class Persistent : - public PersistentBase { - public: +template class Persistent : public PersistentBase { +public: inline Persistent() {} - template inline Persistent(v8::Handle that) + template + inline Persistent(v8::Handle that) : PersistentBase(v8::Persistent::New(that)) { TYPE_CHECK(T, S); } @@ -148,9 +135,8 @@ template class Persistent : Copy(that); } - template - inline Persistent(const Persistent &that) : - PersistentBase() { + template + inline Persistent(const Persistent &that) : PersistentBase() { Copy(that); } @@ -166,13 +152,14 @@ template class Persistent : } inline ~Persistent() { - if (M::kResetInDestructor) this->Reset(); + if (M::kResetInDestructor) + this->Reset(); } - private: +private: inline T *operator*() const { return *PersistentBase::persistent; } - template + template inline void Copy(const Persistent &that) { TYPE_CHECK(T, S); @@ -185,40 +172,38 @@ template class Persistent : } }; -template -class Global : public PersistentBase { +template class Global : public PersistentBase { struct RValue { - inline explicit RValue(Global* obj) : object(obj) {} - Global* object; + inline explicit RValue(Global *obj) : object(obj) {} + Global *object; }; - public: - inline Global() : PersistentBase(0) { } +public: + inline Global() : PersistentBase(0) {} template - inline Global(v8::Local that) // NOLINT(runtime/explicit) + inline Global(v8::Local that) // NOLINT(runtime/explicit) : PersistentBase(v8::Persistent::New(that)) { TYPE_CHECK(T, S); } template - inline Global(const PersistentBase &that) // NOLINT(runtime/explicit) - : PersistentBase(that) { + inline Global(const PersistentBase &that) // NOLINT(runtime/explicit) + : PersistentBase(that) { TYPE_CHECK(T, S); } /** * Move constructor. */ - inline Global(RValue rvalue) // NOLINT(runtime/explicit) - : PersistentBase(rvalue.object->persistent) { + inline Global(RValue rvalue) // NOLINT(runtime/explicit) + : PersistentBase(rvalue.object->persistent) { rvalue.object->Reset(); } inline ~Global() { this->Reset(); } /** * Move via assignment. */ - template - inline Global &operator=(Global rhs) { + template inline Global &operator=(Global rhs) { TYPE_CHECK(T, S); this->Reset(rhs.persistent); rhs.Reset(); @@ -233,10 +218,10 @@ class Global : public PersistentBase { */ Global Pass() { return Global(RValue(this)); } - private: +private: Global(Global &); void operator=(Global &); - template friend class ReturnValue; + template friend class ReturnValue; }; -#endif // NAN_PERSISTENT_PRE_12_INL_H_ +#endif // NAN_PERSISTENT_PRE_12_INL_H_ diff --git a/node_modules/nan/nan_private.h b/node_modules/nan/nan_private.h index 15f44cc..3aabe5e 100644 --- a/node_modules/nan/nan_private.h +++ b/node_modules/nan/nan_private.h @@ -9,8 +9,8 @@ #ifndef NAN_PRIVATE_H_ #define NAN_PRIVATE_H_ -inline Maybe -HasPrivate(v8::Local object, v8::Local key) { +inline Maybe HasPrivate(v8::Local object, + v8::Local key) { HandleScope scope; #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -22,8 +22,8 @@ HasPrivate(v8::Local object, v8::Local key) { #endif } -inline MaybeLocal -GetPrivate(v8::Local object, v8::Local key) { +inline MaybeLocal GetPrivate(v8::Local object, + v8::Local key) { #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope scope(isolate); @@ -41,10 +41,9 @@ GetPrivate(v8::Local object, v8::Local key) { #endif } -inline Maybe SetPrivate( - v8::Local object, - v8::Local key, - v8::Local value) { +inline Maybe SetPrivate(v8::Local object, + v8::Local key, + v8::Local value) { #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION HandleScope scope; v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -56,9 +55,8 @@ inline Maybe SetPrivate( #endif } -inline Maybe DeletePrivate( - v8::Local object, - v8::Local key) { +inline Maybe DeletePrivate(v8::Local object, + v8::Local key) { #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION HandleScope scope; v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -69,5 +67,4 @@ inline Maybe DeletePrivate( #endif } -#endif // NAN_PRIVATE_H_ - +#endif // NAN_PRIVATE_H_ diff --git a/node_modules/nan/nan_scriptorigin.h b/node_modules/nan/nan_scriptorigin.h index 04e55cf..48ce37a 100644 --- a/node_modules/nan/nan_scriptorigin.h +++ b/node_modules/nan/nan_scriptorigin.h @@ -10,84 +10,80 @@ #define NAN_SCRIPTORIGIN_H_ class ScriptOrigin : public v8::ScriptOrigin { - public: - -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 11 \ - && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 7) - explicit ScriptOrigin(v8::Local name) : - v8::ScriptOrigin(name) {} +public: +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 11 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION > 7) + explicit ScriptOrigin(v8::Local name) : v8::ScriptOrigin(name) {} - ScriptOrigin(v8::Local name - , v8::Local line) : - v8::ScriptOrigin(name - , To(line).FromMaybe(0)) {} + ScriptOrigin(v8::Local name, v8::Local line) + : v8::ScriptOrigin(name, To(line).FromMaybe(0)) {} - ScriptOrigin(v8::Local name - , v8::Local line - , v8::Local column) : - v8::ScriptOrigin(name - , To(line).FromMaybe(0) - , To(column).FromMaybe(0)) {} -#elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \ - (V8_MAJOR_VERSION == 9 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 0\ - || (V8_MINOR_VERSION == 0 && defined(V8_BUILD_NUMBER) \ - && V8_BUILD_NUMBER >= 1))))) - explicit ScriptOrigin(v8::Local name) : - v8::ScriptOrigin(v8::Isolate::GetCurrent(), name) {} + ScriptOrigin(v8::Local name, v8::Local line, + v8::Local column) + : v8::ScriptOrigin(name, To(line).FromMaybe(0), + To(column).FromMaybe(0)){} +#elif defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 9 || \ + (V8_MAJOR_VERSION == 9 && \ + (defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 0 || \ + (V8_MINOR_VERSION == 0 && defined(V8_BUILD_NUMBER) && \ + V8_BUILD_NUMBER >= 1))))) + explicit ScriptOrigin(v8::Local name) + : v8::ScriptOrigin(v8::Isolate::GetCurrent(), name) {} - ScriptOrigin(v8::Local name - , v8::Local line) : - v8::ScriptOrigin(v8::Isolate::GetCurrent() - , name - , To(line).FromMaybe(0)) {} + ScriptOrigin(v8::Local name, v8::Local line) + : v8::ScriptOrigin(v8::Isolate::GetCurrent(), name, + To(line).FromMaybe(0)) {} - ScriptOrigin(v8::Local name - , v8::Local line - , v8::Local column) : - v8::ScriptOrigin(v8::Isolate::GetCurrent() - , name - , To(line).FromMaybe(0) - , To(column).FromMaybe(0)) {} -#elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 8 || \ - (V8_MAJOR_VERSION == 8 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 9\ - || (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) \ - && V8_BUILD_NUMBER >= 45))))) + ScriptOrigin(v8::Local name, v8::Local line, + v8::Local column) + : v8::ScriptOrigin(v8::Isolate::GetCurrent(), name, + To(line).FromMaybe(0), + To(column).FromMaybe(0)){} +#elif defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 8 || \ + (V8_MAJOR_VERSION == 8 && \ + (defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 9 || \ + (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) && \ + V8_BUILD_NUMBER >= 45))))) explicit ScriptOrigin(v8::Local name) : v8::ScriptOrigin(name) {} - ScriptOrigin(v8::Local name - , v8::Local line) : - v8::ScriptOrigin(name, To(line).FromMaybe(0)) {} + ScriptOrigin(v8::Local name, v8::Local line) + : v8::ScriptOrigin(name, To(line).FromMaybe(0)) {} - ScriptOrigin(v8::Local name - , v8::Local line - , v8::Local column) : - v8::ScriptOrigin(name - , To(line).FromMaybe(0) - , To(column).FromMaybe(0)) {} + ScriptOrigin(v8::Local name, v8::Local line, + v8::Local column) + : v8::ScriptOrigin(name, To(line).FromMaybe(0), + To(column).FromMaybe(0)) {} #else explicit ScriptOrigin(v8::Local name) : v8::ScriptOrigin(name) {} - ScriptOrigin(v8::Local name - , v8::Local line) : v8::ScriptOrigin(name, line) {} + ScriptOrigin(v8::Local name, v8::Local line) + : v8::ScriptOrigin(name, line) {} - ScriptOrigin(v8::Local name - , v8::Local line - , v8::Local column) : - v8::ScriptOrigin(name, line, column) {} + ScriptOrigin(v8::Local name, v8::Local line, + v8::Local column) + : v8::ScriptOrigin(name, line, column){} #endif -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 8 || \ - (V8_MAJOR_VERSION == 8 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 9\ - || (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) \ - && V8_BUILD_NUMBER >= 45))))) - v8::Local ResourceLineOffset() const { - return New(LineOffset()); - } +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 8 || \ + (V8_MAJOR_VERSION == 8 && \ + (defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 9 || \ + (V8_MINOR_VERSION == 9 && defined(V8_BUILD_NUMBER) && \ + V8_BUILD_NUMBER >= 45))))) + v8::Local ResourceLineOffset() const { + return New(LineOffset()); + } - v8::Local ResourceColumnOffset() const { - return New(ColumnOffset()); - } + v8::Local ResourceColumnOffset() const { + return New(ColumnOffset()); + } #endif }; -#endif // NAN_SCRIPTORIGIN_H_ +#endif // NAN_SCRIPTORIGIN_H_ diff --git a/node_modules/nan/nan_string_bytes.h b/node_modules/nan/nan_string_bytes.h index a2e6437..6c9dcf1 100644 --- a/node_modules/nan/nan_string_bytes.h +++ b/node_modules/nan/nan_string_bytes.h @@ -31,76 +31,73 @@ using v8::Object; using v8::String; using v8::Value; - //// Base 64 //// #define base64_encoded_size(size) ((size + 2 - ((size + 2) % 3)) / 3 * 4) - - //// HEX //// -static bool contains_non_ascii_slow(const char* buf, size_t len) { +static bool contains_non_ascii_slow(const char *buf, size_t len) { for (size_t i = 0; i < len; ++i) { - if (buf[i] & 0x80) return true; + if (buf[i] & 0x80) + return true; } return false; } - -static bool contains_non_ascii(const char* src, size_t len) { +static bool contains_non_ascii(const char *src, size_t len) { if (len < 16) { return contains_non_ascii_slow(src, len); } - const unsigned bytes_per_word = sizeof(void*); + const unsigned bytes_per_word = sizeof(void *); const unsigned align_mask = bytes_per_word - 1; const unsigned unaligned = reinterpret_cast(src) & align_mask; if (unaligned > 0) { const unsigned n = bytes_per_word - unaligned; - if (contains_non_ascii_slow(src, n)) return true; + if (contains_non_ascii_slow(src, n)) + return true; src += n; len -= n; } - #if defined(__x86_64__) || defined(_WIN64) const uintptr_t mask = 0x8080808080808080ll; #else const uintptr_t mask = 0x80808080l; #endif - const uintptr_t* srcw = reinterpret_cast(src); + const uintptr_t *srcw = reinterpret_cast(src); for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { - if (srcw[i] & mask) return true; + if (srcw[i] & mask) + return true; } const unsigned remainder = len & align_mask; if (remainder > 0) { const size_t offset = len - remainder; - if (contains_non_ascii_slow(src + offset, remainder)) return true; + if (contains_non_ascii_slow(src + offset, remainder)) + return true; } return false; } - -static void force_ascii_slow(const char* src, char* dst, size_t len) { +static void force_ascii_slow(const char *src, char *dst, size_t len) { for (size_t i = 0; i < len; ++i) { dst[i] = src[i] & 0x7f; } } - -static void force_ascii(const char* src, char* dst, size_t len) { +static void force_ascii(const char *src, char *dst, size_t len) { if (len < 16) { force_ascii_slow(src, dst, len); return; } - const unsigned bytes_per_word = sizeof(void*); + const unsigned bytes_per_word = sizeof(void *); const unsigned align_mask = bytes_per_word - 1; const unsigned src_unalign = reinterpret_cast(src) & align_mask; const unsigned dst_unalign = reinterpret_cast(dst) & align_mask; @@ -124,8 +121,8 @@ static void force_ascii(const char* src, char* dst, size_t len) { const uintptr_t mask = ~0x80808080l; #endif - const uintptr_t* srcw = reinterpret_cast(src); - uintptr_t* dstw = reinterpret_cast(dst); + const uintptr_t *srcw = reinterpret_cast(src); + uintptr_t *dstw = reinterpret_cast(dst); for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { dstw[i] = srcw[i] & mask; @@ -138,14 +135,11 @@ static void force_ascii(const char* src, char* dst, size_t len) { } } - -static size_t base64_encode(const char* src, - size_t slen, - char* dst, +static size_t base64_encode(const char *src, size_t slen, char *dst, size_t dlen) { // We know how much we'll write, just make sure that there's space. assert(dlen >= base64_encoded_size(slen) && - "not enough space provided for base64 encode"); + "not enough space provided for base64 encode"); dlen = base64_encoded_size(slen); @@ -180,33 +174,31 @@ static size_t base64_encode(const char* src, if (n != slen) { switch (slen - n) { - case 1: - a = src[i + 0] & 0xff; - dst[k + 0] = table[a >> 2]; - dst[k + 1] = table[(a & 3) << 4]; - dst[k + 2] = '='; - dst[k + 3] = '='; - break; - - case 2: - a = src[i + 0] & 0xff; - b = src[i + 1] & 0xff; - dst[k + 0] = table[a >> 2]; - dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; - dst[k + 2] = table[(b & 0x0f) << 2]; - dst[k + 3] = '='; - break; + case 1: + a = src[i + 0] & 0xff; + dst[k + 0] = table[a >> 2]; + dst[k + 1] = table[(a & 3) << 4]; + dst[k + 2] = '='; + dst[k + 3] = '='; + break; + + case 2: + a = src[i + 0] & 0xff; + b = src[i + 1] & 0xff; + dst[k + 0] = table[a >> 2]; + dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; + dst[k + 2] = table[(b & 0x0f) << 2]; + dst[k + 3] = '='; + break; } } return dlen; } - -static size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) { +static size_t hex_encode(const char *src, size_t slen, char *dst, size_t dlen) { // We know how much we'll write, just make sure that there's space. - assert(dlen >= slen * 2 && - "not enough space provided for hex encode"); + assert(dlen >= slen * 2 && "not enough space provided for hex encode"); dlen = slen * 2; for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) { @@ -219,10 +211,7 @@ static size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) { return dlen; } - - -static Local Encode(const char* buf, - size_t buflen, +static Local Encode(const char *buf, size_t buflen, enum Encoding encoding) { assert(buflen <= node::Buffer::kMaxLength); if (!buflen && encoding != BUFFER) @@ -230,69 +219,69 @@ static Local Encode(const char* buf, Local val; switch (encoding) { - case BUFFER: - return CopyBuffer(buf, buflen).ToLocalChecked(); - - case ASCII: - if (contains_non_ascii(buf, buflen)) { - char* out = new char[buflen]; - force_ascii(buf, out, buflen); - val = New(out, buflen).ToLocalChecked(); - delete[] out; - } else { - val = New(buf, buflen).ToLocalChecked(); - } - break; - - case UTF8: + case BUFFER: + return CopyBuffer(buf, buflen).ToLocalChecked(); + + case ASCII: + if (contains_non_ascii(buf, buflen)) { + char *out = new char[buflen]; + force_ascii(buf, out, buflen); + val = New(out, buflen).ToLocalChecked(); + delete[] out; + } else { val = New(buf, buflen).ToLocalChecked(); - break; - - case BINARY: { - // TODO(isaacs) use ExternalTwoByteString? - const unsigned char *cbuf = reinterpret_cast(buf); - uint16_t * twobytebuf = new uint16_t[buflen]; - for (size_t i = 0; i < buflen; i++) { - // XXX is the following line platform independent? - twobytebuf[i] = cbuf[i]; - } - val = New(twobytebuf, buflen).ToLocalChecked(); - delete[] twobytebuf; - break; } + break; + + case UTF8: + val = New(buf, buflen).ToLocalChecked(); + break; + + case BINARY: { + // TODO(isaacs) use ExternalTwoByteString? + const unsigned char *cbuf = reinterpret_cast(buf); + uint16_t *twobytebuf = new uint16_t[buflen]; + for (size_t i = 0; i < buflen; i++) { + // XXX is the following line platform independent? + twobytebuf[i] = cbuf[i]; + } + val = New(twobytebuf, buflen).ToLocalChecked(); + delete[] twobytebuf; + break; + } - case BASE64: { - size_t dlen = base64_encoded_size(buflen); - char* dst = new char[dlen]; + case BASE64: { + size_t dlen = base64_encoded_size(buflen); + char *dst = new char[dlen]; - size_t written = base64_encode(buf, buflen, dst, dlen); - assert(written == dlen); + size_t written = base64_encode(buf, buflen, dst, dlen); + assert(written == dlen); - val = New(dst, dlen).ToLocalChecked(); - delete[] dst; - break; - } + val = New(dst, dlen).ToLocalChecked(); + delete[] dst; + break; + } - case UCS2: { - const uint16_t* data = reinterpret_cast(buf); - val = New(data, buflen / 2).ToLocalChecked(); - break; - } + case UCS2: { + const uint16_t *data = reinterpret_cast(buf); + val = New(data, buflen / 2).ToLocalChecked(); + break; + } - case HEX: { - size_t dlen = buflen * 2; - char* dst = new char[dlen]; - size_t written = hex_encode(buf, buflen, dst, dlen); - assert(written == dlen); + case HEX: { + size_t dlen = buflen * 2; + char *dst = new char[dlen]; + size_t written = hex_encode(buf, buflen, dst, dlen); + assert(written == dlen); - val = New(dst, dlen).ToLocalChecked(); - delete[] dst; - break; - } + val = New(dst, dlen).ToLocalChecked(); + delete[] dst; + break; + } - default: - assert(0 && "unknown encoding"); - break; + default: + assert(0 && "unknown encoding"); + break; } return val; @@ -300,6 +289,6 @@ static Local Encode(const char* buf, #undef base64_encoded_size -} // end of namespace imp +} // end of namespace imp -#endif // NAN_STRING_BYTES_H_ +#endif // NAN_STRING_BYTES_H_ diff --git a/node_modules/nan/nan_typedarray_contents.h b/node_modules/nan/nan_typedarray_contents.h index c6ac8a4..1290854 100644 --- a/node_modules/nan/nan_typedarray_contents.h +++ b/node_modules/nan/nan_typedarray_contents.h @@ -9,24 +9,25 @@ #ifndef NAN_TYPEDARRAY_CONTENTS_H_ #define NAN_TYPEDARRAY_CONTENTS_H_ -template -class TypedArrayContents { - public: - inline explicit TypedArrayContents(v8::Local from) : - length_(0), data_(NULL) { +template class TypedArrayContents { +public: + inline explicit TypedArrayContents(v8::Local from) + : length_(0), data_(NULL) { HandleScope scope; size_t length = 0; - void* data = NULL; + void *data = NULL; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) if (from->IsArrayBufferView()) { v8::Local array = - v8::Local::Cast(from); + v8::Local::Cast(from); - const size_t byte_length = array->ByteLength(); + const size_t byte_length = array->ByteLength(); const ptrdiff_t byte_offset = array->ByteOffset(); v8::Local buffer = array->Buffer(); @@ -34,9 +35,10 @@ class TypedArrayContents { // Actually it's 7.9 here but this would lead to ABI issues with Node.js 13 // using 7.8 till 13.2.0. #if (V8_MAJOR_VERSION >= 8) - data = static_cast(buffer->GetBackingStore()->Data()) + byte_offset; + data = + static_cast(buffer->GetBackingStore()->Data()) + byte_offset; #else - data = static_cast(buffer->GetContents().Data()) + byte_offset; + data = static_cast(buffer->GetContents().Data()) + byte_offset; #endif } @@ -45,18 +47,18 @@ class TypedArrayContents { if (from->IsObject() && !from->IsNull()) { v8::Local array = v8::Local::Cast(from); - MaybeLocal buffer = Get(array, - New("buffer").ToLocalChecked()); - MaybeLocal byte_length = Get(array, - New("byteLength").ToLocalChecked()); - MaybeLocal byte_offset = Get(array, - New("byteOffset").ToLocalChecked()); + MaybeLocal buffer = + Get(array, New("buffer").ToLocalChecked()); + MaybeLocal byte_length = + Get(array, New("byteLength").ToLocalChecked()); + MaybeLocal byte_offset = + Get(array, New("byteOffset").ToLocalChecked()); - if (!buffer.IsEmpty() && - !byte_length.IsEmpty() && byte_length.ToLocalChecked()->IsUint32() && - !byte_offset.IsEmpty() && byte_offset.ToLocalChecked()->IsUint32()) { + if (!buffer.IsEmpty() && !byte_length.IsEmpty() && + byte_length.ToLocalChecked()->IsUint32() && !byte_offset.IsEmpty() && + byte_offset.ToLocalChecked()->IsUint32()) { data = array->GetIndexedPropertiesExternalArrayData(); - if(data) { + if (data) { length = byte_length.ToLocalChecked()->Uint32Value() / sizeof(T); } } @@ -65,32 +67,30 @@ class TypedArrayContents { #endif #if defined(_MSC_VER) && _MSC_VER >= 1900 || __cplusplus >= 201103L - assert(reinterpret_cast(data) % alignof (T) == 0); + assert(reinterpret_cast(data) % alignof(T) == 0); #elif defined(_MSC_VER) && _MSC_VER >= 1600 || defined(__GNUC__) assert(reinterpret_cast(data) % __alignof(T) == 0); #else - assert(reinterpret_cast(data) % sizeof (T) == 0); + assert(reinterpret_cast(data) % sizeof(T) == 0); #endif length_ = length; - data_ = static_cast(data); + data_ = static_cast(data); } - inline size_t length() const { return length_; } - inline T* operator*() { return data_; } - inline const T* operator*() const { return data_; } + inline size_t length() const { return length_; } + inline T *operator*() { return data_; } + inline const T *operator*() const { return data_; } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(TypedArrayContents) - //Disable heap allocation + // Disable heap allocation void *operator new(size_t size); - void operator delete(void *, size_t) { - abort(); - } + void operator delete(void *, size_t) { abort(); } - size_t length_; - T* data_; + size_t length_; + T *data_; }; -#endif // NAN_TYPEDARRAY_CONTENTS_H_ +#endif // NAN_TYPEDARRAY_CONTENTS_H_ diff --git a/node_modules/nan/nan_weak.h b/node_modules/nan/nan_weak.h index 7e7ab07..ce0485c 100644 --- a/node_modules/nan/nan_weak.h +++ b/node_modules/nan/nan_weak.h @@ -12,55 +12,52 @@ static const int kInternalFieldsInWeakCallback = 2; static const int kNoInternalFieldIndex = -1; -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -# define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ - v8::WeakCallbackInfo > const& -# define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ - NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ -# define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ -# define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +#define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ + v8::WeakCallbackInfo> const & +#define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ #elif NODE_MODULE_VERSION > IOJS_1_1_MODULE_VERSION -# define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ - v8::PhantomCallbackData > const& -# define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ - NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ -# define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ -# define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ + v8::PhantomCallbackData> const & +#define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ + NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ #elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION -# define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ - v8::PhantomCallbackData > const& -# define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ - v8::InternalFieldsCallbackData, void> const& -# define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ -# define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ \ + v8::PhantomCallbackData> const & +#define NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ \ + v8::InternalFieldsCallbackData, void> const & +#define NAN_WEAK_PARAMETER_CALLBACK_SIG_ NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_TWOFIELD_CALLBACK_SIG_ NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION -# define NAN_WEAK_CALLBACK_DATA_TYPE_ \ - v8::WeakCallbackData > const& -# define NAN_WEAK_CALLBACK_SIG_ NAN_WEAK_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_CALLBACK_DATA_TYPE_ \ + v8::WeakCallbackData> const & +#define NAN_WEAK_CALLBACK_SIG_ NAN_WEAK_CALLBACK_DATA_TYPE_ #else -# define NAN_WEAK_CALLBACK_DATA_TYPE_ void * -# define NAN_WEAK_CALLBACK_SIG_ \ - v8::Persistent, NAN_WEAK_CALLBACK_DATA_TYPE_ +#define NAN_WEAK_CALLBACK_DATA_TYPE_ void * +#define NAN_WEAK_CALLBACK_SIG_ \ + v8::Persistent, NAN_WEAK_CALLBACK_DATA_TYPE_ #endif -template -class WeakCallbackInfo { - public: - typedef void (*Callback)(const WeakCallbackInfo& data); - WeakCallbackInfo( - Persistent *persistent - , Callback callback - , void *parameter - , void *field1 = 0 - , void *field2 = 0) : - callback_(callback), isolate_(0), parameter_(parameter) { - std::memcpy(&persistent_, persistent, sizeof (v8::Persistent)); +template class WeakCallbackInfo { +public: + typedef void (*Callback)(const WeakCallbackInfo &data); + WeakCallbackInfo(Persistent *persistent, Callback callback, + void *parameter, void *field1 = 0, void *field2 = 0) + : callback_(callback), isolate_(0), parameter_(parameter) { + std::memcpy(&persistent_, persistent, sizeof(v8::Persistent)); internal_fields_[0] = field1; internal_fields_[1] = field2; } inline v8::Isolate *GetIsolate() const { return isolate_; } - inline T *GetParameter() const { return static_cast(parameter_); } + inline T *GetParameter() const { return static_cast(parameter_); } inline void *GetInternalField(int index) const { assert((index == 0 || index == 1) && "internal field index out of bounds"); if (index == 0) { @@ -70,51 +67,53 @@ class WeakCallbackInfo { } } - private: +private: NAN_DISALLOW_ASSIGN_COPY_MOVE(WeakCallbackInfo) Callback callback_; v8::Isolate *isolate_; void *parameter_; void *internal_fields_[kInternalFieldsInWeakCallback]; v8::Persistent persistent_; - template friend class Persistent; - template friend class PersistentBase; + template friend class Persistent; + template friend class PersistentBase; #if NODE_MODULE_VERSION <= NODE_0_12_MODULE_VERSION -# if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION - template - static void invoke(NAN_WEAK_CALLBACK_SIG_ data); - template +#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION + template static void invoke(NAN_WEAK_CALLBACK_SIG_ data); + template static WeakCallbackInfo *unwrap(NAN_WEAK_CALLBACK_DATA_TYPE_ data); -# else +#else static void invoke(NAN_WEAK_CALLBACK_SIG_ data); static WeakCallbackInfo *unwrap(NAN_WEAK_CALLBACK_DATA_TYPE_ data); -# endif +#endif #else -# if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) - template +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) + template static void invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data); - template + template static void invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data); -# else +#else static void invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data); static void invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data); -# endif - static WeakCallbackInfo *unwrapparameter( - NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data); - static WeakCallbackInfo *unwraptwofield( - NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data); +#endif + static WeakCallbackInfo * + unwrapparameter(NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data); + static WeakCallbackInfo * + unwraptwofield(NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data); #endif }; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) - -template -template -void -WeakCallbackInfo::invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { +template +template +void WeakCallbackInfo::invokeparameter( + NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { WeakCallbackInfo *cbinfo = unwrapparameter(data); if (isFirstPass) { cbinfo->persistent_.Reset(); @@ -125,10 +124,9 @@ WeakCallbackInfo::invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { } } -template -template -void -WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { +template +template +void WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { WeakCallbackInfo *cbinfo = unwraptwofield(data); if (isFirstPass) { cbinfo->persistent_.Reset(); @@ -139,20 +137,20 @@ WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { } } -template +template WeakCallbackInfo *WeakCallbackInfo::unwrapparameter( NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data) { WeakCallbackInfo *cbinfo = - static_cast*>(data.GetParameter()); + static_cast *>(data.GetParameter()); cbinfo->isolate_ = data.GetIsolate(); return cbinfo; } -template +template WeakCallbackInfo *WeakCallbackInfo::unwraptwofield( NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data) { WeakCallbackInfo *cbinfo = - static_cast*>(data.GetInternalField(0)); + static_cast *>(data.GetInternalField(0)); cbinfo->isolate_ = data.GetIsolate(); return cbinfo; } @@ -161,40 +159,39 @@ WeakCallbackInfo *WeakCallbackInfo::unwraptwofield( #undef NAN_WEAK_TWOFIELD_CALLBACK_SIG_ #undef NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ #undef NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ -# elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION +#elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION -template -void -WeakCallbackInfo::invokeparameter(NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { +template +void WeakCallbackInfo::invokeparameter( + NAN_WEAK_PARAMETER_CALLBACK_SIG_ data) { WeakCallbackInfo *cbinfo = unwrapparameter(data); cbinfo->persistent_.Reset(); cbinfo->callback_(*cbinfo); delete cbinfo; } -template -void -WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { +template +void WeakCallbackInfo::invoketwofield(NAN_WEAK_TWOFIELD_CALLBACK_SIG_ data) { WeakCallbackInfo *cbinfo = unwraptwofield(data); cbinfo->persistent_.Reset(); cbinfo->callback_(*cbinfo); delete cbinfo; } -template +template WeakCallbackInfo *WeakCallbackInfo::unwrapparameter( NAN_WEAK_PARAMETER_CALLBACK_DATA_TYPE_ data) { WeakCallbackInfo *cbinfo = - static_cast*>(data.GetParameter()); + static_cast *>(data.GetParameter()); cbinfo->isolate_ = data.GetIsolate(); return cbinfo; } -template +template WeakCallbackInfo *WeakCallbackInfo::unwraptwofield( NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ data) { WeakCallbackInfo *cbinfo = - static_cast*>(data.GetInternalField1()); + static_cast *>(data.GetInternalField1()); cbinfo->isolate_ = data.GetIsolate(); return cbinfo; } @@ -205,8 +202,8 @@ WeakCallbackInfo *WeakCallbackInfo::unwraptwofield( #undef NAN_WEAK_TWOFIELD_CALLBACK_DATA_TYPE_ #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION -template -template +template +template void WeakCallbackInfo::invoke(NAN_WEAK_CALLBACK_SIG_ data) { WeakCallbackInfo *cbinfo = unwrap(data); cbinfo->persistent_.Reset(); @@ -214,13 +211,12 @@ void WeakCallbackInfo::invoke(NAN_WEAK_CALLBACK_SIG_ data) { delete cbinfo; } -template -template -WeakCallbackInfo *WeakCallbackInfo::unwrap( - NAN_WEAK_CALLBACK_DATA_TYPE_ data) { +template +template +WeakCallbackInfo * +WeakCallbackInfo::unwrap(NAN_WEAK_CALLBACK_DATA_TYPE_ data) { void *parameter = data.GetParameter(); - WeakCallbackInfo *cbinfo = - static_cast*>(parameter); + WeakCallbackInfo *cbinfo = static_cast *>(parameter); cbinfo->isolate_ = data.GetIsolate(); return cbinfo; } @@ -229,7 +225,7 @@ WeakCallbackInfo *WeakCallbackInfo::unwrap( #undef NAN_WEAK_CALLBACK_DATA_TYPE_ #else -template +template void WeakCallbackInfo::invoke(NAN_WEAK_CALLBACK_SIG_ data) { WeakCallbackInfo *cbinfo = unwrap(data); cbinfo->persistent_.Dispose(); @@ -238,11 +234,10 @@ void WeakCallbackInfo::invoke(NAN_WEAK_CALLBACK_SIG_ data) { delete cbinfo; } -template -WeakCallbackInfo *WeakCallbackInfo::unwrap( - NAN_WEAK_CALLBACK_DATA_TYPE_ data) { - WeakCallbackInfo *cbinfo = - static_cast*>(data); +template +WeakCallbackInfo * +WeakCallbackInfo::unwrap(NAN_WEAK_CALLBACK_DATA_TYPE_ data) { + WeakCallbackInfo *cbinfo = static_cast *>(data); cbinfo->isolate_ = v8::Isolate::GetCurrent(); return cbinfo; } @@ -251,26 +246,25 @@ WeakCallbackInfo *WeakCallbackInfo::unwrap( #undef NAN_WEAK_CALLBACK_DATA_TYPE_ #endif -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ - (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) -template -template -inline void Persistent::SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 3)) +template +template +inline void +Persistent::SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { WeakCallbackInfo

*wcbd; if (type == WeakCallbackType::kParameter) { wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , parameter); + reinterpret_cast *>(this), callback, parameter); v8::PersistentBase::SetWeak( - wcbd - , WeakCallbackInfo

::template invokeparameter - , type); + wcbd, WeakCallbackInfo

::template invokeparameter, type); } else { - v8::Local* self_v(reinterpret_cast*>(this)); + v8::Local *self_v( + reinterpret_cast *>(this)); assert((*self_v)->IsObject()); v8::Local self((*self_v).As()); int count = self->InternalFieldCount(); @@ -279,36 +273,30 @@ inline void Persistent::SetWeak( internal_fields[i] = self->GetAlignedPointerFromInternalField(i); } wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , 0 - , internal_fields[0] - , internal_fields[1]); + reinterpret_cast *>(this), callback, 0, + internal_fields[0], internal_fields[1]); self->SetAlignedPointerInInternalField(0, wcbd); v8::PersistentBase::SetWeak( - static_cast*>(0) - , WeakCallbackInfo

::template invoketwofield - , type); + static_cast *>(0), + WeakCallbackInfo

::template invoketwofield, type); } } #elif NODE_MODULE_VERSION > IOJS_1_1_MODULE_VERSION -template -template -inline void Persistent::SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { +template +template +inline void +Persistent::SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { WeakCallbackInfo

*wcbd; if (type == WeakCallbackType::kParameter) { wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , parameter); - v8::PersistentBase::SetPhantom( - wcbd - , WeakCallbackInfo

::invokeparameter); + reinterpret_cast *>(this), callback, parameter); + v8::PersistentBase::SetPhantom(wcbd, + WeakCallbackInfo

::invokeparameter); } else { - v8::Local* self_v(reinterpret_cast*>(this)); + v8::Local *self_v( + reinterpret_cast *>(this)); assert((*self_v)->IsObject()); v8::Local self((*self_v).As()); int count = self->InternalFieldCount(); @@ -317,37 +305,30 @@ inline void Persistent::SetWeak( internal_fields[i] = self->GetAlignedPointerFromInternalField(i); } wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , 0 - , internal_fields[0] - , internal_fields[1]); + reinterpret_cast *>(this), callback, 0, + internal_fields[0], internal_fields[1]); self->SetAlignedPointerInInternalField(0, wcbd); - v8::PersistentBase::SetPhantom( - static_cast*>(0) - , WeakCallbackInfo

::invoketwofield - , 0 - , count > 1 ? 1 : kNoInternalFieldIndex); + v8::PersistentBase::SetPhantom(static_cast *>(0), + WeakCallbackInfo

::invoketwofield, 0, + count > 1 ? 1 : kNoInternalFieldIndex); } } #elif NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION -template -template -inline void Persistent::SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { +template +template +inline void +Persistent::SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { WeakCallbackInfo

*wcbd; if (type == WeakCallbackType::kParameter) { wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , parameter); - v8::PersistentBase::SetPhantom( - wcbd - , WeakCallbackInfo

::invokeparameter); + reinterpret_cast *>(this), callback, parameter); + v8::PersistentBase::SetPhantom(wcbd, + WeakCallbackInfo

::invokeparameter); } else { - v8::Local* self_v(reinterpret_cast*>(this)); + v8::Local *self_v( + reinterpret_cast *>(this)); assert((*self_v)->IsObject()); v8::Local self((*self_v).As()); int count = self->InternalFieldCount(); @@ -356,34 +337,28 @@ inline void Persistent::SetWeak( internal_fields[i] = self->GetAlignedPointerFromInternalField(i); } wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , 0 - , internal_fields[0] - , internal_fields[1]); + reinterpret_cast *>(this), callback, 0, + internal_fields[0], internal_fields[1]); self->SetAlignedPointerInInternalField(0, wcbd); - v8::PersistentBase::SetPhantom( - WeakCallbackInfo

::invoketwofield - , 0 - , count > 1 ? 1 : kNoInternalFieldIndex); + v8::PersistentBase::SetPhantom(WeakCallbackInfo

::invoketwofield, 0, + count > 1 ? 1 : kNoInternalFieldIndex); } } #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION -template -template -inline void Persistent::SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { +template +template +inline void +Persistent::SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { WeakCallbackInfo

*wcbd; if (type == WeakCallbackType::kParameter) { wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , parameter); + reinterpret_cast *>(this), callback, parameter); v8::PersistentBase::SetWeak(wcbd, WeakCallbackInfo

::invoke); } else { - v8::Local* self_v(reinterpret_cast*>(this)); + v8::Local *self_v( + reinterpret_cast *>(this)); assert((*self_v)->IsObject()); v8::Local self((*self_v).As()); int count = self->InternalFieldCount(); @@ -392,30 +367,26 @@ inline void Persistent::SetWeak( internal_fields[i] = self->GetAlignedPointerFromInternalField(i); } wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , 0 - , internal_fields[0] - , internal_fields[1]); + reinterpret_cast *>(this), callback, 0, + internal_fields[0], internal_fields[1]); v8::PersistentBase::SetWeak(wcbd, WeakCallbackInfo

::invoke); } } #else -template -template -inline void PersistentBase::SetWeak( - P *parameter - , typename WeakCallbackInfo

::Callback callback - , WeakCallbackType type) { +template +template +inline void +PersistentBase::SetWeak(P *parameter, + typename WeakCallbackInfo

::Callback callback, + WeakCallbackType type) { WeakCallbackInfo

*wcbd; if (type == WeakCallbackType::kParameter) { wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , parameter); + reinterpret_cast *>(this), callback, parameter); persistent.MakeWeak(wcbd, WeakCallbackInfo

::invoke); } else { - v8::Local* self_v(reinterpret_cast*>(this)); + v8::Local *self_v( + reinterpret_cast *>(this)); assert((*self_v)->IsObject()); v8::Local self((*self_v).As()); int count = self->InternalFieldCount(); @@ -424,14 +395,11 @@ inline void PersistentBase::SetWeak( internal_fields[i] = self->GetPointerFromInternalField(i); } wcbd = new WeakCallbackInfo

( - reinterpret_cast*>(this) - , callback - , 0 - , internal_fields[0] - , internal_fields[1]); + reinterpret_cast *>(this), callback, 0, + internal_fields[0], internal_fields[1]); persistent.MakeWeak(wcbd, WeakCallbackInfo

::invoke); } } #endif -#endif // NAN_WEAK_H_ +#endif // NAN_WEAK_H_ diff --git a/scripts.js b/scripts.js index f08df1e..40f3df0 100644 --- a/scripts.js +++ b/scripts.js @@ -1,115 +1,120 @@ -document.addEventListener('DOMContentLoaded', () => { - // Fetch and display the user's IP - async function getMyIP() { - try { - const response = await fetch('https://api.ipify.org?format=json'); - const data = await response.json(); - document.getElementById('my-ip').textContent = `Your IP: ${data.ip}`; - } catch (error) { - showError('Error fetching IP.'); - console.error(error); - } +document.addEventListener("DOMContentLoaded", () => { + // Fetch and display the user's IP + async function getMyIP() { + try { + const response = await fetch("https://api.ipify.org?format=json"); + const data = await response.json(); + document.getElementById("my-ip").textContent = `Your IP: ${data.ip}`; + } catch (error) { + showError("Error fetching IP."); + console.error(error); } + } - // IP Lookup / Geolocation with AI integration - async function lookupIP() { - const ip = document.getElementById('ip-input').value; - if (!validateIP(ip)) { - showError('Please enter a valid IP address.'); - return; - } - try { - showLoading(); - const aiPrediction = await getAIIPPrediction(ip); // AI-based prediction - const response = await fetch(`https://ip-api.com/json/${ip}`); - const data = await response.json(); - if (data.status === 'success') { - document.getElementById('ip-info').textContent = - `Location: ${data.city}, ${data.region}, ${data.country} (ISP: ${data.isp}) - AI Prediction: ${aiPrediction}`; - } else { - showError('Invalid IP address.'); - } - } catch (error) { - showError('Error fetching data.'); - console.error(error); - } finally { - hideLoading(); - } + // IP Lookup / Geolocation with AI integration + async function lookupIP() { + const ip = document.getElementById("ip-input").value; + if (!validateIP(ip)) { + showError("Please enter a valid IP address."); + return; } - - // AI-based IP Prediction (AI model can be integrated here) - async function getAIIPPrediction(ip) { - const aiApi = 'https://your-ai-api.com/predict'; // Your AI API endpoint - const response = await fetch(`${aiApi}?ip=${ip}`); - const data = await response.json(); - return data.prediction; // AI's predicted location or data + try { + showLoading(); + const aiPrediction = await getAIIPPrediction(ip); // AI-based prediction + const response = await fetch(`https://ip-api.com/json/${ip}`); + const data = await response.json(); + if (data.status === "success") { + document.getElementById("ip-info").textContent = + `Location: ${data.city}, ${data.region}, ${data.country} (ISP: ${data.isp}) - AI Prediction: ${aiPrediction}`; + } else { + showError("Invalid IP address."); + } + } catch (error) { + showError("Error fetching data."); + console.error(error); + } finally { + hideLoading(); } + } - // Internet Speed Test with AI optimization - function runSpeedTest() { - const start = Date.now(); - const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/a/a7/Logo_of_the_United_States_Department_of_Veterans_Affairs.png'; // Example file URL - fetch(imageUrl) - .then(response => response.blob()) - .then(blob => { - const end = Date.now(); - const timeTaken = (end - start) / 1000; // time in seconds - const speed = (5000000 / timeTaken / 1024).toFixed(2); // speed in KB/s - document.getElementById('speed-results').textContent = `Download speed: ${speed} KB/s`; - }) - .catch(error => { - showError('Speed test failed.'); - console.error(error); - }); - } + // AI-based IP Prediction (AI model can be integrated here) + async function getAIIPPrediction(ip) { + const aiApi = "https://your-ai-api.com/predict"; // Your AI API endpoint + const response = await fetch(`${aiApi}?ip=${ip}`); + const data = await response.json(); + return data.prediction; // AI's predicted location or data + } - // AI-powered Ping - async function ping() { - const url = document.getElementById('ping-url').value; - if (!validateURL(url)) { - showError('Please enter a valid URL.'); - return; - } - const start = Date.now(); - try { - await fetch(url, { method: 'HEAD' }); - const end = Date.now(); - document.getElementById('ping-results').textContent = `Ping: ${end - start} ms`; - } catch (error) { - showError('Ping failed.'); - console.error(error); - } - } + // Internet Speed Test with AI optimization + function runSpeedTest() { + const start = Date.now(); + const imageUrl = + "https://upload.wikimedia.org/wikipedia/commons/a/a7/Logo_of_the_United_States_Department_of_Veterans_Affairs.png"; // Example file URL + fetch(imageUrl) + .then((response) => response.blob()) + .then((blob) => { + const end = Date.now(); + const timeTaken = (end - start) / 1000; // time in seconds + const speed = (5000000 / timeTaken / 1024).toFixed(2); // speed in KB/s + document.getElementById("speed-results").textContent = + `Download speed: ${speed} KB/s`; + }) + .catch((error) => { + showError("Speed test failed."); + console.error(error); + }); + } - // Show error message - function showError(message) { - const errorMessage = document.getElementById('error-message'); - errorMessage.textContent = message; - errorMessage.style.display = 'block'; - setTimeout(() => { - errorMessage.style.display = 'none'; - }, 5000); + // AI-powered Ping + async function ping() { + const url = document.getElementById("ping-url").value; + if (!validateURL(url)) { + showError("Please enter a valid URL."); + return; } - - // Show loading indicator - function showLoading() { - document.getElementById('loading-indicator').style.display = 'block'; + const start = Date.now(); + try { + await fetch(url, { method: "HEAD" }); + const end = Date.now(); + document.getElementById("ping-results").textContent = + `Ping: ${end - start} ms`; + } catch (error) { + showError("Ping failed."); + console.error(error); } + } - // Hide loading indicator - function hideLoading() { - document.getElementById('loading-indicator').style.display = 'none'; - } + // Show error message + function showError(message) { + const errorMessage = document.getElementById("error-message"); + errorMessage.textContent = message; + errorMessage.style.display = "block"; + setTimeout(() => { + errorMessage.style.display = "none"; + }, 5000); + } - // Validate IP address format - function validateIP(ip) { - const regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; - return regex.test(ip); - } + // Show loading indicator + function showLoading() { + document.getElementById("loading-indicator").style.display = "block"; + } - // Validate URL format - function validateURL(url) { - const regex = /^(https?:\/\/)?([a-z0-9]+[.-_])*[a-z0-9]+\.[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$/i; - return regex.test(url); - } + // Hide loading indicator + function hideLoading() { + document.getElementById("loading-indicator").style.display = "none"; + } + + // Validate IP address format + function validateIP(ip) { + const regex = + /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; + return regex.test(ip); + } + + // Validate URL format + function validateURL(url) { + const regex = + /^(https?:\/\/)?(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$/i; + return regex.test(url); + } }); diff --git a/storage-service.js b/storage-service.js index 118e9af..bdf5f11 100644 --- a/storage-service.js +++ b/storage-service.js @@ -1,5 +1,5 @@ // Ensure 'storageService' is declared only once const storageService = { - // ...existing code... + // ...existing code... }; // ...existing code... diff --git a/styles.css b/styles.css index 2bcbd0e..e47cc16 100644 --- a/styles.css +++ b/styles.css @@ -1,48 +1,48 @@ body { - font-family: Arial, sans-serif; - margin: 0; - padding: 0; - line-height: 1.6; + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + line-height: 1.6; } header { - background: #333; - color: #fff; - padding: 1rem; - text-align: center; + background: #333; + color: #fff; + padding: 1rem; + text-align: center; } main { - padding: 1rem; + padding: 1rem; } section#tools div { - margin: 1rem 0; - padding: 1rem; - border: 1px solid #ddd; - border-radius: 5px; - background: #f9f9f9; + margin: 1rem 0; + padding: 1rem; + border: 1px solid #ddd; + border-radius: 5px; + background: #f9f9f9; } button { - margin-top: 0.5rem; - padding: 0.5rem 1rem; - background: #007BFF; - color: #fff; - border: none; - border-radius: 3px; - cursor: pointer; + margin-top: 0.5rem; + padding: 0.5rem 1rem; + background: #007bff; + color: #fff; + border: none; + border-radius: 3px; + cursor: pointer; } button:hover { - background: #0056b3; + background: #0056b3; } #error-message { - background-color: #f8d7da; - color: #721c24; - border: 1px solid #f5c6cb; - padding: 10px; - margin-top: 10px; - border-radius: 5px; + background-color: #f8d7da; + color: #721c24; + border: 1px solid #f5c6cb; + padding: 10px; + margin-top: 10px; + border-radius: 5px; }