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

Espresso, NodeJS 13.5.0 #59

Open
prepare opened this issue Dec 21, 2019 · 2 comments
Open

Espresso, NodeJS 13.5.0 #59

prepare opened this issue Dec 21, 2019 · 2 comments
Labels

Comments

@prepare
Copy link
Owner

prepare commented Dec 21, 2019

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

espr_nd_13_5_0

EspressoND, Http/2, NodeJS13.5.0

@prepare prepare added the INFO label Dec 21, 2019
@prepare prepare changed the title Espressp, NodeJS 13.5.0 Espresso, NodeJS 13.5.0 Dec 21, 2019
@prepare
Copy link
Owner Author

prepare commented Dec 21, 2019

Patches for NodeJS 13.5.0

There are 5 patches,
patches are located here => Espresso\node_patches\node13.5.0_modified

...about line 6

#if defined(LEAK_SANITIZER)
#include <sanitizer/lsan_interface.h>
#endif

#if HAVE_INSPECTOR
#include "inspector/worker_inspector.h"  // ParentInspectorHandle
#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;
using v8::Isolate;
using v8::Local;

patch 1: src/node_main_instance.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);
    ////////////////////////////////	

    { 	
      InternalCallbackScope callback_scope(
          env.get(),
          Local<Object>(),
          { 1, 0 },
          InternalCallbackScope::kAllowEmptyResource |
              InternalCallbackScope::kSkipAsyncHooks);
      LoadEnvironment(env.get());
    }

patch 2: src/node_main_instance.cc


...about line 170

      // Emit `beforeExit` if the loop became alive either after emitting
        // event, or after running some callbacks.
        more = uv_loop_alive(env->event_loop());
      } while (more == true && !env->is_stopping());
      env->performance_state()->Mark(
          node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
    }

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

  env->set_can_call_into_js(false);
  env->stop_sub_worker_contexts();
  ResetStdio();
  env->RunCleanup();

patch 3: src/node_main_instance.cc


@prepare
Copy link
Owner Author

prepare commented Dec 21, 2019

... about line about line 911

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

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


... about line about line 1188

 // 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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant