Skip to content

Commit 7ad6943

Browse files
committed
Fixed up null handling after feedback. Realised I didn't need as HashSet.
1 parent 963c069 commit 7ad6943

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Source/Noesis.Javascript/JavascriptContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ JavascriptContext::JavascriptContext()
163163
isolate->SetFatalErrorHandler(FatalErrorCallback);
164164

165165
mExternals = gcnew System::Collections::Generic::Dictionary<System::Object ^, WrappedJavascriptExternal>();
166-
mFunctions = gcnew System::Collections::Generic::HashSet<System::WeakReference ^>();
166+
mFunctions = gcnew System::Collections::Generic::List<System::WeakReference ^>();
167167
HandleScope scope(isolate);
168168
mContext = new Persistent<Context>(isolate, Context::New(isolate));
169169
terminateRuns = false;
@@ -205,7 +205,7 @@ void JavascriptContext::SetFatalErrorHandler(FatalErrorHandler^ handler)
205205
void JavascriptContext::SetFlags(System::String^ flags)
206206
{
207207
std::string convertedFlags = msclr::interop::marshal_as<std::string>(flags);
208-
v8::V8::SetFlagsFromString(convertedFlags.c_str(), convertedFlags.length());
208+
v8::V8::SetFlagsFromString(convertedFlags.c_str(), (int)convertedFlags.length());
209209
}
210210

211211
////////////////////////////////////////////////////////////////////////////////////////////////////

Source/Noesis.Javascript/JavascriptContext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public ref class JavascriptContext: public System::IDisposable
220220

221221
// Stores every JavascriptFunction we create. Ensures we dispose of them
222222
// all.
223-
System::Collections::Generic::HashSet<System::WeakReference ^> ^mFunctions;
223+
System::Collections::Generic::List<System::WeakReference ^> ^mFunctions;
224224

225225
// See comment for TerminateExecution().
226226
bool terminateRuns;

Source/Noesis.Javascript/JavascriptFunction.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ System::Object^ JavascriptFunction::Call(... cli::array<System::Object^>^ args)
7575

7676
bool JavascriptFunction::operator==(JavascriptFunction^ func1, JavascriptFunction^ func2)
7777
{
78+
bool func1_null = func1 == nullptr,
79+
func2_null = func2 == nullptr;
80+
if (func1_null != func2_null)
81+
return false;
82+
if (func1_null && func2_null)
83+
return true;
7884
if (func1->mFuncHandle == nullptr)
7985
throw gcnew JavascriptException(L"'func1's owning JavascriptContext has been disposed");
8086
if (func2->mFuncHandle == nullptr)
8187
throw gcnew JavascriptException(L"'func2's owning JavascriptContext has been disposed");
8288

83-
if(ReferenceEquals(func2, nullptr)) {
84-
return false;
85-
}
8689
Handle<Function> jsFuncPtr1 = func1->mFuncHandle->Get(func1->mContext->GetCurrentIsolate());
8790
Handle<Function> jsFuncPtr2 = func2->mFuncHandle->Get(func2->mContext->GetCurrentIsolate());
8891

@@ -98,8 +101,10 @@ bool JavascriptFunction::Equals(Object^ other)
98101
{
99102
if (mFuncHandle == nullptr)
100103
throw gcnew JavascriptException(L"This function's owning JavascriptContext has been disposed");
101-
102104
JavascriptFunction^ otherFunc = dynamic_cast<JavascriptFunction^>(other);
105+
if (otherFunc != nullptr && otherFunc->mFuncHandle == nullptr)
106+
throw gcnew JavascriptException(L"This function's owning JavascriptContext has been disposed");
107+
103108
return (otherFunc && this->Equals(otherFunc));
104109
}
105110

0 commit comments

Comments
 (0)