Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Nan 2.0 #90

Merged
merged 4 commits into from
Oct 6, 2015
Merged

Upgraded to Nan 2.0 #90

merged 4 commits into from
Oct 6, 2015

Conversation

tobiashm
Copy link
Contributor

Nan 1.0 does not work with io.js 3.x and node.js >= 4.0, since they use newer versions of V8.

Warning:
This is an automatic conversion, using this script https://gist.github.com/thlorenz/7e9d8ad15566c99fd116 and some minor fixes by hand.
The project builds and the tests passes, but I have no idea what I've done, so I can't guarantee for the correctness.

@tobiashm
Copy link
Contributor Author

This would close #81

@@ -52,9 +52,9 @@ NAN_METHOD(protagonist::ParseSync) {
drafter::ParseBlueprint(*sourceData, options, parseResult);

if (parseResult.report.error.code != snowcrash::Error::OK) {
NanThrowError(SourceAnnotation::WrapSourceAnnotation(parseResult.report.error));
NanReturnUndefined();
Nan::ThrowError(SourceAnnotation::WrapSourceAnnotation(parseResult.report.error).As<v8::Value>());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.As<T>() seems to be a problem in Node 0.10.x

See also: https://ci.appveyor.com/project/Apiary/protagonist/build/1.0.183#L2141

Copy link
Contributor

Choose a reason for hiding this comment

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

I am mostly sure that nan has a solution for this. We need to check thoroughly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, SourceAnnotation::WrapSourceAnnotation is used to create a new object type for warnings and errors. It might be too much to have it return a Nan::Error since it could be “just” a warning? But maybe it could return a v8::Local<v8::Value> instead of Local<Object>?

@tobiashm
Copy link
Contributor Author

Build and test is passing on my machine

$ node -v
v4.0.0

$ npm -v
2.14.2

$  npm install && npm test
npm WARN prefer global node-gyp@3.0.3 should be installed with -g

> protagonist@1.0.0 install /Users/thm/Development/protagonist
> node-gyp rebuild

  CXX(target) Release/obj.target/libmarkdownparser/drafter/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.o
  CXX(target) Release/obj.target/libmarkdownparser/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.o
  CXX(target) Release/obj.target/libmarkdownparser/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.o
  LIBTOOL-STATIC Release/markdownparser.a
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/HTTP.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/MSON.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/MSONOneOfParser.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/MSONSourcemap.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/MSONTypeSectionParser.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/MSONValueMemberParser.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/Blueprint.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/BlueprintSourcemap.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/Section.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/Signature.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/snowcrash.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/UriTemplateParser.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/HeadersParser.o
  CXX(target) Release/obj.target/libsnowcrash/drafter/ext/snowcrash/src/posix/RegexMatch.o
  LIBTOOL-STATIC Release/snowcrash.a
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_href_e.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.o
  CC(target) Release/obj.target/libsundown/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html_smartypants.o
  LIBTOOL-STATIC Release/sundown.a
  CXX(target) Release/obj.target/libdrafter/drafter/src/drafter.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/cdrafter.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/Serialize.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/SerializeAST.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/SerializeSourcemap.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/SerializeResult.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/RefractDataStructure.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/RefractAPI.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/Render.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/Element.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/SerializeCompactVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/SerializeVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/ComparableVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/TypeQueryVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/IsExpandableVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/ExpandVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/RenderJSONVisitor.o
  CXX(target) Release/obj.target/libdrafter/drafter/src/refract/Registry.o
  LIBTOOL-STATIC Release/drafter.a
  CXX(target) Release/obj.target/libsos/drafter/ext/sos/src/sos.o
  LIBTOOL-STATIC Release/sos.a
  CXX(target) Release/obj.target/protagonist/src/annotation.o
  CXX(target) Release/obj.target/protagonist/src/options_parser.o
  CXX(target) Release/obj.target/protagonist/src/parse_async.o
../src/parse_async.cc:134:15: warning: 'FatalException' is deprecated: Use FatalException(isolate, ...)
      [-Wdeprecated-declarations]
        node::FatalException(try_catch);
              ^
/Users/thm/.node-gyp/4.0.0/include/node/node.h:283:29: note: 'FatalException' has been explicitly marked deprecated
      here
                inline void FatalException(const v8::TryCatch& try_catch) {
                            ^
/Users/thm/.node-gyp/4.0.0/include/node/node.h:66:42: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                                         ^
1 warning generated.
  CXX(target) Release/obj.target/protagonist/src/parse_sync.o
  CXX(target) Release/obj.target/protagonist/src/protagonist.o
  CXX(target) Release/obj.target/protagonist/src/result.o
  CXX(target) Release/obj.target/protagonist/src/v8_wrapper.o
  SOLINK_MODULE(target) Release/protagonist.node

> protagonist@1.0.0 test /Users/thm/Development/protagonist
> mocha --compilers coffee:coffee-script -R spec ./test/*-test.coffee

(node) child_process: options.customFds option is deprecated. Use options.stdio instead.


  Parser AST - Async
    ✓ `ast` field conforms to `vnd.apiblueprint.ast+json; version=4.0` 

  Blueprint AST
    blueprint
      ✓ is defined 
      version
        ✓ is defined 
        ✓ is equal to 4.0 
      metadata
        ✓ is defined 
        ✓ is array 
        ✓ has one entry 
        ✓ the entry name is "FORMAT" 
        ✓ the entry value is "1A" 
      name
        ✓ is defined 
        ✓ is "My API" 
      description
        ✓ is defined 
        ✓ is "Lorem Ipsum" 
      resource group
        ✓ is defined 
        ✓ is array 
        ✓ has one resource 
      element
        ✓ is defined 
        ✓ is "category" 
      content
        ✓ is defined 
        ✓ is array 
        ✓ has one entry 
        entry
          ✓ is defined 
          element
            ✓ is defined 
            ✓ is of "category" type 

  MSON Refract
    Attributes
      ✓ are defined 
      ✓ are a data structure 
      ✓ are an object 
      ✓ object has a single member 
      ✓ member is `id` 
    Data structures
      ✓ are defined 
      ✓ have one item 
      ✓ item is a `Person` structure 
      ✓ Person has a `name` member 

  Parser Refract - Async
    ✓ conforms to the refract spec 

  Parser sourcemap
    ✓ `sourcemap` field conforms to `vnd.apiblueprint.sourcemap+json; version=4.0` 

  Parser AST - Sync
    ✓ `ast` field conforms to `vnd.apiblueprint.ast+json; version=4.0` 


  36 passing (85ms)

@ChALkeR
Copy link

ChALkeR commented Sep 21, 2015

Adding to the list: nodejs/node#2798.

Travis CI builds are failing because they use outdated gcc (4.6), while the minimum supported version is 4.8. This has to be configurable somehow on the Travis side, most likely in .travis.yml.

@zdne
Copy link
Contributor

zdne commented Sep 21, 2015

@tobiashm thanks for the contribution! Can you please try to fix the travis CI as @ChALkeR suggests (bumping the GCC version)? Also I do not see the GCC version in your build printout (I assume you are on 4.8).

Meanwhile we will discuss whether cutting support for GCC 4.6 is OK.

@tobiashm
Copy link
Contributor Author

Travis build for Node 4.x now passes with gcc 4.8, but 0.10 & 0.8 still fails due to .As<T>() not being supported for v8::Value in their versions of v8.

I'm on OS X, and it seems I'm using LLVM in place of gcc:

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

@@ -1,12 +1,23 @@
sudo: false
language: node_js
node_js:
- "4.1"
- "4.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have to give both the above versions. Please just add 4 and it should be enough.

Also, please cherry pick this commit and use it before your commits in this PR. 15b7c9d

@tobiashm
Copy link
Contributor Author

So, current status is that tests are passing on all CI builds.

Only outstanding issue, as far as I can see, is the wrapper introduced in 46851de to work around Nan::ThrowError not accepting a Local<Object>.
Does someone know more about handling errors with Nan? And can come up with a better wrapper model which can also hold the error code and location?

I don't know who (what code) is expected to consume the output of SourceAnnotation::WrapSourceAnnotation when using this module. If something will break if the format of the wrapper object changes.

@pksunkara
Copy link
Contributor

@tobiashm I optimized the code a bit and fixed a few issues in #94. Please rebase your work on it and I will work on this PR as soon as that PR is merged.

By the way, I cherry-picked your npm@2 commit in that branch, so you can remove it from here.

@tobiashm
Copy link
Contributor Author

@pksunkara that's great.

I've rebased, and it passes Travis CI.

Notice: The signature of SourceAnnotation::WrapSourceAnnotation has been changed to return Local<Value> instead of Local<Object> – so I basically removed the last ->ToObject() call.
I don't know how this will affect the code in AsyncParseAfter.

@martinheidegger
Copy link

If you could publish this today - oh it would be sooo awesome.

@pksunkara
Copy link
Contributor

The signature of SourceAnnotation::WrapSourceAnnotation has been changed to return Local<Value> instead of Local<Object> – so I basically removed the last ->ToObject() call.
I don't know how this will affect the code in AsyncParseAfter.

Do we need to do that? And yes, I am worried about how it will affect the code. As soon as that PR is merged, I will start looking into this.

@tobiashm
Copy link
Contributor Author

@pksunkara the reason for changing the signature was that passing Local<Object> to Nan::ThrowError doesn't work. This is the output it generates:

../src/parse_sync.cc:57:9: error: call to 'ThrowError' is ambiguous
        Nan::ThrowError(SourceAnnotation::WrapSourceAnnotation(parseResult.report.error));
        ^~~~~~~~~~~~~~~
../node_modules/nan/nan.h:639:3: note: candidate function
  X(Error)
  ^
../node_modules/nan/nan.h:633:21: note: expanded from macro 'X'
    NAN_INLINE void Throw ## NAME(v8::Local<v8::String> msg) {                 \
                    ^
<scratch space>:156:1: note: expanded from here
ThrowError
^
../node_modules/nan/nan.h:647:19: note: candidate function
  NAN_INLINE void ThrowError(v8::Local<v8::Value> error) {
                  ^
1 error generated.

Someone pointed out that this might be a bug in Nan, since Local<Object> is a subtype of Local<Value> but a 'sibling' to Local<String>, so they shouldn't really be ambiguous.
But again, I must point out that it's been around 20 years since I've done any C++ programming. So I don't have a very good idea about what I'm doing here 😁

So perhaps the best way forward would be to try to actually exercise the code that handles warnings and errors, to see how it actually behaves.
I hope you can figure out what's needed to make it work correctly.

@pksunkara
Copy link
Contributor

@tobiashm Can you create an issue in nan repo with the details from the above comment? I still haven't been able to find time to work on this.

@tobiashm
Copy link
Contributor Author

tobiashm commented Oct 6, 2015

@pksunkara I've changed the code back so it doesn't change the signature for SourceAnnotation::WrapSourceAnnotation and instead I just do a type cast in the call to Nan::ThrowError(). All CI builds are passing, so it should be fine.

I've submitted an issue to Nan, but they think it must be a compiler bug. And that's too advanced for me to start looking into 🙀

@pksunkara
Copy link
Contributor

Thanks for the change. The type casting is okay with me. I am now just waiting for #94 to be merged and we can rebase this PR and get this merged too.

@pksunkara
Copy link
Contributor

Can you rebase this over master and update the drafter submodule? Thanks.

pksunkara and others added 4 commits October 6, 2015 23:00
Nan 1.0 does not work with io.js 3.x and node.js >= 4.0, since they use newer versions of V8.

*Warning:*
This is an automatic conversion, using this script https://gist.github.com/thlorenz/7e9d8ad15566c99fd116 and some minor fixes by hand.
The project builds and the tests passes, but I have no idea what I've done, so I can't guarantee for the correctness.
@tobiashm
Copy link
Contributor Author

tobiashm commented Oct 6, 2015

@pksunkara done. Updated drafter to current master.

pksunkara added a commit that referenced this pull request Oct 6, 2015
@pksunkara pksunkara merged commit cff86f7 into apiaryio:master Oct 6, 2015
@pksunkara
Copy link
Contributor

Thanks for the contribution @tobiashm 😄

@tobiashm tobiashm deleted the nan2 branch October 6, 2015 21:41
@tobiashm
Copy link
Contributor Author

tobiashm commented Oct 6, 2015

Awesome :bowtie:
Looking forward to all the projects that depend on protagonist to be able to updated to work with Node 4!

@danielgtaylor
Copy link
Contributor

Nice work! 👍

@rodoabad
Copy link

rodoabad commented Oct 7, 2015

Good job guys!

@dsernst
Copy link

dsernst commented Oct 17, 2015

Will this be republished to npm with this update?

@kylef
Copy link
Member

kylef commented Oct 17, 2015

@dsernst Yes, there should be an update in the coming week with this change.

@rodoabad
Copy link

Good job guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants