Skip to content

Instantly share code, notes, and snippets.

Trevor Norris trevnorris

Block or report user

Report or block trevnorris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View lldb-seg-fault.txt
(lldb) fr v
(node::AsyncWrap *) this = 0x000000000360be20
(node::Environment *) env = 0x00007fffffffc768
(v8::Local<v8::Object>) object = (val_ = 0x00007fffffffba98)
(uv_handle_t *) handle = 0x000000000360bed8
(node::AsyncWrap::ProviderType) provider = PROVIDER_TCPWRAP
(lldb) p this
Segmentation fault (core dumped)
View running-test.txt
# Returning **before** calling the after() run:
$ ./node test/parallel/test-http-catch-uncaughtexception.js
ret_v.IsEmpty() 1: false
ret_v.IsEmpty() 2: false
ret_v.IsEmpty() 3: false
ret_v.IsEmpty() 4: false
ret_v.IsEmpty() 5: false
ret_v.IsEmpty() 6: false
ret_v.IsEmpty() 7: false
@trevnorris
trevnorris / dgram.diff
Created Dec 2, 2016
diff to only call dns lookup for dgram send() if an ip isn't passed
View dgram.diff
diff --git a/lib/dgram.js b/lib/dgram.js
index 31be3ce..281cfc6 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -6,6 +6,7 @@ const util = require('util');
const EventEmitter = require('events');
const UV_UDP_REUSEADDR = process.binding('constants').os.UV_UDP_REUSEADDR;
+const cares = process.binding('cares_wrap');
const UDP = process.binding('udp_wrap').UDP;
@trevnorris
trevnorris / binding.gyp
Created Dec 1, 2016
Example of returning all values from uv_rusage() as tuples w/ no overhead. Values are only valid until getrusage() is called again.
View binding.gyp
{
"targets": [{
"target_name": "addon",
"sources": [ "main.cc" ]
}]
}
@trevnorris
trevnorris / to-bind-or-not-to-bind.js
Created Nov 7, 2016
quick comparison doing a loop of nextTick()'s using different calling methods
View to-bind-or-not-to-bind.js
'use strict';
const print = process._rawDebug;
const ITER = 1e6;
var t = process.hrtime();
(function runner(i) {
if (i > ITER) return printTime();
// Slowest
@trevnorris
trevnorris / tls_wrap-isalive-bad-pointer.diff
Created Oct 25, 2016
Fix when the reference of a TLSWrap instance is kept, but the StreamBase stream_ is free'd.
View tls_wrap-isalive-bad-pointer.diff
diff --git a/src/stream_base.h b/src/stream_base.h
index faddee8..3592975 100644
--- a/src/stream_base.h
+++ b/src/stream_base.h
@@ -146,10 +146,14 @@ class StreamResource {
const uv_buf_t* buf,
uv_handle_type pending,
void* ctx);
+ typedef void (*DestructCb)(void* ctx);
@trevnorris
trevnorris / multi-inheritance-nightmare.cc
Created Oct 20, 2016
log value from a Base class when multi-inheritance is involved
View multi-inheritance-nightmare.cc
#include <cstdio>
#include <type_traits> // std::remove_reference
#ifdef USE_TR1_TYPE_TRAITS
template <typename T> using remove_reference = std::tr1::remove_reference<T>;
#else
template <typename T> using remove_reference = std::remove_reference<T>;
#endif
class Foo {
View async-hooks-promise-catch.js
// map will store all the stack traces recorded at init().
var map = new Map();
var async_hooks = require('async_hooks');
async_hooks.createHook({ init }).enable();
function init(id, type, parentId) {
const obj = {};
// Capture the stack trace, omitting the call to init().
Error.captureStackTrace(obj, init);
View node-class-list.txt
AsyncWrap
- QueryWrap (now handles all Wrap & ClearWrap for child classes)
- QueryAWrap
- QueryAaaaWrap
- QueryCnameWrap
- QueryMxWrap
- QueryNsWrap
- QueryTxtWrap
- QuerySrvWrap
- QueryPtrWrap
View code-6_5.asm
--- Raw source ---
(u){
var s=this;
if(!(typeof(this)==='number')){
if(!(%_ClassOf(this)==='Number')){
throw j(69,'Number.prototype.toString');
}
s=%_ValueOf(this);
}
if((u===(void 0))||u===10){
You can’t perform that action at this time.