Giter Club home page Giter Club logo

native-mate's Introduction

A fork of Chromium's gin library that makes it easier to marshal types between C++ and JavaScript.

Overview

native-mate was forked from gin so that it could be used in Electron without conflicting with Node's Environment. It has also been extended to allow Electron to create classes in JavaScript.

With the help of Chromium's base library, native-mate makes writing JS bindings very easy, and most of the intricate details of converting V8 types to C++ types and back are taken care of auto-magically. In most cases there's no need to use the raw V8 API to implement an API binding.

For example, here's an API binding that doesn't use native-mate:

// static
void Shell::OpenItem(const v8::FunctionCallbackInfo<v8::Value>& args) {
  base::FilePath file_path;
  if (!FromV8Arguments(args, &file_path))
    return node::ThrowTypeError("Bad argument");

  platform_util::OpenItem(file_path);
}

// static
void Shell::Initialize(v8::Handle<v8::Object> target) {
  NODE_SET_METHOD(target, "openItem", OpenItem);
}

And here's the same API binding using native-mate:

void Initialize(v8::Handle<v8::Object> exports) {
  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
  dict.SetMethod("openItem", &platform_util::OpenItem);
}

Code Structure

  • converter.h - Templatized JS<->C++ conversion routines for many common C++ types. You can define your own by specializing Converter.
  • function_template.h - Create JavaScript functions that dispatch to any C++ function, member function pointer, or base::Callback.
  • object_template_builder.h - A handy utility for creation of v8::ObjectTemplate.
  • wrappable.h - Base class for C++ classes that want to be owned by the V8 GC. Wrappable objects are automatically deleted when GC discovers that nothing in the V8 heap refers to them. This is also an easy way to expose C++ objects to JavaScript.

native-mate's People

Contributors

anaisbetts avatar brenca avatar deepak1556 avatar enlight avatar kevinsawicki avatar marshallofsound avatar mgc avatar renaesop avatar sethlu avatar tsekityam avatar yzgyyang avatar zcbenz avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.