Skip to content

Commit

Permalink
src,build: improve the native module subsystem
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aqrln authored and belochub committed Jan 22, 2018
1 parent f62a43d commit d01a902
Show file tree
Hide file tree
Showing 15 changed files with 1,392 additions and 1,180 deletions.
34 changes: 31 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
{
'variables': {
'jstp_base_cflags': ['-Wall', '-Wextra', '-Wno-unused-parameter'],
'jstp_debug_cflags': ['-g', '-O0'],
'jstp_release_cflags': ['-O3']
},
'targets': [
{
'target_name': 'jsrs',
'cflags': ['-O3'],
'sources': ['src/jsrs-impl.cc']
'target_name': 'jstp',
'sources': [
'src/node_bindings.cc',
'src/jsrs_serializer.cc',
'src/jsrs_parser.cc',
'src/packet_parser.cc',
'src/unicode_utils.cc'
],
'configurations': {
'Debug': {
'cflags': ['<@(jstp_debug_cflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(jstp_debug_cflags)']
}
},
'Release': {
'cflags': ['<@(jstp_release_cflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(jstp_release_cflags)']
}
}
},
'cflags': ['<@(jstp_base_cflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(jstp_base_cflags)']
}
}
]
}
12 changes: 6 additions & 6 deletions lib/record-serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ module.exports = jsrs;
// one of our priorities to optimize it.
const USE_NATIVE_SERIALIZER = false;

let jsrsNative;
let jstpNative;

try {
jsrsNative = require('../build/Release/jsrs');
jstpNative = require('../build/Release/jstp');
} catch (e) {
try {
jsrsNative = require('../build/Debug/jsrs');
jstpNative = require('../build/Debug/jstp');
} catch (e) {
console.warn(
'JSTP Record Serialization native module is not built. ' +
'JSTP native addon is not built. ' +
'Run `npm install` in order to build it, otherwise you will get ' +
'poor server performance under load.'
);
module.exports = require('./record-serialization-fallback');
}
}

if (jsrsNative) {
Object.assign(jsrs, jsrsNative);
if (jstpNative) {
Object.assign(jsrs, jstpNative);
if (!USE_NATIVE_SERIALIZER) {
jsrs.stringify = serializerFactory.createSerializer();
}
Expand Down
11 changes: 11 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2016-2017 JSTP project authors. Use of this source code is
// governed by the MIT license that can be found in the LICENSE file.

#ifndef SRC_COMMON_H_
#define SRC_COMMON_H_

#define THROW_EXCEPTION(ex_type, ex_msg) \
isolate->ThrowException(v8::Exception::ex_type( \
v8::String::NewFromUtf8(isolate, ex_msg)))

#endif // SRC_COMMON_H_
Loading

0 comments on commit d01a902

Please sign in to comment.