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