Skip to content

Instantly share code, notes, and snippets.

View gabrielschulhof's full-sized avatar

Gabriel Schulhof gabrielschulhof

  • California, USA
View GitHub Profile
@gabrielschulhof
gabrielschulhof / cctest.diff
Last active July 10, 2018 18:27
V8 inheritance test illustration
diff --git a/test/cctest/BUILD.gn b/test/cctest/BUILD.gn
index 1aa4a07ca4..9f0eaeeb3a 100644
--- a/test/cctest/BUILD.gn
+++ b/test/cctest/BUILD.gn
@@ -192,6 +192,7 @@ v8_source_set("cctest_sources") {
"test-heap-profiler.cc",
"test-identity-map.cc",
"test-inobject-slack-tracking.cc",
+ "test-inheritance.cc",
"test-intl.cc",
@gabrielschulhof
gabrielschulhof / binding.cc
Last active July 6, 2018 13:16
GC behaviour wrt. native function vs. plain object vs. JS function
#include <stdio.h>
#include <node.h>
class WeakRef {
public:
WeakRef(v8::Isolate* isolate, v8::Local<v8::Value> func, const char* string):
string_(string) {
pers_.Reset(isolate, func);
pers_.SetWeak(this, DeleteMe, v8::WeakCallbackType::kParameter);
}
@gabrielschulhof
gabrielschulhof / binding.c
Created June 12, 2018 18:17
N-API multi-context addon example
#include <stdlib.h>
#include <node_api.h>
// As a convenience, wrap N-API calls such that they cause Node.js to abort
// when they are unsuccessful.
#define NAPI_CALL(call) \
do { \
napi_status status = call; \
if (status != napi_ok) { \
napi_fatal_error(#call, NAPI_AUTO_LENGTH, "failed", NAPI_AUTO_LENGTH); \
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <node_api.h>
#define NAPI_CALL(call) \
do { \
napi_status status = call; \
assert(status == napi_ok); \
} while (0)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file, it will be overwritten on install.
Copy the file to $HOME/.config/openbox/ instead. -->
<openbox_config xmlns="http://openbox.org/3.4/rc"
xmlns:xi="http://www.w3.org/2001/XInclude">
<resistance>
<strength>10</strength>
{
"targets": [
{
"target_name": "example_addon",
"sources": [ "example_addon.c" ],
"include_dirs": [ "<!@(node -p \"require('node-addon-api').include\")" ],
"dependencies": [ "<!@(node -p \"require('node-addon-api').gyp\")" ]
}
]
}
> [email protected] pretest /home/nix/node/node-addon-api
> node-gyp rebuild -C test
make: Entering directory '/home/nix/node/node-addon-api/test/build'
g++ '-DNODE_GYP_MODULE_NAME=node-api' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DEXTERNAL_NAPI' '-DDEBUG' '-D_DEBUG' '-DV8_ENABLE_CHECKS' -I/home/nix/node/node/include/node -I/home/nix/node/node/src -I/home/nix/node/node/deps/uv/include -I/home/nix/node/node/deps/v8/include -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -g -O0 -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Debug/.deps/Debug/obj.target/node-api/../src/node_api.o.d.raw -c -o Debug/obj.target/node-api/../src/node_api.o ../../src/node_api.cc
g++ '-DNODE_GYP_MODULE_NAME=node-api' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DEXTERNAL_NAPI' '-DDEBUG' '-D_DEBUG' '-DV8_ENABLE_CHECKS' -I/home/nix/node/node/include/node -I/
000000000004e170 r ._92
000000000004e170 r ._93
000000000004e170 r ._94
000000000004e170 r ._95
U abort@@GLIBC_2.2.5
000000000025f268 B __bss_start
000000000025f268 b completed.6991
U __cxa_allocate_exception@@CXXABI_1.3
U __cxa_begin_catch@@CXXABI_1.3
U __cxa_call_unexpected@@CXXABI_1.3
#include <stdio.h>
#include <string.h>
#include "test-common.h"
#include "jerryscript.h"
static jerry_value_t
native_function (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_value_t args_count)
#include <stdarg.h>
#include <string.h>
#include <ocstack.h>
#include <stdlib.h>
#include "boilerplate.h"
#ifdef __unix__
# include <unistd.h>
#elif defined _WIN32
# include <windows.h>