Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

### Git template
# Created by git for backups. To disable backups in Git:
# $ git config --global mergetool.keepBackup false
*.orig

# Created by git when using merge tools for conflicts
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*_BACKUP_*.txt
*_BASE_*.txt
*_LOCAL_*.txt
*_REMOTE_*.txt

### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Go workspace file
go.work

### CUSTOM IGNORES ###
temp/
tmp/
build/
108 changes: 108 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Contributing

## TODO

### Unstable APIs

```go
// filename: node_api.go

package napi

func BasicFinalize(env Env, finalizeData, finalizeHint unsafe.Pointer) Status {
return Status(C.node_api_basic_finalize(
C.napi_env(env),
finalizeData,
finalizeHint,
))
}


func BasicEnv(env Env) Status {
return Status(C.node_api_basic_env(C.napi_env(env)))
}


func PostFinalizer(env Env, finalizeData, finalizeHint unsafe.Pointer) Status {
return Status(C.node_api_post_finalizer(
C.napi_env(env),
finalizeData,
finalizeHint,
))
}

```

### Fix the following functions

```go
// filename: node_api.go

package napi

/*
#include <stdlib.h>
#include <node/napi_api.h>
*/
import "C"
import "unsafe"

// OpenCallbackScope Function to open a callback scope
func OpenCallbackScope(env Env, resourceObject, context Value) (CallbackScope, Status) {
var scope CallbackScope
status := Status(C.napi_open_callback_scope(
C.napi_env(env),
C.napi_value(resourceObject),
C.napi_value(context),
(*C.napi_callback_scope)(unsafe.Pointer(&scope.scope)),
))
return scope, status
}

func CreateExternalStringLatin1(env Env, str string, finalize Finalize, finalizeHint unsafe.Pointer) (Value, Status) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))

finalizer := FinalizeToFinalizer(finalize)
var result Value
status := Status(C.node_api_create_external_string_latin1(
C.napi_env(env),
cstr,
C.size_t(len([]byte(str))),
C.napi_finalize(unsafe.Pointer(&finalizer)),
finalizeHint,
(*C.napi_value)(unsafe.Pointer(&result)),
))
return result, status
}


func CreateExternalStringUtf16(env Env, str []uint16, finalize Finalize, finalizeHint unsafe.Pointer) (Value, Status) {
var result Value
finalizer := FinalizeToFinalizer(finalize)
status := Status(C.node_api_create_external_string_utf16(
C.napi_env(env),
(*C.char16_t)(unsafe.Pointer(&str[0])),
C.size_t(len(str)),
C.napi_finalize(unsafe.Pointer(&finalizer)),
finalizeHint,
(*C.napi_value)(unsafe.Pointer(&result)),
))
return result, status
}


func CreateBufferFromArrayBuffer(env Env, arrayBuffer Value, byteOffset, length int) (Value, *byte, Status) {
var result Value
var data *byte
status := Status(C.node_api_create_buffer_from_arraybuffer(
C.napi_env(env),
C.napi_value(arrayBuffer),
C.size_t(byteOffset),
C.size_t(length),
unsafe.Pointer(&data),
(*C.napi_value)(unsafe.Pointer(&result)),
))
return result, data, status
}
```
4 changes: 2 additions & 2 deletions js/promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ func (p *Promise) ensurePending() {
}

func (p *Promise) settle() {
st := napi.CallThreadsafeFunction(p.ThreadsafeFunction)
st := napi.CallThreadsafeFunction(p.ThreadsafeFunction, napi.Blocking)
if st != napi.StatusOK {
panic(napi.StatusError(st))
}
}

func (p *Promise) release() {
st := napi.ReleaseThreadsafeFunction(p.ThreadsafeFunction)
st := napi.ReleaseThreadsafeFunction(p.ThreadsafeFunction, napi.Release)
if st == napi.StatusClosing {
p.ThreadsafeFunction = nil
} else if st != napi.StatusOK {
Expand Down
Loading