Skip to content

Commit 6b53daa

Browse files
committed
In JavaScriptEngineSwitcher.ChakraCore:
1. Slightly improved performance; 2. The `CollectGarbage` method is called synchronously again.
1 parent d5181c1 commit 6b53daa

File tree

9 files changed

+417
-394
lines changed

9 files changed

+417
-394
lines changed

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreJsEngine.cs

Lines changed: 145 additions & 187 deletions
Large diffs are not rendered by default.

src/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ This package does not contain the native implementations of ChakraCore. Therefor
2222
* JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64</Description>
2323
<PackageIconUrl>https://raw.githubusercontent.com/Taritsyn/JavaScriptEngineSwitcher/master/Icons/JavaScriptEngineSwitcher_ChakraCore_Logo128x128.png</PackageIconUrl>
2424
<PackageTags>JavaScriptEngineSwitcher;JavaScript;ECMAScript;ChakraCore</PackageTags>
25-
<PackageReleaseNotes>ChakraCore was updated to version 1.11.13.</PackageReleaseNotes>
25+
<PackageReleaseNotes>1. Slightly improved performance;
26+
2. The `CollectGarbage` method is called synchronously again.</PackageReleaseNotes>
2627
</PropertyGroup>
2728

2829
<Import Project="../../build/common.props" />

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsContext.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,24 @@ public static void SetException(JsValue exception)
414414
JsErrorHelpers.ThrowIfError(NativeMethods.JsSetException(exception));
415415
}
416416

