Skip to content

Commit

Permalink
support for node.js 7.x, fix async issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanczuk committed May 7, 2017
1 parent 83d9507 commit be77903
Show file tree
Hide file tree
Showing 55 changed files with 63 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/bootstrap/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@
"type": "platform",
"version": "1.0.0"
},
"Edge.js": "6.5.1",
"Edge.js": "7.10.0",
"Edge.js.CSharp": "1.2.0"
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 4,10 @@ var fs = require('fs')
, edge;

var versionMap = [
[ /^0\.8\./, '0.8.22' ],
[ /^0\.10\./, '0.10.0' ],
[ /^0\.12\./, '0.12.0' ],
[ /^4\./, '4.1.1' ],
[ /^5\./, '5.1.0' ],
[ /^6\./, '6.4.0' ],
[ /^7\./, '7.10.0' ],
];

function determineVersion() {
Expand Down
Binary file removed lib/native/win32/ia32/0.10.0/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/ia32/0.10.0/edge_nativeclr.node
Binary file not shown.
Binary file removed lib/native/win32/ia32/0.12.0/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/ia32/0.12.0/edge_nativeclr.node
Binary file not shown.
1 change: 0 additions & 1 deletion lib/native/win32/ia32/0.8.22/.gitignore

This file was deleted.

Binary file removed lib/native/win32/ia32/0.8.22/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/ia32/0.8.22/edge_nativeclr.node
Binary file not shown.
Binary file modified lib/native/win32/ia32/4.1.1/edge_coreclr.node
Binary file not shown.
Binary file modified lib/native/win32/ia32/4.1.1/edge_nativeclr.node
Binary file not shown.
Binary file modified lib/native/win32/ia32/5.1.0/edge_coreclr.node
Binary file not shown.
Binary file modified lib/native/win32/ia32/5.1.0/edge_nativeclr.node
Binary file not shown.
Binary file modified lib/native/win32/ia32/6.4.0/edge_coreclr.node
Binary file not shown.
Binary file modified lib/native/win32/ia32/6.4.0/edge_nativeclr.node
Binary file not shown.
File renamed without changes.
Binary file added lib/native/win32/ia32/7.10.0/edge_coreclr.node
Binary file not shown.
Binary file added lib/native/win32/ia32/7.10.0/edge_nativeclr.node
Binary file not shown.
1 change: 0 additions & 1 deletion lib/native/win32/x64/0.10.0/.gitignore

This file was deleted.

Binary file removed lib/native/win32/x64/0.10.0/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/x64/0.10.0/edge_nativeclr.node
Binary file not shown.
1 change: 0 additions & 1 deletion lib/native/win32/x64/0.12.0/.gitignore

This file was deleted.

Binary file removed lib/native/win32/x64/0.12.0/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/x64/0.12.0/edge_nativeclr.node
Binary file not shown.
1 change: 0 additions & 1 deletion lib/native/win32/x64/0.8.22/.gitignore

This file was deleted.

Binary file removed lib/native/win32/x64/0.8.22/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/x64/0.8.22/edge_nativeclr.node
Binary file not shown.
Binary file modified lib/native/win32/x64/4.1.1/edge_coreclr.node
Binary file not shown.
Binary file modified lib/native/win32/x64/4.1.1/edge_nativeclr.node
Binary file not shown.
Binary file modified lib/native/win32/x64/5.1.0/edge_coreclr.node
Binary file not shown.
Binary file modified lib/native/win32/x64/5.1.0/edge_nativeclr.node
Binary file not shown.
Binary file modified lib/native/win32/x64/6.4.0/edge_coreclr.node
Binary file not shown.
Binary file modified lib/native/win32/x64/6.4.0/edge_nativeclr.node
Binary file not shown.
File renamed without changes.
Binary file added lib/native/win32/x64/7.10.0/edge_coreclr.node
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@
"url": "http://tomasz.janczuk.org",
"twitter": "tjanczuk"
},
"version": "6.5.1",
"version": "7.10.0",
"description": "Edge.js: run .NET and Node.js in-process on Windows, Mac OS, and Linux",
"tags": [
"owin",
Expand Down
2 changes: 1 addition & 1 deletion src/CoreCLREmbedding/coreclrfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 55,7 @@ v8::Local<v8::Function> CoreClrFunc::InitializeInstance(CoreClrGcHandle function

v8::Local<v8::Value> factoryArgv[] = { Nan::New(proxyFunction), Nan::New<v8::External>((void*)wrap) };
v8::Local<v8::Function> funcProxy =
(Nan::New(proxyFactory)->Call(Nan::GetCurrentContext()->Global(), 2, factoryArgv)).As<v8::Function>();
(Nan::Call(Nan::New(proxyFactory), Nan::GetCurrentContext()->Global(), 2, factoryArgv)).ToLocalChecked().As<v8::Function>();
Nan::Persistent<v8::Function> funcProxyPersistent(funcProxy);
funcProxyPersistent.SetWeak((void*)wrap, &coreClrFuncProxyNearDeath, Nan::WeakCallbackType::kParameter);

Expand Down
20 changes: 9 additions & 11 deletions src/CoreCLREmbedding/coreclrfuncinvokecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 4,7 @@ CoreClrFuncInvokeContext::CoreClrFuncInvokeContext(v8::Local<v8::Value> callback
{
DBG("CoreClrFuncInvokeContext::CoreClrFuncInvokeContext");

this->callback = new Nan::Persistent<Function>();
v8::Local<v8::Function> callbackFunction = v8::Local<v8::Function>::Cast(callback);
this->callback->Reset(callbackFunction);
this->callback = new Nan::Callback(v8::Local<v8::Function>::Cast(callback));
}

CoreClrFuncInvokeContext::~CoreClrFuncInvokeContext()
Expand Down Expand Up @@ -87,15 85,15 @@ void CoreClrFuncInvokeContext::InvokeCallback(void* data)
int argc = 2;

Nan::TryCatch tryCatch;
Nan::New<v8::Function>(*(context->callback))->Call(Nan::GetCurrentContext()->Global(), argc, argv);

DBG("CoreClrFuncInvokeContext::InvokeCallback - Callback function invoked");
delete context;

if (tryCatch.HasCaught())
{
Nan::FatalException(tryCatch);
}
DBG("CoreClrFuncInvokeContext::InvokeCallback - calling JS callback");
context->callback->Call(argc, argv);
delete context;
if (tryCatch.HasCaught())
{
DBG("CoreClrFuncInvokeContext::InvokeCallback - exception in callback");
Nan::FatalException(tryCatch);
}

DBG("CoreClrFuncInvokeContext::InvokeCallback - Complete");
}
7 changes: 6 additions & 1 deletion src/CoreCLREmbedding/coreclrnodejsfuncinvokecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 96,7 @@ void CoreClrNodejsFuncInvokeContext::InvokeCallback(void* data)
TryCatch tryCatch;

DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback - Calling JavaScript function");
Nan::New(*(context->FunctionContext->Func))->Call(Nan::GetCurrentContext()->Global(), 2, argv);
Nan::Call(Nan::New(*(context->FunctionContext->Func)), Nan::GetCurrentContext()->Global(), 2, argv);
DBG("CoreClrNodejsFuncInvokeContext::InvokeCallback - Called JavaScript function");

if (tryCatch.HasCaught())
Expand All @@ -110,4 110,9 @@ void CoreClrNodejsFuncInvokeContext::InvokeCallback(void* data)

context->Complete(TaskStatusFaulted, exceptionData, V8TypeException);
}
else
{
// Kick the next tick
CallbackHelper::KickNextTick();
}
}
2 changes: 1 addition & 1 deletion src/CoreCLREmbedding/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 71,7 @@ typedef enum v8Type
class CoreClrFuncInvokeContext
{
private:
Nan::Persistent<Function>* callback;
Nan::Callback* callback;
CoreClrGcHandle task;
uv_edge_async_t* uv_edge_async;
void* resultData;
Expand Down
3 changes: 3 additions & 0 deletions src/dotnet/nodejsfuncinvokecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 94,10 @@ void NodejsFuncInvokeContext::CallFuncOnV8Thread()

v8::Local<v8::Value> argv[] = { jspayload, callback };
Nan::TryCatch tryCatch;

DBG("NodejsFuncInvokeContext::CallFuncOnV8Thread calling JavaScript function");
Nan::Call(Nan::New(*(this->functionContext->Func)), Nan::GetCurrentContext()->Global(), 2, argv);
DBG("NodejsFuncInvokeContext::CallFuncOnV8Thread called JavaScript function");
if (tryCatch.HasCaught())
{
DBG("NodejsFuncInvokeContext::CallFuncOnV8Thread caught JavaScript exception");
Expand Down
4 changes: 2 additions & 2 deletions src/double/Edge.js/project.json
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
{
"version": "6.5.1",
"description": "With Edge.js you can script Node.js in a .NET application. Edge.js allows you to run Node.js and .NET code in one process. You can call Node.js functions from .NET and .NET functions from Node.js. Edge.js takes care of marshalling data between CLR and V8. Edge.js also reconciles threading models of single threaded V8 and multi-threaded CLR. Edge.js ensures correct lifetime of objects on V8 and CLR heaps. This Edge.js NuGet package supports scripting Node.js v6.5.0.",
"version": "7.10.0",
"description": "With Edge.js you can script Node.js in a .NET application. Edge.js allows you to run Node.js and .NET code in one process. You can call Node.js functions from .NET and .NET functions from Node.js. Edge.js takes care of marshalling data between CLR and V8. Edge.js also reconciles threading models of single threaded V8 and multi-threaded CLR. Edge.js ensures correct lifetime of objects on V8 and CLR heaps. This Edge.js NuGet package supports scripting Node.js v7.10.0.",
"copyright": "Copyright 2015 Tomasz Janczuk",
"packOptions": {
"summary": "Script Node.js in a .NET application.",
Expand Down
2 changes: 1 addition & 1 deletion src/mono/clrfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 58,7 @@ v8::Local<v8::Function> ClrFunc::Initialize(MonoObject* func)

v8::Local<v8::Value> factoryArgv[] = { Nan::New(proxyFunction), Nan::New<v8::External>((void*)wrap) };
v8::Local<v8::Function> funcProxy =
(Nan::New(proxyFactory)->Call(Nan::GetCurrentContext()->Global(), 2, factoryArgv)).As<v8::Function>();
(Nan::Call(Nan::New(proxyFactory), Nan::GetCurrentContext()->Global(), 2, factoryArgv)).ToLocalChecked().As<v8::Function>();
Nan::Persistent<v8::Function> funcProxyPersistent(funcProxy);
funcProxyPersistent.SetWeak((void*)wrap, &clrFuncProxyNearDeath, Nan::WeakCallbackType::kParameter);

Expand Down
13 changes: 7 additions & 6 deletions src/mono/clrfuncinvokecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 29,8 @@ ClrFuncInvokeContext::ClrFuncInvokeContext(v8::Local<v8::Value> callbackOrSync)
DBG("ClrFuncInvokeContext::ClrFuncInvokeContext");
if (callbackOrSync->IsFunction())
{
this->callback = new Nan::Persistent<Function>(); // released in destructor
v8::Local<v8::Function> callbackOrSyncFunction = v8::Local<v8::Function>::Cast(callbackOrSync);
(this->callback)->Reset(callbackOrSyncFunction);
// released in destructor
this->callback = new Nan::Callback(v8::Local<v8::Function>::Cast(callbackOrSync));
this->Sync(FALSE);
}
else
Expand Down Expand Up @@ -132,12 131,14 @@ v8::Local<v8::Value> ClrFuncInvokeContext::CompleteOnV8Thread(bool completedSync
{
// complete the asynchronous call to C# by invoking a callback in JavaScript
Nan::TryCatch try_catch;
Nan::New<v8::Function>(*(this->callback))->Call(Nan::GetCurrentContext()->Global(), argc, argv);
DBG("ClrFuncInvokeContext::CompleteOnV8Thread - calling JS callback");
this->callback->Call(argc, argv);
delete this;
if (try_catch.HasCaught())
if (try_catch.HasCaught())
{
DBG("ClrFuncInvokeContext::CompleteOnV8Thread - exception in callback");
Nan::FatalException(try_catch);
}
}

return scope.Escape(Nan::Undefined());
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 64,7 @@ class Dictionary
class ClrFuncInvokeContext {
private:
GCHandle _this;
Nan::Persistent<v8::Function>* callback;
Nan::Callback* callback;
uv_edge_async_t* uv_edge_async;

public:
Expand Down
7 changes: 6 additions & 1 deletion src/mono/nodejsfuncinvokecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 70,19 @@ void NodejsFuncInvokeContext::CallFuncOnV8Thread(MonoObject* _this, NodejsFunc*
v8::Local<v8::Value> argv[] = { jspayload, callback };
Nan::TryCatch tryCatch;
DBG("NodejsFuncInvokeContext::CallFuncOnV8Thread calling JavaScript function");
Nan::New(*(nativeNodejsFunc->Func))->Call(Nan::GetCurrentContext()->Global(), 2, argv);
Nan::Call(Nan::New(*(nativeNodejsFunc->Func)), Nan::GetCurrentContext()->Global(), 2, argv);
DBG("NodejsFuncInvokeContext::CallFuncOnV8Thread called JavaScript function");
if (tryCatch.HasCaught())
{
DBG("NodejsFuncInvokeContext::CallFuncOnV8Thread caught JavaScript exception");
ctx->Complete((MonoObject*)exceptionV82stringCLR(tryCatch.Exception()), NULL);
// ctx deleted in Complete
}
else
{
// Kick the next tick
CallbackHelper::KickNextTick();
}

// In the absence of exception, processing resumes in v8FuncCallback
}
Expand Down
6 changes: 3 additions & 3 deletions test/double/double_stress/double_stress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="EdgeJs, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Edge.js.4.0.0\lib\EdgeJs.dll</HintPath>
<HintPath>packages\Edge.js.7.10.0\lib\net40\EdgeJs.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -50,10 50,10 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="edge\x64\edge.node">
<None Include="edge\x64\edge_nativeclr.node">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="edge\x86\edge.node">
<None Include="edge\x86\edge_nativeclr.node">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
Expand Down
2 changes: 1 addition & 1 deletion test/double/double_stress/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Edge.js" version="4.0.0" targetFramework="net45" />
<package id="Edge.js" version="7.10.0" targetFramework="net45" />
</packages>
20 changes: 10 additions & 10 deletions test/double/double_test/double_test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="EdgeJs, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Edge.js.6.5.1\lib\net40\EdgeJs.dll</HintPath>
<HintPath>packages\Edge.js.7.10.0\lib\net40\EdgeJs.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
Expand All @@ -58,15 58,6 @@
<Compile Include="DoubleEdge.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="edge\x64\edge_nativeclr.node">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="edge\x86\edge_nativeclr.node">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="edge\double_edge.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -81,6 72,15 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="edge\x64\edge_nativeclr.node">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="edge\x86\edge_nativeclr.node">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/double/double_test/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Edge.js" version="6.5.1" targetFramework="net45" />
<package id="Edge.js" version="7.10.0" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@
"type": "platform",
"version": "1.0.0"
},
"Edge.js": "6.5.1",
"Edge.js": "7.10.0",
"Edge.js.CSharp": "1.2.0",
"System.Xml.XmlSerializer": "4.0.11",
"System.Xml.ReaderWriter": "4.0.11"
Expand Down
6 changes: 4 additions & 2 deletions test/test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 3,19 @@ rem usage: test.bat [ia32|x64 {version}], e.g. test.bat x64 0.10.0
set EDGE_APP_ROOT=%~dp0\bin\Debug\netcoreapp1.0
set NODEEXE=node.exe
set EDGE_USE_CORECLR=
if "%1" neq "" if "%2" neq "" set EDGE_NATIVE=%~dp0\..\lib\native\win32\%1\%2\edge_nativeclr.node
if "%1" neq "" if "%2" neq "" set NODEEXE=%~dp0\..\lib\native\win32\%1\%2\node.exe
echo Using node.js: %NODEEXE%
rmdir /s /q "%~dp0/bin"
rmdir /s /q "%~dp0/obj"
call "%~dp0\build.bat"
if %ERRORLEVEL% NEQ 0 exit /b -1;
pushd "%~dp0\.."
"%NODEEXE%" "%APPDATA%\npm\node_modules\mocha\bin\mocha" -R spec
set EDGE_USE_CORECLR=1
if "%1" neq "" if "%2" neq "" set EDGE_NATIVE=%~dp0\..\lib\native\win32\%1\%2\edge_coreclr.node
REM set EDGE_DEBUG=1
popd
rmdir /s /q "%~dp0/bin"
rmdir /s /q "%~dp0/obj"
call "%~dp0\build.bat"
if %ERRORLEVEL% NEQ 0 exit /b -1;
pushd "%~dp0\.."
Expand Down
8 changes: 2 additions & 6 deletions test/testall.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 10,15 @@ if "%1"=="" set run64=Y
if "%1"=="x64" set run64=Y

if "%run32%"=="Y" (
call "%SELF%\test.bat" ia32 7.10.0
call "%SELF%\test.bat" ia32 6.4.0
call "%SELF%\test.bat" ia32 4.1.1
call "%SELF%\test.bat" ia32 5.1.0
call "%SELF%\test.bat" ia32 0.12.0
call "%SELF%\test.bat" ia32 0.8.22
call "%SELF%\test.bat" ia32 0.10.0
)

if "%run64%"=="Y" (
call "%SELF%\test.bat" x64 7.10.0
call "%SELF%\test.bat" x64 6.4.0
call "%SELF%\test.bat" x64 4.1.1
call "%SELF%\test.bat" x64 5.1.0
call "%SELF%\test.bat" x64 0.12.0
call "%SELF%\test.bat" x64 0.8.22
call "%SELF%\test.bat" x64 0.10.0
)
2 changes: 1 addition & 1 deletion tools/buildall.bat
Original file line number Diff line number Diff line change
@@ -1,2 1,2 @@
@echo off
"%~dp0\build.bat" release 0.8.22 0.10.0 0.12.0 4.1.1 5.1.0 6.4.0
"%~dp0\build.bat" release 4.1.1 5.1.0 6.4.0 7.10.0

0 comments on commit be77903

Please sign in to comment.