Giter Club home page Giter Club logo

fengmk2.github.com's Introduction

This is MK2

Hello World!

fengmk2.github.com's People

Contributors

fengmk2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fengmk2.github.com's Issues

C++ 模块的 Assertion 断言失败会导致 js 层面的调用堆栈丢失

源自于 cnpm/cnpmjs.org#335

目前还找不到具体是那段 js 代码写错了.

但是能写一个模拟重现代码:

var zlib = require('zlib');

var stream = zlib.createGzip();

stream.write('foo');
stream.close();

// Assertion failed: (!ctx->pending_close_ && "close is pending"), function Write, file ../src/node_zlib.cc, line 150.
stream.write('again');

尝新去给 node 提交 pr, 让这个判断放到 js 层面做.

nan 入门手册

最近在尝试改进 hsf 的 c++ 模块实现, 将 hessian 1.0 的 encode 和 decode 暴露出来给 js 调用.

因为需要保证 hsf 模块能在node 0.10.x 和 0.11.x 都能正常使用, 那么必须让此 c++ 模块有良好的代码兼容性.

吐血, c++ 新手还要考虑兼容性, 晴天霹雳.

org, 还好发现了 nan: A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10 and 0.11, and eventually 0.12.

示例代码

@see nan#api

codes at: nan-example

基本类型

// function showTypes() {}
NAN_METHOD(showTypes) {
  NanScope();

  // var foo;
  // var bar = null;
  v8::Local<v8::Value> foo = NanUndefined();
  v8::Local<v8::Value> bar = NanNull();
  v8::Handle<v8::Value> bar2 = NanNull();

  // var t = true;
  // var f = false;
  v8::Local<v8::Boolean> t = NanTrue();
  v8::Local<v8::Boolean> f = NanFalse();

  // var v1 = 100;
  // var v2 = 1024.123;
  // var v3 = 0.123456789;
  v8::Local<v8::Number> v1 = NanNew<v8::Number>(100);
  v8::Local<v8::Number> v2 = NanNew<v8::Number>(1024.123);
  v8::Handle<v8::Number> v3 = NanNew<v8::Number>(0.123456789);

  // var s1 = '';
  // var s2 = 'hello world';
  // var s3 = 'no ascii 还有中文';
  v8::Local<v8::String> s1 = NanNew<v8::String>("");
  v8::Local<v8::String> s2 = NanNew<v8::String>("hello world");
  v8::Local<v8::String> s3 = NanNew<v8::String>("no ascii 还有中文");

  // var now = new Date(1399273631054);
  double timestamp = 1399273631054;
  v8::Local<v8::Date> now = NanNew<v8::Date>(timestamp);

  // var result = {};
  // result['undefined'] = foo;
  // result['null'] = bar;
  // result['null2'] = bar2;
  // result['true'] = t;
  // result['false'] = f;
  // result['v1'] = v1;
  // result['v2'] = v2;
  // result['v3'] = v3;
  // result['s1'] = s1;
  // result['s2'] = s2;
  // result['s3'] = s3;
  // result.now = now;
  v8::Local<v8::Object> result = NanNew<v8::Object>();
  result->Set(NanSymbol("undefined"), foo);
  result->Set(NanSymbol("null"), bar);
  result->Set(NanSymbol("null2"), bar2);
  result->Set(NanSymbol("true"), t);
  result->Set(NanSymbol("false"), f);
  result->Set(NanSymbol("v1"), v1);
  result->Set(NanSymbol("v2"), v2);
  result->Set(NanSymbol("v3"), v3);
  result->Set(NanSymbol("s1"), s1);
  result->Set(NanSymbol("s2"), s2);
  result->Set(NanSymbol("s3"), s3);
  result->Set(NanSymbol("now"), now);

  // var arr = [];
  // arr.push(foo);
  // arr.push(bar);
  // arr.push(bar2);
  // arr.push(t);
  // arr.push(f);
  // arr.push(v1);
  // arr.push(v2);
  // arr.push(v3);
  // arr.push(s1);
  // arr.push(s2);
  // arr.push(s3);
  // arr.push(now);
  int index = 0;
  v8::Local<v8::Array> arr = NanNew<v8::Array>();
  arr->Set(index++, foo);
  arr->Set(index++, bar);
  arr->Set(index++, bar2);
  arr->Set(index++, t);
  arr->Set(index++, f);
  arr->Set(index++, v1);
  arr->Set(index++, v2);
  arr->Set(index++, v3);
  arr->Set(index++, s1);
  arr->Set(index++, s2);
  arr->Set(index++, s3);
  arr->Set(index++, now);

  result->Set(NanSymbol("array"), arr);
  result->Set(NanSymbol("array-length"), NanNew<v8::Number>(arr->Length()));

  NanReturnValue(result);
}

v8::Local 和 v8::Handle 的区别

v8::XXX 和 v8::XXXObject 的区别

Number vs NumberObject

函数

module.exports

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.