From 0a0be13518676b02a31e78a0db8833731017d24b Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Tue, 8 May 2018 21:47:50 +0200 Subject: [PATCH 01/19] Add async-hooks polyfill --- index.js | 2 +- package-lock.json | 5 +++++ package.json | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 140cafa..9a34991 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const libui = require(`${__dirname}/node_libui.node`); -const async_hooks = require('async_hooks'); +const async_hooks = require('@creditkarma/async-hooks'); const EventLoop = libui.EventLoop; delete libui.EventLoop; diff --git a/package-lock.json b/package-lock.json index d3be4a7..ab25807 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,11 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@creditkarma/async-hooks": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@creditkarma/async-hooks/-/async-hooks-0.0.4.tgz", + "integrity": "sha1-tbs0g/Ar9yw7LcDrojFm0/awoFg=" + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", diff --git a/package.json b/package.json index 91d2085..2ebe54c 100755 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "lint": "clang-format -i --glob='{js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js}'" }, "dependencies": { + "@creditkarma/async-hooks": "0.0.4", "home-path": "^1.0.5", "is-ci": "^1.1.0", "mkdirp": "^0.5.1", From 6e5e1cf7c26561906f06b8b2330b523d3cbce5b8 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Wed, 9 May 2018 15:03:48 +0200 Subject: [PATCH 02/19] Manually transpile tools and refactor them --- package.json | 2 +- tools/lib.js | 80 +++++++++++++++++++++ tools/libui-download.js | 131 +++++++++------------------------- tools/libui-napi-download.js | 133 +++++++++-------------------------- 4 files changed, 151 insertions(+), 195 deletions(-) create mode 100644 tools/lib.js diff --git a/package.json b/package.json index 2ebe54c..a09bbdd 100755 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "install": "npm run --silent download-libui && npm run --silent download-libui-napi || npm run build", "test": "tape test.js", "precommit": "check-clang-format \"'npm run lint'\"", - "lint": "clang-format -i --glob='{js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js}'" + "lint": "clang-format -i --glob='{js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js,tools/*.js}'" }, "dependencies": { "@creditkarma/async-hooks": "0.0.4", diff --git a/tools/lib.js b/tools/lib.js new file mode 100644 index 0000000..b759be6 --- /dev/null +++ b/tools/lib.js @@ -0,0 +1,80 @@ +const fs = require('fs'); +const path = require('path'); +const mv = require('mv'); +const https = require('https'); +const homePath = require('home-path'); +const mkdirp = require('mkdirp'); + +const debug = require('debug')('libui-download'); + +const requestHttps = url => new Promise((resolve, reject) => { + const req = https.get(url, resolve); + req.on('error', reject); +}); + +module.exports = function(project) { + const PROJECT = project.toUpperCase(); + return { + requestHttps, + mkCacheDir(cache) { + try { + mkdirp.sync(cache); + return cache; + } catch (err) { + if (err.code !== 'EACCES') { + debug('mkCacheDir error: ', err.stack); + throw err; + } + + // try local folder if homedir is off limits (e.g. some linuxes return '/' + // as homedir) + var localCache = path.resolve('./.' + project); + + mkdirp.sync(localCache); + return localCache; + } + }, + cacheDir(opts) { + opts = opts || {}; + var homeDir = homePath(); + return opts.cache || path.join(homeDir, './.' + project); + }, + buildUrl(opts, filename) { + var url = process.env[`NPM_CONFIG_${PROJECT}_MIRROR`] || + process.env[`${PROJECT}_MIRROR`] || opts.mirror || + `https://github.com/parro-it/${project}/releases/download/`; + + url += process.env[`${PROJECT}_CUSTOM_DIR`] || opts.customDir || opts.version; + url += '/'; + url += process.env[`${PROJECT}_CUSTOM_FILENAME`] || opts.customFilename || + filename; + return url; + }, + doDownload(res, url, target, cachedZip) { + if (res.statusCode !== 200) { + throw new Error(`Https request failed for ${ + res.headers.location} with code ${res.statusCode}.`); + } + + debug(`Https request for ${url} ok with code 200.`); + + const fileWrite = res.pipe(fs.createWriteStream(target)); + + return new Promise(async (resolve, reject) => { + const finish = () => { + debug('end stream reached', target, cachedZip); + mv(target, cachedZip, function(err) { + if (err) { + reject(err); + } else { + resolve(cachedZip); + } + }); + }; + + fileWrite.on('finish', finish); + fileWrite.on('error', reject); + }); + } + }; +}; \ No newline at end of file diff --git a/tools/libui-download.js b/tools/libui-download.js index 180e45d..2617127 100644 --- a/tools/libui-download.js +++ b/tools/libui-download.js @@ -2,88 +2,49 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const mkdirp = require('mkdirp'); -const homePath = require('home-path'); -const mv = require('mv'); const _debug = require('debug'); -const https = require('https'); const tar = require('tar'); -const utils = require('util'); +const {mkCacheDir, cacheDir, buildUrl, requestHttps, doDownload} = + require('./lib')('libui'); -const mkdir = utils.promisify(mkdirp) const debug = _debug('libui-download'); -const requestHttps = url => new Promise((resolve, reject) => { - const req = https.get(url, resolve); - req.on('error', reject); -}); - -const pathExists = utils.promisify(fs.exists); function nodePlatformToOS(arch) { switch (arch) { - case 'darwin': return 'osx'; - case 'win32': return 'windows'; - case 'linux': return 'linux'; - default: throw new Error('Unknown platform ' + arch); + case 'darwin': + return 'osx'; + case 'win32': + return 'windows'; + case 'linux': + return 'linux'; + default: + throw new Error('Unknown platform ' + arch); } } -function cacheDir(opts = {}) { - var homeDir = homePath(); - return opts.cache || path.join(homeDir, './.libui'); -} - -async function mkCacheDir(cache) { - try { - await mkdir(cache); - return cache; - } catch (err) { - if (err.code !== 'EACCES') { - debug('mkCacheDir error: ', err.stack); - throw err; - } - - // try local folder if homedir is off limits (e.g. some linuxes return '/' as homedir) - var localCache = path.resolve('./.libui'); - - await mkdir(localCache); - return localCache; - } -} - -function buildUrl(opts, filename) { - var url = process.env.NPM_CONFIG_LIBUI_MIRROR || - process.env.LIBUI_MIRROR || - opts.mirror || - 'https://github.com/parro-it/libui/releases/download/'; - - url += process.env.LIBUI_CUSTOM_DIR || opts.customDir || opts.version; - url += '/'; - url += process.env.LIBUI_CUSTOM_FILENAME || opts.customFilename || filename; - return url; -} - -async function download(opts) { +function download(opts) { const platform = nodePlatformToOS(opts.platform || os.platform()); const arch = opts.arch || os.arch(); const version = opts.version; const symbols = opts.symbols || false; - const filename = 'libui-shared-' + platform + '-' + arch + '-' + version + (symbols ? '-symbols' : '') + '.tar.gz'; + const filename = 'libui-shared-' + platform + '-' + arch + '-' + version + + (symbols ? '-symbols' : '') + '.tar.gz'; if (!version) { throw new Error('must specify needed version of libui in package.json'); } const url = buildUrl(opts, filename); const cache = cacheDir(opts.cache); - const actualCache = await mkCacheDir(cache); + const actualCache = mkCacheDir(cache); debug('info', {cache: cache, filename: filename, url: url}); let cachedZip = path.join(cache, filename); - const exists = await pathExists(cachedZip); + const exists = fs.existsSync(cachedZip); if (exists) { debug('zip exists', cachedZip); - return cachedZip; + return Promise.resolve(cachedZip); } debug('creating cache/tmp dirs'); @@ -92,56 +53,34 @@ async function download(opts) { cachedZip = path.join(actualCache, filename); // in case cache dir changed // download to tmpdir - var tmpdir = path.join( - os.tmpdir(), - 'libui-tmp-download-' + process.pid + '-' + Date.now() - ); + var tmpdir = + path.join(os.tmpdir(), 'libui-tmp-download-' + process.pid + '-' + Date.now()); - await mkdir(tmpdir); + mkdirp.sync(tmpdir); debug(tmpdir + 'created'); debug('downloading zip', url, 'to', tmpdir); const target = path.join(tmpdir, filename); - const resRedirect = await requestHttps(url); - if (resRedirect.statusCode !== 302) { - throw new Error(`Https request failed for ${url} with code ${resRedirect.statusCode}: resource not found.`); - } - - - const res = await requestHttps(resRedirect.headers.location); - if (res.statusCode !== 200) { - throw new Error(`Https request failed for ${res.headers.location} with code ${res.statusCode}.`); - } - - debug(`Https request for ${url} ok with code 200.`); - - const fileWrite = res.pipe(fs.createWriteStream(target)); - - return await new Promise(async(resolve, reject) => { - - const finish = () => { - debug('end stream reached', target, cachedZip); - mv(target, cachedZip, function (err) { - if (err) { - reject(err); - } else { - resolve(cachedZip); - } - }); - }; - - fileWrite.on('finish', finish); - fileWrite.on('error', reject); - }); + return requestHttps(url) + .then(resRedirect => { + if (resRedirect.statusCode !== 302) { + throw new Error(`Https request failed for ${url} with code ${ + resRedirect.statusCode}: resource not found.`); + } + return resRedirect; + }) + .then(resRedirect => requestHttps(resRedirect.headers.location)) + .then(res => doDownload(res, url, target, cachedZip)) } -async function main() { - const zipPath = await download({version: process.env.npm_package_libui}); - console.log('Downloaded zip:', zipPath); - await tar.extract({file: zipPath}); - console.log('Libui binaries extracted to:', process.cwd()); +function main() { + return download({version: process.env.npm_package_libui}).then(zipPath => { + console.log('Downloaded zip:', zipPath); + tar.extract({file: zipPath, sync: true}); + console.log('Libui binaries extracted to:', process.cwd()); + }); } main().catch(err => { diff --git a/tools/libui-napi-download.js b/tools/libui-napi-download.js index 3fe7809..3c103f0 100644 --- a/tools/libui-napi-download.js +++ b/tools/libui-napi-download.js @@ -2,67 +2,27 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const mkdirp = require('mkdirp'); -const homePath = require('home-path'); -const mv = require('mv'); const _debug = require('debug'); -const https = require('https'); const tar = require('tar'); -const utils = require('util'); const isCI = require('is-ci'); +const {mkCacheDir, cacheDir, buildUrl, requestHttps, doDownload} = + require('./lib')('libui-napi'); -const mkdir = utils.promisify(mkdirp) const debug = _debug('libui-napi-download'); -const requestHttps = url => new Promise((resolve, reject) => { - const req = https.get(url, resolve); - req.on('error', reject); -}); - -const pathExists = utils.promisify(fs.exists); function nodePlatformToOS(arch) { switch (arch) { - case 'darwin': return 'osx'; - case 'win32': return 'win'; - case 'linux': return 'linux'; - default: throw new Error('Unknown platform ' + arch); - } -} - -function cacheDir(opts = {}) { - var homeDir = homePath(); - return opts.cache || path.join(homeDir, './.libui-napi'); -} - -async function mkCacheDir(cache) { - try { - await mkdir(cache); - return cache; - } catch (err) { - if (err.code !== 'EACCES') { - debug('mkCacheDir error: ', err.stack); - throw err; - } - - // try local folder if homedir is off limits (e.g. some linuxes return '/' as homedir) - var localCache = path.resolve('./.libui-napi'); - - await mkdir(localCache); - return localCache; + case 'darwin': + return 'osx'; + case 'win32': + return 'win'; + case 'linux': + return 'linux'; + default: + throw new Error('Unknown platform ' + arch); } } -function buildUrl(opts, filename) { - var url = process.env.NPM_CONFIG_LIBUI_MIRROR || - process.env.LIBUI_MIRROR || - opts.mirror || - 'https://github.com/parro-it/libui-napi/releases/download/'; - - url += process.env.LIBUI_CUSTOM_DIR || opts.customDir || opts.version; - url += '/'; - url += process.env.LIBUI_CUSTOM_FILENAME || opts.customFilename || filename; - return url; -} - async function download(opts) { const platform = nodePlatformToOS(opts.platform || os.platform()); let arch = opts.arch || os.arch(); @@ -77,16 +37,16 @@ async function download(opts) { const url = buildUrl(opts, filename); const cache = cacheDir(opts.cache); - const actualCache = await mkCacheDir(cache); + const actualCache = mkCacheDir(cache); debug('info', {cache: cache, filename: filename, url: url}); let cachedZip = path.join(cache, filename); - const exists = await pathExists(cachedZip); + const exists = fs.existsSync(cachedZip); if (exists) { debug('zip exists', cachedZip); - return cachedZip; + return Promise.resolve(cachedZip); } debug('creating cache/tmp dirs'); @@ -95,66 +55,43 @@ async function download(opts) { cachedZip = path.join(actualCache, filename); // in case cache dir changed // download to tmpdir - var tmpdir = path.join( - os.tmpdir(), - 'libui-napi-tmp-download-' + process.pid + '-' + Date.now() - ); + var tmpdir = path.join(os.tmpdir(), + 'libui-napi-tmp-download-' + process.pid + '-' + Date.now()); - await mkdir(tmpdir); + mkdirp.sync(tmpdir); debug(tmpdir + 'created'); debug('downloading zip', url, 'to', tmpdir); const target = path.join(tmpdir, filename); - const resRedirect = await requestHttps(url); - if (resRedirect.statusCode === 404) { - throw new Error(`Prebuilt binaries not found for your platform and architecture.`); - } - - if (resRedirect.statusCode !== 302) { - throw new Error(`Https request failed for ${url} with code ${resRedirect.statusCode}: resource not found.`); - } - - - const res = await requestHttps(resRedirect.headers.location); - if (res.statusCode !== 200) { - throw new Error(`Https request failed for ${res.headers.location} with code ${res.statusCode}.`); - } - - debug(`Https request for ${url} ok with code 200.`); - - const fileWrite = res.pipe(fs.createWriteStream(target)); - - return new Promise(async(resolve, reject) => { - - const finish = () => { - debug('end stream reached', target, cachedZip); - mv(target, cachedZip, function (err) { - if (err) { - reject(err); - } else { - resolve(cachedZip); - } - }); - }; - - fileWrite.on('finish', finish); - fileWrite.on('error', reject); - }); + return requestHttps(url) + .then(resRedirect => { + if (resRedirect.statusCode === 404) { + throw new Error( + `Prebuilt binaries not found for your platform and architecture.`); + } + if (resRedirect.statusCode !== 302) { + throw new Error(`Https request failed for ${url} with code ${ + resRedirect.statusCode}: resource not found.`); + } + return resRedirect; + }) + .then(resRedirect => requestHttps(resRedirect.headers.location)) + .then(res => doDownload(res, url, target, cachedZip)) } async function main() { - if (isCI) { console.log('Running on a CI server, force rebuild.'); process.exit(1); } - const zipPath = await download({version: process.env.npm_package_version}); - console.log('Downloaded zip:', zipPath); - await tar.extract({file: zipPath}); - console.log('Libui-napi binaries extracted to:', process.cwd()); + return download({version: process.env.npm_package_version}).then(zipPath => { + console.log('Downloaded zip:', zipPath); + tar.extract({file: zipPath, sync: true}); + console.log('Libui-napi binaries extracted to:', process.cwd()); + }); } main().catch(err => { From dc8fc860dfa03aaec659abb5ba768c1fb12b8610 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Wed, 9 May 2018 15:42:24 +0200 Subject: [PATCH 03/19] Add node versions to ci --- .travis.yml | 6 ++++-- appveyor.yml | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ebac674..d8b957c 100755 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,9 @@ language: node_js dist: trusty node_js: - - node + - '10' + - '8' + - '6' addons: apt: @@ -39,6 +41,6 @@ deploy: on: branch: master tags: true - node: node + node: '10' api_key: secure: kkdWKa9iqJNKrfvW1pLgVx0EUBGcx+VGOzKG7xvxSfpNudZpuoGjWL4p9fQQD5TRELGwY7KCpFfZPbp2dnHQ9z82lW2XmnEC+bcskmfO/PXLJi3uyLrEY7iBwR3UhiWSdKRaPptfnndQrC21jmlweJNMCTWW8VqgvYupYITf9mfIq0WbEmFMeXJr7KzRO1yX4uAOOqnSTb60uRSrg+9V000cmDi246ir2ApaRw6NBOmI2v0kbirdbDe/vcAclgD2K0CFV7h8HIucbiU1DWBF2aQY3u5II4mItM4yskv0BmOr4vxXR0+7B/iysZNjWtXLbt4CiekvQKADUqPFpPk33LTjPxtAzdUYhHaoGTwchCIpkJG32KqTBL1+9h2I8WyhB3tKgxbFTZynkBihS2mYJad+rdO2RCXZtFZxf9bPWv6+PGelKnTFFBR9gPGTha4FeIeYZyuxuecAE7I+0UhS+wvwls3Xstro9fw+OwyvTysMEWOrjm1DvBuZyNnkqcfBKt3q4MOZsEHFnTEu6A1htr96FutAj/vap0e1RMokhMSIbe/hwq3whmELzWpRkOVDPEZfN47PCYc3f/UfYf0RMSWthibZOD30IX3207LsOgxZXfH3PDVcG9q0lvowGKWMcKy7d6+VVqgE97Aq7i07fizbpMWbNY7cStNy26m6IxM= diff --git a/appveyor.yml b/appveyor.yml index 64f8e9a..8900943 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,10 @@ skip_branch_with_pr: true image: Visual Studio 2017 environment: - nodejs_version: "10" + matrix: + - nodejs_version: "10" + - nodejs_version: "8" + - nodejs_version: "6" configuration: Release platform: x64 @@ -37,3 +40,4 @@ deploy: secure: eMIAnmLDhZy2Sq/UAXB50fYr1C2BugaafN8XiV6Wur8wMvPLXWIuCKU7Jt/Y9Of6 on: appveyor_repo_tag: true + nodejs_version: "10" From b93070701be68c807dcf1dd14faf836a5dde96c6 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Wed, 9 May 2018 16:04:16 +0200 Subject: [PATCH 04/19] Remove last asyncs in tools --- tools/lib.js | 2 +- tools/libui-napi-download.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/lib.js b/tools/lib.js index b759be6..d01a4aa 100644 --- a/tools/lib.js +++ b/tools/lib.js @@ -60,7 +60,7 @@ module.exports = function(project) { const fileWrite = res.pipe(fs.createWriteStream(target)); - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { const finish = () => { debug('end stream reached', target, cachedZip); mv(target, cachedZip, function(err) { diff --git a/tools/libui-napi-download.js b/tools/libui-napi-download.js index 3c103f0..9abc59d 100644 --- a/tools/libui-napi-download.js +++ b/tools/libui-napi-download.js @@ -23,7 +23,7 @@ function nodePlatformToOS(arch) { } } -async function download(opts) { +function download(opts) { const platform = nodePlatformToOS(opts.platform || os.platform()); let arch = opts.arch || os.arch(); if (platform !== 'win' && arch === 'x64') { @@ -81,7 +81,7 @@ async function download(opts) { .then(res => doDownload(res, url, target, cachedZip)) } -async function main() { +function main() { if (isCI) { console.log('Running on a CI server, force rebuild.'); process.exit(1); From 648d9b664214903dcb8a51d5fbdbff25eb0bbe6c Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 10:12:38 +0200 Subject: [PATCH 05/19] Remove n_api_napi_fatal_exception & n_api_napi_open_callback_scope --- example/errors.js | 50 +++++++++++++++++++++++++++++++++++++++ example/event-loop.js | 6 +++-- example/forms.js | 6 +---- package.json | 2 +- src/events.c | 27 ++++++++++++--------- src/includes/napi_utils.h | 6 +---- 6 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 example/errors.js diff --git a/example/errors.js b/example/errors.js new file mode 100644 index 0000000..820f6f8 --- /dev/null +++ b/example/errors.js @@ -0,0 +1,50 @@ +const libui = require('..'); + +const win = new libui.UiWindow('Errors example', 320, 60, true); +win.margined = true; + +const msg = (err) => { + console.log('Another click will terminate the app.'); + process.removeListener('uncaughtException', msg); +}; + +process.on('uncaughtException', msg); + +const toolbar = new libui.UiHorizontalBox(); +const setEntryBtn = new libui.UiButton('Uncaught error'); +setEntryBtn.onClicked(() => { + throw new Error('ciao'); +}); +toolbar.append(setEntryBtn, false); +const setSearchBtn = new libui.UiButton('No errors'); +setSearchBtn.onClicked(() => { + console.log('clicked'); +}); +toolbar.append(setSearchBtn, false); +const setPasswordBtn = new libui.UiButton('Set password'); +setPasswordBtn.onClicked(() => {}); +toolbar.append(setPasswordBtn, false); + +const setSpinboxBtn = new libui.UiButton('Set number'); +setSpinboxBtn.onClicked(() => {}); +toolbar.append(setSpinboxBtn, false); + +const toggleReadOnlyBtn = new libui.UiButton('Set ReadOnly'); +toggleReadOnlyBtn.onClicked(() => { + + }); +toolbar.append(toggleReadOnlyBtn, false); + +const box = new libui.UiVerticalBox(); +box.padded = true; +box.append(toolbar); +win.setChild(box); + +win.onClosing(() => { + win.close(); + libui.stopLoop(); +}); + +win.show(); + +libui.startLoop(); diff --git a/example/event-loop.js b/example/event-loop.js index dd7e4ff..2b8ba59 100644 --- a/example/event-loop.js +++ b/example/event-loop.js @@ -128,7 +128,8 @@ function makeToolbar() { timeoutHandle = setTimeout((a, b, c) => { const elapsed = Date.now() - now; - logAppend(`Custom setTimeout: ${now} - elapsed ${elapsed} ms. Args: ${a} ${b} ${c}`); + logAppend(`Custom setTimeout: ${now} - elapsed ${elapsed} ms. Args: ${a} ${ + b} ${c}`); }, 1000, 'custom', 'args', 2); }); toolbar.append(btnCustom, false); @@ -144,7 +145,8 @@ function makeToolbar() { let now = Date.now(); intervalHandler = setInterval((a, b, c) => { const elapsed = Date.now() - now; - logAppend(`Custom setInterval: ${now} - elapsed ${elapsed} ms. Args: ${a} ${b} ${c}`); + logAppend(`Custom setInterval: ${now} - elapsed ${elapsed} ms. Args: ${a} ${ + b} ${c}`); now = Date.now(); }, 50, 'my', 'args', 2); }); diff --git a/example/forms.js b/example/forms.js index 74cce2b..9673c45 100644 --- a/example/forms.js +++ b/example/forms.js @@ -37,10 +37,6 @@ win.show(); libui.startLoop(); function setJSON() { - const data = { - name: name.text, - surname: surname.text, - age: age.value - }; + const data = {name: name.text, surname: surname.text, age: age.value}; JSONData.text = JSON.stringify(data, null, 4); } diff --git a/package.json b/package.json index a09bbdd..ed8d5da 100755 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "install": "npm run --silent download-libui && npm run --silent download-libui-napi || npm run build", "test": "tape test.js", "precommit": "check-clang-format \"'npm run lint'\"", - "lint": "clang-format -i --glob='{js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js,tools/*.js}'" + "lint": "clang-format -i --glob='{example/*.js, js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js,tools/*.js}'" }, "dependencies": { "@creditkarma/async-hooks": "0.0.4", diff --git a/src/events.c b/src/events.c index 2c22a6e..981deb9 100644 --- a/src/events.c +++ b/src/events.c @@ -11,11 +11,11 @@ napi_value fire_event(struct event_t *event) { napi_value resource_object; status = napi_create_object(env, &resource_object); CHECK_STATUS_UNCAUGHT(status, napi_create_object, NULL); - - napi_callback_scope scope; - status = napi_open_callback_scope(env, resource_object, event->context, &scope); - CHECK_STATUS_UNCAUGHT(status, napi_open_callback_scope, NULL); - + /* + napi_callback_scope scope; + status = napi_open_callback_scope(env, resource_object, event->context, &scope); + CHECK_STATUS_UNCAUGHT(status, napi_open_callback_scope, NULL); + */ napi_value cb; status = napi_get_reference_value(env, event->cb_ref, &cb); CHECK_STATUS_UNCAUGHT(status, napi_get_reference_value, NULL); @@ -28,15 +28,20 @@ napi_value fire_event(struct event_t *event) { if (status == napi_pending_exception) { napi_value last_exception; napi_get_and_clear_last_exception(env, &last_exception); - napi_fatal_exception(env, last_exception); - return NULL; + napi_value stack; + size_t string_len = 5000; + char stack_str[string_len + 1]; + napi_get_named_property(env, last_exception, "stack", &stack); + napi_get_value_string_utf8(env, stack, stack_str, string_len + 1, &string_len); + napi_fatal_error("fire_event", NAPI_AUTO_LENGTH, stack_str, NAPI_AUTO_LENGTH); + return last_exception; } CHECK_STATUS_UNCAUGHT(status, napi_make_callback, NULL); - - status = napi_close_callback_scope(env, scope); - CHECK_STATUS_UNCAUGHT(status, napi_close_callback_scope, NULL); - + /* + status = napi_close_callback_scope(env, scope); + CHECK_STATUS_UNCAUGHT(status, napi_close_callback_scope, NULL); + */ status = napi_close_handle_scope(env, handle_scope); CHECK_STATUS_UNCAUGHT(status, napi_close_handle_scope, NULL); diff --git a/src/includes/napi_utils.h b/src/includes/napi_utils.h index 0f06889..5798a8d 100644 --- a/src/includes/napi_utils.h +++ b/src/includes/napi_utils.h @@ -154,11 +154,7 @@ NULL, &ret); \ char err[1024]; \ snprintf(err, 1024, #FN " failed with code %d: %s\n", result->engine_error_code, \ result->error_message); \ - napi_value error; \ - napi_value error_msg; \ - napi_create_string_utf8(env, err, NAPI_AUTO_LENGTH, &error_msg); \ - napi_create_error(env, NULL, error_msg, &error); \ - napi_fatal_exception(env, error); \ + napi_fatal_error("", NAPI_AUTO_LENGTH, err, NAPI_AUTO_LENGTH); \ return ERROR_RET; \ } From a2cc7a1c203c50c3c0f77167b7a3d0fb7cd49b2c Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 10:13:48 +0200 Subject: [PATCH 06/19] Add node 9 to CI --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d8b957c..3a1a3a5 100755 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ dist: trusty node_js: - '10' + - '9' - '8' - '6' diff --git a/appveyor.yml b/appveyor.yml index 8900943..23091c0 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,6 +7,7 @@ image: Visual Studio 2017 environment: matrix: - nodejs_version: "10" + - nodejs_version: "9" - nodejs_version: "8" - nodejs_version: "6" From e719041f5eee7227df853f82c12b2c0ad3d08bb3 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 10:21:45 +0200 Subject: [PATCH 07/19] Windows require compile-time constant array size? --- src/events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events.c b/src/events.c index 981deb9..73fc4d8 100644 --- a/src/events.c +++ b/src/events.c @@ -30,7 +30,7 @@ napi_value fire_event(struct event_t *event) { napi_get_and_clear_last_exception(env, &last_exception); napi_value stack; size_t string_len = 5000; - char stack_str[string_len + 1]; + char stack_str[5001]; napi_get_named_property(env, last_exception, "stack", &stack); napi_get_value_string_utf8(env, stack, stack_str, string_len + 1, &string_len); napi_fatal_error("fire_event", NAPI_AUTO_LENGTH, stack_str, NAPI_AUTO_LENGTH); From a1e62cce23a27d04b2dedcecfecdd6b895caecdb Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 10:40:26 +0200 Subject: [PATCH 08/19] Try to force AppVeyor to install correct node ver --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 23091c0..e1fdd7c 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,7 +9,7 @@ environment: - nodejs_version: "10" - nodejs_version: "9" - nodejs_version: "8" - - nodejs_version: "6" + - nodejs_version: "6.14.2" configuration: Release platform: x64 From 55b30a03e37c405eb14459072bb3f09f357626b8 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 12:47:03 +0200 Subject: [PATCH 09/19] Try nvm on appveyor --- appveyor.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e1fdd7c..5850115 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,13 +9,14 @@ environment: - nodejs_version: "10" - nodejs_version: "9" - nodejs_version: "8" - - nodejs_version: "6.14.2" + - nodejs_version: "6" configuration: Release platform: x64 install: - - ps: Install-Product node $env:nodejs_version $env:platform + - wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash + - nvm install $env:nodejs_version - npm install test_script: From 07a1ac1eda36626b91a15b7e5ab9ff141e49f58c Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 12:48:19 +0200 Subject: [PATCH 10/19] Try with CURL --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5850115..986ea48 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ configuration: Release platform: x64 install: - - wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash + - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash - nvm install $env:nodejs_version - npm install From 0340db7e1da50a51513303186ba3914d84df2ab3 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 12:51:54 +0200 Subject: [PATCH 11/19] Use Install-module --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 986ea48..c61a2b9 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ configuration: Release platform: x64 install: - - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash + - Install-Module nvm - nvm install $env:nodejs_version - npm install From 83bdc7b965e291683597fd92d3363ace2223e517 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 12:53:32 +0200 Subject: [PATCH 12/19] ps --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index c61a2b9..83b4a4d 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ configuration: Release platform: x64 install: - - Install-Module nvm + - ps: Install-Module nvm - nvm install $env:nodejs_version - npm install From b848f816032c1ab20d75fe7b9bcf56cbc2770b69 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 12:57:39 +0200 Subject: [PATCH 13/19] I read the instruction as my wife always insists. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 83b4a4d..601e85a 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ platform: x64 install: - ps: Install-Module nvm - - nvm install $env:nodejs_version + - ps: Install-NodeVersion $env:nodejs_version - npm install test_script: From a94eb396775af048730c2f3c70f10ba22596570f Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 12:59:45 +0200 Subject: [PATCH 14/19] Force it --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 601e85a..a44920a 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ configuration: Release platform: x64 install: - - ps: Install-Module nvm + - ps: Install-Module nvm -Scope CurrentUser -Force - ps: Install-NodeVersion $env:nodejs_version - npm install From aaa0762cf9fcbf39141539ff66020a6cd955d4f3 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 13:05:05 +0200 Subject: [PATCH 15/19] activate node --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index a44920a..a1ab6d3 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,6 +17,9 @@ platform: x64 install: - ps: Install-Module nvm -Scope CurrentUser -Force - ps: Install-NodeVersion $env:nodejs_version + - ps: Set-NodeVersion $env:nodejs_version + - node --version + - npm --version - npm install test_script: From d75b2caf9a286fcb946b957420314fe471377a8b Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 13:06:40 +0200 Subject: [PATCH 16/19] use ps --- appveyor.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a1ab6d3..c900b70 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,14 +18,14 @@ install: - ps: Install-Module nvm -Scope CurrentUser -Force - ps: Install-NodeVersion $env:nodejs_version - ps: Set-NodeVersion $env:nodejs_version - - node --version - - npm --version - - npm install + - ps: node --version + - ps: npm --version + - ps: npm install test_script: - - node --version - - npm --version - - npm test + - ps: node --version + - ps: npm --version + - ps: npm test after_test: - if defined APPVEYOR_REPO_TAG_NAME ( From 2f3f59dfac0218ec4ac4e19714bb0c19a64029cc Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 13:14:40 +0200 Subject: [PATCH 17/19] Update-NodeJsInstallation --- appveyor.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c900b70..1f8141f 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,17 +15,12 @@ configuration: Release platform: x64 install: - - ps: Install-Module nvm -Scope CurrentUser -Force - - ps: Install-NodeVersion $env:nodejs_version - - ps: Set-NodeVersion $env:nodejs_version - - ps: node --version - - ps: npm --version - - ps: npm install + - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) + - node --version + - npm --version test_script: - - ps: node --version - - ps: npm --version - - ps: npm test + - npm test after_test: - if defined APPVEYOR_REPO_TAG_NAME ( From e59a9cadfb827e620b2cd4cf240214d3d87511c1 Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 13:16:45 +0200 Subject: [PATCH 18/19] install.it --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 1f8141f..2883696 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,6 +18,7 @@ install: - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) - node --version - npm --version + - npm install test_script: - npm test From 948948f2fb43956e16d585ebbf047f6b641aea1a Mon Sep 17 00:00:00 2001 From: Andrea Parodi Date: Fri, 11 May 2018 13:19:38 +0200 Subject: [PATCH 19/19] downgrade node engine version to 6.14.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed8d5da..33ae7f3 100755 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "GUI" ], "engines": { - "node": ">=8" + "node": ">=6.14.2" }, "libui": "alpha3.5-master-002", "scripts": {