Skip to content

Instantly share code, notes, and snippets.

View gabrielschulhof's full-sized avatar

Gabriel Schulhof gabrielschulhof

  • California, USA
View GitHub Profile
const Module = require('node:module')
const path = require('node:path')
const load = Module._load
const aliases = [['myawesomemodule', path.dirname(require.resolve('./myawesomemodule/'))]]
Module._load = function (request, parent) {
const alias = aliases.find(([module]) => request.startsWith(module))
@gabrielschulhof
gabrielschulhof / example.js
Created December 5, 2024 21:36
Async function equivalence
// These two functions are identical.
const fn1 = async () => { return 5 }
const fn2 = () => new Promise((resolve, reject) => {
try {
resolve(5)
} catch (e) {
reject(e)
}
$ grep -nH name -- test/{node-api,js-native-api}/*/binding.gyp | awk '{print $NF;}' | sed -e 's/"//g' -e "s/'//g" | sort
2_function_arguments,
3_callbacks,
4_object_factory,
5_function_factory,
6_object_wrap,
7_factory_wrap,
8_passing_wrapped,
binding,
binding,
diff --git a/src/js_native_api.h b/src/js_native_api.h
index 07e3df1340..dbb69ace45 100644
--- a/src/js_native_api.h
+++ b/src/js_native_api.h
@@ -534,11 +534,16 @@ napi_add_finalizer(napi_env env,
#ifdef NAPI_EXPERIMENTAL
#define NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
+#if defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT)
+#define node_api_post_finalizer(env, finalize_cb, finalize_data, finalize_hint) \
import fs from 'node:fs'
import async_hooks from 'node:async_hooks'
import process from 'node:process'
declare global {
var promises: Record<string, number>
var enableHook: () => {}
var disableHook: () => {}
var dumpPromises: () => void
}
global.promises = {}
const result = await fetch('https://some-place/some/path)
.then(
res => {
doSomethingComplicatedWith(res)
},
err => {
console.log('Failed to fetch')
}
)
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget *view;
GtkTextBuffer *buffer;
GtkWidget *window;
GdkDisplay *display;
GdkScreen *screen;
GtkCssProvider *provider;
# Script to be used with gdb to trace changes to the maps file as Node.js
# performs mmaps.
import io
import os
import sys
import gdb
import shutil
import subprocess
set pagination off
set breakpoint pending on
set style enabled off
set environment NODE_ENV=production
define domaps
shell echo "*** Start Event ***"
bt 10
python gdb.execute('finish');
shell echo "*** End Event *****"
continue
class FinishMapsBreak (gdb.FinishBreakpoint):
def stop(self):
gdb.write('----------- End Event ------------\n')
gdb.flush()
return False
def out_of_scope(self):
return self.stop()
class MapsBreak (gdb.Breakpoint):