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 11.12.0 #52

Closed prepare closed 4 years ago

prepare commented 5 years ago

Patches for NodeJS 11.12.0

patches are located here => Espresso\node_patches\node11.12.0_modified

... about line 116


#include <string>
#include <vector>

//////////////////////////////////
//#espresso ,#1
#include "../src/libespresso/bridge2.h"
void DoEngineSetupCallback(JsEngine* engine, JsContext* jsContext);
void DoEngineClosingCallback(JsEngine* engine, JsContext* jsContext,int exitCode);
//////////////////////////////////

namespace node {

using options_parser::kAllowedInEnvironment;
using options_parser::kDisallowedInEnvironment;

patch 1: src/node.cc


... about line 778

inline int StartNodeWithIsolate(Isolate* isolate,
                                IsolateData* isolate_data,
                                const std::vector<std::string>& args,
                                const std::vector<std::string>& exec_args) {
  HandleScope handle_scope(isolate);
  Local<Context> context = NewContext(isolate);
  Context::Scope context_scope(context);
  int exit_code = 0;
  Environment env(
      isolate_data,
      context,
      static_cast<Environment::Flags>(Environment::kIsMainThread |
                                      Environment::kOwnsProcessState |
                                      Environment::kOwnsInspector));
  env.InitializeLibuv(per_process::v8_is_profiling);
  env.ProcessCliArgs(args, exec_args);

  ////////////////////////////////
  //#espresso ,#2
  JsEngine* jsEngine = JsEngine::NewFromExistingIsolate(isolate);
  v8::Persistent<Context>* pcontext =
  new v8::Persistent<Context>(isolate, context);
  JsContext* jscontext = JsContext::NewFromExistingContext(0, jsEngine, pcontext);
  DoEngineSetupCallback(jsEngine, jscontext);
  ////////////////////////////////

#if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM
  CHECK(!env.inspector_agent()->IsListening());

patch2: src/node.cc


about line 856

  env.set_trace_sync_io(false);

  exit_code = EmitExit(&env);

  ////////////////////////////////
  //#espresso ,#3
  DoEngineClosingCallback(jsEngine, jscontext,exit_code);
  ////////////////////////////////

  WaitForInspectorDisconnect(&env);

exit:
  env.set_can_call_into_js(false);
  env.stop_sub_worker_contexts();
  uv_tty_reset_mode();
  env.RunCleanup();
  RunAtExit(&env);

patch3: src/node.cc

prepare commented 5 years ago

... about line about line 603

function tryModuleLoad(module, filename) {
  var threw = true;
  try {
    module.load(filename);
    threw = false;
  } finally {
    if (threw) {
      delete Module._cache[filename];
    }
  }
}

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 797

// 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.external_loader= LibEspresso;
Module._extensions['.espr'] = function (module, filename) {
    //this make node to callback to our module
    var content = Module.external_loader.LoadMainSrcFile();
    module._compile(stripBOM(content), filename);
};
//////////////////////////////////

if (experimentalModules) {
  if (asyncESM === undefined) lazyLoadESM();
  Module._extensions['.mjs'] = function(module, filename) {
    throw new ERR_REQUIRE_ESM(filename);
  };
}

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


prepare commented 5 years ago

Espresso-ND based on NodeJS 11.12.0, there are 5 patches


Espresso-VE based on v8 from NodeJS 11.12.0

to build release mode of the 'VE' version for 32 bits on Windows, one should build it with x64_x86 CrossTools command promt

eg ...

msbuild libespresso.vcxproj /p:Configuration=Release

prepare commented 5 years ago

Espresso-ND, v8 from NodeJS, http2 test

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