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

2020-04计划 #2

Open
huenchao opened this issue Apr 11, 2020 · 5 comments
Open

2020-04计划 #2

huenchao opened this issue Apr 11, 2020 · 5 comments

Comments

@huenchao
Copy link
Owner

  1. kafka node客户端 https://itnext.io/a-simple-guide-to-load-c-c-code-into-node-js-javascript-applications-3fcccf54fd32
    2.faas服务落地规划
@huenchao
Copy link
Owner Author

参考书籍 《来一打c扩展》 、《nodecpp-ebook》

@huenchao
Copy link
Owner Author

@huenchao
Copy link
Owner Author

huenchao commented Apr 19, 2020

  1. 在nodejs中,什么叫module? nodejs中,一个文件就是一个module.
    流程:(1)Module.runMain() ---> (2) Module._load(process.argv[1], null, true);
    其中(2):
    // Check the cache for the requested file.
    // 1. If a module already exists in the cache: return its exports object.
    // 2. If the module is native: call
    // NativeModule.prototype.compileForPublicLoader() and return the exports.
    // 3. Otherwise, create a new module for the file and save it to the cache.
    // Then have it load the file contents before returning its exports
    // object.

@huenchao
Copy link
Owner Author

huenchao commented Apr 20, 2020

inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
                            const char* name,
                            v8::FunctionCallback callback) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  v8::HandleScope handle_scope(isolate);
  v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
                                                                callback);
  v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
      v8::NewStringType::kInternalized).ToLocalChecked();
  t->SetClassName(fn_name);
  recv->Set(fn_name, t);
}

@huenchao
Copy link
Owner Author

inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
                            const char* name,
                            v8::FunctionCallback callback) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  v8::HandleScope handle_scope(isolate);
  v8::Local<v8::Context> context = isolate->GetCurrentContext();
  v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
                                                                callback);
  v8::Local<v8::Function> fn = t->GetFunction(context).ToLocalChecked();
  v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
      v8::NewStringType::kInternalized).ToLocalChecked();
  fn->SetName(fn_name);
  recv->Set(context, fn_name, fn).Check();
}

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

No branches or pull requests

1 participant