prepare / Espresso

☕ Bridge your C# soul to the power of Javascript (V8 Javascript Engine / NodeJs)
MIT License
60 stars 11 forks source link

Espresso, NodeJS 12.11.1 #58

Open prepare opened 5 years ago

prepare commented 5 years ago

Bridge your C# soul to the power of Javascript (V8 Javascript Engine / NodeJs)

node_v12 EspressoND, Http/2, NodeJS12.11.1

prepare commented 5 years ago

Patches for NodeJS 12.11.1

There are 5 patches, patches are located here => Espresso\node_patches\node12.11.1_modified

...about line 8

#if defined(LEAK_SANITIZER)
#include <sanitizer/lsan_interface.h>
#endif
//////////////////////////////////
//#espresso ,#1
#include "../src/libespresso/bridge2.h"
void DoEngineSetupCallback(JsEngine* engine, JsContext* jsContext);
void DoEngineClosingCallback(JsEngine* engine,
                             JsContext* jsContext,
                             int exitCode);
//////////////////////////////////
namespace node {

using v8::Context;
using v8::HandleScope;

_patch 1: src/node_maininstance.cc


...about line 113

 int NodeMainInstance::Run() {
  Locker locker(isolate_);
  Isolate::Scope isolate_scope(isolate_);
  HandleScope handle_scope(isolate_);

  int exit_code = 0;
  std::unique_ptr<Environment> env = CreateMainEnvironment(&exit_code);

  CHECK_NOT_NULL(env);
  Context::Scope context_scope(env->context());

  if (exit_code == 0) {
    ////////////////////////////////
    //#espresso ,#2
    JsEngine* jsEngine = JsEngine::NewFromExistingIsolate(isolate_);
    v8::Persistent<Context>* pcontext =
        new v8::Persistent<Context>(isolate_, env->context());
    JsContext* jscontext =
        JsContext::NewFromExistingContext(0, jsEngine, pcontext);
    DoEngineSetupCallback(jsEngine, jscontext);
    ////////////////////////////////
    {
      AsyncCallbackScope callback_scope(env.get());
      env->async_hooks()->push_async_ids(1, 0);
      LoadEnvironment(env.get());
      env->async_hooks()->pop_async_id(1);
    }

_patch 2: src/node_maininstance.cc


...about line 162

   env->set_trace_sync_io(false);
    exit_code = EmitExit(env.get());
    ////////////////////////////////
    //#espresso ,#3
    DoEngineClosingCallback(jsEngine, jscontext, exit_code);
    ////////////////////////////////
    WaitForInspectorDisconnect(env.get());
  }

_patch 3: src/node_maininstance.cc


prepare commented 5 years ago

... about line about line 725


Module._resolveFilename = function(request, parent, isMain, options) {
  if (NativeModule.canBeRequiredByUsers(request)) {
    return request;
  }
  ////////////////////////////////////////////
  //#espresso, #4
  if (request.endsWith(".espr")) {
      return request;
  }
  ////////////////////////////////////////////
  var paths;

patch4: lib/internal/modules/cjs/loader.js


... about line about line 989

 // Native extension for .node
Module._extensions['.node'] = function(module, filename) {
  if (manifest) {
    const content = fs.readFileSync(filename);
    const moduleURL = pathToFileURL(filename);
    manifest.assertIntegrity(moduleURL, content);
  }
  // Be aware this doesn't use `content`
  return process.dlopen(module, path.toNamespacedPath(filename));
};
//////////////////////////////////
//#espresso, #5 
Module._extensions['.espr'] = function (module, filename) {
    //this make node to callback to our module
    var content = LibEspresso.LoadMainSrcFile();
    module._compile(stripBOM(content), filename);
};
//////////////////////////////////

patch5: lib/internal/modules/cjs/loader.js


prepare commented 5 years ago

for x86 on Windows "x86 release nobuild full-icu"