417+
/// <summary>
418+
/// Sets a promise continuation callback function that is called by the context when a task
419+
/// needs to be queued for future execution
420+
/// </summary>
421+
/// <remarks>
422+
/// <para>
423+
/// Requires an active script context.
424+
/// </para>
425+
/// </remarks>
426+
/// <param name="promiseContinuationCallback">The callback function being set</param>
427+
/// <param name="callbackState">User provided state that will be passed back to the callback</param>
428+
public static void SetPromiseContinuationCallback(JsPromiseContinuationCallback promiseContinuationCallback,
429+
IntPtr callbackState)
430+
{
431+
JsErrorHelpers.ThrowIfError(NativeMethods.JsSetPromiseContinuationCallback(promiseContinuationCallback,
432+
callbackState));
433+
}
434+
417435
/// <summary>
418436
/// Adds a reference to a script context
419437
/// </summary>

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsErrorHelpers.cs

Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,114 +8,114 @@ internal static class JsErrorHelpers
88
/// <summary>
99
/// Throws if a native method returns an error code
1010
/// </summary>
11-
/// <param name="error">The error</param>
12-
public static void ThrowIfError(JsErrorCode error)
11+
/// <param name="errorCode">The error code</param>
12+
public static void ThrowIfError(JsErrorCode errorCode)
1313
{
14-
if (error != JsErrorCode.NoError)
14+
if (errorCode != JsErrorCode.NoError)
1515
{
16-
switch (error)
16+
switch (errorCode)
1717
{
1818
#region Usage
1919

2020
case JsErrorCode.InvalidArgument:
21-
throw new JsUsageException(error, "Invalid argument.");
21+
throw new JsUsageException(errorCode, "Invalid argument.");
2222

2323
case JsErrorCode.NullArgument:
24-
throw new JsUsageException(error, "Null argument.");
24+
throw new JsUsageException(errorCode, "Null argument.");
2525

2626
case JsErrorCode.NoCurrentContext:
27-
throw new JsUsageException(error, "No current context.");
27+
throw new JsUsageException(errorCode, "No current context.");
2828

2929
case JsErrorCode.InExceptionState:
30-
throw new JsUsageException(error, "Runtime is in exception state.");
30+
throw new JsUsageException(errorCode, "Runtime is in exception state.");
3131

3232
case JsErrorCode.NotImplemented:
33-
throw new JsUsageException(error, "Method is not implemented.");
33+
throw new JsUsageException(errorCode, "Method is not implemented.");
3434

3535
case JsErrorCode.WrongThread:
36-
throw new JsUsageException(error, "Runtime is active on another thread.");
36+
throw new JsUsageException(errorCode, "Runtime is active on another thread.");
3737

3838
case JsErrorCode.RuntimeInUse:
39-
throw new JsUsageException(error, "Runtime is in use.");
39+
throw new JsUsageException(errorCode, "Runtime is in use.");
4040

4141
case JsErrorCode.BadSerializedScript:
42-
throw new JsUsageException(error, "Bad serialized script.");
42+
throw new JsUsageException(errorCode, "Bad serialized script.");
4343

4444
case JsErrorCode.InDisabledState:
45-
throw new JsUsageException(error, "Runtime is disabled.");
45+
throw new JsUsageException(errorCode, "Runtime is disabled.");
4646

4747
case JsErrorCode.CannotDisableExecution:
48-
throw new JsUsageException(error, "Cannot disable execution.");
48+
throw new JsUsageException(errorCode, "Cannot disable execution.");
4949

5050
case JsErrorCode.HeapEnumInProgress:
51-
throw new JsUsageException(error, "Heap enumeration is in progress.");
51+
throw new JsUsageException(errorCode, "Heap enumeration is in progress.");
5252

5353
case JsErrorCode.ArgumentNotObject:
54-
throw new JsUsageException(error, "Argument is not an object.");
54+
throw new JsUsageException(errorCode, "Argument is not an object.");
5555

5656
case JsErrorCode.InProfileCallback:
57-
throw new JsUsageException(error, "In a profile callback.");
57+
throw new JsUsageException(errorCode, "In a profile callback.");
5858

5959
case JsErrorCode.InThreadServiceCallback:
60-
throw new JsUsageException(error, "In a thread service callback.");
60+
throw new JsUsageException(errorCode, "In a thread service callback.");
6161

6262
case JsErrorCode.CannotSerializeDebugScript:
63-
throw new JsUsageException(error, "Cannot serialize a debug script.");
63+
throw new JsUsageException(errorCode, "Cannot serialize a debug script.");
6464

6565
case JsErrorCode.AlreadyDebuggingContext:
66-
throw new JsUsageException(error, "Context is already in debug mode.");
66+
throw new JsUsageException(errorCode, "Context is already in debug mode.");
6767

6868
case JsErrorCode.AlreadyProfilingContext:
69-
throw new JsUsageException(error, "Already profiling this context.");
69+
throw new JsUsageException(errorCode, "Already profiling this context.");
7070

7171
case JsErrorCode.IdleNotEnabled:
72-
throw new JsUsageException(error, "Idle is not enabled.");
72+
throw new JsUsageException(errorCode, "Idle is not enabled.");
7373

7474
case JsErrorCode.CannotSetProjectionEnqueueCallback:
75-
throw new JsUsageException(error, "Cannot set projection enqueue callback.");
75+
throw new JsUsageException(errorCode, "Cannot set projection enqueue callback.");
7676

7777
case JsErrorCode.CannotStartProjection:
78-
throw new JsUsageException(error, "Cannot start projection.");
78+
throw new JsUsageException(errorCode, "Cannot start projection.");
7979

8080
case JsErrorCode.InObjectBeforeCollectCallback:
81-
throw new JsUsageException(error, "In object before collect callback.");
81+
throw new JsUsageException(errorCode, "In object before collect callback.");
8282

8383
case JsErrorCode.ObjectNotInspectable:
84-
throw new JsUsageException(error, "Object not inspectable.");
84+
throw new JsUsageException(errorCode, "Object not inspectable.");
8585

8686
case JsErrorCode.PropertyNotSymbol:
87-
throw new JsUsageException(error, "Property not symbol.");
87+
throw new JsUsageException(errorCode, "Property not symbol.");
8888

8989
case JsErrorCode.PropertyNotString:
90-
throw new JsUsageException(error, "Property not string.");
90+
throw new JsUsageException(errorCode, "Property not string.");
9191

9292
case JsErrorCode.InvalidContext:
93-
throw new JsUsageException(error, "Invalid context.");
93+
throw new JsUsageException(errorCode, "Invalid context.");
9494

9595
case JsErrorCode.InvalidModuleHostInfoKind:
96-
throw new JsUsageException(error, "Invalid module host info kind.");
96+
throw new JsUsageException(errorCode, "Invalid module host info kind.");
9797

9898
case JsErrorCode.ModuleParsed:
99-
throw new JsUsageException(error, "Module parsed.");
99+
throw new JsUsageException(errorCode, "Module parsed.");
100100

101101
case JsErrorCode.NoWeakRefRequired:
102-
throw new JsUsageException(error, "No weak reference is required, the value will never be collected.");
102+
throw new JsUsageException(errorCode, "No weak reference is required, the value will never be collected.");
103103

104104
case JsErrorCode.PromisePending:
105-
throw new JsUsageException(error, "The `Promise` object is still in the pending state.");
105+
throw new JsUsageException(errorCode, "The `Promise` object is still in the pending state.");
106106

107107
case JsErrorCode.ModuleNotEvaluated:
108-
throw new JsUsageException(error, "Module was not yet evaluated when `JsGetModuleNamespace` was called.");
108+
throw new JsUsageException(errorCode, "Module was not yet evaluated when `JsGetModuleNamespace` was called.");
109109

110110
#endregion
111111

112112
#region Engine
113113

114114
case JsErrorCode.OutOfMemory:
115-
throw new JsEngineException(error, "Out of memory.");
115+
throw new JsEngineException(errorCode, "Out of memory.");
116116

117117
case JsErrorCode.BadFPUState:
118-
throw new JsEngineException(error, "Bad the Floating Point Unit state.");
118+
throw new JsEngineException(errorCode, "Bad the Floating Point Unit state.");
119119

120120
#endregion
121121

@@ -125,39 +125,39 @@ public static void ThrowIfError(JsErrorCode error)
125125
case JsErrorCode.ScriptCompile:
126126
{
127127
JsValue errorMetadata;
128-
JsErrorCode innerError = NativeMethods.JsGetAndClearExceptionWithMetadata(out errorMetadata);
128+
JsErrorCode innerErrorCode = NativeMethods.JsGetAndClearExceptionWithMetadata(out errorMetadata);
129129

130-
if (innerError != JsErrorCode.NoError)
130+
if (innerErrorCode != JsErrorCode.NoError)
131131
{
132-
throw new JsFatalException(innerError);
132+
throw new JsFatalException(innerErrorCode);
133133
}
134134

135-
string message = error == JsErrorCode.ScriptCompile ?
135+
string message = errorCode == JsErrorCode.ScriptCompile ?
136136
"Compile error." : "Script threw an exception.";
137137

138-
throw new JsScriptException(error, errorMetadata, message);
138+
throw new JsScriptException(errorCode, errorMetadata, message);
139139
}
140140

141141
case JsErrorCode.ScriptTerminated:
142-
throw new JsScriptException(error, JsValue.Invalid, "Script was terminated.");
142+
throw new JsScriptException(errorCode, JsValue.Invalid, "Script was terminated.");
143143

144144
case JsErrorCode.ScriptEvalDisabled:
145-
throw new JsScriptException(error, JsValue.Invalid, "Eval of strings is disabled in this runtime.");
145+
throw new JsScriptException(errorCode, JsValue.Invalid, "Eval of strings is disabled in this runtime.");
146146

147147
#endregion
148148

149149
#region Fatal
150150

151151
case JsErrorCode.Fatal:
152-
throw new JsFatalException(error, "Fatal error.");
152+
throw new JsFatalException(errorCode, "Fatal error.");
153153

154154
case JsErrorCode.WrongRuntime:
155-
throw new JsFatalException(error, "Wrong runtime.");
155+
throw new JsFatalException(errorCode, "Wrong runtime.");
156156

157157
#endregion
158158

159159
default:
160-
throw new JsFatalException(error);
160+
throw new JsFatalException(errorCode);
161161
}
162162
}
163163
}
@@ -257,21 +257,5 @@ public static JsValue CreateUriError(string message)
257257

258258
return errorValue;
259259
}
260-
261-
/// <summary>
262-
/// Sets a exception
263-
/// </summary>
264-
/// <remarks>
265-
/// Requires an active script context.
266-
/// </remarks>
267-
/// <param name="exception">The error object</param>
268-
public static void SetException(JsValue exception)
269-
{
270-
JsErrorCode innerError = NativeMethods.JsSetException(exception);
271-
if (innerError != JsErrorCode.NoError)
272-
{
273-
throw new JsFatalException(innerError);
274-
}
275-
}
276260
}
277261
}

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsRuntime.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,6 @@ public static JsRuntime Create(JsRuntimeAttributes attributes, JsThreadServiceCa
131131
return handle;
132132
}
133133

134-
/// <summary>
135-
/// Sets a promise continuation callback function that is called by the context when a task
136-
/// needs to be queued for future execution
137-
/// </summary>
138-
/// <remarks>
139-
/// <para>
140-
/// Requires an active script context.
141-
/// </para>
142-
/// </remarks>
143-
/// <param name="promiseContinuationCallback">The callback function being set</param>
144-
/// <param name="callbackState">User provided state that will be passed back to the callback</param>
145-
public static void SetPromiseContinuationCallback(JsPromiseContinuationCallback promiseContinuationCallback,
146-
IntPtr callbackState)
147-
{
148-
JsErrorHelpers.ThrowIfError(NativeMethods.JsSetPromiseContinuationCallback(promiseContinuationCallback,
149-
callbackState));
150-
}
151-
152134
/// <summary>
153135
/// Performs a full garbage collection
154136
/// </summary>

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsScope.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)