Simplifying the expansion of the Google V8 JS engine with Nan

Source: Internet
Author: User

Google V8 JS engine through C + + extension of the article many, Google V8 JS Belt example is easy to understand. But most of the articles are of the Hello World type, and the real use of it is found everywhere is a pit. The most classic example of extension V8 is node, and if you want to do a real project, it's great to look at node itself and its extension modules.

The C + + extension that mentions node has to mention that Nan,nan is native abstractions for node. JS, which makes it easy to extend V8, especially when extended with classes.

Classes inherit from Objectwrap, such as:

class Location: public ObjectWrap {public:    Location();    ~Location();...

Convert the JS object to a C + + object with Objectwrap::unwrap:

NAN_SETTER(LocationSetProtocol) {    NanScope();    Location*= ObjectWrap::Unwrap<Location>(args.This());    if (value->IsString()) {        v8::String::Utf8Value nativeValue(value);        obj->setProtocol(*nativeValue);    }else{        printf("invalid data type for Location.protocol\n");    }}

For complete code, please refer to: https://github.com/drawapp8/cantk-runtime-v8/tree/master/src/cantk-rt

Nan relies on some macros and functions with node, and I took some time to separate it out, you can download it here: Https://github.com/drawapp8/v8-native-binding-generator/tree/master/nan

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Simplifying the expansion of the Google V8 JS engine with Nan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.