new Promise
console.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ make LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 | |
BUILD: Doing 'make -j8' parallel build | |
HOSTCC fixdep.o | |
HOSTLD fixdep-in.o | |
LINK fixdep | |
Auto-detecting system features: | |
... dwarf: [ on ] | |
... dwarf_getlocations: [ on ] | |
... glibc: [ on ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node v10.15.3 | |
uprobe:/home/mmarchini/.nvm/versions/node/v10.15.3/bin/node:_ZN2v88internal17Builtin_JsonParseEiPPNS0_6ObjectEPNS0_7IsolateE | |
{ | |
// Load constants | |
$kPointerSize = (uint32)(1 << (*uaddr("v8dbg_PointerSizeLog2"))); | |
$stringLengthOffset = (uint32)*uaddr("v8dbg_class_String__length__SMI"); | |
$kTag = (uint32)*uaddr("v8dbg_HeapObjectTag"); | |
$kTagMask = (uint32)*uaddr("v8dbg_SmiTagMask"); | |
$kShiftSize = (uint32)*uaddr("v8dbg_SmiShiftSize"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Uncomment deb-src lines on /etc/apt/sources.list | |
sudo apt-get update | |
# Or replace ~/glibc with preferred path to store libc source | |
mkdir -p ~/glibc | |
cd ~/glibc | |
sudo apt-get install -y dpkg-dev | |
sudo apt-get build-deps libc6 | |
apt-get source libc6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.reject(new Error()); // This will result in a rejection | |
new Promise((fulfill, reject) => { | |
reject(new Error()); // This will result in a rejection | |
}); | |
new Promise(() => { | |
throw new Error(); // This will result in a rejection | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Callback version | |
const { readFile } = require('fs'); | |
function readJsonFile(file, cb) { | |
readFile(file, (err, data) => { | |
if (err) { | |
// If error while reading file, propagate the error via callback | |
return cb(err, null); | |
} | |
// Unexpected invalid JSON input, code will throw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// async function version | |
const { readFile } = require('fs').promises; | |
async function readJsonFile(file) { | |
// Promise is rejected if fails to read or if unexpected JSON input. | |
return JSON.parse(await readFile(file)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function foo() { | |
throw new Error(); | |
} | |
foo() // 1. Unhandled at this point | |
.catch(() => console.error("an error occured")); // 2. Now it's handled | |
try { | |
await foo(); | |
} catch(e) { // 3. Handled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const server = http.createServer(handle); | |
server.listen(3000); | |
function handle (req, res) { | |
doStuff() | |
.then((body) => { | |
res.end(body); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const server = http.createServer(handle); | |
server.listen(3000); | |
process.on('unhandledRejection', (err) => { | |
throw err; | |
}); | |
function handle (req, res) { |