Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Convert binding to N-API #2440

Open
wants to merge 27 commits into
base: v5
Choose a base branch
from
Open

Convert binding to N-API #2440

wants to merge 27 commits into from

Conversation

xzyfer
Copy link
Contributor

@xzyfer xzyfer commented Jul 8, 2018

Heavy work in progress of replacing NAN with N-API.

Attempting to combine the prior work boingoing#1 with the drift in master, namely #2128 #2298.

Fixes #1988

@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 11, 2018

This is getting pretty close. There's a segfault in one of the tests I still need to debug.

It's worth noting this unwinds the work @stefanpenner's to implement Nan::ObjectWrap (#2128) largely because I couldn't get my head around how to make Napi::ObjectWrap<T> work.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 11, 2018

This potentially unwinds @kkoopa's work to propagate async context (#2295) because I couldn't find the equivalent in N-API.

@xzyfer xzyfer force-pushed the napi branch 4 times, most recently from a342097 to cec10ba Compare July 12, 2018 14:00
@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 12, 2018

I have it compiling and running most of the tests. There is a segfault that seems semi random. I'll need to investigate.

I've update the the install scripts to use the N-API version instead of module version. Have confirmed binary compiled Node 10 executes on Node 6, 8, 9, 10. Although 9 displays an annoying warning that people will definitely files issues about because...

@xzyfer xzyfer force-pushed the napi branch 2 times, most recently from 96b5e31 to 73a9cea Compare July 16, 2018 14:08
@xzyfer xzyfer changed the base branch from master to v5 July 16, 2018 14:09
@xzyfer xzyfer changed the title [WIP] N-API Convert binding to N-API Jul 16, 2018
@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 16, 2018

I've resolved the segfault. All tests are passing locally (OSX) on all Node LTS and current.

We'll need to rejig CI a bit since the binary no longer builds on Node < 10.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 16, 2018

We have our first green N-API builds
https://travis-ci.org/sass/node-sass/builds/404487187

Just for kicks the current hacked CI setup shows that binaries built on Node 10 work on other LTS Node.

@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 16, 2018

@nschonni note this means we probably can't have node-gyp fallback to build

@nschonni
Copy link
Contributor

No, the node-pre-gyp handles napi vs the module version in it's download and fallback

@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 16, 2018

Sorry what I mean is that with N-API we can no longer compile the binary on Node < 10. So if the download fails there's no point node-pre-gyp falling back to build locally.

@nschonni
Copy link
Contributor

Ah, gotcha, but I think it is backported to v6 & v8. I think older stuff may be able to have support through https://github.com/nodejs/node-addon-api/blob/master/doc/setup.md but I'm not 💯

@xzyfer
Copy link
Contributor Author

xzyfer commented Jul 16, 2018 via email

xzyfer and others added 19 commits November 8, 2019 22:21
This was a non-standared feature in LibSass we had to support. It
is being removed in LibSass 3.6.0.

This prevents people from output their source directory.

See sass/libsass#2611
See #2184
See #2006
See #1933
See #1925
See #1867
See #1845
Four years ago there was a test that mutated `process.cwd` but
didn't correctly reset it. The altered global state resulted in
future tests having incorrect assetions. I only noticed this because
for some reason it manifested in failures in only _some_ Node
versions when N-API was being used.
This flag means we skip a bunch of code paths in CI which is not
ideal. Since we tell people to use `npm rebuild` we should eat our
own dog food.

With this patch we do an install, then do a rebuild hitting all the
major install code paths.

Fixes #1453
indent_type_len == 1 ? '\t' : ' '
).c_str());

napi_value propertyLinefeed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation problem?

binding.gyp Outdated
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
'OTHER_CPLUSPLUSFLAGS': [
'-std=c++11'
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do need this? should be covered by line 33 already...

// We can opt-in to later versions as we choose to adopt new API features.
//
// See https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix
Math.min(process.versions.napi, 3),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will napi version change when libuv interface is modified? we use that heavily as well.

napi_value Color::getConstructor(napi_env env, napi_callback cb) {
napi_value ctor;
napi_property_descriptor descriptors[] = {
{ "getR", nullptr, GetR },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

../src/sass_types/color.cpp:66:31: warning: missing field 'getter'
      initializer [-Wmissing-field-initializers]
      { "getR", nullptr, GetR },

and for others, too

@@ -2,30 +2,32 @@
#define CALLBACK_BRIDGE_H

#include <vector>
#include <nan.h>
#include <algorithm>
#include <uv.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including <uv.h> breaks guarantees of ABI stability offered by N-API. #2312 (comment)


namespace SassTypes
{
// This is the interface that all sass values must comply with
class Value : public Nan::ObjectWrap {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probable need to rebuild this without inheritance at all. Maybe this should become a template? We definitely need https://github.com/nodejs/node-addon-api/blob/master/doc/object_wrap.md here

givingwu and others added 2 commits November 9, 2019 18:13
…2620)

* fix: the function only need to execute once enough

* fix: typo `;`
@gabrielschulhof
Copy link

Is anyone still working on this 👋

jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this pull request Apr 7, 2024
…overread

Fix file content malloc to avoid reading beyond buffer
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants