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

Latest node #56

Open
wants to merge 5 commits into
base: v_11_15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Espresso.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "NodeJsEngineHelper", "Tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNode01_NetworkClients", "Tests\TestNode01_NetworkClients\TestNode01_NetworkClients.csproj", "{3D1E03EB-863D-4B02-9021-C69805C73F7C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libespr", "libespresso\libespresso.vcxproj", "{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Tests\NodeJsEngineHelper\NodeJsEngineHelper.projitems*{25c800d8-d92c-4ee9-9512-3fe928e2b6c4}*SharedItemsImports = 13
Expand Down Expand Up @@ -346,6 +348,24 @@ Global
{3D1E03EB-863D-4B02-9021-C69805C73F7C}.Release|x64.Build.0 = Release|Any CPU
{3D1E03EB-863D-4B02-9021-C69805C73F7C}.Release|x86.ActiveCfg = Release|Any CPU
{3D1E03EB-863D-4B02-9021-C69805C73F7C}.Release|x86.Build.0 = Release|Any CPU
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|Any CPU.ActiveCfg = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|Win32.ActiveCfg = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|Win32.Build.0 = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|x64.ActiveCfg = Debug|x64
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|x64.Build.0 = Debug|x64
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|x86.ActiveCfg = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Debug|x86.Build.0 = Debug|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|Any CPU.ActiveCfg = Release|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|Mixed Platforms.Build.0 = Release|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|Win32.ActiveCfg = Release|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|Win32.Build.0 = Release|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|x64.ActiveCfg = Release|x64
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|x64.Build.0 = Release|x64
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|x86.ActiveCfg = Release|Win32
{880EF82B-4FAD-42B1-98A6-09B5835F5FE6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Espresso Modified by John Chen
===============
Modified to build with the latest version of Nuget-V8 (7.4.288.11). NodeJS support dropped.

License:
MIT, 2013, Federico Di Gregorio fog@initd.org, https://github.com/fogzot/vroomjs

MIT, 2015-2019, WinterDev

MIT, 2019, John Chen

Espresso / Espresso-VE / Espresso-ND
===============

Expand Down
3 changes: 2 additions & 1 deletion build/Net20/EspressoCore/0_Start/JsBridgeForNet20.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//MIT, 2015-present, WinterDev, EngineKit, brezza92
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Espresso
{
Expand All @@ -19,7 +20,7 @@ public static void LoadV8(string dllfile, bool doV8Init = true)
if (doV8Init)
{
//sometime we set to false , and let underlying lib init the v8 engine.
NativeV8JsInterOp.V8Init();
NativeV8JsInterOp.V8Init(Path.GetDirectoryName(dllfile));
}
}

Expand Down
9 changes: 7 additions & 2 deletions build/Net20/EspressoCore/EspressoCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EspressoCore</RootNamespace>
<AssemblyName>EspressoCore</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -21,7 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,6 +33,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -41,6 +44,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
Expand All @@ -51,6 +55,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
12 changes: 9 additions & 3 deletions build/Net20/SandBox2/SandBox2.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
Expand All @@ -10,18 +10,20 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SandBox2</RootNamespace>
<AssemblyName>SandBox2</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -31,6 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand All @@ -50,6 +53,9 @@
<Name>EspressoCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
18 changes: 10 additions & 8 deletions build/Net20/SandBox2/Sandbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace Sandbox

public class debugtest
{
public int TestProp { get; set; }
public static int TestProp { get; set; }

public static bool BoolTest(int a, int b)
public bool BoolTest(int a, int b)
{
return a == b;
}
Expand Down Expand Up @@ -64,15 +64,17 @@ class Sandbox
{
public static void Main(string[] args)
{
// string lodash = File.ReadAllText(@"c:\lodash.js");
using (JsEngine engine = new JsEngine())
// string lodash = File.ReadAllText(@"c:\lodash.js");
Espresso.JsBridge.V8Init(Environment.CurrentDirectory + "\\");
using (JsEngine engine = new JsEngine())
{
//Stopwatch watch = new Stopwatch();
// watch.Start();
JsScript script = engine.CompileScript("3+3", "<unnamed>");
using (JsContext ctx = engine.CreateContext())
{
ctx.Execute(script);
object result = ctx.Execute(script);
Console.WriteLine(result);
}
}

Expand All @@ -88,12 +90,12 @@ public static void Main(string[] args)
{
using (JsContext context = js.CreateContext())
{
//context.SetVariable("dbg", dbg);
context.SetVariableFromAny("dbg", dbg);
//object result = context.Execute("dbg.Write(dbg.valueOf());");
context.SetVariableFromAny("Debug", typeof(debugtest));

object result = context.Execute("Debug.BoolTest(3,4);");

object result = context.Execute("Debug.TestProp;");
Console.WriteLine(result);
}
GC.Collect();
js.DumpHeapStats();
Expand Down
2 changes: 1 addition & 1 deletion libespresso/bridge2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef void(CALLINGCONVENTION* del_engineClosingCb)(JsEngine* jsEngine, JsConte
extern "C" {

EXPORT int TestCallBack();
EXPORT void V8Init();
EXPORT void V8Init(char* location);
//---------------------------------------------------------------------
//for managed code to register its callback method
EXPORT void RegisterManagedCallback(void* callback, int callBackKind);
Expand Down
15 changes: 12 additions & 3 deletions libespresso/bridge2_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
using namespace v8;

#include "espresso.h"
#include "bridge2.h"

del02 managedListner; //for debug
Expand Down Expand Up @@ -100,7 +102,8 @@ ManagedRef* JsContext::CreateWrapperForManagedObject(int mIndex, ExternalTypeDef
{

Local<ObjectTemplate> objTemplate = Local<ObjectTemplate>::New(isolate_, externalTypeDef->handlerToJsObjectTemplate);
Local<Object> instance = objTemplate->NewInstance();
Local<Object> instance;
objTemplate->NewInstance(ctx).ToLocal(&instance);
handler->v8InstanceHandler.Reset(isolate_, instance);
Local<Object> hd = Local<v8::Object>::New(isolate_, handler->v8InstanceHandler);
hd->SetInternalField(0, External::New(isolate_, handler));
Expand Down Expand Up @@ -384,11 +387,17 @@ int ArgCount(MetCallingArgs* args)
//======================================================

static v8::Platform* default_platform;
void V8Init()
static bool Initialized = false;

void V8Init(char* location)
{
if (Initialized) return;
const int thread_pool_size = 4;
/*auto p = V8::*/
default_platform = v8::platform::CreateDefaultPlatform(thread_pool_size);
v8::V8::InitializeICUDefaultLocation(location);
v8::V8::InitializeExternalStartupData(location);
default_platform = v8::platform::NewDefaultPlatform(thread_pool_size).release();
V8::InitializePlatform(default_platform);
V8::Initialize();
Initialized = true;
}
15 changes: 10 additions & 5 deletions libespresso/jscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ JsContext* JsContext::New(int id, JsEngine* engine) {
Locker locker(context->isolate_);
Isolate::Scope isolate_scope(context->isolate_);
HandleScope scope(context->isolate_);

auto current = Context::New(context->isolate_);
current->Global()->Set(current, String::NewFromUtf8(context->isolate_, "global"), current->Global());

context->context_ = new Persistent<Context>(
context->isolate_, Context::New(context->isolate_));
context->isolate_, current);
}
return context;
}
Expand Down Expand Up @@ -151,7 +155,8 @@ void JsContext::SetVariable(const uint16_t* name,
if (ctx->Global()->Set(String::NewFromTwoByte(isolate_, name), v) ==
false) { // 0.12.x
// TODO: Return an error if set failed.
}
ctx->Exit();
} else

ctx->Exit();

Expand Down Expand Up @@ -208,7 +213,7 @@ void JsContext::GetPropertyNames(Persistent<Object>* obj, jsvalue* output) {
TryCatch trycatch(isolate_);

Local<Object> objLocal = Local<Object>::New(isolate_, *obj);
Local<Value> value = objLocal->GetPropertyNames();
Local<Value> value = objLocal->GetPropertyNames(ctx).ToLocalChecked();
if (!value.IsEmpty()) {
engine_->AnyFromV8(value, Handle<Object>(), output);
} else {
Expand Down Expand Up @@ -294,7 +299,7 @@ void JsContext::InvokeFunction(Persistent<Function>* func,
// TODO: Check ArrayToV8Args return value (but right now can't fail, right?)
Local<Function> func = Local<Function>::Cast(prop);
Local<Value> value =
func->Call(reciever, args->i32, &argv[0]); // i32 as length
func->Call(ctx, reciever, args->i32, &argv[0]).ToLocalChecked(); // i32 as length
if (!value.IsEmpty()) {
engine_->AnyFromV8(value, Handle<Object>(), output);
} else {
Expand Down Expand Up @@ -331,7 +336,7 @@ void JsContext::InvokeProperty(Persistent<Object>* obj,
Local<Function> func = Local<Function>::Cast(prop);

Local<Value> value =
func->Call(objLocal, args->i32, &argv[0]); // i32 as length
func->Call(ctx, objLocal, args->i32, &argv[0]).ToLocalChecked(); // i32 as length
if (!value.IsEmpty()) {
engine_->AnyFromV8(value, Handle<Object>(), output);
} else {
Expand Down
Loading