Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,build: improve the native module subsystem #36

Closed
wants to merge 11 commits into from
Closed

Conversation

aqrln
Copy link
Member

@aqrln aqrln commented Jan 30, 2017

  • Split jsrs-impl.cc into separate modules and make stylistic fixes.
  • Rename the native addon to jstp since there already is a function that is not a part of JSRS.
  • Fix binding.gyp: make cflags not ignored on macOS (as it appeared they used to be) and do not use -O3 in Debug configuration.
  • Make v8::String instantiations and throwing V8 exceptions macros to avoid boilerplate code.

* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
@aqrln aqrln requested a review from belochub January 30, 2017 23:48
@aqrln aqrln self-assigned this Jan 30, 2017
// string, but always at least by two, even when the function
// returns nullptr.
static const char* GetEscapedControlChar(char str, size_t* size) {
static const char* control_chars[0x20] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Google C++ Style Guide it is better to use constexpr instead of const in this situation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@belochub and get a warning: ISO C++11 does not allow conversion from string literal to 'char *const' 😉

Copy link
Member Author

@aqrln aqrln Jan 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char* key_str = *key;
for (int i = 0; i < key.length(); i++) {
if (key_str[i] == '_') continue;
if ((i == 0 && !isalpha(key_str[i])) || !isalnum(key_str[i])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions std::isalpha and std::isalnum are both defined in <cctype> header which is not included in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 07eafcc

int index = 0;

while (parsed_size < total_size) {
auto chunk_size = strlen(curr_chunk);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::strlen is defined in <cstring> which is not included.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

HandleScope scope(isolate);

String::Utf8Value str(args[0]->ToString());
auto array = Local<Array>::Cast(args[1]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is better to use v8::Local::As here to keep cast style consistent, but this one is optional and completely up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aqrln
Copy link
Member Author

aqrln commented Jan 31, 2017

@belochub I've added new commits that fix mentioned nits and issues. Does this LGTY?

Since the C headers are included as <clib> instead of <lib.h>, treat
them as a part of C++ standard library, move the #include directives to
the same group as C++ includes and add `using` statements.
@aqrln
Copy link
Member Author

aqrln commented Jan 31, 2017

@belochub I don't think we need separate macros to create strings. It was only isolate->ThrowException together with string instantiation thing that created lots of boilerplate code, and that its handled by a single macro, so I mark the last item as completed. What do you think?

@aqrln aqrln changed the title src,build: improve the native module subsystem [WIP] src,build: improve the native module subsystem Jan 31, 2017
@belochub
Copy link
Member

@aqrln, yes, I think at can be marked as completed. Changes LGTM.

aqrln added a commit that referenced this pull request Jan 31, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: #36
@aqrln
Copy link
Member Author

aqrln commented Jan 31, 2017

Landed in 56c57fe.

@aqrln aqrln closed this Jan 31, 2017
@aqrln aqrln deleted the refactor-src branch January 31, 2017 15:46
aqrln added a commit that referenced this pull request Jan 31, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: #36
aqrln added a commit that referenced this pull request Apr 2, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

Backport-of: #36
@aqrln
Copy link
Member Author

aqrln commented Apr 2, 2017

@belochub do you know why was this marker as minor and not patch?

@belochub
Copy link
Member

belochub commented Apr 2, 2017

@aqrln, I don't remember the actual reason.

@aqrln
Copy link
Member Author

aqrln commented Apr 2, 2017

Ah, doesn't matter for now. Minor and patch are the same till 1.0. Marked the backport PR as minor though too.

aqrln added a commit that referenced this pull request Apr 2, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

Backport-of: #36
aqrln added a commit that referenced this pull request Apr 2, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

Backport-of: #36
PR-URL: #110
aqrln added a commit that referenced this pull request Apr 2, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

Backport-of: #36
PR-URL: #110
aqrln added a commit that referenced this pull request Apr 3, 2017
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

Backport-of: #36
PR-URL: #110
belochub pushed a commit that referenced this pull request Jan 22, 2018
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: #36
belochub pushed a commit that referenced this pull request Jan 22, 2018
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: #36
belochub added a commit that referenced this pull request Jan 22, 2018
This is a new and shiny first major release for `metarhia-jstp`.
Changes include API refactoring and improvements, implementations of
CLI, sessions, and application versions, native addon build optimizations,
lots of bug fixes, test coverage increase, and other, less notable changes.

This release also denotes the bump of the protocol version to v1.0.
The only difference from the previous version of the protocol is that
"old" heartbeat messages (`{}`) are now deprecated and `ping`/`pong`
messages must be used for this purpose instead.

Notable changes:

 * **src,build:** improve the native module subsystem
   *(Alexey Orlenko)*
   [#36](#36)
   **\[semver-minor\]**
 * **build:** compile in ISO C++11 mode
   *(Alexey Orlenko)*
   [#37](#37)
   **\[semver-minor\]**
 * **build:** improve error handling
   *(Alexey Orlenko)*
   [#40](#40)
   **\[semver-minor\]**
 * **lib:** refactor record-serialization.js
   *(Alexey Orlenko)*
   [#41](#41)
   **\[semver-minor\]**
 * **protocol:** change the format of handshake packets
   *(Alexey Orlenko)*
   [#54](#54)
   **\[semver-major\]**
 * **parser:** remove special case for '\0' literal
   *(Mykola Bilochub)*
   [#68](#68)
   **\[semver-major\]**
 * **client:** drop redundant callback argument
   *(Alexey Orlenko)*
   [#104](#104)
   **\[semver-major\]**
 * **client:** handle errors in connectAndInspect
   *(Alexey Orlenko)*
   [#105](#105)
   **\[semver-major\]**
 * **socket,ws:** use socket.destroy() properly
   *(Alexey Orlenko)*
   [#84](#84)
   **\[semver-major\]**
 * **cli:** add basic implementation
   *(Mykola Bilochub)*
   [#107](#107)
   **\[semver-minor\]**
 * **connection:** fix error handling in optional cbs
   *(Alexey Orlenko)*
   [#147](#147)
   **\[semver-major\]**
 * **lib:** change event signature
   *(Denys Otrishko)*
   [#187](#187)
   **\[semver-major\]**
 * **lib:** add address method to Server
   *(Denys Otrishko)*
   [#190](#190)
   **\[semver-minor\]**
 * **lib:** optimize connection events
   *(Denys Otrishko)*
   [#222](#222)
   **\[semver-major\]**
 * **lib:** refactor server and client API
   *(Denys Otrishko)*
   [#209](#209)
   **\[semver-major\]**
 * **lib,src:** rename term packet usages to message
   *(Denys Otrishko)*
   [#270](#270)
   **\[semver-major\]**
 * **lib:** emit events about connection messages
   *(Denys Otrishko)*
   [#252](#252)
   **\[semver-minor\]**
 * **connection:** make callback method private
   *(Alexey Orlenko)*
   [#306](#306)
   **\[semver-major\]**
 * **lib:** implement sessions
   *(Mykola Bilochub)*
   [#289](#289)
   **\[semver-major\]**
 * **connection:** use ping-pong instead of heartbeat
   *(Dmytro Nechai)*
   [#303](#303)
   **\[semver-major\]**
@belochub belochub mentioned this pull request Jan 22, 2018
belochub added a commit that referenced this pull request Jan 23, 2018
This is a new and shiny first major release for `metarhia-jstp`.
Changes include API refactoring and improvements, implementations of
CLI, sessions, and application versions, native addon build optimizations,
lots of bug fixes, test coverage increase, and other, less notable changes.

This release also denotes the bump of the protocol version to v1.0.
The only difference from the previous version of the protocol is that
"old" heartbeat messages (`{}`) are now deprecated and `ping`/`pong`
messages must be used for this purpose instead.

Notable changes:

 * **src,build:** improve the native module subsystem
   *(Alexey Orlenko)*
   [#36](#36)
   **\[semver-minor\]**
 * **build:** compile in ISO C++11 mode
   *(Alexey Orlenko)*
   [#37](#37)
   **\[semver-minor\]**
 * **build:** improve error handling
   *(Alexey Orlenko)*
   [#40](#40)
   **\[semver-minor\]**
 * **lib:** refactor record-serialization.js
   *(Alexey Orlenko)*
   [#41](#41)
 * **parser:** fix a possible memory leak
   *(Alexey Orlenko)*
   [#44](#44)
   **\[semver-minor\]**
 * **protocol:** change the format of handshake packets
   *(Alexey Orlenko)*
   [#54](#54)
   **\[semver-major\]**
 * **parser:** make parser single-pass
   *(Mykola Bilochub)*
   [#61](#61)
 * **parser:** remove special case for '\0' literal
   *(Mykola Bilochub)*
   [#68](#68)
   **\[semver-major\]**
 * **parser:** fix bug causing node to crash
   *(Mykola Bilochub)*
   [#75](#75)
 * **client:** drop redundant callback argument
   *(Alexey Orlenko)*
   [#104](#104)
   **\[semver-major\]**
 * **client:** handle errors in connectAndInspect
   *(Alexey Orlenko)*
   [#105](#105)
   **\[semver-major\]**
 * **socket,ws:** use socket.destroy() properly
   *(Alexey Orlenko)*
   [#84](#84)
   **\[semver-major\]**
 * **cli:** add basic implementation
   *(Mykola Bilochub)*
   [#107](#107)
   **\[semver-minor\]**
 * **connection:** fix error handling in optional cbs
   *(Alexey Orlenko)*
   [#147](#147)
   **\[semver-major\]**
 * **test:** add JSON5 specs test suite
   *(Alexey Orlenko)*
   [#158](#158)
 * **lib:** change event signature
   *(Denys Otrishko)*
   [#187](#187)
   **\[semver-major\]**
 * **lib:** add address method to Server
   *(Denys Otrishko)*
   [#190](#190)
   **\[semver-minor\]**
 * **parser:** implement NaN and Infinity parsing
   *(Mykola Bilochub)*
   [#201](#201)
 * **parser:** improve string parsing performance
   *(Mykola Bilochub)*
   [#220](#220)
 * **lib:** optimize connection events
   *(Denys Otrishko)*
   [#222](#222)
   **\[semver-major\]**
 * **lib:** refactor server and client API
   *(Denys Otrishko)*
   [#209](#209)
   **\[semver-major\]**
 * **lib,src:** rename term packet usages to message
   *(Denys Otrishko)*
   [#270](#270)
   **\[semver-major\]**
 * **lib:** emit events about connection messages
   *(Denys Otrishko)*
   [#252](#252)
   **\[semver-minor\]**
 * **lib:** implement API versioning
   *(Denys Otrishko)*
   [#231](#231)
   **\[semver-minor\]**
 * **lib:** allow to set event handlers in application
   *(Denys Otrishko)*
   [#286](#286)
   **\[semver-minor\]**
 * **lib:** allow to broadcast events from server
   *(Denys Otrishko)*
   [#287](#287)
   **\[semver-minor\]**
 * **connection:** make callback method private
   *(Alexey Orlenko)*
   [#306](#306)
   **\[semver-major\]**
 * **lib:** implement sessions
   *(Mykola Bilochub)*
   [#289](#289)
   **\[semver-major\]**
 * **connection:** use ping-pong instead of heartbeat
   *(Dmytro Nechai)*
   [#303](#303)
   **\[semver-major\]**
belochub pushed a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: metarhia/jstp#36
belochub pushed a commit to metarhia/mdsf that referenced this pull request Jul 19, 2018
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: metarhia/jstp#36
belochub pushed a commit to metarhia/mdsf that referenced this pull request Jul 21, 2018
* Split `jsrs-impl.cc` into separate modules.
* Make some refactoring.
* Rename the native addon to `jstp` since there already is a function
  that is not a part of JSRS.
* Fix `binding.gyp`: make `cflags` not ignored on macOS (as it appeared
  they used to be) and do not use `-O3` in Debug configuration.
* Use a macro to throw V8 exceptions to avoid boilerplate code.

PR-URL: metarhia/jstp#36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants