Skip to content

Commit 8a72b75

Browse files
fix(ChakraBridge) - do not eval results as JSON
1 parent 87fc61f commit 8a72b75

File tree

3 files changed

+24
-58
lines changed

3 files changed

+24
-58
lines changed

ReactWindows/ChakraBridge/NativeJavaScriptExecutor.cpp

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,20 @@ ChakraStringResult NativeJavaScriptExecutor::GetGlobalVariable(String^ variableN
4141
return finalResult;
4242
}
4343

44-
ChakraStringResult NativeJavaScriptExecutor::RunScript(String^ source, String^ sourceUri)
44+
int NativeJavaScriptExecutor::RunScript(String^ source, String^ sourceUri)
4545
{
4646
JsValueRef result;
47-
IfFailRetNullPtr(this->host.RunScript(source->Data(), sourceUri->Data(), &result));
47+
IfFailRet(this->host.RunScript(source->Data(), sourceUri->Data(), &result));
4848

49-
JsValueRef resultJson;
50-
IfFailRetNullPtr(this->host.JsonStringify(result, &resultJson));
51-
52-
const wchar_t* szBuf;
53-
size_t bufLen;
54-
IfFailRetNullPtr(JsStringToPointer(resultJson, &szBuf, &bufLen));
55-
56-
ChakraStringResult finalResult = { JsNoError, ref new String(szBuf, bufLen) };
57-
return finalResult;
49+
return JsNoError;
5850
}
5951

60-
ChakraStringResult NativeJavaScriptExecutor::RunScriptFromFile(String^ sourceFilePath, String^ sourceUri)
52+
int NativeJavaScriptExecutor::RunScriptFromFile(String^ sourceFilePath, String^ sourceUri)
6153
{
6254
JsValueRef result;
63-
IfFailRetNullPtr(this->host.RunScriptFromFile(sourceFilePath->Data(), sourceUri->Data(), &result));
64-
65-
JsValueRef resultJson;
66-
IfFailRetNullPtr(this->host.JsonStringify(result, &resultJson));
67-
68-
const wchar_t* szBuf;
69-
size_t bufLen;
70-
IfFailRetNullPtr(JsStringToPointer(resultJson, &szBuf, &bufLen));
55+
IfFailRet(this->host.RunScriptFromFile(sourceFilePath->Data(), sourceUri->Data(), &result));
7156

72-
ChakraStringResult finalResult = { JsNoError, ref new String(szBuf, bufLen) };
73-
return finalResult;
57+
return JsNoError;
7458
}
7559

7660
int NativeJavaScriptExecutor::SerializeScript(String^ source, String^ destination) {
@@ -82,36 +66,20 @@ int NativeJavaScriptExecutor::SerializeScriptFromFile(String^ file, String^ dest
8266
return this->host.SerializeScriptFromFile(file->Data(), destination->Data());
8367
}
8468

85-
ChakraStringResult NativeJavaScriptExecutor::RunSerializedScript(const Array<byte>^ buffer, String^ sourceFilePath, String^ sourceUri)
69+
int NativeJavaScriptExecutor::RunSerializedScript(const Array<byte>^ buffer, String^ sourceFilePath, String^ sourceUri)
8670
{
8771
JsValueRef result;
88-
IfFailRetNullPtr(this->host.RunSerailizedScript(buffer->Data, sourceFilePath->Data(), sourceUri->Data(), &result));
89-
90-
JsValueRef resultJson;
91-
IfFailRetNullPtr(this->host.JsonStringify(result, &resultJson));
72+
IfFailRet(this->host.RunSerailizedScript(buffer->Data, sourceFilePath->Data(), sourceUri->Data(), &result));
9273

93-
const wchar_t* szBuf;
94-
size_t bufLen;
95-
IfFailRetNullPtr(JsStringToPointer(resultJson, &szBuf, &bufLen));
96-
97-
ChakraStringResult finalResult = { JsNoError, ref new String(szBuf, bufLen) };
98-
return finalResult;
74+
return JsNoError;
9975
}
10076

101-
ChakraStringResult NativeJavaScriptExecutor::RunSerializedScriptFromFile(String^ serializedPath, String^ sourceFilePath, String^ sourceUri)
77+
int NativeJavaScriptExecutor::RunSerializedScriptFromFile(String^ serializedPath, String^ sourceFilePath, String^ sourceUri)
10278
{
10379
JsValueRef result;
104-
IfFailRetNullPtr(this->host.RunSerializedScriptFromFile(serializedPath->Data(), sourceFilePath->Data(), sourceUri->Data(), &result));
105-
106-
JsValueRef resultJson;
107-
IfFailRetNullPtr(this->host.JsonStringify(result, &resultJson));
80+
IfFailRet(this->host.RunSerializedScriptFromFile(serializedPath->Data(), sourceFilePath->Data(), sourceUri->Data(), &result));
10881

109-
const wchar_t* szBuf;
110-
size_t bufLen;
111-
IfFailRetNullPtr(JsStringToPointer(resultJson, &szBuf, &bufLen));
112-
113-
ChakraStringResult finalResult = { JsNoError, ref new String(szBuf, bufLen) };
114-
return finalResult;
82+
return JsNoError;
11583
}
11684

11785
ChakraStringResult NativeJavaScriptExecutor::CallFunctionAndReturnFlushedQueue(String^ moduleName, String^ methodName, String^ args)

ReactWindows/ChakraBridge/NativeJavaScriptExecutor.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ref class NativeJavaScriptExecutor sealed
5757
/// <returns>
5858
/// A compount result with the JSON stringified value and an error code if any occurred.
5959
/// </returns>
60-
ChakraStringResult RunScript(String^ source, String^ sourceUri);
60+
int RunScript(String^ source, String^ sourceUri);
6161

6262
/// <summary>
6363
/// Runs the script from the file location and source URI and returns the result.
@@ -67,7 +67,7 @@ public ref class NativeJavaScriptExecutor sealed
6767
/// <returns>
6868
/// A compount result with the JSON stringified value and an error code if any occurred.
6969
/// </returns>
70-
ChakraStringResult RunScriptFromFile(String^ sourceFilePath, String^ sourceUri);
70+
int RunScriptFromFile(String^ sourceFilePath, String^ sourceUri);
7171

7272
/// <summary>
7373
/// Serializes a source script to a file destination.
@@ -98,8 +98,8 @@ public ref class NativeJavaScriptExecutor sealed
9898
/// <returns>
9999
/// A compount result with the JSON stringified value and an error code if any occurred.
100100
/// </returns>
101-
ChakraStringResult RunSerializedScript(const Array<byte>^ buffer, String^ sourceFilePath, String^ sourceUri);
102-
101+
int RunSerializedScript(const Array<byte>^ buffer, String^ sourceFilePath, String^ sourceUri);
102+
103103
/// <summary>
104104
/// Runs a serialzed script from the serialized path, the source file path and source URI.
105105
/// </summary>
@@ -109,7 +109,7 @@ public ref class NativeJavaScriptExecutor sealed
109109
/// <returns>
110110
/// A compount result with the JSON stringified value and an error code if any occurred.
111111
/// </returns>
112-
ChakraStringResult RunSerializedScriptFromFile(String^ serializedPath, String^ sourceFilePath, String^ sourceUri);
112+
int RunSerializedScriptFromFile(String^ serializedPath, String^ sourceFilePath, String^ sourceUri);
113113

114114
/// <summary>
115115
/// Calls the underlying function with the given module and method name and JSON stringified arguments.
@@ -120,8 +120,8 @@ public ref class NativeJavaScriptExecutor sealed
120120
/// <returns>
121121
/// A compount result with the JSON stringified value and an error code if any occurred.
122122
/// </returns>
123-
ChakraStringResult CallFunctionAndReturnFlushedQueue(String^ moduleName, String^ methodName, String^ args);
124-
123+
ChakraStringResult CallFunctionAndReturnFlushedQueue(String^ moduleName, String^ methodName, String^ args);
124+
125125
/// <summary>
126126
/// Calls the underlying function with the callback ID and JSON stringified arguments.
127127
/// </summary>
@@ -130,15 +130,15 @@ public ref class NativeJavaScriptExecutor sealed
130130
/// <returns>
131131
/// A compount result with the JSON stringified value and an error code if any occurred.
132132
/// </returns>
133-
ChakraStringResult InvokeCallbackAndReturnFlushedQueue(int callbackId, String^ args);
134-
133+
ChakraStringResult InvokeCallbackAndReturnFlushedQueue(int callbackId, String^ args);
134+
135135
/// <summary>
136136
/// Calls the flush queue function.
137137
/// </summary>
138138
/// <returns>
139139
/// A compount result with the JSON stringified value and an error code if any occurred.
140140
/// </returns>
141-
ChakraStringResult FlushedQueue();
141+
ChakraStringResult FlushedQueue();
142142
private:
143143
ChakraHost host;
144144
};

ReactWindows/ReactNative/Chakra/Executor/NativeJavaScriptExecutor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ private void RunNormalScript(string script, string sourceUrl)
9696
{
9797
try
9898
{
99-
var result = _executor.RunScriptFromFile(script, sourceUrl);
100-
Native.ThrowIfError((JavaScriptErrorCode)result.ErrorCode);
99+
Native.ThrowIfError((JavaScriptErrorCode)_executor.RunScriptFromFile(script, sourceUrl));
101100
}
102101
catch (JavaScriptScriptException ex)
103102
{
@@ -121,8 +120,7 @@ private void RunSerializedScript(string script, string sourceUrl)
121120
Native.ThrowIfError((JavaScriptErrorCode)_executor.SerializeScriptFromFile(script, binPath));
122121
}
123122

124-
var result = _executor.RunSerializedScriptFromFile(binPath, script, sourceUrl);
125-
Native.ThrowIfError((JavaScriptErrorCode)result.ErrorCode);
123+
Native.ThrowIfError((JavaScriptErrorCode)_executor.RunSerializedScriptFromFile(binPath, script, sourceUrl));
126124
}
127125
catch (JavaScriptScriptException ex)
128126
{

0 commit comments

Comments
 (0)