Skip to content

Commit ea75e47

Browse files
Fixed exceptions thrown from V8Runtime.Compile (GitHub Issue ClearFoundry#66).
1 parent 486bd53 commit ea75e47

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

ClearScript/V8/ClearScriptV8/V8Exception.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void DECLSPEC_NORETURN V8Exception::ThrowScriptEngineException() const
1212
auto gcEngineName = m_EngineName.ToManagedString();
1313
auto gcMessage = m_Message.ToManagedString();
1414
auto gcStackTrace = m_StackTrace.ToManagedString();
15-
auto gcScriptException = ScriptEngine::Current->MarshalToHost(V8ContextProxyImpl::ExportValue(m_ScriptException), false);
15+
auto gcEngine = ScriptEngine::Current;
16+
auto gcScriptException = (gcEngine != nullptr) ? gcEngine->MarshalToHost(V8ContextProxyImpl::ExportValue(m_ScriptException), false) : nullptr;
1617
auto gcInnerException = V8ProxyHelpers::MarshalExceptionToHost(V8ContextProxyImpl::ExportValue(m_InnerException));
1718

1819
switch (m_Type)

ClearScriptTest/BugFixTest.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public void BugFix_V8RuntimeConstraintScale()
11321132
{
11331133
const int maxNewSpaceSize = 16;
11341134
const int maxOldSpaceSize = 512;
1135-
const double tolerance = .05;
1135+
const double tolerance = .05;
11361136

11371137
var constraints = new V8RuntimeConstraints
11381138
{
@@ -1143,10 +1143,10 @@ public void BugFix_V8RuntimeConstraintScale()
11431143
using (var tempEngine = new V8ScriptEngine(constraints))
11441144
{
11451145
Assert.AreEqual(Math.PI, tempEngine.Evaluate("Math.PI"));
1146-
var expected = Convert.ToDouble(maxNewSpaceSize * 2 + maxOldSpaceSize);
1147-
var actual = Convert.ToDouble(tempEngine.GetRuntimeHeapInfo().HeapSizeLimit / (1024 * 1024));
1148-
var ratio = actual / expected;
1149-
Assert.IsTrue((ratio >= 1 - tolerance) && (ratio <= 1 + tolerance));
1146+
var expected = Convert.ToDouble(maxNewSpaceSize * 2 + maxOldSpaceSize);
1147+
var actual = Convert.ToDouble(tempEngine.GetRuntimeHeapInfo().HeapSizeLimit / (1024 * 1024));
1148+
var ratio = actual / expected;
1149+
Assert.IsTrue((ratio >= 1 - tolerance) && (ratio <= 1 + tolerance));
11501150
}
11511151

11521152
constraints = new V8RuntimeConstraints
@@ -1158,12 +1158,12 @@ public void BugFix_V8RuntimeConstraintScale()
11581158
using (var tempEngine = new V8ScriptEngine(constraints))
11591159
{
11601160
Assert.AreEqual(Math.E, tempEngine.Evaluate("Math.E"));
1161-
var expected = Convert.ToDouble(maxNewSpaceSize * 2 + maxOldSpaceSize);
1162-
var actual = Convert.ToDouble(tempEngine.GetRuntimeHeapInfo().HeapSizeLimit / (1024 * 1024));
1163-
var ratio = actual / expected;
1164-
Assert.IsTrue((ratio >= 1 - tolerance) && (ratio <= 1 + tolerance));
1165-
}
1166-
}
1161+
var expected = Convert.ToDouble(maxNewSpaceSize * 2 + maxOldSpaceSize);
1162+
var actual = Convert.ToDouble(tempEngine.GetRuntimeHeapInfo().HeapSizeLimit / (1024 * 1024));
1163+
var ratio = actual / expected;
1164+
Assert.IsTrue((ratio >= 1 - tolerance) && (ratio <= 1 + tolerance));
1165+
}
1166+
}
11671167

11681168
[TestMethod, TestCategory("BugFix")]
11691169
public void BugFix_TooManyDebugApplications()
@@ -2357,6 +2357,15 @@ public void BugFix_JsonDotNetSerialization()
23572357
Assert.AreEqual("{\"foo\":123,\"bar\":\"baz\"}", JsonConvert.SerializeObject(obj));
23582358
}
23592359

2360+
[TestMethod, TestCategory("BugFix")]
2361+
public void BugFix_RuntimeCompileException()
2362+
{
2363+
using (var runtime = new V8Runtime())
2364+
{
2365+
TestUtil.AssertException<ScriptEngineException>(() => runtime.Compile("function foo bar () {}"));
2366+
}
2367+
}
2368+
23602369
// ReSharper restore InconsistentNaming
23612370

23622371
#endregion

0 commit comments

Comments
 (0)